Skip to content

Commit

Permalink
CCIP-4288 Refactor MockCCIPRouter to support EVMExtraArgsV2 (#15301)
Browse files Browse the repository at this point in the history
* feat: refactor MockCCIPRouter to support EVMExtraArgsV2

* chore: commit changeset

* CCIP-4288 add changeset
  • Loading branch information
andrejrakic authored and RensR committed Nov 28, 2024
1 parent 75b1a6f commit 78704d3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
7 changes: 7 additions & 0 deletions contracts/.changeset/wet-eyes-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@chainlink/contracts': patch
---

Refactor MockCCIPRouter to support EVMExtraArgsV2

PR issue : CCIP-4288
11 changes: 7 additions & 4 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ MerkleMultiProofTest:test_EmptyLeaf_Revert() (gas: 3585)
MerkleMultiProofTest:test_MerkleRoot256() (gas: 394891)
MerkleMultiProofTest:test_MerkleRootSingleLeaf_Success() (gas: 3661)
MerkleMultiProofTest:test_SpecSync_gas() (gas: 34129)
MockRouterTest:test_ccipSendWithEVMExtraArgsV1_Success() (gas: 110073)
MockRouterTest:test_ccipSendWithEVMExtraArgsV2_Success() (gas: 132614)
MockRouterTest:test_ccipSendWithInsufficientNativeTokens_Revert() (gas: 34037)
MockRouterTest:test_ccipSendWithInvalidMsgValue_Revert() (gas: 60842)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126576)
MockRouterTest:test_ccipSendWithLinkFeeTokenbutInsufficientAllowance_Revert() (gas: 63455)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 44012)
MockRouterTest:test_ccipSendWithInvalidEVMExtraArgs_Revert() (gas: 106684)
MockRouterTest:test_ccipSendWithInvalidMsgValue_Revert() (gas: 60886)
MockRouterTest:test_ccipSendWithLinkFeeTokenAndValidMsgValue_Success() (gas: 126640)
MockRouterTest:test_ccipSendWithLinkFeeTokenButInsufficientAllowance_Revert() (gas: 63478)
MockRouterTest:test_ccipSendWithSufficientNativeFeeTokens_Success() (gas: 44048)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigsBothLanes_Success() (gas: 133528)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_MultipleConfigs_Success() (gas: 315630)
MultiAggregateRateLimiter_applyRateLimiterConfigUpdates:test_OnlyCallableByOwner_Revert() (gas: 17864)
Expand Down
17 changes: 13 additions & 4 deletions contracts/src/v0.8/ccip/test/mocks/MockRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ contract MockCCIPRouter is IRouter, IRouterClient {
return mockMsgId;
}

function _fromBytes(bytes calldata extraArgs) internal pure returns (Client.EVMExtraArgsV1 memory) {
function _fromBytes(
bytes calldata extraArgs
) internal pure returns (Client.EVMExtraArgsV2 memory) {
if (extraArgs.length == 0) {
return Client.EVMExtraArgsV1({gasLimit: DEFAULT_GAS_LIMIT});
return Client.EVMExtraArgsV2({gasLimit: DEFAULT_GAS_LIMIT, allowOutOfOrderExecution: false});
}
if (bytes4(extraArgs) != Client.EVM_EXTRA_ARGS_V1_TAG) revert InvalidExtraArgsTag();
return abi.decode(extraArgs[4:], (Client.EVMExtraArgsV1));

bytes4 extraArgsTag = bytes4(extraArgs);
if (extraArgsTag == Client.EVM_EXTRA_ARGS_V2_TAG) {
return abi.decode(extraArgs[4:], (Client.EVMExtraArgsV2));
} else if (extraArgsTag == Client.EVM_EXTRA_ARGS_V1_TAG) {
return Client.EVMExtraArgsV2({gasLimit: abi.decode(extraArgs[4:], (uint256)), allowOutOfOrderExecution: false});
}

revert InvalidExtraArgsTag();
}

/// @notice Always returns true to make sure this check can be performed on any chain.
Expand Down
22 changes: 21 additions & 1 deletion contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract MockRouterTest is TokenSetup {
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithLinkFeeTokenbutInsufficientAllowance_Revert() public {
function test_ccipSendWithLinkFeeTokenButInsufficientAllowance_Revert() public {
message.feeToken = s_sourceFeeToken;

vm.expectRevert(bytes("ERC20: insufficient allowance"));
Expand All @@ -65,4 +65,24 @@ contract MockRouterTest is TokenSetup {

mockRouter.ccipSend(mockChainSelector, message);
}

function test_ccipSendWithEVMExtraArgsV1_Success() public {
Client.EVMExtraArgsV1 memory extraArgs = Client.EVMExtraArgsV1({gasLimit: 500_000});
message.extraArgs = Client._argsToBytes(extraArgs);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithEVMExtraArgsV2_Success() public {
Client.EVMExtraArgsV2 memory extraArgs = Client.EVMExtraArgsV2({gasLimit: 500_000, allowOutOfOrderExecution: true});
message.extraArgs = Client._argsToBytes(extraArgs);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}

function test_ccipSendWithInvalidEVMExtraArgs_Revert() public {
uint256 gasLimit = 500_000;
bytes4 invalidExtraArgsTag = bytes4(keccak256("CCIP EVMExtraArgsInvalid"));
message.extraArgs = abi.encodeWithSelector(invalidExtraArgsTag, gasLimit);
vm.expectRevert(MockCCIPRouter.InvalidExtraArgsTag.selector);
mockRouter.ccipSend{value: 0.1 ether}(mockChainSelector, message);
}
}

0 comments on commit 78704d3

Please sign in to comment.