Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Feb 12, 2024
1 parent b5400cc commit ce85db3
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions test/fuzz/child/ChildERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_MapToken(address rootToken, string memory name, string memory symbol, uint8 decimals) public {
vm.assume(rootToken != address(0) && bytes(name).length != 0 && bytes(symbol).length != 0 && decimals > 0);
vm.assume(rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX());
vm.assume(rootToken > address(10) && bytes(name).length != 0 && bytes(symbol).length != 0 && decimals > 0);
vm.assume(rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX() && rootToken != ROOT_IMX_TOKEN);

// Map token on L1 triggers call on child bridge.
bytes memory data = abi.encode(MAP_TOKEN_SIG, rootToken, name, symbol, decimals);
Expand All @@ -78,11 +78,12 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_DepositIMX(address sender, address recipient, uint256 depositAmt) public {
vm.assume(sender != address(0) && recipient != address(0) && depositAmt > 0);
vm.assume(sender > address(10) && recipient > address(10) && depositAmt > 0);
vm.assume(sender.code.length == 0 && recipient.code.length == 0);
vm.assume(recipient.balance == 0);
vm.deal(address(bridge), depositAmt);

assertEq(address(bridge).balance, depositAmt, "Bridge should have depositAmt of IMX");
assertEq(recipient.balance, 0, "Recipient should have 0 IMX");

// Deposit IMX on L1 triggers call on child bridge.
bytes memory data = abi.encode(DEPOSIT_SIG, bridge.rootIMXToken(), sender, recipient, depositAmt);
Expand All @@ -97,7 +98,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_WithdrawIMX(address user, uint256 balance, uint256 gasAmt, uint256 withdrawAmt) public {
vm.assume(user != address(0));
vm.assume(user > address(10));
vm.assume(user.code.length == 0);
vm.assume(balance > 0 && withdrawAmt > 0 && gasAmt > 0);
vm.assume(balance < type(uint256).max - gasAmt);
vm.assume(balance > withdrawAmt && balance - withdrawAmt > gasAmt);
Expand Down Expand Up @@ -133,7 +135,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_WithdrawWIMX(address user, uint256 balance, uint256 gasAmt, uint256 withdrawAmt) public {
vm.assume(user != address(0));
vm.assume(user > address(10));
vm.assume(user.code.length == 0);
vm.assume(balance > 0 && withdrawAmt > 0 && gasAmt > 0);
vm.assume(balance < type(uint256).max);
vm.assume(balance > withdrawAmt && balance - withdrawAmt > gasAmt);
Expand Down Expand Up @@ -181,8 +184,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_DepositETH(address sender, address recipient, uint256 depositAmt) public {
vm.assume(sender != address(0) && recipient != address(0) && depositAmt > 0);

vm.assume(sender > address(10) && recipient > address(10) && depositAmt > 0);
vm.assume(sender.code.length == 0 && recipient.code.length == 0);
assertEq(IChildERC20(bridge.childETHToken()).balanceOf(recipient), 0, "Recipient should have 0 ETH");

// Deposit ETH on L1 triggers call on child bridge.
Expand All @@ -201,7 +204,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_WithdrawETH(address user, uint256 balance, uint256 gasAmt, uint256 withdrawAmt) public {
vm.assume(user != address(0));
vm.assume(user > address(10));
vm.assume(user.code.length == 0);
vm.assume(balance > 0 && withdrawAmt > 0 && gasAmt > 0);
vm.assume(balance < type(uint256).max);
vm.assume(balance > withdrawAmt);
Expand Down Expand Up @@ -242,9 +246,11 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
}

function testFuzz_DepositERC20(address rootToken, address sender, address recipient, uint256 depositAmt) public {
vm.assume(rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX());
vm.assume(rootToken != address(0) && rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX());
vm.assume(sender != address(0) && recipient != address(0) && depositAmt > 0);
vm.assume(
rootToken > address(10) && rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX()
&& rootToken != ROOT_IMX_TOKEN
);
vm.assume(sender > address(10) && recipient > address(10) && depositAmt > 0);

// Map
bytes memory data = abi.encode(MAP_TOKEN_SIG, rootToken, "Test token", "Test", 18);
Expand Down Expand Up @@ -274,8 +280,8 @@ contract ChildERC20BridgeTest is Test, IChildERC20BridgeEvents {
uint256 gasAmt,
uint256 withdrawAmt
) public {
vm.assume(rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX());
vm.assume(rootToken != address(0) && user != address(0));
vm.assume(rootToken != bridge.NATIVE_ETH() && rootToken != bridge.NATIVE_IMX() && rootToken != ROOT_IMX_TOKEN);
vm.assume(rootToken > address(10) && user > address(10));
vm.assume(balance > 0 && withdrawAmt > 0 && gasAmt > 0);
vm.assume(balance < type(uint256).max);
vm.assume(balance > withdrawAmt);
Expand Down

0 comments on commit ce85db3

Please sign in to comment.