Skip to content

Commit

Permalink
feat(evm): more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Oct 17, 2024
1 parent 8a867ac commit d3331bc
Show file tree
Hide file tree
Showing 2 changed files with 262 additions and 6 deletions.
247 changes: 247 additions & 0 deletions evm/tests/src/04-channel/IBCPacket.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,54 @@ contract IBCPacketTests is Test {
test_recvPacket_ok(sourceChannel, message, 1);
}

function test_recvPacket_ok_5(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 5);
}

function test_recvPacket_ok_10(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 10);
}

function test_recvPacket_ok_15(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 15);
}

function test_recvPacket_ok_20(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 20);
}

function test_recvPacket_ok_25(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 25);
}

function test_recvPacket_ok_30(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvPacket_ok(sourceChannel, message, 30);
}

function test_recvPacket_ok(
uint32 sourceChannel,
bytes calldata message,
Expand Down Expand Up @@ -382,6 +430,54 @@ contract IBCPacketTests is Test {
test_recvIntentPacket_ok(sourceChannel, message, 1);
}

function test_recvIntentPacket_ok_5(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 5);
}

function test_recvIntentPacket_ok_10(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 10);
}

function test_recvIntentPacket_ok_15(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 15);
}

function test_recvIntentPacket_ok_20(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 20);
}

function test_recvIntentPacket_ok_25(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 25);
}

function test_recvIntentPacket_ok_30(
uint32 sourceChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_recvIntentPacket_ok(sourceChannel, message, 30);
}

function test_recvIntentPacket_ok(
uint32 sourceChannel,
bytes calldata message,
Expand All @@ -402,6 +498,7 @@ contract IBCPacketTests is Test {
}
vm.resumeGasMetering();
handler.recvIntentPacket(msg_);
vm.pauseGasMetering();
}

function test_recvIntentPacket_commitmentSaved(
Expand Down Expand Up @@ -520,6 +617,54 @@ contract IBCPacketTests is Test {
test_acknowledgePacket_ok(destinationChannel, message, 1);
}

function test_acknowledgePacket_ok_5(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 5);
}

function test_acknowledgePacket_ok_10(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 10);
}

function test_acknowledgePacket_ok_15(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 15);
}

function test_acknowledgePacket_ok_20(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 20);
}

function test_acknowledgePacket_ok_25(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 25);
}

function test_acknowledgePacket_ok_30(
uint32 destinationChannel,
bytes calldata message
) public {
vm.pauseGasMetering();
test_acknowledgePacket_ok(destinationChannel, message, 30);
}

function test_acknowledgePacket_tampered(
uint32 destinationChannel,
bytes calldata message,
Expand Down Expand Up @@ -929,6 +1074,22 @@ contract IBCPacketTests is Test {
return packets;
}

function test_batchSend_ok_2(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 2);
}

function test_batchSend_ok_5(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 5);
}

function test_batchSend_ok_10(
uint64 timeoutTimestamp,
uint64 timeoutHeight
Expand All @@ -937,6 +1098,38 @@ contract IBCPacketTests is Test {
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 10);
}

function test_batchSend_ok_15(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 15);
}

function test_batchSend_ok_20(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 20);
}

function test_batchSend_ok_25(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 25);
}

function test_batchSend_ok_30(
uint64 timeoutTimestamp,
uint64 timeoutHeight
) public {
vm.pauseGasMetering();
test_batchSend_ok(timeoutTimestamp, timeoutHeight, 30);
}

function test_batchSend_commitmentSaved(
uint64 timeoutTimestamp,
uint64 timeoutHeight,
Expand Down Expand Up @@ -1018,6 +1211,24 @@ contract IBCPacketTests is Test {
return (msg_, acks);
}

function test_batchAcks_afterRecvPacket_ok_2(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 2, ack);
}

function test_batchAcks_afterRecvPacket_ok_5(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 5, ack);
}

function test_batchAcks_afterRecvPacket_ok_10(
uint32 sourceChannel,
bytes calldata message,
Expand All @@ -1027,6 +1238,42 @@ contract IBCPacketTests is Test {
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 10, ack);
}

function test_batchAcks_afterRecvPacket_ok_15(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 15, ack);
}

function test_batchAcks_afterRecvPacket_ok_20(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 20, ack);
}

function test_batchAcks_afterRecvPacket_ok_25(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 25, ack);
}

function test_batchAcks_afterRecvPacket_ok_30(
uint32 sourceChannel,
bytes calldata message,
bytes calldata ack
) public {
vm.pauseGasMetering();
test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 30, ack);
}

function test_batchAcks_afterRecvPacket_commitmentSaved(
uint32 sourceChannel,
bytes calldata message,
Expand Down
21 changes: 15 additions & 6 deletions evm/tests/src/core/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ pragma solidity ^0.8.27;

import "../../../contracts/core/25-handler/IBCHandler.sol";
import "../../../contracts/apps/Base.sol";
import "forge-std/Test.sol";

library TestModuleLib {
bytes public constant ACKNOWLEDGEMENT = hex"BEEF";
}

contract TestModule is IBCAppBase {
contract TestModule is IBCAppBase, Test {
IBCHandler private immutable ibcHandler;

bool ack;
Expand Down Expand Up @@ -44,18 +45,26 @@ contract TestModule is IBCAppBase {
address,
bytes calldata
) external virtual override onlyIBC returns (bytes memory) {
if (!ack) {
return hex"";
} else {
return ackValue;
vm.pauseGasMetering();
bytes memory v = hex"";
if (ack) {
v = ackValue;
}
vm.resumeGasMetering();
return v;
}

function onRecvIntentPacket(
IBCPacket calldata,
address,
bytes calldata
) external virtual override onlyIBC returns (bytes memory) {
return ackValue;
vm.pauseGasMetering();
bytes memory v = hex"";
if (ack) {
v = ackValue;
}
vm.resumeGasMetering();
return v;
}
}

0 comments on commit d3331bc

Please sign in to comment.