Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve anvil startup and teardown #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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