github.com/evdatsion/aphelion-dpos-bft@v0.32.1/test/p2p/atomic_broadcast/test.sh (about)

     1  #! /bin/bash
     2  set -u
     3  
     4  N=$1
     5  
     6  ###################################################################
     7  # assumes peers are already synced up
     8  # test sending txs
     9  # for each peer:
    10  #	send a tx, wait for commit
    11  #	assert app hash on every peer reflects the post tx state
    12  ###################################################################
    13  
    14  echo ""
    15  # run the test on each of them
    16  for i in $(seq 1 "$N"); do
    17      addr=$(test/p2p/ip.sh "$i"):26657
    18  
    19      # current state
    20      HASH1=$(curl -s "$addr/status" | jq .result.sync_info.latest_app_hash)
    21  
    22      # - send a tx
    23      TX=aadeadbeefbeefbeef0$i
    24      echo "Broadcast Tx $TX"
    25      curl -s "$addr/broadcast_tx_commit?tx=0x$TX"
    26      echo ""
    27  
    28      # we need to wait another block to get the new app_hash
    29      h1=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height | jq fromjson)
    30      h2=$h1
    31      while [ "$h2" == "$h1" ]; do
    32          sleep 1
    33          h2=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height | jq fromjson)
    34      done
    35  
    36      # wait for all other peers to get to this height
    37      minHeight=$h2
    38      for j in $(seq 1 "$N"); do
    39          if [[ "$i" != "$j" ]]; then
    40              addrJ=$(test/p2p/ip.sh "$j"):26657
    41  
    42              h=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_block_height | jq fromjson)
    43              while [ "$h" -lt "$minHeight" ]; do
    44                  sleep 1
    45                  h=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_block_height | jq fromjson)
    46              done
    47          fi
    48      done
    49  
    50      # check that hash was updated
    51      HASH2=$(curl -s "$addr/status" | jq .result.sync_info.latest_app_hash)
    52      if [[ "$HASH1" == "$HASH2" ]]; then
    53          echo "Expected state hash to update from $HASH1. Got $HASH2"
    54          exit 1
    55      fi
    56  
    57      # check we get the same new hash on all other nodes
    58      for j in $(seq 1 "$N"); do
    59          if [[ "$i" != "$j" ]]; then
    60              addrJ=$(test/p2p/ip.sh "$j"):26657
    61              HASH3=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_app_hash)
    62  
    63              if [[ "$HASH2" != "$HASH3" ]]; then
    64                  echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2"
    65                  exit 1
    66              fi
    67          fi
    68      done
    69  
    70      echo "All nodes are up to date"
    71  done
    72  
    73  echo ""
    74  echo "PASS"
    75  echo ""