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

Refactor MockCCIPRouter to support EVMExtraArgsV2 #1532

Open
wants to merge 8 commits into
base: ccip-develop
Choose a base branch
from
16 changes: 12 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,20 @@ 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
20 changes: 20 additions & 0 deletions contracts/src/v0.8/ccip/test/mocks/test/MockRouterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading