diff --git a/src/V3FactoryOwner.sol b/src/V3FactoryOwner.sol index 990f0ec..1d78825 100644 --- a/src/V3FactoryOwner.sol +++ b/src/V3FactoryOwner.sol @@ -7,13 +7,16 @@ contract V3FactoryOwner { event AdminUpdated(address indexed oldAmin, address indexed newAdmin); error V3FactoryOwner__Unauthorized(); + error V3FactoryOwner__InvalidAddress(); constructor(address _admin) { + if (_admin == address(0)) revert V3FactoryOwner__InvalidAddress(); admin = _admin; } function setAdmin(address _newAdmin) external { _revertIfNotAdmin(); + if (_newAdmin == address(0)) revert V3FactoryOwner__InvalidAddress(); emit AdminUpdated(admin, _newAdmin); admin = _newAdmin; } diff --git a/test/V3FactoryOwner.t.sol b/test/V3FactoryOwner.t.sol index aaa3859..f82b92d 100644 --- a/test/V3FactoryOwner.t.sol +++ b/test/V3FactoryOwner.t.sol @@ -22,13 +22,21 @@ contract Constructor is V3FactoryOwnerTest { } function testFuzz_SetTheAdminToAnArbitraryAddress(address _admin) public { + vm.assume(_admin != address(0)); V3FactoryOwner _factoryOwner = new V3FactoryOwner(_admin); assertEq(_factoryOwner.admin(), _admin); } + + function test_RevertIf_TheAdminIsAddressZero() public { + vm.expectRevert(V3FactoryOwner.V3FactoryOwner__InvalidAddress.selector); + new V3FactoryOwner(address(0)); + } } contract SetAdmin is V3FactoryOwnerTest { function testFuzz_UpdatesTheAdminWhenCalledByTheCurrentAdmin(address _newAdmin) public { + vm.assume(_newAdmin != address(0)); + vm.prank(admin); factoryOwner.setAdmin(_newAdmin); @@ -36,6 +44,8 @@ contract SetAdmin is V3FactoryOwnerTest { } function testFuzz_EmitsAnEventWhenUpdatingTheAdmin(address _newAdmin) public { + vm.assume(_newAdmin != address(0)); + vm.expectEmit(true, true, true, true); vm.prank(admin); emit AdminUpdated(admin, _newAdmin); @@ -51,4 +61,11 @@ contract SetAdmin is V3FactoryOwnerTest { vm.prank(_notAdmin); factoryOwner.setAdmin(_newAdmin); } + + function test_RevertIf_TheNewAdminIsAddressZero() public { + vm.prank(admin); + + vm.expectRevert(V3FactoryOwner.V3FactoryOwner__InvalidAddress.selector); + factoryOwner.setAdmin(address(0)); + } }