Skip to content

Commit

Permalink
Fix invariant test in CI (#104)
Browse files Browse the repository at this point in the history
* Fix CI

* Update IChainManager.sol
  • Loading branch information
wcgcyx authored Jul 23, 2024
1 parent 7ec8341 commit 0a56c7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions test/invariant/IChainManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache 2.0
pragma solidity 0.8.19;

interface IChainManager {
function switchToChain(uint256 chainId) external;
}
11 changes: 8 additions & 3 deletions test/invariant/InvariantBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {RootERC20BridgeFlowRate} from "../../src/root/flowrate/RootERC20BridgeFl
import {MockAdaptor} from "./MockAdaptor.sol";
import {ChildHelper} from "./child/ChildHelper.sol";
import {RootHelper} from "./root/RootHelper.sol";
import {IChainManager} from "./IChainManager.sol";
import {ChildERC20BridgeHandler} from "./child/ChildERC20BridgeHandler.sol";
import {RootERC20BridgeFlowRateHandler} from "./root/RootERC20BridgeFlowRateHandler.sol";
import "forge-std/console.sol";

contract InvariantBridge is Test {
contract InvariantBridge is Test, IChainManager {
string public constant CHAIN_URL = "http://127.0.0.1:8500";
uint256 public constant IMX_DEPOSIT_LIMIT = 10000 ether;
uint256 public constant MAX_AMOUNT = 10000;
Expand All @@ -40,6 +41,10 @@ contract InvariantBridge is Test {

uint256 mappingGas;

function switchToChain(uint256 chainId) external {
vm.selectFork(chainId);
}

function setUp() public {
childId = vm.createFork(CHAIN_URL);
rootId = vm.createFork(CHAIN_URL);
Expand Down Expand Up @@ -77,7 +82,7 @@ contract InvariantBridge is Test {

// Configure contracts on child chain.
vm.selectFork(childId);
childAdaptor.initialize(rootId, address(childBridge));
childAdaptor.initialize(rootId, address(childBridge), address(this));
IChildERC20Bridge.InitializationRoles memory childRoles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: address(this),
Expand All @@ -93,7 +98,7 @@ contract InvariantBridge is Test {

// Configure contracts on root chain.
vm.selectFork(rootId);
rootAdaptor.initialize(childId, address(rootBridge));
rootAdaptor.initialize(childId, address(rootBridge), address(this));
IRootERC20Bridge.InitializationRoles memory rootRoles = IRootERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: address(this),
Expand Down
9 changes: 6 additions & 3 deletions test/invariant/MockAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.19;
import {Test} from "forge-std/Test.sol";
import {IChildBridgeAdaptor} from "../../src/interfaces/child/IChildBridgeAdaptor.sol";
import {IRootBridgeAdaptor} from "../../src/interfaces/root/IRootBridgeAdaptor.sol";
import {IChainManager} from "./IChainManager.sol";

interface MessageReceiver {
function onMessageReceive(bytes calldata data) external;
Expand All @@ -12,12 +13,14 @@ interface MessageReceiver {
contract MockAdaptor is Test, IChildBridgeAdaptor, IRootBridgeAdaptor {
uint256 otherChainId;
MessageReceiver messageReceiver;
IChainManager chainManager;

constructor() {}

function initialize(uint256 _otherChainId, address _messageReceiver) public {
function initialize(uint256 _otherChainId, address _messageReceiver, address _chainManager) public {
otherChainId = _otherChainId;
messageReceiver = MessageReceiver(_messageReceiver);
chainManager = IChainManager(_chainManager);
}

function sendMessage(bytes calldata payload, address /*refundRecipient*/ )
Expand All @@ -28,10 +31,10 @@ contract MockAdaptor is Test, IChildBridgeAdaptor, IRootBridgeAdaptor {
uint256 original = vm.activeFork();

// Switch to the other chain.
vm.selectFork(otherChainId);
chainManager.switchToChain(otherChainId);
onMessageReceive(payload);

vm.selectFork(original);
chainManager.switchToChain(original);
}

function onMessageReceive(bytes calldata data) public {
Expand Down

0 comments on commit 0a56c7c

Please sign in to comment.