github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/test/p2p/basic/test.sh (about)

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