From adf9f9cbdd39178d0462768116e123fbefa8703d Mon Sep 17 00:00:00 2001 From: James Snewin Date: Tue, 14 Nov 2023 14:07:52 +1000 Subject: [PATCH] impl zero reciever tests and clean ups --- src/child/ChildERC20Bridge.sol | 1 + .../child/withdrawals/ChildAxelarBridgeWithdraw.t.sol | 3 +-- .../withdrawals/ChildAxelarBridgeWithdrawWIMX.t.sol | 3 +-- test/unit/child/ChildERC20Bridge.t.sol | 2 ++ .../withdrawals/ChildERC20BridgeWithdrawTo.t.sol | 11 +++++++++-- .../withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol | 7 +++++++ .../withdrawals/ChildERC20BridgeWithdrawWIMXTo.t.sol | 9 ++++++++- 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/child/ChildERC20Bridge.sol b/src/child/ChildERC20Bridge.sol index 6da0848c..8daf8473 100644 --- a/src/child/ChildERC20Bridge.sol +++ b/src/child/ChildERC20Bridge.sol @@ -222,6 +222,7 @@ contract ChildERC20Bridge is * Requirements: * * - `childTokenAddr` must not be the zero address. + * - `reciever` must not be the zero address. * - `amount` must be greater than zero. * - `msg.value` must be greater than zero. * - `childToken` must exist. diff --git a/test/integration/child/withdrawals/ChildAxelarBridgeWithdraw.t.sol b/test/integration/child/withdrawals/ChildAxelarBridgeWithdraw.t.sol index 2052fe7c..60c389e7 100644 --- a/test/integration/child/withdrawals/ChildAxelarBridgeWithdraw.t.sol +++ b/test/integration/child/withdrawals/ChildAxelarBridgeWithdraw.t.sol @@ -19,7 +19,7 @@ contract ChildERC20BridgeWithdrawIntegrationTest is IChildAxelarBridgeAdaptorEvents, IChildAxelarBridgeAdaptorErrors, Utils -{ +{ // Define here to avoid error collisions between IChildERC20BridgeErrors and IChildAxelarBridgeAdaptorErrors error ZeroValue(); @@ -132,7 +132,6 @@ contract ChildERC20BridgeWithdrawIntegrationTest is } function test_RevertIf_WithdrawWithNoGas() public { - ChildERC20 childToken = ChildERC20(childBridge.rootTokenToChildToken(rootToken)); vm.expectRevert(ZeroValue.selector); diff --git a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawWIMX.t.sol b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawWIMX.t.sol index 7816e614..e0ed7b6e 100644 --- a/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawWIMX.t.sol +++ b/test/integration/child/withdrawals/ChildAxelarBridgeWithdrawWIMX.t.sol @@ -37,8 +37,7 @@ contract ChildERC20BridgeWithdrawWIMXIntegrationTest is WIMX public wIMXToken; function setUp() public { - (childBridge, axelarAdaptor, , , , mockAxelarGasService, mockAxelarGateway) = - childIntegrationSetup(); + (childBridge, axelarAdaptor,,,, mockAxelarGasService, mockAxelarGateway) = childIntegrationSetup(); wIMXToken = WIMX(payable(WRAPPED_IMX)); Address.sendValue(payable(wIMXToken), 100 ether); } diff --git a/test/unit/child/ChildERC20Bridge.t.sol b/test/unit/child/ChildERC20Bridge.t.sol index a4b4ced8..e96a30f5 100644 --- a/test/unit/child/ChildERC20Bridge.t.sol +++ b/test/unit/child/ChildERC20Bridge.t.sol @@ -365,6 +365,8 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B address newAdaptorAddress = address(0x11111); assertEq(address(childBridge.bridgeAdaptor()), address(this), "bridgeAdaptor not set"); + vm.expectEmit(true, true, true, true); + emit BridgeAdaptorUpdated(address(childBridge.bridgeAdaptor()), newAdaptorAddress); childBridge.updateBridgeAdaptor(newAdaptorAddress); assertEq(address(childBridge.bridgeAdaptor()), newAdaptorAddress, "bridgeAdaptor not updated"); } diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol index 124d2d4c..6bd246aa 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawTo.t.sol @@ -9,7 +9,7 @@ import { IChildERC20BridgeEvents, IChildERC20BridgeErrors } from "../../../../src/child/ChildERC20Bridge.sol"; -import {IChildERC20,ChildERC20} from "../../../../src/child/ChildERC20.sol"; +import {IChildERC20, ChildERC20} from "../../../../src/child/ChildERC20.sol"; import {MockAdaptor} from "../../../../src/test/root/MockAdaptor.sol"; import {Utils} from "../../../utils.t.sol"; @@ -66,7 +66,14 @@ contract ChildERC20BridgeWithdrawToUnitTest is Test, IChildERC20BridgeEvents, IC childToken.approve(address(childBridge), 1000000 ether); } - function test_RevertsIf_WithdrawToCalledWithZeroFee() public { + function test_RevertsIf_WithdrawToCalledWithZeroReciever() public { + uint256 withdrawAmount = 300; + + vm.expectRevert(ZeroAddress.selector); + childBridge.withdrawTo{value: 1 ether}(IChildERC20(address(2222222)), address(0), withdrawAmount); + } + + function test_RevertsIf_WithdrawToCalledWithZeroFee() public { uint256 withdrawAmount = 300; vm.expectRevert(ZeroValue.selector); diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol index d51f7200..907248ab 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawToIMX.t.sol @@ -52,6 +52,13 @@ contract ChildERC20BridgeWithdrawIMXToUnitTest is Test, IChildERC20BridgeEvents, ); } + function test_RevertsIf_withdrawIMXToCalledWithZeroReciever() public { + uint256 withdrawAmount = 7 ether; + + vm.expectRevert(ZeroAddress.selector); + childBridge.withdrawIMXTo{value: 1 ether}(address(0), withdrawAmount); + } + function test_RevertsIf_withdrawIMXToCalledWithZeroFee() public { uint256 withdrawAmount = 7 ether; diff --git a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawWIMXTo.t.sol b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawWIMXTo.t.sol index 3f36d60e..0b786fce 100644 --- a/test/unit/child/withdrawals/ChildERC20BridgeWithdrawWIMXTo.t.sol +++ b/test/unit/child/withdrawals/ChildERC20BridgeWithdrawWIMXTo.t.sol @@ -7,7 +7,7 @@ import { ChildERC20Bridge, IChildERC20Bridge, IChildERC20BridgeEvents, - IChildERC20BridgeErrors + IChildERC20BridgeErrors } from "../../../../src/child/ChildERC20Bridge.sol"; import {ChildERC20} from "../../../../src/child/ChildERC20.sol"; import {MockAdaptor} from "../../../../src/test/root/MockAdaptor.sol"; @@ -54,6 +54,13 @@ contract ChildERC20BridgeWithdrawWIMXToUnitTest is Test, IChildERC20BridgeEvents ); } + function test_RevertsIf_withdrawWIMXToCalledWithZeroReciever() public { + uint256 withdrawAmount = 7 ether; + + vm.expectRevert(ZeroAddress.selector); + childBridge.withdrawWIMXTo{value: 1 ether}(address(0), withdrawAmount); + } + function test_RevertsIf_withdrawWIMXToCalledWithZeroFee() public { uint256 withdrawAmount = 7 ether;