Skip to content

Commit

Permalink
Add reduced logging option
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Oct 21, 2024
1 parent b9f359e commit 1f4c206
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 48 deletions.
57 changes: 37 additions & 20 deletions contracts/src/v0.8/ccip/test/MOAFT/CCIPTestSuite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -110,22 +110,29 @@ contract CCIPTestSuite is Test {
}

function sendAllTokens(
bool onlyPreviousSuccess
bool postMigration
) external {
uint256[] memory remoteChains = s_remoteChainSelectors.values();

uint256 totalSuccessfulTokens = 0;
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)]);
Expand All @@ -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];

Expand All @@ -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++;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/test/MOAFT/ForkedChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
61 changes: 34 additions & 27 deletions contracts/src/v0.8/ccip/test/MOAFT/chainLoading.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +25,7 @@ contract ChainLoading is Test {
CCIPSetup ccipSetup;
string name;
uint256 forkId;
uint256 postMigrationBlock;
uint64 postMigrationBlock;
CCIPTestSuite testSuite;
}

Expand All @@ -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);
}

Expand All @@ -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 {
Expand All @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 1f4c206

Please sign in to comment.