From c7808253afeacb4e497b629361266e8baf062569 Mon Sep 17 00:00:00 2001 From: wcgcyx Date: Mon, 6 Nov 2023 12:30:55 +1000 Subject: [PATCH 1/8] Add withdraw IMX handler on L1 --- src/root/RootERC20Bridge.sol | 12 ++- .../RootERC20BridgeWithdraw.t.sol | 74 ++++++++++++++++ .../withdrawals/RootERC20BridgeWithdraw.t.sol | 85 +++++++++++++++++-- 3 files changed, 163 insertions(+), 8 deletions(-) diff --git a/src/root/RootERC20Bridge.sol b/src/root/RootERC20Bridge.sol index bf72034d..2e58e0b9 100644 --- a/src/root/RootERC20Bridge.sol +++ b/src/root/RootERC20Bridge.sol @@ -41,6 +41,7 @@ contract RootERC20Bridge is bytes32 public constant DEPOSIT_SIG = keccak256("DEPOSIT"); bytes32 public constant WITHDRAW_SIG = keccak256("WITHDRAW"); address public constant NATIVE_ETH = address(0xeee); + address public constant NATIVE_IMX = address(0xfff); IRootERC20BridgeAdaptor public rootBridgeAdaptor; /// @dev Used to verify source address in messages sent from child chain. @@ -352,9 +353,14 @@ contract RootERC20Bridge is function _withdraw(bytes memory data) private { (address rootToken, address withdrawer, address receiver, uint256 amount) = abi.decode(data, (address, address, address, uint256)); - address childToken = rootTokenToChildToken[rootToken]; - if (childToken == address(0)) { - revert NotMapped(); + address childToken; + if (address(rootToken) == rootIMXToken) { + childToken = NATIVE_IMX; + } else { + childToken = rootTokenToChildToken[rootToken]; + if (childToken == address(0)) { + revert NotMapped(); + } } _executeTransfer(rootToken, childToken, withdrawer, receiver, amount); } diff --git a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol index 70b0d140..be75eb22 100644 --- a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol +++ b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol @@ -32,6 +32,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is address constant IMX_TOKEN_ADDRESS = address(0xccc); address constant NATIVE_ETH = address(0xeee); address constant WRAPPED_ETH = address(0xddd); + address public constant NATIVE_IMX = address(0xfff); uint256 constant UNLIMITED_IMX_DEPOSIT_LIMIT = 0; uint256 constant withdrawAmount = 0.5 ether; @@ -59,6 +60,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is rootBridge.mapToken{value: 1}(token); // And give the bridge some tokens token.transfer(address(rootBridge), 100 ether); + imxToken.transfer(address(rootBridge), 100 ether); } function test_RevertsIf_WithdrawWithInvalidSourceAddress() public { @@ -119,6 +121,24 @@ contract RootERC20BridgeWithdrawIntegrationTest is assertEq(bridgePostBal, bridgePreBal - withdrawAmount, "Incorrect bridge balance after withdraw"); } + function test_withdrawIMX_TransfersIMX() public { + bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN_ADDRESS, address(this), address(this), withdrawAmount); + + bytes32 commandId = bytes32("testCommandId"); + string memory sourceAddress = rootBridge.childBridgeAdaptor(); + + uint256 thisPreBal = imxToken.balanceOf(address(this)); + uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); + + axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); + + uint256 thisPostBal = imxToken.balanceOf(address(this)); + uint256 bridgePostBal = imxToken.balanceOf(address(rootBridge)); + + assertEq(thisPostBal, thisPreBal + withdrawAmount, "Incorrect user balance after withdraw"); + assertEq(bridgePostBal, bridgePreBal - withdrawAmount, "Incorrect bridge balance after withdraw"); + } + function test_withdraw_TransfersTokens_DifferentReceiver() public { address receiver = address(987654321); bytes memory data = abi.encode(WITHDRAW_SIG, address(token), address(this), receiver, withdrawAmount); @@ -138,6 +158,25 @@ contract RootERC20BridgeWithdrawIntegrationTest is assertEq(bridgePostBal, bridgePreBal - withdrawAmount, "Incorrect bridge balance after withdraw"); } + function test_withdrawIMX_TransfersIMX_DifferentReceiver() public { + address receiver = address(987654321); + bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN_ADDRESS, address(this), receiver, withdrawAmount); + + bytes32 commandId = bytes32("testCommandId"); + string memory sourceAddress = rootBridge.childBridgeAdaptor(); + + uint256 thisPreBal = imxToken.balanceOf(receiver); + uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); + + axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); + + uint256 thisPostBal = imxToken.balanceOf(receiver); + uint256 bridgePostBal = imxToken.balanceOf(address(rootBridge)); + + assertEq(thisPostBal, thisPreBal + withdrawAmount, "Incorrect user balance after withdraw"); + assertEq(bridgePostBal, bridgePreBal - withdrawAmount, "Incorrect bridge balance after withdraw"); + } + function test_withdraw_EmitsRootChainERC20WithdrawEvent() public { bytes memory data = abi.encode(WITHDRAW_SIG, address(token), address(this), address(this), withdrawAmount); @@ -155,6 +194,23 @@ contract RootERC20BridgeWithdrawIntegrationTest is axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); } + function test_withdrawIMX_EmitsRootChainERC20WithdrawEvent() public { + bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN_ADDRESS, address(this), address(this), withdrawAmount); + + bytes32 commandId = bytes32("testCommandId"); + string memory sourceAddress = rootBridge.childBridgeAdaptor(); + + vm.expectEmit(); + emit RootChainERC20Withdraw( + address(imxToken), + NATIVE_IMX, + address(this), + address(this), + withdrawAmount + ); + axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); + } + function test_withdraw_EmitsRootChainERC20WithdrawEvent_DifferentReceiver() public { address receiver = address(987654321); bytes memory data = abi.encode(WITHDRAW_SIG, address(token), address(this), receiver, withdrawAmount); @@ -168,4 +224,22 @@ contract RootERC20BridgeWithdrawIntegrationTest is ); axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); } + + function test_withdrawIMX_EmitsRootChainERC20WithdrawEvent_DifferentReceiver() public { + address receiver = address(987654321); + bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN_ADDRESS, address(this), receiver, withdrawAmount); + + bytes32 commandId = bytes32("testCommandId"); + string memory sourceAddress = rootBridge.childBridgeAdaptor(); + + vm.expectEmit(); + emit RootChainERC20Withdraw( + address(imxToken), + NATIVE_IMX, + address(this), + receiver, + withdrawAmount + ); + axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); + } } diff --git a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol index 5ea3c0e4..c4a050c7 100644 --- a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol +++ b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol @@ -17,13 +17,16 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE address constant CHILD_BRIDGE_ADAPTOR = address(4); string CHILD_BRIDGE_ADAPTOR_STRING = Strings.toHexString(CHILD_BRIDGE_ADAPTOR); string constant CHILD_CHAIN_NAME = "test"; + address constant UnmappedToken = address(0xbbb); address constant IMX_TOKEN = address(0xccc); address constant WRAPPED_ETH = address(0xddd); + address public constant NATIVE_IMX = address(0xfff); uint256 constant mapTokenFee = 300; uint256 constant withdrawAmount = 0.5 ether; uint256 constant UNLIMITED_IMX_DEPOSIT_LIMIT = 0; ERC20PresetMinterPauser public token; + ERC20PresetMinterPauser public imxToken; RootERC20Bridge public rootBridge; MockAdaptor public mockAxelarAdaptor; MockAxelarGateway public mockAxelarGateway; @@ -33,6 +36,8 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE token = new ERC20PresetMinterPauser("Test", "TST"); token.mint(address(this), 100 ether); deployCodeTo("ERC20PresetMinterPauser.sol", abi.encode("ImmutableX", "IMX"), IMX_TOKEN); + imxToken = ERC20PresetMinterPauser(IMX_TOKEN); + imxToken.mint(address(this), 100 ether); deployCodeTo("WETH.sol", abi.encode("Wrapped ETH", "WETH"), WRAPPED_ETH); @@ -56,14 +61,14 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE } function test_RevertsIf_WithdrawWithInvalidSender() public { - bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN, address(this), address(this), withdrawAmount); + bytes memory data = abi.encode(WITHDRAW_SIG, token, address(this), address(this), withdrawAmount); vm.expectRevert(NotBridgeAdaptor.selector); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } function test_RevertsIf_OnMessageReceiveWithInvalidSourceChain() public { - bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN, address(this), address(this), withdrawAmount); + bytes memory data = abi.encode(WITHDRAW_SIG, token, address(this), address(this), withdrawAmount); vm.prank(address(mockAxelarAdaptor)); vm.expectRevert(InvalidSourceChain.selector); @@ -71,7 +76,7 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE } function test_RevertsIf_OnMessageReceiveWithInvalidSourceAddress() public { - bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN, address(this), address(this), withdrawAmount); + bytes memory data = abi.encode(WITHDRAW_SIG, token, address(this), address(this), withdrawAmount); console2.log(CHILD_CHAIN_NAME); console2.log(rootBridge.childChain()); @@ -89,14 +94,14 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE } function test_RevertsIf_OnMessageReceiveWithInvalidSignature() public { - bytes memory data = abi.encode(keccak256("RANDOM"), IMX_TOKEN, address(this), address(this), withdrawAmount); + bytes memory data = abi.encode(keccak256("RANDOM"), token, address(this), address(this), withdrawAmount); vm.prank(address(mockAxelarAdaptor)); vm.expectRevert(InvalidData.selector); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } function test_RevertsIf_OnMessageReceiveWithUnmappedToken() public { - bytes memory data = abi.encode(WITHDRAW_SIG, IMX_TOKEN, address(this), address(this), withdrawAmount); + bytes memory data = abi.encode(WITHDRAW_SIG, UnmappedToken, address(this), address(this), withdrawAmount); vm.prank(address(mockAxelarAdaptor)); vm.expectRevert(NotMapped.selector); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); @@ -121,6 +126,23 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE ); } + function test_onMessageReceive_TransfersIMXTokens() public { + // Give bridge some IMX tokens + imxToken.transfer(address(rootBridge), 100 ether); + + uint256 thisPreBal = imxToken.balanceOf(address(this)); + uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); + + bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), address(this), withdrawAmount); + vm.prank(address(mockAxelarAdaptor)); + rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); + + assertEq(imxToken.balanceOf(address(this)), thisPreBal + withdrawAmount, "IMX not transferred to receiver"); + assertEq( + imxToken.balanceOf(address(rootBridge)), bridgePreBal - withdrawAmount, "IMX not transferred from bridge" + ); + } + function test_onMessageReceive_TransfersTokens_DifferentReceiver() public { address receiver = address(123456); // Need to first map the token. @@ -141,6 +163,24 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE ); } + function test_onMessageReceive_TransfersIMXTokens_DifferentReceiver() public { + address receiver = address(123456); + // Give bridge some IMX tokens + imxToken.transfer(address(rootBridge), 100 ether); + + uint256 thisPreBal = imxToken.balanceOf(address(receiver)); + uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); + + bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), receiver, withdrawAmount); + vm.prank(address(mockAxelarAdaptor)); + rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); + + assertEq(imxToken.balanceOf(address(receiver)), thisPreBal + withdrawAmount, "IMX not transferred to receiver"); + assertEq( + imxToken.balanceOf(address(rootBridge)), bridgePreBal - withdrawAmount, "IMX not transferred from bridge" + ); + } + function test_onMessageReceive_EmitsRootChainERC20WithdrawEvent() public { // Need to first map the token. rootBridge.mapToken(token); @@ -160,6 +200,23 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } + function test_onMessageReceive_EmitsRootChainERC20WithdrawEventForIMX() public { + // Give bridge some IMX tokens + imxToken.transfer(address(rootBridge), 100 ether); + + bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), address(this), withdrawAmount); + vm.expectEmit(); + emit RootChainERC20Withdraw( + address(imxToken), + NATIVE_IMX, + address(this), + address(this), + withdrawAmount + ); + vm.prank(address(mockAxelarAdaptor)); + rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); + } + function test_onMessageReceive_EmitsRootChainERC20WithdrawEvent_DifferentReceiver() public { address receiver = address(123456); // Need to first map the token. @@ -175,4 +232,22 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE vm.prank(address(mockAxelarAdaptor)); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } + + function test_onMessageReceive_EmitsRootChainERC20WithdrawEventForIMX_DifferentReceiver() public { + address receiver = address(123456); + // Give bridge some IMX tokens + imxToken.transfer(address(rootBridge), 100 ether); + + bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), receiver, withdrawAmount); + vm.expectEmit(); + emit RootChainERC20Withdraw( + address(imxToken), + NATIVE_IMX, + address(this), + receiver, + withdrawAmount + ); + vm.prank(address(mockAxelarAdaptor)); + rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); + } } From 8adc3199573ed590a0bd10dfa6b7e2e92e6f7cb8 Mon Sep 17 00:00:00 2001 From: wcgcyx Date: Mon, 6 Nov 2023 12:31:12 +1000 Subject: [PATCH 2/8] Fmt --- .../RootERC20BridgeWithdraw.t.sol | 16 ++-------------- .../withdrawals/RootERC20BridgeWithdraw.t.sol | 16 ++-------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol index be75eb22..1446194e 100644 --- a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol +++ b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol @@ -201,13 +201,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is string memory sourceAddress = rootBridge.childBridgeAdaptor(); vm.expectEmit(); - emit RootChainERC20Withdraw( - address(imxToken), - NATIVE_IMX, - address(this), - address(this), - withdrawAmount - ); + emit RootChainERC20Withdraw(address(imxToken), NATIVE_IMX, address(this), address(this), withdrawAmount); axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); } @@ -233,13 +227,7 @@ contract RootERC20BridgeWithdrawIntegrationTest is string memory sourceAddress = rootBridge.childBridgeAdaptor(); vm.expectEmit(); - emit RootChainERC20Withdraw( - address(imxToken), - NATIVE_IMX, - address(this), - receiver, - withdrawAmount - ); + emit RootChainERC20Withdraw(address(imxToken), NATIVE_IMX, address(this), receiver, withdrawAmount); axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); } } diff --git a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol index c4a050c7..14d5d32b 100644 --- a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol +++ b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol @@ -206,13 +206,7 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), address(this), withdrawAmount); vm.expectEmit(); - emit RootChainERC20Withdraw( - address(imxToken), - NATIVE_IMX, - address(this), - address(this), - withdrawAmount - ); + emit RootChainERC20Withdraw(address(imxToken), NATIVE_IMX, address(this), address(this), withdrawAmount); vm.prank(address(mockAxelarAdaptor)); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } @@ -240,13 +234,7 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), receiver, withdrawAmount); vm.expectEmit(); - emit RootChainERC20Withdraw( - address(imxToken), - NATIVE_IMX, - address(this), - receiver, - withdrawAmount - ); + emit RootChainERC20Withdraw(address(imxToken), NATIVE_IMX, address(this), receiver, withdrawAmount); vm.prank(address(mockAxelarAdaptor)); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); } From 2bff7a929704e06d664ae637175545660acb9f89 Mon Sep 17 00:00:00 2001 From: wcgcyx Date: Mon, 6 Nov 2023 17:08:53 +1000 Subject: [PATCH 3/8] Update --- .../root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol | 6 +++--- test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol index 1446194e..e571e5e4 100644 --- a/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol +++ b/test/integration/root/withdrawals.t.sol/RootERC20BridgeWithdraw.t.sol @@ -165,15 +165,15 @@ contract RootERC20BridgeWithdrawIntegrationTest is bytes32 commandId = bytes32("testCommandId"); string memory sourceAddress = rootBridge.childBridgeAdaptor(); - uint256 thisPreBal = imxToken.balanceOf(receiver); + uint256 receiverPreBal = imxToken.balanceOf(receiver); uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); axelarAdaptor.execute(commandId, CHILD_CHAIN_NAME, sourceAddress, data); - uint256 thisPostBal = imxToken.balanceOf(receiver); + uint256 receiverPostBal = imxToken.balanceOf(receiver); uint256 bridgePostBal = imxToken.balanceOf(address(rootBridge)); - assertEq(thisPostBal, thisPreBal + withdrawAmount, "Incorrect user balance after withdraw"); + assertEq(receiverPostBal, receiverPreBal + withdrawAmount, "Incorrect user balance after withdraw"); assertEq(bridgePostBal, bridgePreBal - withdrawAmount, "Incorrect bridge balance after withdraw"); } diff --git a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol index 14d5d32b..61c79980 100644 --- a/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol +++ b/test/unit/root/withdrawals/RootERC20BridgeWithdraw.t.sol @@ -168,14 +168,16 @@ contract RootERC20BridgeWithdrawUnitTest is Test, IRootERC20BridgeEvents, IRootE // Give bridge some IMX tokens imxToken.transfer(address(rootBridge), 100 ether); - uint256 thisPreBal = imxToken.balanceOf(address(receiver)); + uint256 receiverPreBal = imxToken.balanceOf(address(receiver)); uint256 bridgePreBal = imxToken.balanceOf(address(rootBridge)); bytes memory data = abi.encode(WITHDRAW_SIG, imxToken, address(this), receiver, withdrawAmount); vm.prank(address(mockAxelarAdaptor)); rootBridge.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data); - assertEq(imxToken.balanceOf(address(receiver)), thisPreBal + withdrawAmount, "IMX not transferred to receiver"); + assertEq( + imxToken.balanceOf(address(receiver)), receiverPreBal + withdrawAmount, "IMX not transferred to receiver" + ); assertEq( imxToken.balanceOf(address(rootBridge)), bridgePreBal - withdrawAmount, "IMX not transferred from bridge" ); From fe96c6c095ec7d16369f1b8f0a5f47167b1ad04b Mon Sep 17 00:00:00 2001 From: wcgcyx Date: Tue, 7 Nov 2023 10:12:09 +1000 Subject: [PATCH 4/8] Fix build issue --- .../child/withdrawals/ChildAxelarBridgeWithdrawIMX.t.sol | 4 ++-- .../withdrawals/ChildAxelarBridgeWithdrawToIMX.t.sol | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawIMX.t.sol b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawIMX.t.sol index 0396c0de..61dd35c2 100644 --- a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawIMX.t.sol +++ b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawIMX.t.sol @@ -102,7 +102,7 @@ contract ChildERC20BridgeWithdrawIMXIntegrationTest is childBridge.withdrawIMX{value: withdrawFee + withdrawAmount}(withdrawAmount); } - function test_WithdrawIMX_EmitsAxelarMessageEvent() public { + function test_WithdrawIMX_EmitsAxelarMessageSentEvent() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; @@ -110,7 +110,7 @@ contract ChildERC20BridgeWithdrawIMXIntegrationTest is abi.encode(WITHDRAW_SIG, ROOT_IMX_TOKEN, address(this), address(this), withdrawAmount); vm.expectEmit(address(axelarAdaptor)); - emit AxelarMessage(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); + emit AxelarMessageSent(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); childBridge.withdrawIMX{value: withdrawFee + withdrawAmount}(withdrawAmount); } diff --git a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawToIMX.t.sol b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawToIMX.t.sol index 8c6e1fea..a2a09223 100644 --- a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawToIMX.t.sol +++ b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawToIMX.t.sol @@ -163,7 +163,7 @@ contract ChildERC20BridgewithdrawIMXToIntegrationTest is childBridge.withdrawIMXTo{value: withdrawFee + withdrawAmount}(receiver, withdrawAmount); } - function test_withdrawIMXTo_EmitsAxelarMessageEvent() public { + function test_withdrawIMXTo_EmitsAxelarMessageSentEvent() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; @@ -171,12 +171,12 @@ contract ChildERC20BridgewithdrawIMXToIntegrationTest is abi.encode(WITHDRAW_SIG, ROOT_IMX_TOKEN, address(this), address(this), withdrawAmount); vm.expectEmit(address(axelarAdaptor)); - emit AxelarMessage(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); + emit AxelarMessageSent(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); childBridge.withdrawIMXTo{value: withdrawFee + withdrawAmount}(address(this), withdrawAmount); } - function test_withdrawIMXToWithDifferentAccount_EmitsAxelarMessageEvent() public { + function test_withdrawIMXToWithDifferentAccount_EmitsAxelarMessageSentEvent() public { address receiver = address(0xabcd); uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; @@ -185,7 +185,7 @@ contract ChildERC20BridgewithdrawIMXToIntegrationTest is abi.encode(WITHDRAW_SIG, ROOT_IMX_TOKEN, address(this), receiver, withdrawAmount); vm.expectEmit(address(axelarAdaptor)); - emit AxelarMessage(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); + emit AxelarMessageSent(childBridge.rootChain(), childBridge.rootERC20BridgeAdaptor(), predictedPayload); childBridge.withdrawIMXTo{value: withdrawFee + withdrawAmount}(receiver, withdrawAmount); } From 7631a969b12e224aa67557713ed6e24b32ad5f2e Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Tue, 7 Nov 2023 21:19:38 +1100 Subject: [PATCH 5/8] Fix test naming inconsistencies --- test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol | 4 ++-- .../child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol index a2b67262..0f187841 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol @@ -135,7 +135,7 @@ contract ChildERC20BridgeWithdrawToUnitTest is Test, IChildERC20BridgeEvents, IC childBridge.withdrawTo{value: withdrawFee}(IChildERC20(address(childToken)), address(this), withdrawAmount); } - function test_withdraw_ReducesBalance() public { + function test_withdrawTo_ReducesBalance() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; @@ -147,7 +147,7 @@ contract ChildERC20BridgeWithdrawToUnitTest is Test, IChildERC20BridgeEvents, IC assertEq(postBal, preBal - withdrawAmount); } - function test_withdraw_ReducesTotalSupply() public { + function test_withdrawTo_ReducesTotalSupply() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol index c8d997ea..e69be526 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol @@ -16,7 +16,7 @@ import {ChildERC20} from "../../../../src/child/ChildERC20.sol"; import {MockAdaptor} from "../../../../src/test/root/MockAdaptor.sol"; import {Utils} from "../../../utils.t.sol"; -contract ChildERC20BridgewithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents, IChildERC20BridgeErrors, Utils { +contract ChildERC20BridgeWithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents, IChildERC20BridgeErrors, Utils { address constant ROOT_BRIDGE = address(3); string public ROOT_BRIDGE_ADAPTOR = Strings.toHexString(address(4)); string constant ROOT_CHAIN_NAME = "test"; From cb03f92a4119fcd6d56e5091b10326187b1a76c1 Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Tue, 7 Nov 2023 22:01:45 +1100 Subject: [PATCH 6/8] Fix incorrect test name --- test/unit/root/RootAxelarBridgeAdaptor.t.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/root/RootAxelarBridgeAdaptor.t.sol b/test/unit/root/RootAxelarBridgeAdaptor.t.sol index 76281fce..0182e95c 100644 --- a/test/unit/root/RootAxelarBridgeAdaptor.t.sol +++ b/test/unit/root/RootAxelarBridgeAdaptor.t.sol @@ -38,20 +38,20 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR vm.deal(address(stubRootBridge), 99999999999); } - function test_Constructor() public { + function test_Initialize() public { assertEq(address(axelarAdaptor.rootBridge()), address(stubRootBridge), "rootBridge not set"); assertEq(axelarAdaptor.childChain(), CHILD_CHAIN_NAME, "childChain not set"); assertEq(address(axelarAdaptor.gateway()), address(mockAxelarGateway), "axelarGateway not set"); assertEq(address(axelarAdaptor.gasService()), address(axelarGasService), "axelarGasService not set"); } - function test_RevertWhen_InitializerGivenZeroAddress() public { + function test_RevertWhen_InitializeGivenZeroAddress() public { RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway)); vm.expectRevert(ZeroAddresses.selector); newAdaptor.initialize(address(0), CHILD_CHAIN_NAME, address(axelarGasService)); } - function test_RevertWhen_ConstructorGivenEmptyChildChainName() public { + function test_RevertWhen_InitializeGivenEmptyChildChainName() public { RootAxelarBridgeAdaptor newAdaptor = new RootAxelarBridgeAdaptor(address(mockAxelarGateway)); vm.expectRevert(InvalidChildChain.selector); newAdaptor.initialize(address(this), "", address(axelarGasService)); From 1ae35ccfe131282d28f56c0633bb40728f33726d Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Tue, 7 Nov 2023 22:24:49 +1100 Subject: [PATCH 7/8] Fix incorrect test name --- test/unit/child/ChildAxelarBridgeAdaptor.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/child/ChildAxelarBridgeAdaptor.t.sol b/test/unit/child/ChildAxelarBridgeAdaptor.t.sol index 148445c6..eaea950c 100644 --- a/test/unit/child/ChildAxelarBridgeAdaptor.t.sol +++ b/test/unit/child/ChildAxelarBridgeAdaptor.t.sol @@ -34,7 +34,7 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro axelarAdaptor.initialize(ROOT_CHAIN_NAME, address(mockChildERC20Bridge), address(mockChildAxelarGasService)); } - function test_Constructor_SetsValues() public { + function test_Initialize() public { assertEq(address(axelarAdaptor.childBridge()), address(mockChildERC20Bridge), "childBridge not set"); assertEq(address(axelarAdaptor.gateway()), address(mockChildAxelarGateway), "gateway not set"); assertEq(axelarAdaptor.rootChain(), ROOT_CHAIN_NAME, "rootChain not set"); From c3898fd4c5b0cb3498fc73e9802b5634d7e1708f Mon Sep 17 00:00:00 2001 From: Ermyas Abebe Date: Wed, 8 Nov 2023 09:06:23 +1100 Subject: [PATCH 8/8] Fix incorrect test name --- .../child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol index e69be526..1aea350d 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol @@ -105,7 +105,7 @@ contract ChildERC20BridgeWithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents, childBridge.withdrawIMXTo{value: withdrawFee + withdrawAmount}(receiver, withdrawAmount); } - function test_WithdrawIMX_ReducesBalance() public { + function test_WithdrawIMXTo_ReducesBalance() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether; @@ -117,7 +117,7 @@ contract ChildERC20BridgeWithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents, assertEq(postBal, preBal - withdrawAmount - withdrawFee, "Balance not reduced"); } - function test_WithdrawIMX_PaysFee() public { + function test_WithdrawIMXTo_PaysFee() public { uint256 withdrawFee = 300; uint256 withdrawAmount = 7 ether;