diff --git a/test/p2p/atomic_broadcast/test.sh b/test/p2p/atomic_broadcast/test.sh index 3b78166d6..3eef2d5eb 100644 --- a/test/p2p/atomic_broadcast/test.sh +++ b/test/p2p/atomic_broadcast/test.sh @@ -1,52 +1,21 @@ #! /bin/bash +set -u + +N=$1 ################################################################### -# wait for all peers to come online +# assumes peers are already synced up +# test sending txs # for each peer: -# wait to have 3 peers -# wait to be at height > 1 # send a tx, wait for commit # assert app hash on every peer reflects the post tx state ################################################################### -N=4 - -# wait for everyone to come online -echo "Waiting for nodes to come online" -for i in `seq 1 $N`; do - addr=$(test/p2p/ip.sh $i):46657 - curl -s $addr/status > /dev/null - ERR=$? - while [ "$ERR" != 0 ]; do - sleep 1 - curl -s $addr/status > /dev/null - ERR=$? - done - echo "... node $i is up" -done - echo "" # run the test on each of them for i in `seq 1 $N`; do addr=$(test/p2p/ip.sh $i):46657 - # - assert everyone has 3 other peers - N_PEERS=`curl -s $addr/net_info | jq '.result[1].peers | length'` - while [ "$N_PEERS" != 3 ]; do - echo "Waiting for node $i to connect to all peers ..." - sleep 1 - N_PEERS=`curl -s $addr/net_info | jq '.result[1].peers | length'` - done - - # - assert block height is greater than 1 - BLOCK_HEIGHT=`curl -s $addr/status | jq .result[1].latest_block_height` - while [ "$BLOCK_HEIGHT" -le 1 ]; do - echo "Waiting for node $i to commit a block ..." - sleep 1 - BLOCK_HEIGHT=`curl -s $addr/status | jq .result[1].latest_block_height` - done - echo "Node $i is connected to all peers and at block $BLOCK_HEIGHT" - # current state HASH1=`curl -s $addr/status | jq .result[1].latest_app_hash` diff --git a/test/p2p/basic/test.sh b/test/p2p/basic/test.sh new file mode 100644 index 000000000..3399515a8 --- /dev/null +++ b/test/p2p/basic/test.sh @@ -0,0 +1,53 @@ +#! /bin/bash +set -u + +N=$1 + +################################################################### +# wait for all peers to come online +# for each peer: +# wait to have N-1 peers +# wait to be at height > 1 +################################################################### + +# wait for everyone to come online +echo "Waiting for nodes to come online" +for i in `seq 1 $N`; do + addr=$(test/p2p/ip.sh $i):46657 + curl -s $addr/status > /dev/null + ERR=$? + while [ "$ERR" != 0 ]; do + sleep 1 + curl -s $addr/status > /dev/null + ERR=$? + done + echo "... node $i is up" +done + +echo "" +# wait for each of them to sync up +for i in `seq 1 $N`; do + addr=$(test/p2p/ip.sh $i):46657 + N_1=$(($N - 1)) + + # - assert everyone has N-1 other peers + N_PEERS=`curl -s $addr/net_info | jq '.result[1].peers | length'` + while [ "$N_PEERS" != $N_1 ]; do + echo "Waiting for node $i to connect to all peers ..." + sleep 1 + N_PEERS=`curl -s $addr/net_info | jq '.result[1].peers | length'` + done + + # - assert block height is greater than 1 + BLOCK_HEIGHT=`curl -s $addr/status | jq .result[1].latest_block_height` + while [ "$BLOCK_HEIGHT" -le 1 ]; do + echo "Waiting for node $i to commit a block ..." + sleep 1 + BLOCK_HEIGHT=`curl -s $addr/status | jq .result[1].latest_block_height` + done + echo "Node $i is connected to all peers and at block $BLOCK_HEIGHT" +done + +echo "" +echo "PASS" +echo "" diff --git a/test/p2p/fast_sync/restart_peer.sh b/test/p2p/fast_sync/check_peer.sh similarity index 81% rename from test/p2p/fast_sync/restart_peer.sh rename to test/p2p/fast_sync/check_peer.sh index 7a5453f00..c459277d2 100644 --- a/test/p2p/fast_sync/restart_peer.sh +++ b/test/p2p/fast_sync/check_peer.sh @@ -2,15 +2,14 @@ set -eu set -o pipefail -############################################################### -# for each peer: -# kill peer -# bring it back online via fast sync -# check app hash -############################################################### - ID=$1 +########################################### +# +# Wait for peer to catchup to other peers +# +########################################### + addr=$(test/p2p/ip.sh $ID):46657 peerID=$(( $(($ID % 4)) + 1 )) # 1->2 ... 3->4 ... 4->1 peer_addr=$(test/p2p/ip.sh $peerID):46657 diff --git a/test/p2p/fast_sync/test.sh b/test/p2p/fast_sync/test.sh index 43c5d041a..b4ac90f99 100644 --- a/test/p2p/fast_sync/test.sh +++ b/test/p2p/fast_sync/test.sh @@ -3,26 +3,13 @@ set -eu DOCKER_IMAGE=$1 NETWORK_NAME=$2 -COUNT=$3 -N=$4 +N=$3 -echo "Testing fasysync on node $COUNT" +cd $GOPATH/src/github.com/tendermint/tendermint -# kill peer -set +e # circle sigh :( -docker rm -vf local_testnet_$COUNT -set -e - -# restart peer - should have an empty blockchain -SEEDS="$(test/p2p/ip.sh 1):46656" -for j in `seq 2 $N`; do - SEEDS="$SEEDS,$(test/p2p/ip.sh $j):46656" +# run it on each of them +for i in `seq 1 $N`; do + bash test/p2p/fast_sync/test_peer.sh $DOCKER_IMAGE $NETWORK_NAME $i $N done -bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $COUNT $SEEDS - -bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$COUNT "test/p2p/fast_sync/restart_peer.sh $COUNT" -echo "" -echo "PASS" -echo "" diff --git a/test/p2p/fast_sync/test_peer.sh b/test/p2p/fast_sync/test_peer.sh new file mode 100644 index 000000000..d3c101293 --- /dev/null +++ b/test/p2p/fast_sync/test_peer.sh @@ -0,0 +1,37 @@ +#! /bin/bash +set -eu + +DOCKER_IMAGE=$1 +NETWORK_NAME=$2 +COUNT=$3 +N=$4 + +############################################################### +# this runs on each peer: +# kill peer +# bring it back online via fast sync +# wait for it to sync and check the app hash +############################################################### + + +echo "Testing fasysync on node $COUNT" + +# kill peer +set +e # circle sigh :( +docker rm -vf local_testnet_$COUNT +set -e + +# restart peer - should have an empty blockchain +SEEDS="$(test/p2p/ip.sh 1):46656" +for j in `seq 2 $N`; do + SEEDS="$SEEDS,$(test/p2p/ip.sh $j):46656" +done +bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $COUNT $SEEDS + +# wait for peer to sync and check the app hash +bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$COUNT "test/p2p/fast_sync/check_peer.sh $COUNT" + +echo "" +echo "PASS" +echo "" + diff --git a/test/p2p/local_testnet.sh b/test/p2p/local_testnet.sh index 9380adfd4..50297d62d 100644 --- a/test/p2p/local_testnet.sh +++ b/test/p2p/local_testnet.sh @@ -3,13 +3,13 @@ set -eu DOCKER_IMAGE=$1 NETWORK_NAME=$2 +N=$3 cd $GOPATH/src/github.com/tendermint/tendermint # create docker network docker network create --driver bridge --subnet 172.57.0.0/16 $NETWORK_NAME -N=4 seeds="$(test/p2p/ip.sh 1):46656" for i in `seq 2 $N`; do seeds="$seeds,$(test/p2p/ip.sh $i):46656" diff --git a/test/p2p/test.sh b/test/p2p/test.sh index 9ca50737c..7a64d464a 100644 --- a/test/p2p/test.sh +++ b/test/p2p/test.sh @@ -3,18 +3,21 @@ set -eu DOCKER_IMAGE=$1 NETWORK_NAME=local_testnet +N=4 cd $GOPATH/src/github.com/tendermint/tendermint # start the testnet on a local network -bash test/p2p/local_testnet.sh $DOCKER_IMAGE $NETWORK_NAME +bash test/p2p/local_testnet.sh $DOCKER_IMAGE $NETWORK_NAME $N -# test atomic broadcast -bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME ab test/p2p/atomic_broadcast/test.sh +# test basic connectivity and consensus +# start client container and check the num peers and height for all nodes +bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME basic "test/p2p/basic/test.sh $N" -# test fast sync (from current state of network) -# run it on each of them -N=4 -for i in `seq 1 $N`; do - bash test/p2p/fast_sync/test.sh $DOCKER_IMAGE $NETWORK_NAME $i $N -done +# test atomic broadcast: +# start client container and test sending a tx to each node +bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME ab "test/p2p/atomic_broadcast/test.sh $N" + +# test fast sync (from current state of network): +# for each node, kill it and readd via fast sync +bash test/p2p/fast_sync/test.sh $DOCKER_IMAGE $NETWORK_NAME $N