Skip to content

Commit

Permalink
fix compilation and test issues that arose during merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub committed Sep 5, 2024
1 parent 5722746 commit e01e113
Show file tree
Hide file tree
Showing 12 changed files with 2,861 additions and 511 deletions.
6 changes: 0 additions & 6 deletions contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ compileContract () {
echo "OffRamp uses $OPTIMIZE_RUNS_OFFRAMP optimizer runs."
optimize_runs=$OPTIMIZE_RUNS_OFFRAMP
;;
"ccip/offRamp/OffRamp.sol")
echo "MultiOffRamp uses $OPTIMIZE_RUNS_MULTI_OFFRAMP optimizer runs."
optimize_runs=$OPTIMIZE_RUNS_MULTI_OFFRAMP
;;
"ccip/onRamp/EVM2EVMOnRamp.sol")
echo "OnRamp uses $OPTIMIZE_RUNS_ONRAMP optimizer runs."
optimize_runs=$OPTIMIZE_RUNS_ONRAMP
Expand All @@ -58,15 +54,13 @@ compileContract () {
# Solc produces and overwrites intermediary contracts.
# Contracts should be ordered in reverse-import-complexity-order to minimize overwrite risks.
compileContract ccip/offRamp/EVM2EVMOffRamp.sol
compileContract ccip/offRamp/EVM2EVMMultiOffRamp.sol
compileContract ccip/applications/internal/PingPongDemo.sol
compileContract ccip/applications/internal/SelfFundedPingPong.sol
compileContract ccip/applications/external/CCIPClient.sol
compileContract ccip/applications/external/CCIPClientWithACK.sol
compileContract ccip/applications/external/CCIPReceiver.sol
compileContract ccip/applications/external/CCIPReceiverWithACK.sol
compileContract ccip/applications/external/CCIPSender.sol
compileContract ccip/onRamp/EVM2EVMMultiOnRamp.sol
compileContract ccip/offRamp/OffRamp.sol
compileContract ccip/rmn/RMNRemote.sol
compileContract ccip/onRamp/OnRamp.sol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IAny2EVMMessageReceiver} from "../../interfaces/IAny2EVMMessageReceiver.

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

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

