Skip to content

Commit

Permalink
fix(test): fix the occasional noNetwork error in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jan 4, 2023
1 parent dd0f011 commit 61069a1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
10 changes: 6 additions & 4 deletions packages/protocol/test/bridge/Bridge.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";
import { BigNumber, Signer } from "ethers";
import { Message } from "../utils/message";
import hre, { ethers } from "hardhat";
import { getLatestBlockHeader, getSignalProof } from "../../tasks/utils";
import {
AddressManager,
Bridge,
Expand All @@ -11,7 +11,7 @@ import {
TestHeaderSync,
TestLibBridgeData,
} from "../../typechain";
import { getLatestBlockHeader, getSignalProof } from "../../tasks/utils";
import { Message } from "../utils/message";

async function deployBridge(
signer: Signer,
Expand Down Expand Up @@ -443,7 +443,9 @@ describe("integration:Bridge", function () {
);

const l2Signer = await l2Provider.getSigner(
"0x4D9E82AC620246f6782EAaBaC3E3c86895f3f0F8"
(
await l2Provider.listAccounts()
)[0]
);

const l2NonOwner = await l2Provider.getSigner();
Expand Down
68 changes: 41 additions & 27 deletions packages/protocol/test/test_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
set -eou pipefail

DIR=$(cd $(dirname ${BASH_SOURCE[0]}); pwd)
TEST_NODE_CONTAINER_NAME="test-ethereum-node"
TEST_NODE_CONTAINER_NAME_L1="test-ethereum-node-l1"
TEST_NODE_CONTAINER_NAME_L2="test-ethereum-node-l2"
TEST_IMPORT_TEST_ACCOUNT_ETH_JOB_NAME="import-test-account-eth"
TEST_ACCOUNT_ADDRESS="0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39"
TEST_ACCOUNT_PRIV_KEY="2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200"
Expand All @@ -18,35 +19,49 @@ if ! docker info > /dev/null 2>&1; then
exit 1
fi

docker rm --force $TEST_NODE_CONTAINER_NAME $TEST_IMPORT_TEST_ACCOUNT_ETH_JOB_NAME &> /dev/null
docker rm --force $TEST_NODE_CONTAINER_NAME_L1 \
$TEST_NODE_CONTAINER_NAME_L2 \
$TEST_IMPORT_TEST_ACCOUNT_ETH_JOB_NAME &> /dev/null

# Start a test ethereum node
docker run -d \
--name $TEST_NODE_CONTAINER_NAME \
--name $TEST_NODE_CONTAINER_NAME_L1 \
-p 18545:8545 \
ethereum/client-go:latest \
--dev --http --http.addr 0.0.0.0 --http.vhosts "*" \
--http.api debug,eth,net,web3,txpool,miner

# Wait till the test node fully started
RETRIES=30
i=0
until curl \
--silent \
--fail \
--noproxy localhost \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":0,"method":"eth_chainId","params":[]}' \
http://localhost:18545
do
sleep 1
if [ $i -eq $RETRIES ]; then
echo 'Timed out waiting for test node'
exit 1
fi
((i=i+1))
done
docker run -d \
--name $TEST_NODE_CONTAINER_NAME_L2 \
-p 28545:8545 \
gcr.io/evmchain/hardhat-node:latest \
hardhat node --hostname "0.0.0.0"

function waitTestNode {
echo "Waiting test node: $1"
# Wait till the test node fully started
RETRIES=30
i=0
until curl \
--silent \
--fail \
--noproxy localhost \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":0,"method":"eth_chainId","params":[]}' \
$1
do
sleep 1
if [ $i -eq $RETRIES ]; then
echo 'Timed out waiting for test node'
exit 1
fi
((i=i+1))
done
}

waitTestNode http://localhost:18545
waitTestNode http://localhost:28545

# Import ETHs from the random pre-allocated developer account to the test account
docker run -d \
Expand All @@ -55,15 +70,14 @@ docker run -d \
ethereum/client-go:latest \
--exec 'eth.sendTransaction({from: eth.coinbase, to: "'0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39'", value: web3.toWei(1024, "'ether'")})' attach http://host.docker.internal:18545

function cleanup {
docker rm --force $TEST_NODE_CONTAINER_NAME $TEST_IMPORT_TEST_ACCOUNT_ETH_JOB_NAME &> /dev/null
kill -9 $(lsof -ti:28545) &> /dev/null
function cleanup {
docker rm --force $TEST_NODE_CONTAINER_NAME_L1 \
$TEST_NODE_CONTAINER_NAME_L2 \
$TEST_IMPORT_TEST_ACCOUNT_ETH_JOB_NAME &> /dev/null
}

trap cleanup EXIT INT KILL ERR

PRIVATE_KEY=$TEST_ACCOUNT_PRIV_KEY \
npx hardhat node --port 28545 &
# Run the tests
PRIVATE_KEY=$TEST_ACCOUNT_PRIV_KEY \
npx hardhat test --network l1_test --grep "^integration"

0 comments on commit 61069a1

Please sign in to comment.