Skip to content

Commit

Permalink
Add balance checks to demo smoketest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed May 8, 2024
1 parent d1a138c commit a46cf22
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion scripts/smoke-test-demo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
# load env vars in .env
set -a; source .env; set +a;

SEQUENCER_API=http://localhost:$ESPRESSO_SEQUENCER_API_PORT
SEQUENCER_API=http://localhost:$ESPRESSO_SEQUENCER1_API_PORT
LOAD_GENERATOR=http://localhost:$ESPRESSO_SUBMIT_TRANSACTIONS_PRIVATE_PORT
SEQUENCER_BLOCKS_TIMEOUT=120

Expand All @@ -29,17 +29,31 @@ function wait_for() {
echo "Endpoint $what @ $url is Ok, after $elapsed seconds"
}

# usage: get_balance <address> <block>
function get_balance() {
(
unset MNEMONIC
cargo run --release --all-features --bin bridge -- balance -e $SEQUENCER_API -a $1 -b $2
)
}

# Wait for the load generator to start.
wait_for 300 "demo load generator" "$LOAD_GENERATOR/healthcheck"

# Get the block height and number of transactions, wait some time, and check that these numbers have
# both increased.
block_height=`curl -sL $SEQUENCER_API/node/block-height`
num_tx=`curl -sL $SEQUENCER_API/node/transactions/count`
# Get the balance of the builder and burner accounts. The former should decrease over time while the
# latter should increase.
builder_balance=`get_balance 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f $block_height`
burner_balance=`get_balance 0x0000000000000000000000000000000000000000 $block_height`

echo "Initial state:"
echo " block_height: $block_height"
echo " transactions: $num_tx"
echo " builder_balance: $builder_balance"
echo " burner_balance: $burner_balance"

# Bash magic to get the current time in seconds since start of this shell
START=$SECONDS
Expand All @@ -50,10 +64,21 @@ while true; do
new_block_height=`curl -sL $SEQUENCER_API/node/block-height`
new_num_tx=`curl -sL $SEQUENCER_API/node/transactions/count`
if [[ $new_block_height -gt $block_height && $new_num_tx -gt $num_tx ]]; then
new_builder_balance=`get_balance 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f $new_block_height`
new_burner_balance=`get_balance 0x0000000000000000000000000000000000000000 $new_block_height`

echo "Final state:"
echo " block_height: $new_block_height"
echo " transactions: $new_num_tx"
echo " builder_balance: $new_builder_balance"
echo " burner_balance: $new_burner_balance"
echo "Block height and transaction count are increasing. Great!"

if [[ $((builder_balance + burner_balance)) != $((new_builder_balance + new_burner_balance)) ]]; then
echo "Balance not conserved!"
exit 1
fi

break
fi
sleep 1
Expand Down

0 comments on commit a46cf22

Please sign in to comment.