Skip to content

Commit 9599b72

Browse files
authored
feat: validates constructor parameters (#9)
Closes EFI-448
1 parent 58fd12b commit 9599b72

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/contracts/L2Resolver.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ contract L2Resolver is IL2Resolver, IERC165 {
4444
* @param _parentNode The parent node namehash.
4545
*/
4646
constructor(address _ensRegistry, address _nameWrapper, address _reverseAdmin, bytes32 _parentNode) {
47+
if (
48+
_ensRegistry == address(0) || _nameWrapper == address(0) || _reverseAdmin == address(0)
49+
|| _parentNode == bytes32(0)
50+
) {
51+
revert AddressCannotBeZero();
52+
}
53+
4754
ENS_REGISTRY = IENS(_ensRegistry);
4855
NAME_WRAPPER = INameWrapper(_nameWrapper);
4956
REVERSE_ADMIN = _reverseAdmin;

src/interfaces/IL2Resolver.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ interface IL2Resolver {
3030
*/
3131
error NotAuthorized();
3232

33+
/**
34+
* @notice Thrown when an address is zero.
35+
*/
36+
error AddressCannotBeZero();
37+
3338
/*///////////////////////////////////////////////////////////////
3439
LOGIC
3540
//////////////////////////////////////////////////////////////*/

test/unit/L2Resolver.t.sol

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ contract UnitL2Resolver is Test {
3434
vm.etch(address(_nameWrapper), new bytes(0x1));
3535
}
3636

37-
function test_ConstructorWhenDeployingTheContract() external view {
37+
function test_ConstructorWhenDeployingTheContractWithValidParameters() external view {
3838
// it sets the ENS registry address
3939
assertEq(address(_l2Resolver.ENS_REGISTRY()), _ensRegistry);
4040
// it sets the name wrapper address
@@ -45,6 +45,30 @@ contract UnitL2Resolver is Test {
4545
assertEq(_l2Resolver.PARENT_NODE(), _parentNodeNameHash);
4646
}
4747

48+
function test_ConstructorWhenDeployingTheContractWithZeroAddressENSRegistry() external {
49+
// it reverts
50+
vm.expectRevert(abi.encodeWithSelector(IL2Resolver.AddressCannotBeZero.selector));
51+
new L2Resolver(address(0), _nameWrapper, _reverseAdmin, _parentNodeNameHash);
52+
}
53+
54+
function test_ConstructorWhenDeployingTheContractWithZeroAddressNameWrapper() external {
55+
// it reverts
56+
vm.expectRevert(abi.encodeWithSelector(IL2Resolver.AddressCannotBeZero.selector));
57+
new L2Resolver(_ensRegistry, address(0), _reverseAdmin, _parentNodeNameHash);
58+
}
59+
60+
function test_ConstructorWhenDeployingTheContractWithZeroAddressReverseAdmin() external {
61+
// it reverts
62+
vm.expectRevert(abi.encodeWithSelector(IL2Resolver.AddressCannotBeZero.selector));
63+
new L2Resolver(_ensRegistry, _nameWrapper, address(0), _parentNodeNameHash);
64+
}
65+
66+
function test_ConstructorWhenDeployingTheContractWithZeroAddressParentNode() external {
67+
// it reverts
68+
vm.expectRevert(abi.encodeWithSelector(IL2Resolver.AddressCannotBeZero.selector));
69+
new L2Resolver(_ensRegistry, _nameWrapper, _reverseAdmin, bytes32(0));
70+
}
71+
4872
modifier whenTheNodeIsTheReverseLookupNode() {
4973
_;
5074
}

test/unit/L2Resolver.tree

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
UnitL2Resolver::constructor
2-
└── when deploying the contract
3-
├── it sets the ENS registry address
4-
├── it sets the name wrapper address
5-
├── it sets the reverse admin address
6-
└── it sets the parent node namehash
2+
├── when deploying the contract with valid parameters
3+
│ ├── it sets the ENS registry address
4+
│ ├── it sets the name wrapper address
5+
│ ├── it sets the reverse admin address
6+
│ └── it sets the parent node namehash
7+
├── when deploying the contract with zero address ENS registry
8+
│ └── it reverts
9+
├── when deploying the contract with zero address Name Wrapper
10+
│ └── it reverts
11+
├── when deploying the contract with zero address reverse admin
12+
│ └── it reverts
13+
└── when deploying the contract with zero address parent node
14+
└── it reverts
15+
716

817
UnitL2Resolver::setRecord
918
├── when the node is the reverse lookup node

0 commit comments

Comments
 (0)