Skip to content

Commit

Permalink
test: add timeout for evm instance
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranzav committed Sep 26, 2022
1 parent b13a85f commit 554e010
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/evm
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

TESTRPC_PORT=${TESTRPC_PORT:-8545}
MAX_RETRIES=120

evm_running() {
nc -z localhost "$TESTRPC_PORT" > /dev/null
}

ping_evm() {
evm_ping() {
PORT=$1
curl --location --request POST "localhost:$PORT/" \
--header 'Content-Type: application/json' \
Expand All @@ -21,7 +22,13 @@ ping_evm() {
evm_start() {
echo "Starting our own evm instance at port $TESTRPC_PORT"
npx hardhat node --port "$TESTRPC_PORT" > /dev/null &
while ! ping_evm $TESTRPC_PORT; do
retries=0
while ! evm_ping $TESTRPC_PORT; do
((retries=retries+1))
if [ $retries -gt $MAX_RETRIES ]; then
echo "Timeout waiting for evm instance"
exit 1
fi
sleep 1
done
}
Expand Down

0 comments on commit 554e010

Please sign in to comment.