Skip to content

Commit

Permalink
Add tests ORMP.t.sol (#129)
Browse files Browse the repository at this point in the history
5 New Tests!
  • Loading branch information
TradMod authored Mar 11, 2024
1 parent 5f935ec commit 3b6b499
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/ORMP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,54 @@ contract ORMPTest is Test, Verifier {
vm.chainId(2);
}

function test_Refunds() public {
uint256 f = ormp.fee(2, self, 0, "", "");
ormp.send{value: f+5}(2, self, 0, "", address(5), "");
assertEq(address(5).balance, 5);
}

function testFail_sendSameMsg() public {
uint256 f1 = ormp.fee(2, self, 0, "", "");
bytes32 msgHash1 = ormp.send{value: f1}(2, self, 0, "", self, "");

uint256 f2 = ormp.fee(2, self, 0, "", "");
bytes32 msgHash2 = ormp.send{value: f2}(2, self, 0, "", self, "");
vm.chainId(2);

assertEq(msgHash1, msgHash2);
}

function testFail_SendWithZeroNativeFee() public {
ormp.send{value: 0}(2, self, 0, "", address(5), "");
proof = Proof({blockNumber: block.number, messageIndex: ormp.messageCount() - 1, messageProof: ormp.prove()});
vm.chainId(2);
}

function test_recv() public {
perform_send();
bool r = ormp.recv(message, abi.encode(proof));
assertEq(r, false);
}

function testFail_recvTwice() public {
perform_send();
bool r = ormp.recv(message, abi.encode(proof));
assertEq(r, false);
ormp.recv(message, abi.encode(proof));
}

function test_failedMsgDispactedSuccess_PoC() public {
uint256 f = ormp.fee(2, self, 0, "", "");
ormp.send{value: f}(2, self, 0, "", self, "");
proof = Proof({blockNumber: block.number, messageIndex: ormp.messageCount() - 1, messageProof: ormp.prove()});

vm.chainId(2);

bool returnValue = ormp.recv(message, abi.encode(proof));
assertEq(returnValue, false); /// msg delivery failed
assertEq(ormp.dones(hash(message)), true); /// but marked dispatched
}

function fee(uint256, address) external pure returns (uint256) {
return 2;
}
Expand Down

0 comments on commit 3b6b499

Please sign in to comment.