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

Add ccip message assertion to e2e tests #1584

Open
wants to merge 11 commits into
base: ccip-develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,70 @@ pragma solidity 0.8.24;

import {IAny2EVMMessageReceiver} from "../../../interfaces/IAny2EVMMessageReceiver.sol";
import {Client} from "../../../libraries/Client.sol";

import {IERC165} from "../../../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/introspection/IERC165.sol";
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v5.0.2/contracts/token/ERC20/IERC20.sol";

contract MaybeRevertMessageReceiver is IAny2EVMMessageReceiver, IERC165 {
error ReceiveRevert();
error CustomError(bytes err);
error Unauthorized();
error InsufficientBalance(uint256 available, uint256 required);
error TransferFailed();

event ValueReceived(uint256 amount);
event MessageReceived();
event FundsWithdrawn(address indexed owner, uint256 amount);
event TokensWithdrawn(address indexed token, address indexed owner, uint256 amount);
event MessageReceived(
bytes32 messageId,
uint64 sourceChainSelector,
bytes sender,
bytes data,
Client.EVMTokenAmount[] destTokenAmounts
);

address private s_manager;
address private immutable s_manager;
bool public s_toRevert;
bytes private s_err;

constructor(
bool toRevert
) {
constructor(bool toRevert) {
s_manager = msg.sender;
s_toRevert = toRevert;
}

function setRevert(
bool toRevert
) external {
modifier onlyManager() {
if (msg.sender != s_manager) {
revert Unauthorized();
}
_;
}

function setRevert(bool toRevert) external onlyManager {
s_toRevert = toRevert;
}

function setErr(
bytes memory err
) external {
function setErr(bytes memory err) external onlyManager {
s_err = err;
}

/// @notice IERC165 supports an interfaceId
/// @param interfaceId The interfaceId to check
/// @return true if the interfaceId is supported
function supportsInterface(
bytes4 interfaceId
) public pure override returns (bool) {
function supportsInterface(bytes4 interfaceId) public pure override returns (bool) {
return interfaceId == type(IAny2EVMMessageReceiver).interfaceId || interfaceId == type(IERC165).interfaceId;
}

function ccipReceive(
Client.Any2EVMMessage calldata
) external override {
function ccipReceive(Client.Any2EVMMessage calldata message) external override {
if (s_toRevert) {
revert CustomError(s_err);
}
emit MessageReceived();

emit MessageReceived(
message.messageId,
message.sourceChainSelector,
message.sender,
message.data,
message.destTokenAmounts
);
}

receive() external payable {
Expand All @@ -61,4 +76,45 @@ contract MaybeRevertMessageReceiver is IAny2EVMMessageReceiver, IERC165 {

emit ValueReceived(msg.value);
}

/// @notice Allows the manager (deployer) to withdraw all Ether from the contract
function withdrawFunds() external onlyManager {
uint256 balance = address(this).balance;
if (balance == 0) {
revert InsufficientBalance(0, 1);
}

(bool success, ) = s_manager.call{value: balance}("");
if (!success) {
revert TransferFailed();
}

emit FundsWithdrawn(s_manager, balance);
}

/// @notice Allows the manager to withdraw ERC-20 tokens from the contract
/// @param token The address of the ERC-20 token contract
/// @param amount The amount of tokens to withdraw
function withdrawTokens(address token, uint256 amount) external onlyManager {
IERC20 erc20 = IERC20(token);
uint256 balance = erc20.balanceOf(address(this));
if (balance < amount) {
revert InsufficientBalance(balance, amount);
}

bool success = erc20.transfer(s_manager, amount);
if (!success) {
revert TransferFailed();
}

emit TokensWithdrawn(token, s_manager, amount);
}

/// @notice Fetches the balance of an ERC-20 token held by the contract
/// @param token The address of the ERC-20 token contract
/// @return The balance of the specified ERC-20 token
function balanceOfToken(address token) external view returns (uint256) {
IERC20 erc20 = IERC20(token);
return erc20.balanceOf(address(this));
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ evm_2_evm_onramp: ../../../contracts/solc/v0.8.24/EVM2EVMOnRamp/EVM2EVMOnRamp.ab
fee_quoter: ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.abi ../../../contracts/solc/v0.8.24/FeeQuoter/FeeQuoter.bin 503823a939ff99fe3bdaaef7a89cd4bbe475e260d3921335dbf9c80d4f584b76
lock_release_token_pool: ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.bin 1067f557abeb5570f1da7f050ea982ffad0f35dc064e668a8a0e6af128df490c
lock_release_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.bin e632b08be0fbd1d013e8b3a9d75293d0d532b83071c531ff2be1deec1fa48ec1
maybe_revert_message_receiver: ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin d73956c26232ebcc4a5444429fa99cbefed960e323be9b5a24925885c2e477d5
maybe_revert_message_receiver: ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin 16455149f447d4a288f3c7acd00afbdfd594d2625a50f9858142fee46a4ab217
message_hasher: ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.abi ../../../contracts/solc/v0.8.24/MessageHasher/MessageHasher.bin 0a2661da24147160383ad61d56a258515d1cc07f5e0f471ec5cbb4bccaf82389
mock_lbtc_token_pool: ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.abi ../../../contracts/solc/v0.8.24/MockLBTCTokenPool/MockLBTCTokenPool.bin 1bb773ea4cd73712c84335de3e56afc2f738c9b96f3417316b5136e47591b5cc
mock_usdc_token_messenger: ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.abi ../../../contracts/solc/v0.8.24/MockE2EUSDCTokenMessenger/MockE2EUSDCTokenMessenger.bin d976651d36b33ac2196b32b9d2f4fa6690c6a18d41b621365659fce1c1d1e737
Expand Down
Loading
Loading