Skip to content

Commit cdd4326

Browse files
committed
Add registrar controller switch-over integration test
1 parent cadfc45 commit cdd4326

File tree

2 files changed

+124
-14
lines changed

2 files changed

+124
-14
lines changed

test/Integration/IntegrationTestBase.t.sol

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,18 @@ contract IntegrationTestBase is Test {
118118
vm.stopPrank();
119119
}
120120

121-
function test_integration_register() public {
122-
vm.stopPrank();
123-
vm.startPrank(alice);
121+
function _getBasePrices() internal pure returns (uint256[] memory) {
122+
uint256[] memory rentPrices = new uint256[](6);
123+
rentPrices[0] = 316_808_781_402;
124+
rentPrices[1] = 31_680_878_140;
125+
rentPrices[2] = 3_168_087_814;
126+
rentPrices[3] = 316_808_781;
127+
rentPrices[4] = 31_680_878;
128+
rentPrices[5] = 3_168_087; // 3,168,808.781402895 = 1e14 / (365.25 * 24 * 3600)
129+
return rentPrices;
130+
}
124131

132+
function _registerAlice() internal {
125133
string memory name = "alice";
126134
uint256 duration = 365.25 days;
127135

@@ -139,15 +147,4 @@ contract IntegrationTestBase is Test {
139147

140148
registrarController.register{value: registerPrice}(request);
141149
}
142-
143-
function _getBasePrices() internal pure returns (uint256[] memory) {
144-
uint256[] memory rentPrices = new uint256[](6);
145-
rentPrices[0] = 316_808_781_402;
146-
rentPrices[1] = 31_680_878_140;
147-
rentPrices[2] = 3_168_087_814;
148-
rentPrices[3] = 316_808_781;
149-
rentPrices[4] = 31_680_878;
150-
rentPrices[5] = 3_168_087; // 3,168,808.781402895 = 1e14 / (365.25 * 24 * 3600)
151-
return rentPrices;
152-
}
153150
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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

Comments
 (0)