From 1f4c206465747d8fa973052f2493d2c16e9c457d Mon Sep 17 00:00:00 2001 From: Rens Rooimans Date: Mon, 21 Oct 2024 12:35:12 +0200 Subject: [PATCH] Add reduced logging option --- .../v0.8/ccip/test/MOAFT/CCIPTestSuite.sol | 57 +++++++++++------ .../src/v0.8/ccip/test/MOAFT/ForkedChain.sol | 2 +- .../src/v0.8/ccip/test/MOAFT/chainLoading.sol | 61 +++++++++++-------- 3 files changed, 72 insertions(+), 48 deletions(-) diff --git a/contracts/src/v0.8/ccip/test/MOAFT/CCIPTestSuite.sol b/contracts/src/v0.8/ccip/test/MOAFT/CCIPTestSuite.sol index ebd2b46474..6f45230b65 100644 --- a/contracts/src/v0.8/ccip/test/MOAFT/CCIPTestSuite.sol +++ b/contracts/src/v0.8/ccip/test/MOAFT/CCIPTestSuite.sol @@ -62,6 +62,7 @@ contract CCIPTestSuite is Test { uint256 internal s_pseudoRandomSeed = uint256(keccak256(abi.encodePacked(block.timestamp, block.number))); Router internal immutable i_router; + bool internal immutable i_fullLogging; struct RemoteChainConfig { EVM2EVMOnRamp OldOnRamp; @@ -81,10 +82,9 @@ contract CCIPTestSuite is Test { mapping(address token => string) public s_tokenNames; - constructor( - address router - ) { + constructor(address router, bool fullLogging) { i_router = Router(router); + i_fullLogging = fullLogging; _loadDestChainInfo(); vm.deal(address(this), 1e18 ether); @@ -110,7 +110,7 @@ contract CCIPTestSuite is Test { } function sendAllTokens( - bool onlyPreviousSuccess + bool postMigration ) external { uint256[] memory remoteChains = s_remoteChainSelectors.values(); @@ -118,14 +118,21 @@ contract CCIPTestSuite is Test { uint256 totalFailedTokens = 0; for (uint256 i = 0; i < remoteChains.length; ++i) { uint64 remoteChainSelector = uint64(remoteChains[i]); - (uint256 numberOfSuccesses, uint256 failed) = _sendTokenToChain(onlyPreviousSuccess, remoteChainSelector); + (uint256 numberOfSuccesses, uint256 failed) = _sendTokenToChain(postMigration, remoteChainSelector); totalSuccessfulTokens += numberOfSuccesses; totalFailedTokens += failed; } - console2.log("--------------------------------------- +"); + if (i_fullLogging) { + console2.log("--------------------------------------- +"); + } console2.log("Total sent: success", totalSuccessfulTokens, "failed", totalFailedTokens); console2.log(""); + + if (!postMigration) { + return; + } + console2.log("Failed tokens initially:"); for (uint256 i = 0; i < s_failedTokensInitially.length(); ++i) { console2.log(unicode"❓", s_failedTokensInitially.at(i), s_tokenNames[s_failedTokensInitially.at(i)]); @@ -146,14 +153,18 @@ contract CCIPTestSuite is Test { } function _sendTokenToChain( - bool onlyPreviousSuccess, + bool postMigration, uint64 remoteChainSelector ) internal returns (uint256 successful, uint256 failed) { uint256 successfulTokens = 0; - console2.log("Sending tokens to chain: ", remoteChainSelector, Constants._resolveChainSelector(remoteChainSelector)); + if (i_fullLogging) { + console2.log( + "Sending tokens to chain: ", remoteChainSelector, Constants._resolveChainSelector(remoteChainSelector) + ); + } RemoteChainConfig storage remoteChainConfig = s_remoteChainConfigs[remoteChainSelector]; - address[] memory tokens = onlyPreviousSuccess ? remoteChainConfig.oldSuccessfulTokens : remoteChainConfig.tokens; + address[] memory tokens = postMigration ? remoteChainConfig.oldSuccessfulTokens : remoteChainConfig.tokens; for (uint256 j = 0; j < tokens.length; ++j) { address token = tokens[j]; @@ -166,8 +177,10 @@ contract CCIPTestSuite is Test { ); if (success) { - console2.log(unicode"✅ token", token, s_tokenNames[token]); - if (!onlyPreviousSuccess) { + if (i_fullLogging) { + console2.log(unicode"✅", token, s_tokenNames[token]); + } + if (!postMigration) { s_remoteChainConfigs[remoteChainSelector].oldSuccessfulTokens.push(token); } successfulTokens++; @@ -177,7 +190,7 @@ contract CCIPTestSuite is Test { bool tokenSupportDropped = keccak256(retData) == keccak256(abi.encodeWithSelector(EVM2EVMOnRamp.UnsupportedToken.selector, token)); - if (!onlyPreviousSuccess) { + if (!postMigration) { s_failedTokensInitially.add(token); } else { if (tokenSupportDropped) { @@ -187,15 +200,19 @@ contract CCIPTestSuite is Test { } } - if (tokenSupportDropped) { - console2.log(unicode"🟠 DROPPED SUPPORT for token", token, s_tokenNames[token]); - } else { - console2.log(unicode"❌ broken token", token, s_tokenNames[token]); - console2.logBytes(retData); + if (i_fullLogging) { + if (tokenSupportDropped) { + console2.log(unicode"🟠 DROPPED SUPPORT", token, s_tokenNames[token]); + } else { + console2.log(unicode"❌ broken", token, s_tokenNames[token]); + console2.logBytes(retData); + } } } - console2.log("Tokens sent: success", successfulTokens, "failed", tokens.length - successfulTokens); - console2.log(""); + if (i_fullLogging) { + console2.log("Tokens sent: success", successfulTokens, "failed", tokens.length - successfulTokens); + console2.log(""); + } return (successfulTokens, tokens.length - successfulTokens); } @@ -233,7 +250,7 @@ contract CCIPTestSuite is Test { vm.startPrank(address(offRamp)); uint32[] memory gasOverrides = new uint32[](1); - gasOverrides[0] = 250_000; + gasOverrides[0] = 100_000; // uint32[] memory gasOverrides = new uint32[](0); uint256 succeeded = 0; diff --git a/contracts/src/v0.8/ccip/test/MOAFT/ForkedChain.sol b/contracts/src/v0.8/ccip/test/MOAFT/ForkedChain.sol index 4e322b0064..bcbed83506 100644 --- a/contracts/src/v0.8/ccip/test/MOAFT/ForkedChain.sol +++ b/contracts/src/v0.8/ccip/test/MOAFT/ForkedChain.sol @@ -18,7 +18,7 @@ library ForkedChain { function _loadChainConfig(Vm vm, string memory name) internal view returns (Chain memory) { Chain memory chain; chain.rpcUrl = vm.envString(string.concat(name, "_RPC_URL")); - chain.block = vm.envUint(string.concat(name, "_PRE_BLOCK")); + chain.block = uint64(vm.envUint(string.concat(name, "_PRE_BLOCK"))); chain.name = name; return chain; } diff --git a/contracts/src/v0.8/ccip/test/MOAFT/chainLoading.sol b/contracts/src/v0.8/ccip/test/MOAFT/chainLoading.sol index 835d62f34a..e6b8cfcb53 100644 --- a/contracts/src/v0.8/ccip/test/MOAFT/chainLoading.sol +++ b/contracts/src/v0.8/ccip/test/MOAFT/chainLoading.sol @@ -11,12 +11,12 @@ import {console2} from "forge-std/Console2.sol"; import {Test} from "forge-std/Test.sol"; contract ChainLoading is Test { - string internal constant MAINNET = "SEPOLIA"; - string internal constant ARBITRUM = "ARB"; + string internal constant SEPOLIA = "SEPOLIA"; + string internal constant ARBITRUM_SEPOLIA = "ARB_SEPOLIA"; - uint256 internal constant TwentyFiveHours = 25 * 60 * 60; + uint256 internal constant FourHours = 4 * 60 * 60; - string[] internal chainNames = [MAINNET]; + string[] internal chainNames = [SEPOLIA]; mapping(string chainName => ForkedChainTestSetup) public s_chains; @@ -25,7 +25,7 @@ contract ChainLoading is Test { CCIPSetup ccipSetup; string name; uint256 forkId; - uint256 postMigrationBlock; + uint64 postMigrationBlock; CCIPTestSuite testSuite; } @@ -41,25 +41,33 @@ contract ChainLoading is Test { } function test_Chain_Sepolia() public { - run(MAINNET); + run(SEPOLIA); } function test_Chain_Arbitrum() public { - run(ARBITRUM); + run(ARBITRUM_SEPOLIA); } function test_Lane_SepoliaToArbitrum() public { - _loadSingleChain(MAINNET); - _loadSingleChain(ARBITRUM); + _loadSingleChain(SEPOLIA); + _loadSingleChain(ARBITRUM_SEPOLIA); - ForkedChainTestSetup memory chain = _activateFork(MAINNET); + ForkedChainTestSetup memory chain = _activateFork(SEPOLIA); - vm.rollFork(chain.postMigrationBlock); + // Apply proposal on source + _setProposalOnMCMS(chain); + _executeProposalOnTimeLock(chain); + // Send messages Internal.EVM2EVMMessage[] memory msgs = chain.testSuite.sendTokensSingleLane(3478487238524512106); - ForkedChainTestSetup memory destChain = _activateFork(ARBITRUM); - vm.rollFork(destChain.postMigrationBlock); + ForkedChainTestSetup memory destChain = _activateFork(ARBITRUM_SEPOLIA); + + // Apply proposal on dest + _setProposalOnMCMS(destChain); + _executeProposalOnTimeLock(destChain); + + // Execute messages destChain.testSuite.ExecuteMsgs(msgs); } @@ -77,29 +85,27 @@ contract ChainLoading is Test { chain.testSuite.sendAllTokens(false); - // _setProposalOnMCMS(chain.mcmsSetup); - // vm.warp(block.timestamp + TwentyFiveHours); - // _executeProposalOnTimeLock(chain.mcmsSetup); - console2.logString(" +------------------------------------------------+"); - console2.logString(" | Latest block |"); + console2.logString(" | After migration |"); console2.logString(" +------------------------------------------------+"); - vm.rollFork(chain.postMigrationBlock); + _setProposalOnMCMS(chain); + _executeProposalOnTimeLock(chain); + chain.testSuite.sendAllTokens(true); } function _setProposalOnMCMS( - MCMSSetup memory chain + ForkedChainTestSetup memory chain ) internal { // TODO } function _executeProposalOnTimeLock( - MCMSSetup memory chain + ForkedChainTestSetup memory chain ) internal { - // TODO - //vm.rollFork(6807978); - // vm.rollFork(6904314); + // TODO actual MCMS proposal execution. For testing, we can use chains that already have the proposal executed + // and roll to a block after the migration. + vm.rollFork(chain.postMigrationBlock); } function _loadAllChains() internal { @@ -118,7 +124,7 @@ contract ChainLoading is Test { // setup.mcmsSetup.callProxyPayload = vm.envBytes(string.concat(name, "_CALL_PROXY_PAYLOAD")); setup.ccipSetup.router = vm.envAddress(string.concat(name, "_ROUTER")); - setup.postMigrationBlock = vm.envUint(string.concat(name, "_POST_BLOCK")); + setup.postMigrationBlock = uint64(vm.envUint(string.concat(name, "_POST_BLOCK"))); setup.name = string(name); @@ -134,13 +140,14 @@ contract ChainLoading is Test { config.forkId = ForkedChain.LoadAndActivateFork(vm, config.name); } - console2.logString(string.concat("Activating chain: ", name)); + console2.log("Activating chain: ", name); vm.selectFork(config.forkId); // If no test suite was deployed, deploy one if (address(config.testSuite) == address(0)) { - config.testSuite = new CCIPTestSuite(config.ccipSetup.router); + bool fullLogging = vm.envBool("FULL_LOGGING"); + config.testSuite = new CCIPTestSuite(config.ccipSetup.router, fullLogging); } return config;