You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB

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