Skip to content

Commit

Permalink
Merge pull request #442 from superform-xyz/coverage-crosschain-data
Browse files Browse the repository at this point in the history
chore: add more tests for `crosschain-data`
  • Loading branch information
0xTimepunk authored Jan 18, 2024
2 parents ab55073 + 31a898f commit ec24b9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/fuzz/crosschain-data/adapters/HyperlaneImplementation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,30 @@ contract HyperlaneImplementationTest is CommonProtocolActions {
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
hyperlaneImplementation.estimateFees(100, "", "");
}

function test_dispatchPayload_InvalidChainId() public {
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
vm.prank(getContract(ETH, "CoreStateRegistry"));
hyperlaneImplementation.dispatchPayload(deployer, 420, bytes("hi test"), "");
}

function test_retryPayload_InvalidRetryFee() public {
uint32 destination = 10;
bytes32 messageId = 0x024a45f20750393b28c9aac33aafc694857b6d09e9da4a8ed9f2b0e144685348;

vm.prank(deployer);
/// @dev note these values don't make sense, should be estimated properly
uint256 fees = hyperlaneImplementation.igp().quoteGasPayment(destination, 1_500_000);
vm.expectRevert(Error.INVALID_RETRY_FEE.selector);
hyperlaneImplementation.retryPayload{ value: fees - 100 wei }(abi.encode(messageId, destination, 1_500_000));
}

function test_handle_InvalidChainId() public {
vm.prank(address(hyperlaneImplementation.mailbox()));
AMBMessage memory ambMessage;
ambMessage.txInfo = DataLib.packTxInfo(0, 0, 0, 1, address(0), 0);

vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
hyperlaneImplementation.handle(0, bytes32(uint256(uint160(address(0)))), abi.encode(ambMessage));
}
}
23 changes: 23 additions & 0 deletions test/fuzz/crosschain-data/adapters/LayerzeroImplementation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,27 @@ contract LayerzeroImplementationTest is BaseSetup {

return (ambMessage, ambExtraData, coreStateRegistry);
}

function test_isTrustedRemote_InvalidChainId() public {
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
layerzeroImplementation.isTrustedRemote(0, bytes("hello"));
}

function test_dispatchPayloadInvalidChainId() public {
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
vm.prank(getContract(ETH, "CoreStateRegistry"));
layerzeroImplementation.dispatchPayload(deployer, 420, bytes("hi test"), "");
}

function test_lzReceive_InvalidChainId() public {
vm.prank(deployer);
layerzeroImplementation.setTrustedRemote(0, bytes("test"));

vm.prank(address(layerzeroImplementation.lzEndpoint()));
AMBMessage memory ambMessage;
ambMessage.txInfo = DataLib.packTxInfo(0, 0, 0, 1, address(0), 0);

layerzeroImplementation.lzReceive(0, bytes("test"), 420, abi.encode(ambMessage));
assertGt(layerzeroImplementation.failedMessages(0, bytes("test"), 420).length, 0);
}
}

0 comments on commit ec24b9a

Please sign in to comment.