diff --git a/scripts/evm b/scripts/evm index 77b1b679f..e63e2e9dc 100644 --- a/scripts/evm +++ b/scripts/evm @@ -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' \ @@ -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 }