From ffa101791d229d8691d08fe4f9b87058a0d800f5 Mon Sep 17 00:00:00 2001 From: James Snewin Date: Thu, 16 Nov 2023 11:21:12 +1000 Subject: [PATCH] fix tests with adding abstract contract --- src/child/ChildERC20Bridge.sol | 15 ++++----------- src/root/RootERC20Bridge.sol | 12 +++--------- test/integration/child/ChildAxelarBridge.t.sol | 2 +- test/unit/child/ChildERC20Bridge.t.sol | 6 +++--- .../withdrawals/ChildERC20BridgeWithdraw.t.sol | 2 +- .../withdrawals/ChildERC20BridgeWithdrawTo.t.sol | 2 +- test/unit/root/RootERC20Bridge.t.sol | 4 ++-- 7 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/child/ChildERC20Bridge.sol b/src/child/ChildERC20Bridge.sol index 3fdcae1b..1828e01c 100644 --- a/src/child/ChildERC20Bridge.sol +++ b/src/child/ChildERC20Bridge.sol @@ -15,6 +15,7 @@ import { import {IChildERC20BridgeAdaptor} from "../interfaces/child/IChildERC20BridgeAdaptor.sol"; import {IChildERC20} from "../interfaces/child/IChildERC20.sol"; import {IWIMX} from "../interfaces/child/IWIMX.sol"; +import {BridgeRoles} from "../common/BridgeRoles.sol"; /** * @notice RootERC20Bridge is a bridge that allows ERC20 tokens to be transferred from the root chain to the child chain. @@ -28,21 +29,14 @@ contract ChildERC20Bridge is AccessControlUpgradeable, // AccessControlUpgradeable inherits Initializable IChildERC20BridgeErrors, IChildERC20Bridge, - IChildERC20BridgeEvents + IChildERC20BridgeEvents, + BridgeRoles { using SafeERC20 for IERC20Metadata; /// @dev leave this as the first param for the integration tests mapping(address => address) public rootTokenToChildToken; - /** - * ROLES - */ - bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); - bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE"); - bytes32 public constant VARIABLE_MANAGER_ROLE = keccak256("VARIABLE_MANAGER_ROLE"); - bytes32 public constant ADAPTOR_MANAGER_ROLE = keccak256("ADAPTOR_MANAGER_ROLE"); - bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); bytes32 public constant DEPOSIT_SIG = keccak256("DEPOSIT"); bytes32 public constant WITHDRAW_SIG = keccak256("WITHDRAW"); @@ -97,8 +91,7 @@ contract ChildERC20Bridge is if ( newBridgeAdaptor == address(0) || newChildTokenTemplate == address(0) || newRootIMXToken == address(0) || newRoles.defaultAdmin == address(0) || newRoles.pauser == address(0) || newRoles.unpauser == address(0) - || newRoles.variableManager == address(0) || newRoles.adaptorManager == address(0) - || newWIMXToken == address(0) + || newRoles.variableManager == address(0) || newRoles.adaptorManager == address(0) || newWIMXToken == address(0) ) { revert ZeroAddress(); } diff --git a/src/root/RootERC20Bridge.sol b/src/root/RootERC20Bridge.sol index 5995053e..f62b770e 100644 --- a/src/root/RootERC20Bridge.sol +++ b/src/root/RootERC20Bridge.sol @@ -16,6 +16,7 @@ import { import {IRootERC20BridgeAdaptor} from "../interfaces/root/IRootERC20BridgeAdaptor.sol"; import {IChildERC20} from "../interfaces/child/IChildERC20.sol"; import {IWETH} from "../interfaces/root/IWETH.sol"; +import {BridgeRoles} from "../common/BridgeRoles.sol"; /** * @notice RootERC20Bridge is a bridge that allows ERC20 tokens to be transferred from the root chain to the child chain. @@ -29,21 +30,14 @@ contract RootERC20Bridge is AccessControlUpgradeable, // AccessControlUpgradeable inherits Initializable IRootERC20Bridge, IRootERC20BridgeEvents, - IRootERC20BridgeErrors + IRootERC20BridgeErrors, + BridgeRoles { using SafeERC20 for IERC20Metadata; /// @dev leave this as the first param for the integration tests mapping(address => address) public rootTokenToChildToken; - /** - * ROLES - */ - bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); - bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE"); - bytes32 public constant VARIABLE_MANAGER_ROLE = keccak256("VARIABLE_MANAGER_ROLE"); - bytes32 public constant ADAPTOR_MANAGER_ROLE = keccak256("ADAPTOR_MANAGER_ROLE"); - uint256 public constant UNLIMITED_DEPOSIT = 0; bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); bytes32 public constant DEPOSIT_SIG = keccak256("DEPOSIT"); diff --git a/test/integration/child/ChildAxelarBridge.t.sol b/test/integration/child/ChildAxelarBridge.t.sol index 4ed35a39..4aeba841 100644 --- a/test/integration/child/ChildAxelarBridge.t.sol +++ b/test/integration/child/ChildAxelarBridge.t.sol @@ -309,7 +309,7 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil address rootAddress = address(0x123); { // Found by running `forge inspect src/child/ChildERC20Bridge.sol:ChildERC20Bridge storageLayout | grep -B3 -A5 -i "rootTokenToChildToken"` - uint256 rootTokenToChildTokenMappingSlot = 151; + uint256 rootTokenToChildTokenMappingSlot = 201; address childAddress = address(444444); bytes32 slot = getMappingStorageSlotFor(rootAddress, rootTokenToChildTokenMappingSlot); bytes32 data = bytes32(uint256(uint160(childAddress))); diff --git a/test/unit/child/ChildERC20Bridge.t.sol b/test/unit/child/ChildERC20Bridge.t.sol index e25e4082..ec70df2f 100644 --- a/test/unit/child/ChildERC20Bridge.t.sol +++ b/test/unit/child/ChildERC20Bridge.t.sol @@ -65,8 +65,8 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B function test_NativeTransferFromWIMX() public { address caller = address(0x123a); payable(caller).transfer(2 ether); - - uint256 wIMXStorageSlot = 158; + // forge inspect src/child/ChildERC20Bridge.sol:ChildERC20Bridge storageLayout | grep -B3 -A5 -i "wIMXToken" + uint256 wIMXStorageSlot = 208; vm.store(address(childBridge), bytes32(wIMXStorageSlot), bytes32(uint256(uint160(caller)))); vm.startPrank(caller); @@ -605,7 +605,7 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B address rootAddress = address(0x123); { // Found by running `forge inspect src/child/ChildERC20Bridge.sol:ChildERC20Bridge storageLayout | grep -B3 -A5 -i "rootTokenToChildToken"` - uint256 rootTokenToChildTokenMappingSlot = 151; + uint256 rootTokenToChildTokenMappingSlot = 201; address childAddress = address(444444); bytes32 slot = getMappingStorageSlotFor(rootAddress, rootTokenToChildTokenMappingSlot); bytes32 data = bytes32(uint256(uint160(childAddress))); diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol index 50e60253..714ab7ef 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol @@ -97,7 +97,7 @@ contract ChildERC20BridgeWithdrawUnitTest is Test, IChildERC20BridgeEvents, IChi // Slot is 2 because of the Ownable, Initializable contracts coming first. // Found by running `forge inspect src/child/ChildERC20Bridge.sol:ChildERC20Bridge storageLayout | grep -B3 -A5 -i "rootTokenToChildToken"` - uint256 rootTokenToChildTokenMappingSlot = 151; + uint256 rootTokenToChildTokenMappingSlot = 201; bytes32 slot = getMappingStorageSlotFor(address(0), rootTokenToChildTokenMappingSlot); bytes32 data = bytes32(uint256(uint160(address(childToken)))); diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol index 71a10a67..7d4ab6cc 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol @@ -103,7 +103,7 @@ contract ChildERC20BridgeWithdrawToUnitTest is Test, IChildERC20BridgeEvents, IC /* Then, set rootTokenToChildToken[address(0)] to the child token (to bypass the NotMapped check) */ // Found by running `forge inspect src/child/ChildERC20Bridge.sol:ChildERC20Bridge storageLayout | grep -B3 -A5 -i "rootTokenToChildToken"` - uint256 rootTokenToChildTokenMappingSlot = 151; + uint256 rootTokenToChildTokenMappingSlot = 201; bytes32 slot = getMappingStorageSlotFor(address(0), rootTokenToChildTokenMappingSlot); bytes32 data = bytes32(uint256(uint160(address(childToken)))); diff --git a/test/unit/root/RootERC20Bridge.t.sol b/test/unit/root/RootERC20Bridge.t.sol index fddccb87..fa8cc74c 100644 --- a/test/unit/root/RootERC20Bridge.t.sol +++ b/test/unit/root/RootERC20Bridge.t.sol @@ -90,8 +90,8 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid function test_NativeTransferFromWETH() public { address caller = address(0x123a); payable(caller).transfer(2 ether); - - uint256 wETHStorageSlot = 158; + // forge inspect src/root/RootERC20Bridge.sol:RootERC20Bridge storageLayout | grep -B3 -A5 -i "rootWETHToken" + uint256 wETHStorageSlot = 208; vm.store(address(rootBridge), bytes32(wETHStorageSlot), bytes32(uint256(uint160(caller)))); vm.startPrank(caller);