Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Mar 6, 2024
1 parent 7071c46 commit d731c78
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ jobs:

- name: Run Invariant Tests
run: |
yarn local:threechains
yarn local:testchain
forge test --match-path "test/invariant/**" -vvvvv
id: invariant_test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"local:ci": "cd scripts/localdev; rm -rf .child.bridge.contracts.json .root.bridge.contracts.json; ./ci.sh && ./deploy.sh && AXELAR_API_URL=skip npx mocha --require mocha-suppress-logs ../e2e/e2e.ts && ./stop.sh",
"local:chainonly": "cd scripts/localdev; LOCAL_CHAIN_ONLY=true ./start.sh",
"local:axelaronly": "cd scripts/localdev; npx ts-node axelar_setup.ts",
"local:threechains": "cd scripts/localdev; ./chains.sh",
"local:testchain": "cd scripts/localdev; ./chains.sh",
"stop": "cd scripts/localdev; ./stop.sh"
},
"author": "",
Expand Down
2 changes: 0 additions & 2 deletions scripts/localdev/chains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ set -o pipefail

# Start root & child chain.
npx hardhat node --config ./rootchain.config.ts --port 8500 > /dev/null 2>&1 &
npx hardhat node --config ./childchain.config.ts --port 8501 > /dev/null 2>&1 &
npx hardhat node --config ./resetchain.config.ts --port 8502 > /dev/null 2>&1 &
sleep 10
22 changes: 10 additions & 12 deletions test/invariant/InvariantBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ import {RootERC20BridgeFlowRateHandler} from "./root/RootERC20BridgeFlowRateHand
import "forge-std/console.sol";

contract InvariantBridge is Test {
string public constant CHILD_CHAIN_URL = "http://127.0.0.1:8500";
string public constant ROOT_CHAIN_URL = "http://127.0.0.1:8501";
// Forge has an issue that fails to reset state at the end of each run.
// For example, we found out that if the context stays at child chain at the end of setUp(),
// the state on child chain will not be reset or if the context stays at root chain, the state
// on the root chain will not be reset, which causes subsequent runs to fail.
// We introduced a third chain called reset chain and we make the context to stay on the reset chain
// in order to reset state on both child chain and root chain.
string public constant RESET_CHAIN_URL = "http://127.0.0.1:8502";
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;
address public constant ADMIN = address(0x111);
Expand All @@ -49,9 +41,15 @@ contract InvariantBridge is Test {
uint256 mappingGas;

function setUp() public {
childId = vm.createFork(CHILD_CHAIN_URL);
rootId = vm.createFork(ROOT_CHAIN_URL);
resetId = vm.createFork(RESET_CHAIN_URL);
childId = vm.createFork(CHAIN_URL);
rootId = vm.createFork(CHAIN_URL);
// Forge has an issue that fails to reset state at the end of each run.
// For example, we found out that if the context stays at child chain at the end of setUp(),
// the state on child chain will not be reset or if the context stays at root chain, the state
// on the root chain will not be reset, which causes subsequent runs to fail.
// We introduced a third chain called reset chain and we make the context to stay on the reset chain
// in order to reset state on both child chain and root chain.
resetId = vm.createFork(CHAIN_URL);

// Deploy contracts on child chain.
vm.selectFork(childId);
Expand Down

0 comments on commit d731c78

Please sign in to comment.