From b99831d4eb77adf9d1dca2077c1c34e8f55ee6f4 Mon Sep 17 00:00:00 2001 From: kukoomomo Date: Wed, 18 Dec 2024 16:53:58 +0800 Subject: [PATCH] fix forge test --- .../test/L1CrossDomainMessenger.t.sol | 65 ----------------- .../contracts/test/L1CustomERC20Gateway.t.sol | 25 ------- .../contracts/test/L1ERC1155Gateway.t.sol | 64 ----------------- .../contracts/test/L1ERC721Gateway.t.sol | 59 --------------- contracts/contracts/test/L1ETHGateway.t.sol | 29 -------- contracts/contracts/test/L1MessageQueue.t.sol | 72 ------------------- .../test/L1StandardERC20Gateway.t.sol | 34 --------- contracts/contracts/test/L1WETHGateway.t.sol | 23 ------ 8 files changed, 371 deletions(-) diff --git a/contracts/contracts/test/L1CrossDomainMessenger.t.sol b/contracts/contracts/test/L1CrossDomainMessenger.t.sol index 47af5645..0dcb9f1f 100644 --- a/contracts/contracts/test/L1CrossDomainMessenger.t.sol +++ b/contracts/contracts/test/L1CrossDomainMessenger.t.sol @@ -427,69 +427,6 @@ contract L1CrossDomainMessengerTest is L1GatewayBaseTest { assertEq(nonce + 2, l1CrossDomainMessenger.messageNonce()); } - function test_dropMessage_notEnqueued_reverts() external { - address sender = address(this); - address to = address(bob); - bytes memory data = "send message"; - // hevm.deal(sender, 10 ether); - - // send value zero - uint256 value = 0; - uint256 nonce = l1MessageQueueWithGasPriceOracle.nextCrossDomainMessageIndex(); - - // Expect revert when the message has not been enqueued. - hevm.expectRevert("Provided message has not been enqueued"); - l1CrossDomainMessenger.dropMessage(sender, to, value, nonce, data); - } - - function test_dropMessage_succeeds(uint256 amount, address recipient, bytes memory dataToCall) public { - amount = bound(amount, 1, address(this).balance); - bytes memory message = abi.encodeCall( - IL2ETHGateway.finalizeDepositETH, - (address(this), recipient, amount, dataToCall) - ); - - l1ETHGateway.depositETHAndCall{value: amount}(recipient, amount, dataToCall, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // Drop message 0 and verify balance - revertOnReceive = false; - uint256 balance = address(this).balance; - l1CrossDomainMessenger.dropMessage(address(l1ETHGateway), address(counterpartGateway), amount, 0, message); - assertEq(balance + amount, address(this).balance); - } - - function test_dropMessage_dropAgain_reverts(uint256 amount, address recipient, bytes memory dataToCall) public { - amount = bound(amount, 1, address(this).balance); - bytes memory message = abi.encodeCall( - IL2ETHGateway.finalizeDepositETH, - (address(this), recipient, amount, dataToCall) - ); - - l1ETHGateway.depositETHAndCall{value: amount}(recipient, amount, dataToCall, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // Drop message 0 and verify balance - revertOnReceive = false; - uint256 balance = address(this).balance; - l1CrossDomainMessenger.dropMessage(address(l1ETHGateway), address(counterpartGateway), amount, 0, message); - assertEq(balance + amount, address(this).balance); - - // Expect revert when trying to drop the same message again. - hevm.expectRevert("Message already dropped"); - l1CrossDomainMessenger.dropMessage(address(l1ETHGateway), address(counterpartGateway), amount, 0, message); - } - function test_updateMaxReplayTimes_succeeds(uint256 _maxReplayTimes) external { hevm.assume(_maxReplayTimes > 0); // not owner, revert @@ -529,8 +466,6 @@ contract L1CrossDomainMessengerTest is L1GatewayBaseTest { l1CrossDomainMessenger.proveAndRelayMessage(address(0), address(0), 0, 0, new bytes(0), wdProof, wdRoot); hevm.expectRevert("Pausable: paused"); l1CrossDomainMessenger.replayMessage(address(0), address(0), 0, 0, new bytes(0), 0, address(0)); - hevm.expectRevert("Pausable: paused"); - l1CrossDomainMessenger.dropMessage(address(0), address(0), 0, 0, new bytes(0)); // unpause hevm.prank(multisig); diff --git a/contracts/contracts/test/L1CustomERC20Gateway.t.sol b/contracts/contracts/test/L1CustomERC20Gateway.t.sol index 8ac88ce0..f1a63821 100644 --- a/contracts/contracts/test/L1CustomERC20Gateway.t.sol +++ b/contracts/contracts/test/L1CustomERC20Gateway.t.sol @@ -182,31 +182,6 @@ contract L1CustomERC20GatewayTest is L1GatewayBaseTest { _depositERC20WithRecipientAndCalldata(false, amount, recipient, dataToCall, gasLimit, feePerGas); } - function test_dropMessage_succeeds(uint256 amount, address recipient, bytes memory dataToCall) public { - gateway.updateTokenMapping(address(l1Token), address(l2Token)); - - amount = bound(amount, 1, l1Token.balanceOf(address(this))); - bytes memory message = abi.encodeCall( - IL2ERC20Gateway.finalizeDepositERC20, - (address(l1Token), address(l2Token), address(this), recipient, amount, dataToCall) - ); - gateway.depositERC20AndCall(address(l1Token), recipient, amount, dataToCall, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC20Gateway.RefundERC20(address(l1Token), address(this), amount); - - uint256 balance = l1Token.balanceOf(address(this)); - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), 0, 0, message); - assertEq(balance + amount, l1Token.balanceOf(address(this))); - } - function test_onDropMessage_beforeDropMessage_reverts() public { uint256 amount = 1000; diff --git a/contracts/contracts/test/L1ERC1155Gateway.t.sol b/contracts/contracts/test/L1ERC1155Gateway.t.sol index b81e9270..18fc2f8a 100644 --- a/contracts/contracts/test/L1ERC1155Gateway.t.sol +++ b/contracts/contracts/test/L1ERC1155Gateway.t.sol @@ -157,70 +157,6 @@ contract L1ERC1155GatewayTest is L1GatewayBaseTest, ERC1155TokenReceiver { _testBatchDepositERC1155WithRecipient(tokenCount, amount, recipient, gasLimit, feePerGas); } - function test_dropMessage_succeeds(uint256 tokenId, uint256 amount) public { - gateway.updateTokenMapping(address(l1Token), address(l2Token)); - - tokenId = bound(tokenId, 0, TOKEN_COUNT - 1); - amount = bound(amount, 1, MAX_TOKEN_BALANCE); - bytes memory message = abi.encodeCall( - IL2ERC1155Gateway.finalizeDepositERC1155, - (address(l1Token), address(l2Token), address(this), address(this), tokenId, amount) - ); - gateway.depositERC1155(address(l1Token), tokenId, amount, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC1155Gateway.RefundERC1155(address(l1Token), address(this), tokenId, amount); - - uint256 balance = l1Token.balanceOf(address(this), tokenId); - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), 0, 0, message); - assertEq(balance + amount, l1Token.balanceOf(address(this), tokenId)); - } - - function test_dropMessageBatch_succeeds(uint256 tokenCount, uint256 amount) public { - tokenCount = bound(tokenCount, 1, TOKEN_COUNT); - amount = bound(amount, 1, MAX_TOKEN_BALANCE); - gateway.updateTokenMapping(address(l1Token), address(l2Token)); - - uint256[] memory _tokenIds = new uint256[](tokenCount); - uint256[] memory _amounts = new uint256[](tokenCount); - for (uint256 i = 0; i < tokenCount; i++) { - _tokenIds[i] = i; - _amounts[i] = amount; - } - - bytes memory message = abi.encodeCall( - IL2ERC1155Gateway.finalizeBatchDepositERC1155, - (address(l1Token), address(l2Token), address(this), address(this), _tokenIds, _amounts) - ); - gateway.batchDepositERC1155(address(l1Token), _tokenIds, _amounts, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC1155Gateway.BatchRefundERC1155(address(l1Token), address(this), _tokenIds, _amounts); - - uint256[] memory balances = new uint256[](tokenCount); - for (uint256 i = 0; i < tokenCount; i++) { - balances[i] = l1Token.balanceOf(address(this), _tokenIds[i]); - } - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), 0, 0, message); - for (uint256 i = 0; i < tokenCount; i++) { - assertEq(balances[i] + _amounts[i], l1Token.balanceOf(address(this), _tokenIds[i])); - } - } - function test_onDropMessage_revert(uint256 tokenId, uint256 amount) external { gateway.updateTokenMapping(address(l1Token), address(l2Token)); tokenId = bound(tokenId, 0, TOKEN_COUNT - 1); diff --git a/contracts/contracts/test/L1ERC721Gateway.t.sol b/contracts/contracts/test/L1ERC721Gateway.t.sol index 17db63c8..b71e36b6 100644 --- a/contracts/contracts/test/L1ERC721Gateway.t.sol +++ b/contracts/contracts/test/L1ERC721Gateway.t.sol @@ -174,65 +174,6 @@ contract L1ERC721GatewayTest is L1GatewayBaseTest, ERC721TokenReceiver { _testBatchDepositERC721WithRecipient(tokenCount, recipient, gasLimit, feePerGas); } - function test_dropMessage_succeeds(uint256 tokenId) public { - gateway.updateTokenMapping(address(l1Token), address(l2Token)); - - tokenId = bound(tokenId, 0, TOKEN_COUNT - 1); - bytes memory message = abi.encodeCall( - IL2ERC721Gateway.finalizeDepositERC721, - (address(l1Token), address(l2Token), address(this), address(this), tokenId) - ); - gateway.depositERC721(address(l1Token), tokenId, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC721Gateway.RefundERC721(address(l1Token), address(this), tokenId); - - assertEq(l1Token.ownerOf(tokenId), address(gateway)); - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), 0, 0, message); - assertEq(l1Token.ownerOf(tokenId), address(this)); - } - - function test_dropMessageBatch_succeeds(uint256 tokenCount) public { - tokenCount = bound(tokenCount, 1, TOKEN_COUNT); - gateway.updateTokenMapping(address(l1Token), address(l2Token)); - - uint256[] memory _tokenIds = new uint256[](tokenCount); - for (uint256 i = 0; i < tokenCount; i++) { - _tokenIds[i] = i; - } - - bytes memory message = abi.encodeCall( - IL2ERC721Gateway.finalizeBatchDepositERC721, - (address(l1Token), address(l2Token), address(this), address(this), _tokenIds) - ); - gateway.batchDepositERC721(address(l1Token), _tokenIds, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC721Gateway.BatchRefundERC721(address(l1Token), address(this), _tokenIds); - for (uint256 i = 0; i < tokenCount; i++) { - assertEq(l1Token.ownerOf(_tokenIds[i]), address(gateway)); - } - - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), 0, 0, message); - for (uint256 i = 0; i < tokenCount; i++) { - assertEq(l1Token.ownerOf(_tokenIds[i]), address(this)); - } - } - function test_finalizeWithdrawERC721_counterError_fails(address sender, address recipient, uint256 tokenId) public { hevm.assume(recipient != address(0)); tokenId = bound(tokenId, 0, TOKEN_COUNT - 1); diff --git a/contracts/contracts/test/L1ETHGateway.t.sol b/contracts/contracts/test/L1ETHGateway.t.sol index 488e2777..d7e979b4 100644 --- a/contracts/contracts/test/L1ETHGateway.t.sol +++ b/contracts/contracts/test/L1ETHGateway.t.sol @@ -167,35 +167,6 @@ contract L1ETHGatewayTest is L1GatewayBaseTest { _depositETHWithRecipientAndCalldata(true, amount, recipient, dataToCall, gasLimit, feePerGas); } - function test_dropMessage_succeeds(uint256 amount, address recipient, bytes memory dataToCall) public { - amount = bound(amount, 1, address(this).balance); - bytes memory message = abi.encodeCall( - IL2ETHGateway.finalizeDepositETH, - (address(this), recipient, amount, dataToCall) - ); - l1ETHGateway.depositETHAndCall{value: amount}(recipient, amount, dataToCall, defaultGasLimit); - - // pop message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // ETH transfer failed, revert - revertOnReceive = true; - hevm.expectRevert("ETH transfer failed"); - l1CrossDomainMessenger.dropMessage(address(l1ETHGateway), address(counterpartGateway), amount, 0, message); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ETHGateway.RefundETH(address(this), amount); - - revertOnReceive = false; - uint256 balance = address(this).balance; - l1CrossDomainMessenger.dropMessage(address(l1ETHGateway), address(counterpartGateway), amount, 0, message); - assertEq(balance + amount, address(this).balance); - } - function test_finalizeWithdrawETH_counterErr_fails( address sender, address recipient, diff --git a/contracts/contracts/test/L1MessageQueue.t.sol b/contracts/contracts/test/L1MessageQueue.t.sol index 2620f2e6..c11fa8f3 100644 --- a/contracts/contracts/test/L1MessageQueue.t.sol +++ b/contracts/contracts/test/L1MessageQueue.t.sol @@ -238,78 +238,6 @@ contract L1MessageQueueTest is L1MessageBaseTest { l1MessageQueue.popCrossDomainMessage(1, 2); } - function test_dropCrossDomainMessage_cannotDropPending_reverts() external { - bytes memory _calldata = "0x0"; - uint256 gasLimit = l1MessageQueue.calculateIntrinsicGasFee(_calldata); - - // Store alice as messenger and rollup. - upgradeStorage(address(alice), address(alice), address(alice)); - - // Expect revert when (_index < pendingQueueIndex) is false. - hevm.prank(alice); - l1MessageQueue.appendCrossDomainMessage(alice, gasLimit, _calldata); - hevm.prank(alice); - hevm.expectRevert("cannot drop pending message"); - l1MessageQueue.dropCrossDomainMessage(0); - } - - function test_pop_dropCrossDomainMessage_succeeds() external { - // store alice as messenger and rollup - upgradeStorage(address(alice), address(alice), address(alice)); - assertEq(alice, l1MessageQueue.MESSENGER()); - assertEq(alice, l1MessageQueue.ROLLUP_CONTRACT()); - bytes memory _calldata = "0x0"; - uint256 gasLimit = l1MessageQueue.calculateIntrinsicGasFee(_calldata); - // append 10 message - hevm.startPrank(alice); - for (uint64 i = 0; i < 10; i++) { - l1MessageQueue.appendCrossDomainMessage(alice, gasLimit, _calldata); - } - - // Verify the event QueueTransaction is emitted successfully. - hevm.expectEmit(false, false, false, true); - emit IL1MessageQueue.DequeueTransaction(0, 10); - - // pop all 10 message - l1MessageQueue.popCrossDomainMessage(0, 10); - - // drop all 10 message - for (uint64 i = 0; i < 10; i++) { - l1MessageQueue.dropCrossDomainMessage(i); - assertTrue(l1MessageQueue.isMessageDropped(i)); - } - hevm.stopPrank(); - } - - function test_dropCrossDomainMessage_dropAgain_reverts() external { - // store alice as messenger and rollup - upgradeStorage(address(alice), address(alice), address(alice)); - assertEq(alice, l1MessageQueue.MESSENGER()); - assertEq(alice, l1MessageQueue.ROLLUP_CONTRACT()); - bytes memory _calldata = "0x0"; - uint256 gasLimit = l1MessageQueue.calculateIntrinsicGasFee(_calldata); - // append 10 message - hevm.startPrank(alice); - for (uint64 i = 0; i < 10; i++) { - l1MessageQueue.appendCrossDomainMessage(alice, gasLimit, _calldata); - } - - // pop all 10 message - l1MessageQueue.popCrossDomainMessage(0, 10); - - // drop all 10 message - for (uint64 i = 0; i < 10; i++) { - l1MessageQueue.dropCrossDomainMessage(i); - assertTrue(l1MessageQueue.isMessageDropped(i)); - } - hevm.stopPrank(); - - // Expect revert when message already dropped. - hevm.prank(alice); - hevm.expectRevert("message already dropped"); - l1MessageQueue.dropCrossDomainMessage(1); - } - function test_updateMaxGasLimit_notOwner_reverts() external { // Verify the modifier onlyOwner works successfully. // It throws an error "Ownable: caller is not the owner" when msg.sender is not the owner. diff --git a/contracts/contracts/test/L1StandardERC20Gateway.t.sol b/contracts/contracts/test/L1StandardERC20Gateway.t.sol index 00bbe5e6..d9440daf 100644 --- a/contracts/contracts/test/L1StandardERC20Gateway.t.sol +++ b/contracts/contracts/test/L1StandardERC20Gateway.t.sol @@ -287,40 +287,6 @@ contract L1StandardERC20GatewayTest is L1GatewayBaseTest { assertEq(balanceBefore + amount - fee, balanceAfter); } - function test_dropMessage_succeeds(uint256 amount, address recipient, bytes memory dataToCall) public { - amount = bound(amount, 1, l1Token.balanceOf(address(this)) / 2); - bytes memory message = abi.encodeCall( - IL2ERC20Gateway.finalizeDepositERC20, - ( - address(l1Token), - address(l2Token), - address(this), - recipient, - amount, - abi.encode( - true, - abi.encode(dataToCall, abi.encode(l1Token.symbol(), l1Token.name(), l1Token.decimals())) - ) - ) - ); - l1StandardERC20Gateway.depositERC20AndCall(address(l1Token), recipient, amount, dataToCall, defaultGasLimit); - l1StandardERC20Gateway.depositERC20AndCall(address(l1Token), recipient, amount, dataToCall, defaultGasLimit); - - // pop message 0 and 1 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 2); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 2); - hevm.stopPrank(); - - // drop message 1 - hevm.expectEmit(true, true, false, true); - emit IL1ERC20Gateway.RefundERC20(address(l1Token), address(this), amount); - - uint256 balance = l1Token.balanceOf(address(this)); - l1CrossDomainMessenger.dropMessage(address(l1StandardERC20Gateway), address(counterpartGateway), 0, 1, message); - assertEq(balance + amount, l1Token.balanceOf(address(this))); - } - function test_finalizeWithdrawERC20_beforeFinalizeWithdrawERC20_reverts() public { address recipient = address(2048); address _from = address(counterpartGateway); diff --git a/contracts/contracts/test/L1WETHGateway.t.sol b/contracts/contracts/test/L1WETHGateway.t.sol index f4de6bac..1a8aa309 100644 --- a/contracts/contracts/test/L1WETHGateway.t.sol +++ b/contracts/contracts/test/L1WETHGateway.t.sol @@ -197,29 +197,6 @@ contract L1WETHGatewayTest is L1GatewayBaseTest { _depositERC20WithRecipientAndCalldata(true, amount, recipient, dataToCall, gasLimit, feePerGas); } - function test_dropMessage_succeeds(uint256 amount, address recipient, bytes memory dataToCall) public { - amount = bound(amount, 1, l1weth.balanceOf(address(this))); - bytes memory message = abi.encodeCall( - IL2ERC20Gateway.finalizeDepositERC20, - (address(l1weth), address(l2weth), address(this), recipient, amount, dataToCall) - ); - gateway.depositERC20AndCall(address(l1weth), recipient, amount, dataToCall, defaultGasLimit); - - // skip message 0 - hevm.startPrank(address(rollup)); - l1MessageQueueWithGasPriceOracle.popCrossDomainMessage(0, 1); - assertEq(l1MessageQueueWithGasPriceOracle.pendingQueueIndex(), 1); - hevm.stopPrank(); - - // drop message 0 - hevm.expectEmit(true, true, false, true); - emit IL1ERC20Gateway.RefundERC20(address(l1weth), address(this), amount); - - uint256 balance = l1weth.balanceOf(address(this)); - l1CrossDomainMessenger.dropMessage(address(gateway), address(counterpartGateway), amount, 0, message); - assertEq(balance + amount, l1weth.balanceOf(address(this))); - } - function test_finalizeWithdrawERC20_counterErr_fails( address sender, address recipient,