Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zp/update mockrouter #1427

Merged
merged 7 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ MerkleMultiProofTest:test_MerkleRootSingleLeaf_Success() (gas: 3649)
MerkleMultiProofTest:test_SpecSync_gas() (gas: 34123)
MockRouterTest:test_ccipSendWithInsufficientNativeTokens_Revert() (gas: 34019)
MockRouterTest:test_ccipSendWithInvalidMsgValue_Revert() (gas: 60812)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126480)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126540)
MockRouterTest:test_ccipSendWithLinkFeeTokenbutInsufficientAllowance_Revert() (gas: 63419)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 43952)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 44012)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigsBothLanes_Success() (gas: 132457)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigs_Success() (gas: 313023)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_OnlyCallableByOwner_Revert() (gas: 17750)
Expand Down
15 changes: 13 additions & 2 deletions contracts/src/v0.8/ccip/test/mocks/MockRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@ contract MockCCIPRouter is IRouter, IRouterClient {
uint256 gasLimit,
address receiver
) internal returns (bool success, bytes memory retData, uint256 gasUsed) {
// Only send through the router if the receiver is a contract and implements the IAny2EVMMessageReceiver interface.
if (receiver.code.length == 0 || !receiver.supportsInterface(type(IAny2EVMMessageReceiver).interfaceId)) {
// There are three cases in which we skip calling the receiver:
// 1. If the message data is empty AND the gas limit is 0.
// This indicates a message that only transfers tokens. It is valid to only send tokens to a contract
// that supports the IAny2EVMMessageReceiver interface, but without this first check we would call the
// receiver without any gas, which would revert the transaction.
// 2. If the receiver is not a contract.
// 3. If the receiver is a contract but it does not support the IAny2EVMMessageReceiver interface.
//
// The ordering of these checks is important, as the first check is the cheapest to execute.
if (
(message.data.length == 0 && gasLimit == 0) || receiver.code.length == 0
|| !receiver.supportsInterface(type(IAny2EVMMessageReceiver).interfaceId)
) {
return (true, "", 0);
}

Expand Down
Loading