From 974699cc98d60debcaf41efa765230852dd01d14 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 11 May 2023 12:07:40 +0300 Subject: [PATCH] fuzz tests for OwnableWithGuardian and TransparentProxyFactory (#18) --- test/OwnableWithGuardian.t.sol | 12 +++++---- test/TransparentProxyFactory.t.sol | 43 +++++++++++++----------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/test/OwnableWithGuardian.t.sol b/test/OwnableWithGuardian.t.sol index b3431b8..2bb4760 100644 --- a/test/OwnableWithGuardian.t.sol +++ b/test/OwnableWithGuardian.t.sol @@ -18,13 +18,15 @@ contract TestOfOwnableWithGuardian is Test { assertEq(withGuardian.guardian(), address(this)); } - function testGuardianUpdate() external { - withGuardian.updateGuardian(0x0000000000000000000000000000000000000001); + function testGuardianUpdate(address guardian) external { + withGuardian.updateGuardian(guardian); } - function testGuardianUpdateNoAccess() external { - vm.prank(0x0000000000000000000000000000000000000001); + function testGuardianUpdateNoAccess(address guardian) external { + vm.assume(guardian != address(this)); + + vm.prank(guardian); vm.expectRevert('ONLY_BY_GUARDIAN'); - withGuardian.updateGuardian(0x0000000000000000000000000000000000000001); + withGuardian.updateGuardian(guardian); } } diff --git a/test/TransparentProxyFactory.t.sol b/test/TransparentProxyFactory.t.sol index ab71f93..052879e 100644 --- a/test/TransparentProxyFactory.t.sol +++ b/test/TransparentProxyFactory.t.sol @@ -16,33 +16,28 @@ contract TestTransparentProxyFactory is Test { mockImpl = new MockImpl(); } - function testCreateDeterministic() public { + function testCreateDeterministic(address admin, bytes32 salt) public { uint256 FOO = 2; bytes memory data = abi.encodeWithSelector(mockImpl.initialize.selector, FOO); address predictedAddress1 = factory.predictCreateDeterministic( address(mockImpl), - address(1), + admin, data, - bytes32(uint256(1)) + salt ); - address proxy1 = factory.createDeterministic( - address(mockImpl), - address(1), - data, - bytes32(uint256(1)) - ); + address proxy1 = factory.createDeterministic(address(mockImpl), admin, data, salt); assertEq(predictedAddress1, proxy1); assertEq(MockImpl(proxy1).getFoo(), FOO); } - function testCreateDeterministicWithDeterministicProxy() public { - address deterministicProxyAdmin = factory.predictCreateDeterministicProxyAdmin( - bytes32(uint256(2)) - ); + function testCreateDeterministicWithDeterministicProxy(bytes32 proxyAdminSalt, bytes32 proxySalt) + public + { + address deterministicProxyAdmin = factory.predictCreateDeterministicProxyAdmin(proxyAdminSalt); uint256 FOO = 2; @@ -52,35 +47,35 @@ contract TestTransparentProxyFactory is Test { address(mockImpl), deterministicProxyAdmin, data, - bytes32(uint256(1)) + proxySalt ); address proxy1 = factory.createDeterministic( address(mockImpl), deterministicProxyAdmin, data, - bytes32(uint256(1)) + proxySalt ); assertEq(predictedAddress1, proxy1); assertEq(MockImpl(proxy1).getFoo(), FOO); } - function testCreateDeterministicProxyAdmin() public { - address proxyAdmin = factory.createDeterministicProxyAdmin(address(2), bytes32(uint256(2))); + function testCreateDeterministicProxyAdmin(address proxyAdminOwner, bytes32 proxyAdminSalt) + public + { + address proxyAdmin = factory.createDeterministicProxyAdmin(proxyAdminOwner, proxyAdminSalt); - address predictedProxyAdmin = factory.predictCreateDeterministicProxyAdmin(bytes32(uint256(2))); + address predictedProxyAdmin = factory.predictCreateDeterministicProxyAdmin(proxyAdminSalt); address proxyOwner = IOwnable(proxyAdmin).owner(); assertEq(predictedProxyAdmin, proxyAdmin); - assertEq(proxyOwner, address(2)); + assertEq(proxyOwner, proxyAdminOwner); } - function testCreateProxyAdmin() public { - address proxyAdmin = factory.createDeterministicProxyAdmin(address(2), bytes32(uint256(2))); - - address proxyOwner = IOwnable(proxyAdmin).owner(); - assertEq(proxyOwner, address(2)); + function testCreateProxyAdmin(address proxyAdminOwner, bytes32 proxyAdminSalt) public { + address proxyAdmin = factory.createDeterministicProxyAdmin(proxyAdminOwner, proxyAdminSalt); + assertEq(IOwnable(proxyAdmin).owner(), proxyAdminOwner); } }