Skip to content

Commit

Permalink
fix forge test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukoomomo committed Dec 18, 2024
1 parent b47dba3 commit b99831d
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 371 deletions.
65 changes: 0 additions & 65 deletions contracts/contracts/test/L1CrossDomainMessenger.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 0 additions & 25 deletions contracts/contracts/test/L1CustomERC20Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
64 changes: 0 additions & 64 deletions contracts/contracts/test/L1ERC1155Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 0 additions & 59 deletions contracts/contracts/test/L1ERC721Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 0 additions & 29 deletions contracts/contracts/test/L1ETHGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
72 changes: 0 additions & 72 deletions contracts/contracts/test/L1MessageQueue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit b99831d

Please sign in to comment.