From c8c533cc23294bcab9d76391d1ee696ce371ffd4 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 28 Nov 2017 05:51:32 +0000 Subject: [PATCH] test/p2p/atomic_broadcast: wait for node heights before checking app hash --- test/p2p/atomic_broadcast/test.sh | 80 ++++++++++++++++++------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/test/p2p/atomic_broadcast/test.sh b/test/p2p/atomic_broadcast/test.sh index 534b9a77..3224c042 100644 --- a/test/p2p/atomic_broadcast/test.sh +++ b/test/p2p/atomic_broadcast/test.sh @@ -14,46 +14,60 @@ N=$1 echo "" # run the test on each of them for i in $(seq 1 "$N"); do - addr=$(test/p2p/ip.sh "$i"):46657 + addr=$(test/p2p/ip.sh "$i"):46657 - # current state - HASH1=$(curl -s "$addr/status" | jq .result.latest_app_hash) + # current state + HASH1=$(curl -s "$addr/status" | jq .result.latest_app_hash) - # - send a tx - TX=aadeadbeefbeefbeef0$i - echo "Broadcast Tx $TX" - curl -s "$addr/broadcast_tx_commit?tx=0x$TX" - echo "" + # - send a tx + TX=aadeadbeefbeefbeef0$i + echo "Broadcast Tx $TX" + curl -s "$addr/broadcast_tx_commit?tx=0x$TX" + echo "" - # we need to wait another block to get the new app_hash - h1=$(curl -s "$addr/status" | jq .result.latest_block_height) - h2=$h1 - while [ "$h2" == "$h1" ]; do - sleep 1 - h2=$(curl -s "$addr/status" | jq .result.latest_block_height) - done + # we need to wait another block to get the new app_hash + h1=$(curl -s "$addr/status" | jq .result.latest_block_height) + h2=$h1 + while [ "$h2" == "$h1" ]; do + sleep 1 + h2=$(curl -s "$addr/status" | jq .result.latest_block_height) + done - # check that hash was updated - HASH2=$(curl -s "$addr/status" | jq .result.latest_app_hash) - if [[ "$HASH1" == "$HASH2" ]]; then - echo "Expected state hash to update from $HASH1. Got $HASH2" - exit 1 - fi + # wait for all other peers to get to this height + minHeight=$h2 + for j in $(seq 1 "$N"); do + if [[ "$i" != "$j" ]]; then + addrJ=$(test/p2p/ip.sh "$j"):46657 - # check we get the same new hash on all other nodes - for j in $(seq 1 "$N"); do - if [[ "$i" != "$j" ]]; then - addrJ=$(test/p2p/ip.sh "$j"):46657 - HASH3=$(curl -s "$addrJ/status" | jq .result.latest_app_hash) + h=$(curl -s "$addrJ/status" | jq .result.latest_block_height) + while [ "$h" -lt "$minHeight" ]; do + sleep 1 + h=$(curl -s "$addrJ/status" | jq .result.latest_block_height) + done + fi + done - if [[ "$HASH2" != "$HASH3" ]]; then - echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2" - exit 1 - fi - fi - done + # check that hash was updated + HASH2=$(curl -s "$addr/status" | jq .result.latest_app_hash) + if [[ "$HASH1" == "$HASH2" ]]; then + echo "Expected state hash to update from $HASH1. Got $HASH2" + exit 1 + fi - echo "All nodes are up to date" + # check we get the same new hash on all other nodes + for j in $(seq 1 "$N"); do + if [[ "$i" != "$j" ]]; then + addrJ=$(test/p2p/ip.sh "$j"):46657 + HASH3=$(curl -s "$addrJ/status" | jq .result.latest_app_hash) + + if [[ "$HASH2" != "$HASH3" ]]; then + echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2" + exit 1 + fi + fi + done + + echo "All nodes are up to date" done echo ""