Skip to content

Commit

Permalink
still wip for refactoring bridge testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed May 20, 2024
1 parent f2c3076 commit 2ece5a4
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 308 deletions.
112 changes: 0 additions & 112 deletions src/testing/ZkEVMDomain.sol

This file was deleted.

58 changes: 58 additions & 0 deletions src/testing/bridges/AMBBridgeTesting.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

import { Vm } from "forge-std/Vm.sol";

import { RecordedLogs } from "src/testing/utils/RecordedLogs.sol";
import { BridgeData } from "./BridgeData.sol";

library AMBBridgeTesting {

using DomainHelpers for *;

Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

function createBridge(Domain memory source, Domain memory destination) internal returns (BridgeData memory bridge) {
return init(BridgeData({
source: ethereum,
destination: arbitrumInstance,
sourceCrossChainMessenger: _getMessengerFromChainAlias(source.chain.chainAlias),
destinationCrossChainMessenger: _getMessengerFromChainAlias(destination.chain.chainAlias),
lastSourceLogIndex: 0,
lastDestinationLogIndex: 0,
extraData: ""
}));
}

function getMessengerFromChainAlias(string memory chainAlias) internal pure returns (address) {
bytes32 name = keccak256(bytes(chainAlias));
if (name == keccak256("mainnet")) {
return 0x0a992d191DEeC32aFe36203Ad87D7d289a738F81;
} else if (name == keccak256("avalanche")) {
return 0x8186359aF5F57FbB40c6b14A588d2A59C0C29880;
} else if (name == keccak256("optimism")) {
return 0x4D41f22c5a0e5c74090899E5a8Fb597a8842b3e8;
} else if (name == keccak256("arbitrum_one")) {
return 0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca;
} else if (name == keccak256("base")) {
return 0xAD09780d193884d503182aD4588450C416D6F9D4;
} else if (name == keccak256("polygon")) {
return 0xF3be9355363857F3e001be68856A2f96b4C39Ba9;
} else {
revert("Unsupported chain");
}
}

function init(BridgeData memory bridge) internal returns (BridgeData memory bridge) {

}

function relayMessagesToDestination(BridgeData memory bridge, bool switchToDestinationFork) internal {

}

function relayMessagesToSource(BridgeData memory bridge, bool switchToSourceFork) internal {

}

}
27 changes: 13 additions & 14 deletions src/testing/bridges/ArbitrumBridgeTesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract ArbSysOverride {
library ArbitrumBridgeTesting {

using DomainHelpers for *;
using RecordedLogs for *;

Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

Expand Down Expand Up @@ -123,11 +124,11 @@ library ArbitrumBridgeTesting {

// Read all L1 -> L2 messages and relay them under Arbitrum fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastFromHostLogIndex < logs.length; lastFromHostLogIndex++) {
Vm.Log memory log = logs[lastFromHostLogIndex];
for (; bridge.lastSourceLogIndex < logs.length; bridge.lastSourceLogIndex++) {
Vm.Log memory log = logs[bridge.lastSourceLogIndex];
if (log.topics[0] == MESSAGE_DELIVERED_TOPIC) {
// We need both the current event and the one that follows for all the relevant data
Vm.Log memory logWithData = logs[lastFromHostLogIndex + 1];
Vm.Log memory logWithData = logs[bridge.lastSourceLogIndex + 1];
(,, address sender,,,) = abi.decode(log.data, (address, uint8, address, bytes32, uint256, uint64));
(address target, bytes memory message) = _parseData(logWithData.data);
vm.startPrank(sender);
Expand All @@ -150,17 +151,15 @@ library ArbitrumBridgeTesting {
bridge.source.selectFork();

// Read all L2 -> L1 messages and relay them under host fork
Vm.Log[] memory logs = RecordedLogs.getLogs();
for (; lastToHostLogIndex < logs.length; lastToHostLogIndex++) {
Vm.Log memory log = logs[lastToHostLogIndex];
if (log.topics[0] == SEND_TO_L1_TOPIC) {
(address sender, address target, bytes memory message) = abi.decode(log.data, (address, address, bytes));
//l2ToL1Sender = sender;
(bool success, bytes memory response) = InboxLike(data.sourceCrossChainMessenger).bridge().executeCall(target, 0, message);
if (!success) {
assembly {
revert(add(response, 32), mload(response))
}
Vm.Log[] memory logs = bridge.ingestAndFilterLogs(false, SEND_TO_L1_TOPIC, address(0));
for (uint256 i = 0; i < logs.length; i++) {
Vm.Log memory log = logs[i];
(address sender, address target, bytes memory message) = abi.decode(log.data, (address, address, bytes));
//l2ToL1Sender = sender;
(bool success, bytes memory response) = InboxLike(data.sourceCrossChainMessenger).bridge().executeCall(target, 0, message);
if (!success) {
assembly {
revert(add(response, 32), mload(response))
}
}
}
Expand Down
106 changes: 0 additions & 106 deletions src/testing/bridges/CCTPBridge.sol

This file was deleted.

Loading

0 comments on commit 2ece5a4

Please sign in to comment.