From 46dcff90820d24ab51c30d9bc162285b5005c98e Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 14 Oct 2024 13:42:49 +0200 Subject: [PATCH] tests fixes --- v2/test/GatewayEVM.t.sol | 15 +++++++++++++++ v2/test/GatewayZEVM.t.sol | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/v2/test/GatewayEVM.t.sol b/v2/test/GatewayEVM.t.sol index ebb7176f..e97d140d 100644 --- a/v2/test/GatewayEVM.t.sol +++ b/v2/test/GatewayEVM.t.sol @@ -446,6 +446,15 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR gateway.deposit(destination, amount, address(token), revertOptions); } + function testDepositERC20ToCustodyFailsIfPayloadSizeExceeded() public { + uint256 amount = 100_000; + token.approve(address(gateway), amount); + revertOptions.revertMessage = new bytes(gateway.MAX_PAYLOAD_SIZE() + 1); + + vm.expectRevert(PayloadSizeExceeded.selector); + gateway.deposit(destination, amount, address(token), revertOptions); + } + function testDepositZetaToConnector() public { uint256 amount = 100_000; zeta.approve(address(gateway), amount); @@ -492,6 +501,12 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR gateway.deposit{ value: amount }(destination, revertOptions); } + function testFailDepositEthToTssIfPayloadSizeExceeded() public { + revertOptions.revertMessage = new bytes(gateway.MAX_PAYLOAD_SIZE() + 1); + vm.expectRevert("PayloadSizeExceeded"); + gateway.deposit{ value: 1 }(destination, revertOptions); + } + function testFailDepositEthToTssIfReceiverIsZeroAddress() public { uint256 amount = 1; diff --git a/v2/test/GatewayZEVM.t.sol b/v2/test/GatewayZEVM.t.sol index b9512ded..35fe0e89 100644 --- a/v2/test/GatewayZEVM.t.sol +++ b/v2/test/GatewayZEVM.t.sol @@ -131,6 +131,12 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors gateway.withdraw(abi.encodePacked(addr1), amount, address(zrc20), revertOptions); } + function testWithdrawZRC20FailsIfMessageSizeExceeded() public { + revertOptions.revertMessage = new bytes(gateway.MAX_MESSAGE_SIZE() + 1); + vm.expectRevert(MessageSizeExceeded.selector); + gateway.withdraw(abi.encodePacked(addr1), 2, address(zrc20), revertOptions); + } + function testWithdrawZRC20FailsIsAmountIs0() public { vm.expectRevert(InsufficientZRC20Amount.selector); gateway.withdraw(abi.encodePacked(addr1), 0, address(zrc20), revertOptions); @@ -164,8 +170,8 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors } function testWithdrawAndCallZRC20FailsIfMessageSizeExceeded() public { - bytes memory message = new bytes(512); - revertOptions.revertMessage = new bytes(512); + bytes memory message = new bytes(gateway.MAX_MESSAGE_SIZE() / 2); + revertOptions.revertMessage = new bytes(gateway.MAX_MESSAGE_SIZE() / 2 + 1); vm.expectRevert(MessageSizeExceeded.selector); gateway.withdrawAndCall(abi.encodePacked(addr1), 1, address(zrc20), message, 1, revertOptions); @@ -231,6 +237,12 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors // gateway.withdraw(abi.encodePacked(addr1), 0, 1, revertOptions); // } + // function testWithdrawZETAFailsIfMessageSizeExceeded() public { + // revertOptions.revertMessage = new bytes(gateway.MAX_MESSAGE_SIZE() + 1); + // vm.expectRevert(MessageSizeExceeded.selector); + // gateway.withdraw(abi.encodePacked(addr1), 1, 1, revertOptions); + // } + // function testWithdrawZETAFailsIfReceiverIsZeroAddress() public { // vm.expectRevert(ZeroAddress.selector); // gateway.withdraw(abi.encodePacked(""), 0, 1, revertOptions); @@ -367,8 +379,8 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors } function testCallFailsIfMessageSizeExceeded() public { - bytes memory message = new bytes(512); - revertOptions.revertMessage = new bytes(512); + bytes memory message = new bytes(gateway.MAX_MESSAGE_SIZE() / 2); + revertOptions.revertMessage = new bytes(gateway.MAX_MESSAGE_SIZE() / 2 + 1); vm.expectRevert(MessageSizeExceeded.selector); gateway.call(abi.encodePacked(addr1), address(zrc20), message, 1, revertOptions); }