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

     1  #! /bin/bash
     2  set -u
     3  
     4  N=$1
     5  
     6  ###################################################################
     7  # wait for all peers to come online
     8  # for each peer:
     9  # 	wait to have N-1 peers
    10  #	wait to be at height > 1
    11  ###################################################################
    12  
    13  # wait 60s per step per peer
    14  MAX_SLEEP=60
    15  
    16  # wait for everyone to come online
    17  echo "Waiting for nodes to come online"
    18  for i in `seq 1 $N`; do
    19  	addr=$(test/p2p/ip.sh $i):26657
    20  	curl -s $addr/status > /dev/null
    21  	ERR=$?
    22  	COUNT=0
    23  	while [ "$ERR" != 0 ]; do
    24  		sleep 1
    25  		curl -s $addr/status > /dev/null
    26  		ERR=$?
    27  		COUNT=$((COUNT+1))
    28  		if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
    29  			echo "Waited too long for node $i to come online"
    30  			exit 1
    31  		fi
    32  	done
    33  	echo "... node $i is up"
    34  done
    35  
    36  echo ""
    37  # wait for each of them to sync up
    38  for i in `seq 1 $N`; do
    39  	addr=$(test/p2p/ip.sh $i):26657
    40  	N_1=$(($N - 1))
    41  
    42  	# - assert everyone has N-1 other peers
    43  	N_PEERS=`curl -s $addr/net_info | jq '.result.peers | length'`
    44  	COUNT=0
    45  	while [ "$N_PEERS" != $N_1 ]; do
    46  		echo "Waiting for node $i to connect to all peers ..."
    47  		sleep 1
    48  		N_PEERS=`curl -s $addr/net_info | jq '.result.peers | length'`
    49  		COUNT=$((COUNT+1))
    50  		if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
    51  			echo "Waited too long for node $i to connect to all peers"
    52  			exit 1
    53  		fi
    54  	done
    55  
    56  	# - assert block height is greater than 1
    57  	BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height | jq fromjson`
    58  	COUNT=0
    59  	echo "$$BLOCK_HEIGHT IS $BLOCK_HEIGHT"
    60  	while [ "$BLOCK_HEIGHT" -le 1 ]; do
    61  		echo "Waiting for node $i to commit a block ..."
    62  		sleep 1
    63  		BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height | jq fromjson`
    64  		COUNT=$((COUNT+1))
    65  		if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
    66  			echo "Waited too long for node $i to commit a block"
    67  			exit 1
    68  		fi
    69  	done
    70  	echo "Node $i is connected to all peers and at block $BLOCK_HEIGHT"
    71  done
    72  
    73  echo ""
    74  echo "PASS"
    75  echo ""