diff --git a/test/programs/build_anvil_state.sh b/test/programs/build_anvil_state.sh index 2d105e0..699cd59 100755 --- a/test/programs/build_anvil_state.sh +++ b/test/programs/build_anvil_state.sh @@ -9,8 +9,40 @@ rm -f $program_path/anvil_state.json anvil --disable-code-size-limit --preserve-historical-states --slots-in-an-epoch 1 \ --dump-state $program_path/anvil_state.json > $program_path/_anvil.log 2>&1 & anvil_pid=$! -sleep 5 - +trap 'kill $anvil_pid' EXIT + +# wait for anvil to start listening +num_tries=10 +while true +do + if chain_id=$(cast chain-id 2>/dev/null) + then + if [[ $chain_id == 31337 ]] + then + >&2 echo "Anvil is listening." + break + else + >&2 echo "Anvil has unexpected chain ID $chain_id." + exit 1 + fi + else + if kill -0 $anvil_pid + then + if [[ $num_tries == 0 ]] + then + >&2 echo "Anvil is not listening." + exit 1 + else + >&2 echo "Waiting for Anvil to start listening... ($num_tries tries left)" + num_tries=$(( $num_tries - 1 )) + sleep 1 + fi + else + >&2 echo "Anvil exited..." + exit 1 + fi + fi +done # deploy smart contracts initial_hash=`xxd -p -c32 "${program_path}/machine-image/hash"` @@ -29,8 +61,3 @@ jq -r '.transactions[] | select(.transactionType=="CREATE") | select(.contractNa >> $program_path/addresses cast rpc anvil_mine 2 - -# -# kill anvil, thus dumping its state, to be loaded later by tests -kill -INT "$anvil_pid" -wait $anvil_pid