Skip to content

Commit

Permalink
fix tests with adding abstract contract
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnewnami committed Nov 16, 2023
1 parent 6905cee commit ffa1017
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 28 deletions.
15 changes: 4 additions & 11 deletions src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 3 additions & 9 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/integration/child/ChildAxelarBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
6 changes: 3 additions & 3 deletions test/unit/child/ChildERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/child/withdrawals/ChildERC20BridgeWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))));

Expand Down
4 changes: 2 additions & 2 deletions test/unit/root/RootERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ffa1017

Please sign in to comment.