Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsuryansh committed Dec 8, 2024
1 parent 3db41bf commit d1f8ec9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
11 changes: 7 additions & 4 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,13 @@ OffRamp_setDynamicConfig:test_FeeQuoterZeroAddress_Revert() (gas: 11465)
OffRamp_setDynamicConfig:test_NonOwner_Revert() (gas: 13975)
OffRamp_setDynamicConfig:test_SetDynamicConfigWithInterceptor_Success() (gas: 47491)
OffRamp_setDynamicConfig:test_SetDynamicConfig_Success() (gas: 25464)
OffRamp_trialExecute:test_trialExecute() (gas: 271771)
OffRamp_trialExecute:test_trialExecute_RateLimitError() (gas: 127497)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 138807)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 289492)
OffRamp_trialExecute:test_trialExecute() (gas: 271751)
OffRamp_trialExecute:test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() (gas: 60045)
OffRamp_trialExecute:test_trialExecute_RateLimitError() (gas: 127460)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() (gas: 65552)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() (gas: 65686)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 138682)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 289388)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy_Success() (gas: 251706)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 17227)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_Revert() (gas: 67101)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
i_rmnRemote = staticConfig.rmnRemote;
i_tokenAdminRegistry = staticConfig.tokenAdminRegistry;
i_nonceManager = staticConfig.nonceManager;

emit StaticConfigSet(staticConfig);

_setDynamicConfig(dynamicConfig);
_applySourceChainConfigUpdates(sourceChainConfigs);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {CallWithExactGas} from "../../../../shared/call/CallWithExactGas.sol";
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {MultiOCR3Base} from "../../../ocr/MultiOCR3Base.sol";
import {OffRamp} from "../../../offRamp/OffRamp.sol";
import {OffRampSetup} from "./OffRampSetup.t.sol";

import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract OffRamp_trialExecute is OffRampSetup {
function setUp() public virtual override {
super.setUp();
Expand Down Expand Up @@ -117,4 +118,75 @@ contract OffRamp_trialExecute is OffRampSetup {
assertEq(uint256(Internal.MessageExecutionState.FAILURE), uint256(newState));
assertEq(abi.encodeWithSelector(OffRamp.NotACompatiblePool.selector, address(0)), err);
}

function test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() public {
uint256[] memory amounts = new uint256[](2);
amounts[0] = 1000;
amounts[1] = 50;
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageWithTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1, amounts);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeWithSelector(s_offRamp.executeSingleMessage.selector, message, offchainTokenData, tokenGasOverrides),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);

IERC20 dstToken0 = IERC20(s_destTokens[0]);

(Internal.MessageExecutionState newState, bytes memory err) =
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
assertEq(uint256(Internal.MessageExecutionState.FAILURE), uint256(newState));
}

function test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() public {
uint256[] memory amounts = new uint256[](2);
amounts[0] = 1000;
amounts[1] = 50;
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageWithTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1, amounts);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeWithSelector(s_offRamp.executeSingleMessage.selector, message, offchainTokenData, tokenGasOverrides),
abi.encodeWithSelector(CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG, "")
);

IERC20 dstToken0 = IERC20(s_destTokens[0]);

vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
changePrank(address(1));
(Internal.MessageExecutionState newState, bytes memory err) =
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
}

function test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() public {
uint256[] memory amounts = new uint256[](2);
amounts[0] = 1000;
amounts[1] = 50;
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageWithTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1, amounts);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeWithSelector(s_offRamp.executeSingleMessage.selector, message, offchainTokenData, tokenGasOverrides),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);

IERC20 dstToken0 = IERC20(s_destTokens[0]);

vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
changePrank(address(1));
(Internal.MessageExecutionState newState, bytes memory err) =
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
}
}

0 comments on commit d1f8ec9

Please sign in to comment.