Skip to content

Commit

Permalink
refactor: improve anvil startup and teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Feb 10, 2025
1 parent c24cce4 commit f8f8fdb
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions test/programs/build_anvil_state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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

0 comments on commit f8f8fdb

Please sign in to comment.