/// @title CCIPReceiver - Base contract for CCIP applications that can receive messages.
abstract contract CCIPReceiver is IAny2EVMMessageReceiver, IERC165 {
Expand Down
30 changes: 30 additions & 0 deletions contracts/src/v0.8/ccip/applications/internal/PingPongDemo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ pragma solidity ^0.8.0;
import {Client} from "../../libraries/Client.sol";
import {CCIPClient} from "../external/CCIPClient.sol";

import {EVM2EVMOnRamp} from "../../onRamp/EVM2EVMOnRamp.sol";
import {IRouter} from "../../interfaces/IRouter.sol";

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

/// @title PingPongDemo - A simple ping-pong contract for demonstrating cross-chain communication
contract PingPongDemo is CCIPClient {

event Ping(uint256 pingPongCount);
event Pong(uint256 pingPongCount);
event OutOfOrderExecutionChange(bool isOutOfOrder);

// The chain ID of the counterpart ping pong contract
uint64 internal s_counterpartChainSelector;
Expand All @@ -20,6 +25,8 @@ contract PingPongDemo is CCIPClient {
// Pause ping-ponging
bool private s_isPaused;

bool private s_allowOutOfOrderExecution;

// CCIPClient will handle the token approval so there's no need to do it here
constructor(address router, IERC20 feeToken) CCIPClient(router, feeToken, true) {}

Expand Down Expand Up @@ -98,4 +105,27 @@ contract PingPongDemo is CCIPClient {
function isPaused() external view returns (bool) {
return s_isPaused;
}

function getOutOfOrderExecution() external view returns (bool) {
return s_allowOutOfOrderExecution;
}

function setOutOfOrderExecution(bool outOfOrderExecution) external onlyOwner {
// It adds gas having the extra storage slot, but the alternative is a bunch of very messy assembly code
// to slice it out of the extra args.
s_allowOutOfOrderExecution = outOfOrderExecution;

address onRamp = IRouter(s_ccipRouter).getOnRamp(s_counterpartChainSelector);
EVM2EVMOnRamp.StaticConfig memory staticConfig = EVM2EVMOnRamp(onRamp).getStaticConfig();

// Enabling out of order execution also requires setting a manual gas limit, therefore the on-ramp default
// gas limit is used to ensure consistency, but can be overwritten manually by the contract owner using
// the applyChainUpdates function.
s_chainConfigs[s_counterpartChainSelector].extraArgsBytes = Client._argsToBytes(
Client.EVMExtraArgsV2({gasLimit: staticConfig.defaultTxGasLimit, allowOutOfOrderExecution: outOfOrderExecution})
);

emit OutOfOrderExecutionChange(outOfOrderExecution);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ contract CCIPClientWithACKTest is EVM2EVMOnRampSetup {

uint256 receiverBalanceBefore = IERC20(s_sourceFeeToken).balanceOf(address(s_sender));

vm.expectEmit(true, true, false, false);
// Check the messageId since we can control that, but not ackMessageId since its generated at execution time
vm.expectEmit(true, false, true, false, address(s_sender));
emit MessageSent(messageId, ackMessageId);

s_sender.ccipReceive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract CCIPReceiverWithAckTest is EVM2EVMOnRampSetup {

uint256 receiverBalanceBefore = IERC20(s_sourceFeeToken).balanceOf(address(s_receiver));

vm.expectEmit(false, true, false, false);
vm.expectEmit(true, false, true, false);
emit MessageSent(messageId, ackMessageId);

s_receiver.ccipReceive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,45 @@ contract PingPongDappSetup is EVM2EVMOnRampSetup {
}

contract PingPong_example_startPingPong is PingPongDappSetup {
function test_StartPingPong_Success() public {
uint256 pingPongNumber = 1;
bytes memory data = abi.encode(pingPongNumber);
bytes data = abi.encode(pingPongNumber);

function test_StartPingPong_Success() public {
Client.EVM2AnyMessage memory sentMessage = Client.EVM2AnyMessage({
receiver: abi.encode(i_pongContract),
data: data,
tokenAmounts: new Client.EVMTokenAmount[](0),
feeToken: s_sourceFeeToken,
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 2e5}))
});

uint256 expectedFee = s_sourceRouter.getFee(DEST_CHAIN_SELECTOR, sentMessage);

Internal.EVM2EVMMessage memory message = Internal.EVM2EVMMessage({
sequenceNumber: 1,
feeTokenAmount: expectedFee,
sourceChainSelector: SOURCE_CHAIN_SELECTOR,
sender: address(s_pingPong),
receiver: i_pongContract,
nonce: 1,
data: data,
tokenAmounts: sentMessage.tokenAmounts,
sourceTokenData: new bytes[](sentMessage.tokenAmounts.length),
gasLimit: 2e5,
feeToken: sentMessage.feeToken,
strict: false,
messageId: ""
});
message.messageId = Internal._hash(message, s_metadataHash);

vm.expectEmit();
emit PingPongDemo.Ping(pingPongNumber);

vm.expectEmit();
emit EVM2EVMOnRamp.CCIPSendRequested(message);

s_pingPong.startPingPong();
}

function test_StartPingPong_With_Sequenced_Ordered_Success() public {
Client.EVM2AnyMessage memory sentMessage = Client.EVM2AnyMessage({
Expand Down Expand Up @@ -86,7 +122,7 @@ contract PingPong_example_startPingPong is PingPongDappSetup {
data: abi.encode(pingPongNumber),
tokenAmounts: sentMessage.tokenAmounts,
sourceTokenData: new bytes[](sentMessage.tokenAmounts.length),
gasLimit: 200_000,
gasLimit: GAS_LIMIT,
feeToken: sentMessage.feeToken,
strict: false,
messageId: ""
Expand Down Expand Up @@ -133,19 +169,24 @@ contract PingPong_example_ccipReceive is PingPongDappSetup {

contract PingPong_plumbing is PingPongDappSetup {
function test_Fuzz_CounterPartChainSelector_Success(uint64 chainSelector) public {
s_pingPong.setCounterpartChainSelector(chainSelector);
vm.assume(chainSelector != 0);

s_pingPong.setCounterpart(chainSelector, address(0x1234));

assertEq(s_pingPong.getCounterpartChainSelector(), chainSelector);
}

function test_Fuzz_CounterPartAddress_Success(address counterpartAddress) public {
s_pingPong.setCounterpartAddress(counterpartAddress);
vm.assume(counterpartAddress != address(0));

s_pingPong.setCounterpart(1, counterpartAddress);

assertEq(s_pingPong.getCounterpartAddress(), counterpartAddress);
}

function test_Fuzz_CounterPartAddress_Success(uint64 chainSelector, address counterpartAddress) public {
s_pingPong.setCounterpartChainSelector(chainSelector);
vm.assume(chainSelector != 0);
vm.assume(counterpartAddress != address(0));

s_pingPong.setCounterpart(chainSelector, counterpartAddress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.19;

import {Client} from "../../../libraries/Client.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {EVM2EVMMultiOffRamp} from "../../../offRamp/EVM2EVMMultiOffRamp.sol";
import {EVM2EVMOffRamp} from "../../../offRamp/EVM2EVMOffRamp.sol";
import {CCIPReceiverBasic} from "./CCIPReceiverBasic.sol";
import {OffRamp} from "../../../offRamp/OffRamp.sol";

Expand All @@ -14,7 +14,7 @@ contract ReentrancyAbuserMultiRamp is CCIPReceiverBasic {
Internal.ExecutionReportSingleChain internal s_payload;
OffRamp internal s_offRamp;

constructor(address router, EVM2EVMMultiOffRamp offRamp) CCIPReceiverBasic(router) {
constructor(address router, OffRamp offRamp) CCIPReceiverBasic(router) {
s_offRamp = offRamp;
}

Expand Down
Loading

0 comments on commit e01e113

Please sign in to comment.