|
| 1 | +//SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.23; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | +import {console} from "forge-std/console.sol"; |
| 6 | + |
| 7 | +import {IntegrationTestBase} from "./IntegrationTestBase.t.sol"; |
| 8 | +import {MockL2ReverseRegistrar} from "test/mocks/MockL2ReverseRegistrar.sol"; |
| 9 | + |
| 10 | +import {ExponentialPremiumPriceOracle} from "src/L2/ExponentialPremiumPriceOracle.sol"; |
| 11 | +import {IPriceOracle} from "src/L2/interface/IPriceOracle.sol"; |
| 12 | +import {UpgradeableRegistrarController} from "src/L2/UpgradeableRegistrarController.sol"; |
| 13 | +import {TransparentUpgradeableProxy} from |
| 14 | + "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 15 | + |
| 16 | +import {BASE_ETH_NODE} from "src/util/Constants.sol"; |
| 17 | + |
| 18 | +contract SwitchToUpgradeableRegistrarController is IntegrationTestBase { |
| 19 | + UpgradeableRegistrarController public controllerImpl; |
| 20 | + UpgradeableRegistrarController public controller; |
| 21 | + TransparentUpgradeableProxy public proxy; |
| 22 | + MockL2ReverseRegistrar public l2ReverseRegistrar; |
| 23 | + |
| 24 | + address admin; |
| 25 | + |
| 26 | + uint256 constant UPGRADE_TIMESTAMP = 1746057600; // May 1 2025 |
| 27 | + |
| 28 | + function setUp() public override { |
| 29 | + super.setUp(); |
| 30 | + _registerAlice(); |
| 31 | + |
| 32 | + vm.warp(UPGRADE_TIMESTAMP); |
| 33 | + |
| 34 | + admin = makeAddr("admin"); |
| 35 | + |
| 36 | + l2ReverseRegistrar = new MockL2ReverseRegistrar(); |
| 37 | + |
| 38 | + exponentialPremiumPriceOracle = new ExponentialPremiumPriceOracle( |
| 39 | + _getBasePrices(), EXPIRY_AUCTION_START_PRICE, EXPIRY_AUCTION_DURATION_DAYS |
| 40 | + ); |
| 41 | + |
| 42 | + bytes memory controllerInitData = abi.encodeWithSelector( |
| 43 | + UpgradeableRegistrarController.initialize.selector, |
| 44 | + baseRegistrar, |
| 45 | + exponentialPremiumPriceOracle, |
| 46 | + reverseRegistrar, |
| 47 | + owner, |
| 48 | + BASE_ETH_NODE, |
| 49 | + ".base.eth", |
| 50 | + payments, |
| 51 | + address(registrarController), |
| 52 | + address(l2ReverseRegistrar) |
| 53 | + ); |
| 54 | + |
| 55 | + controllerImpl = new UpgradeableRegistrarController(); |
| 56 | + proxy = new TransparentUpgradeableProxy(address(controllerImpl), admin, controllerInitData); |
| 57 | + controller = UpgradeableRegistrarController(address(proxy)); |
| 58 | + |
| 59 | + _postDeployConfig(); |
| 60 | + } |
| 61 | + |
| 62 | + function _postDeployConfig() internal { |
| 63 | + vm.startPrank(owner); |
| 64 | + baseRegistrar.addController(address(proxy)); |
| 65 | + reverseRegistrar.setControllerApproval(address(proxy), true); |
| 66 | + defaultL2Resolver.setRegistrarController(address(proxy)); |
| 67 | + vm.stopPrank(); |
| 68 | + } |
| 69 | + |
| 70 | + function test_canRegisterANewName() public { |
| 71 | + string memory name = "new-name"; |
| 72 | + uint256 duration = 365.25 days; |
| 73 | + uint256[] memory cointypes = new uint256[](1); |
| 74 | + cointypes[0] = 0x80000000 | 0x00002105; |
| 75 | + |
| 76 | + console.log("fetching price"); |
| 77 | + |
| 78 | + uint256 registerPrice = controller.registerPrice(name, duration); |
| 79 | + |
| 80 | + uint256 expectedPrice = _getBasePrices()[4] * duration; |
| 81 | + |
| 82 | + vm.assertEq(registerPrice, expectedPrice); |
| 83 | + |
| 84 | + console.log("Fetched Price"); |
| 85 | + |
| 86 | + UpgradeableRegistrarController.RegisterRequest memory request = UpgradeableRegistrarController.RegisterRequest({ |
| 87 | + name: name, |
| 88 | + owner: alice, |
| 89 | + duration: duration, |
| 90 | + resolver: address(defaultL2Resolver), |
| 91 | + data: new bytes[](0), |
| 92 | + reverseRecord: true, |
| 93 | + cointypes: cointypes, |
| 94 | + signatureExpiry: block.timestamp, |
| 95 | + signature: "" |
| 96 | + }); |
| 97 | + |
| 98 | + vm.deal(alice, 1 ether); |
| 99 | + vm.prank(alice); |
| 100 | + controller.register{value: registerPrice}(request); |
| 101 | + } |
| 102 | + |
| 103 | + function test_canRenewExistingName() public { |
| 104 | + string memory name = "alice"; |
| 105 | + uint256 duration = 365.25 days; |
| 106 | + |
| 107 | + IPriceOracle.Price memory prices = controller.rentPrice(name, duration); |
| 108 | + |
| 109 | + vm.deal(alice, 1 ether); |
| 110 | + vm.prank(alice); |
| 111 | + controller.renew{value: prices.base}(name, duration); |
| 112 | + } |
| 113 | +} |
0 commit comments