-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-License-Identifier: Apache 2.0 | ||
pragma solidity 0.8.19; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {ChildERC20} from "../../src/child/ChildERC20.sol"; | ||
import {WIMX} from "../../src/child/WIMX.sol"; | ||
import {IChildERC20Bridge, ChildERC20Bridge} from "../../src/child/ChildERC20Bridge.sol"; | ||
import {IRootERC20Bridge, IERC20Metadata} from "../../src/root/RootERC20Bridge.sol"; | ||
import {RootERC20BridgeFlowRate} from "../../src/root/flowrate/RootERC20BridgeFlowRate.sol"; | ||
import {MockAdaptor} from "./MockAdaptor.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract InvariantBridge is Test { | ||
string public constant ROOT_CHAIN_URL = "http://127.0.0.1:8500"; | ||
string public constant CHILD_CHAIN_URL = "http://127.0.0.1:8501"; | ||
uint256 public constant IMX_DEPOSIT_LIMIT = 10000 ether; | ||
address public constant ADMIN = address(0x111); | ||
|
||
uint256 childId; | ||
uint256 rootId; | ||
ChildERC20Bridge childBridge; | ||
RootERC20BridgeFlowRate rootBridge; | ||
MockAdaptor childAdaptor; | ||
MockAdaptor rootAdaptor; | ||
|
||
function setUp() public { | ||
childId = vm.createFork(CHILD_CHAIN_URL); | ||
rootId = vm.createFork(ROOT_CHAIN_URL); | ||
|
||
// Deploy contracts on child chain. | ||
vm.selectFork(childId); | ||
vm.startPrank(ADMIN); | ||
ChildERC20 childTokenTemplate = new ChildERC20(); | ||
childTokenTemplate.initialize(address(123), "Test", "TST", 18); | ||
childAdaptor = new MockAdaptor(); | ||
vm.stopPrank(); | ||
childBridge = new ChildERC20Bridge(address(this)); | ||
WIMX wIMX = new WIMX(); | ||
|
||
// Deploy contracts on root chain. | ||
vm.selectFork(rootId); | ||
vm.startPrank(ADMIN); | ||
ChildERC20 rootTokenTemplate = new ChildERC20(); | ||
rootTokenTemplate.initialize(address(123), "Test", "TST", 18); | ||
rootAdaptor = new MockAdaptor(); | ||
vm.stopPrank(); | ||
rootBridge = new RootERC20BridgeFlowRate(address(this)); | ||
ChildERC20 rootIMXToken = new ChildERC20(); | ||
rootIMXToken.initialize(address(123), "Immutable X", "IMX", 18); | ||
WIMX wETH = new WIMX(); | ||
|
||
// Configure contracts on child chain. | ||
vm.selectFork(childId); | ||
childAdaptor.initialize(rootId, address(childBridge), address(rootAdaptor)); | ||
IChildERC20Bridge.InitializationRoles memory childRoles = IChildERC20Bridge.InitializationRoles({ | ||
defaultAdmin: address(this), | ||
pauser: address(this), | ||
unpauser: address(this), | ||
adaptorManager: address(this), | ||
initialDepositor: address(this), | ||
treasuryManager: address(this) | ||
}); | ||
childBridge.initialize( | ||
childRoles, address(childAdaptor), address(childTokenTemplate), address(rootIMXToken), address(wIMX) | ||
); | ||
|
||
// Configure contracts on root chain. | ||
vm.selectFork(rootId); | ||
rootAdaptor.initialize(childId, address(rootBridge), address(childAdaptor)); | ||
IRootERC20Bridge.InitializationRoles memory rootRoles = IRootERC20Bridge.InitializationRoles({ | ||
defaultAdmin: address(this), | ||
pauser: address(this), | ||
unpauser: address(this), | ||
variableManager: address(this), | ||
adaptorManager: address(this) | ||
}); | ||
rootBridge.initialize( | ||
rootRoles, | ||
address(rootAdaptor), | ||
address(childBridge), | ||
address(rootTokenTemplate), | ||
address(rootIMXToken), | ||
address(wETH), | ||
IMX_DEPOSIT_LIMIT, | ||
ADMIN | ||
); | ||
|
||
// Try to map one token | ||
ChildERC20 testRootToken = new ChildERC20(); | ||
testRootToken.initialize(address(123), "Test", "TST", 18); | ||
|
||
rootBridge.mapToken{value: 1}(IERC20Metadata(address(testRootToken))); | ||
|
||
// Verify | ||
console.log(rootBridge.rootTokenToChildToken(address(testRootToken))); | ||
vm.selectFork(childId); | ||
console.log(childBridge.rootTokenToChildToken(address(testRootToken))); | ||
} | ||
|
||
function test1() public {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters