Skip to content

Commit

Permalink
feat: Simplify CCIPLocalSimulator.sol using MockRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejrakic committed Apr 16, 2024
1 parent 0fdd6b0 commit b8e5d15
Show file tree
Hide file tree
Showing 16 changed files with 2,931 additions and 712 deletions.
2,700 changes: 2,416 additions & 284 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"hardhat": "^2.20.1"
},
"dependencies": {
"@chainlink/contracts-ccip": "^1.2.1"
"@chainlink/contracts-ccip": "^1.4.0"
}
}
437 changes: 37 additions & 400 deletions src/ccip/CCIPLocalSimulator.sol

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/ccip/CCIPLocalSimulatorFork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ pragma solidity 0.8.19;

import {Test, Vm} from "forge-std/Test.sol";
import {Register} from "./Register.sol";
import {Internal, Router} from "./CCIPLocalSimulator.sol";
import {Router} from "@chainlink/contracts-ccip/src/v0.8/ccip/Router.sol";
import {Internal} from "@chainlink/contracts-ccip/src/v0.8/ccip/onRamp/EVM2EVMOnRamp.sol";
import {EVM2EVMOffRamp} from "@chainlink/contracts-ccip/src/v0.8/ccip/offRamp/EVM2EVMOffRamp.sol";
import {IERC20} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

// @notice Works with Foundry only
contract CCIPLocalSimulatorFork is Test {
Expand Down
449 changes: 449 additions & 0 deletions src/ccip/CCIPLocalSimulatorV0.sol

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/ccip/MockEvm2EvmOffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {EnumerableMapAddresses} from "@chainlink/contracts-ccip/src/v0.8/shared/
import {RateLimiter} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/RateLimiter.sol";
import {USDPriceWith18Decimals} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/USDPriceWith18Decimals.sol";
import {AggregateRateLimiter} from "@chainlink/contracts-ccip/src/v0.8/ccip/AggregateRateLimiter.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {Address} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/utils/Address.sol";
import {ERC165Checker} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/utils/introspection/ERC165Checker.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {Address} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/utils/Address.sol";
import {ERC165Checker} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/utils/introspection/ERC165Checker.sol";

contract MockEvm2EvmOffRamp is AggregateRateLimiter {
using EnumerableMapAddresses for EnumerableMapAddresses.AddressToAddressMap;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ccip/BasicTokenSender.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/test/ccip/CCIPSender_Unsafe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.19;

import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract CCIPSender_Unsafe {
address link;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ccip/Ping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.19;

import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";

contract Ping is CCIPReceiver {
Expand All @@ -27,7 +27,7 @@ contract Ping is CCIPReceiver {
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: Client._argsToBytes(
// Additional arguments, setting gas limit
Client.EVMExtraArgsV1({gasLimit: 2_500_000})
Client.EVMExtraArgsV1({gasLimit: 500_000})
),
feeToken: link
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/ccip/Pong.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.19;

import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";

contract Pong is CCIPReceiver {
Expand Down
21 changes: 10 additions & 11 deletions src/test/ccip/ProgrammableDefensiveTokenTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/O
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableMap} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/utils/structs/EnumerableMap.sol";
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableMap.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand All @@ -37,9 +37,8 @@ contract ProgrammableDefensiveTokenTransfers is CCIPReceiver, OwnerIsCreator {
error MessageNotFailed(bytes32 messageId);

// Example error code, could have many different error codes.
enum ErrorCode
// RESOLVED is first so that the default value is resolved.
{
enum ErrorCode {
// RESOLVED is first so that the default value is resolved.
RESOLVED,
// Could have any number of error codes here.
FAILED
Expand All @@ -58,7 +57,8 @@ contract ProgrammableDefensiveTokenTransfers is CCIPReceiver, OwnerIsCreator {
// The token amount that was transferred.
// the token address used to pay CCIP fees.
// The fees paid for sending the message.
event MessageSent( // The unique ID of the CCIP message.
// The unique ID of the CCIP message.
event MessageSent(
bytes32 indexed messageId,
uint64 indexed destinationChainSelector,
address receiver,
Expand All @@ -75,7 +75,8 @@ contract ProgrammableDefensiveTokenTransfers is CCIPReceiver, OwnerIsCreator {
// The text that was received.
// The token address that was transferred.
// The token amount that was transferred.
event MessageReceived( // The unique ID of the CCIP message.
// The unique ID of the CCIP message.
event MessageReceived(
bytes32 indexed messageId,
uint64 indexed sourceChainSelector,
address sender,
Expand Down Expand Up @@ -309,9 +310,7 @@ contract ProgrammableDefensiveTokenTransfers is CCIPReceiver, OwnerIsCreator {

// Calculate the actual number of items to return (can't exceed total length or requested limit)
uint256 returnLength = (offset + limit > length) ? length - offset : limit;
FailedMessage[] memory failedMessages = new FailedMessage[](
returnLength
);
FailedMessage[] memory failedMessages = new FailedMessage[](returnLength);

// Adjust loop to respect pagination (start at offset, end at offset + limit or total length)
for (uint256 i = 0; i < returnLength; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ccip/ProgrammableTokenTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ccip/TokenTransferor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.19;
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
Expand Down
3 changes: 2 additions & 1 deletion test/smoke/ccip/PayWithNative.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.19;

import {Test, console2} from "forge-std/Test.sol";
import {BasicTokenSender} from "../../../src/test/ccip/BasicTokenSender.sol";
import {CCIPLocalSimulator, Router, BurnMintERC677Helper, Client} from "@chainlink/local/src/ccip/CCIPLocalSimulator.sol";
import {CCIPLocalSimulator, Router, BurnMintERC677Helper} from "@chainlink/local/src/ccip/CCIPLocalSimulator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";

contract PayWithNativeTest is Test {
CCIPLocalSimulator public ccipLocalSimulator;
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/ccip/ProgrammableTokenTransfers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract ProgrammableTokenTransfersTest is Test {
ccipBnM = ccipBnM_;
}

function testSmoke() public {
function testProgrammableTokenTransfer() public {
uint256 amountToSend = 0.001 ether;
uint256 amountForFees = 1 ether;
string memory textToSend = "Hello World";
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/ccip/TokenTransferor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract TokenTransferorTest is Test {
ccipBnM = ccipBnM_;
}

function testSmoke() public {
function testTokenTransfer() public {
uint256 amountToSend = 0.001 ether;
uint256 amountForFees = 1 ether;
address receiver = msg.sender;
Expand Down

0 comments on commit b8e5d15

Please sign in to comment.