From fd28e4e884a389662786d98e71d5a22635c5fb22 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 20 Jun 2017 13:46:49 +0200 Subject: [PATCH 1/5] Added tests on handling restarts well, cleaned up common --- tests/cli/common.sh | 33 +++++++++++--- tests/cli/restart.sh | 106 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 7 deletions(-) create mode 100755 tests/cli/restart.sh diff --git a/tests/cli/common.sh b/tests/cli/common.sh index edc7c0e125ed..12ca5d5a6fc7 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -1,13 +1,13 @@ # This is not executable, but helper functions for the other scripts # XXX XXX XXX XXX XXX -# The following global variables must be defined before calling common functions: +# The following global variables must be defined before calling common functions: # SERVER_EXE=foobar # Server binary name # CLIENT_EXE=foobarcli # Client binary name -# ACCOUNTS=(foo bar) # List of accounts for initialization +# ACCOUNTS=(foo bar) # List of accounts for initialization # RICH=${ACCOUNTS[0]} # Account to assign genesis balance -# XXX Ex Usage: quickSetup $WORK_NAME $CHAIN_ID +# XXX Ex Usage: quickSetup $WORK_NAME $CHAIN_ID # Desc: Start the program, use with shunit2 OneTimeSetUp() quickSetup() { # These are passed in as args @@ -73,17 +73,30 @@ initServer() { fi echo "Starting ${SERVER_EXE} server..." - ${SERVER_EXE} start --home=$SERVE_DIR >>$SERVER_LOG 2>&1 & + startServer $SERVE_DIR $SERVER_LOG + return $? +} + +# usage: startServer SERVE_DIR SERVER_LOG +startServer() { + ${SERVER_EXE} start --home=$1 >>$2 2>&1 & sleep 5 PID_SERVER=$! disown if ! ps $PID_SERVER >/dev/null; then echo "**FAILED**" - # cat $SERVER_LOG - # return 1 + cat $SERVER_LOG + return 1 fi } +# XXX Ex Usage: stopServer $PID_SERVER +stopServer() { + echo "stopping $SERVER_EXE test server..." + kill -9 $1 >/dev/null 2>&1 + sleep 1 +} + # XXX Ex Usage1: initClient $CHAINID # XXX Ex Usage2: initClient $CHAINID $PORTPREFIX # Desc: Initialize the client program @@ -121,7 +134,11 @@ getAddr() { checkAccount() { # make sure sender goes down ACCT=$(${CLIENT_EXE} query account $1) - assertTrue "must have genesis account" $? + if ! assertTrue "account must exist: $ACCT" $?; then + return 1 + fi + + if [ -n "$DEBUG" ]; then echo $ACCT; echo; fi assertEquals "proper sequence" "$2" $(echo $ACCT | jq .data.sequence) assertEquals "proper money" "$3" $(echo $ACCT | jq .data.coins[0].amount) return $? @@ -145,6 +162,8 @@ txSucceeded() { checkSendTx() { TX=$(${CLIENT_EXE} query tx $1) assertTrue "found tx" $? + if [ -n "$DEBUG" ]; then echo $TX; echo; fi + assertEquals "proper height" $2 $(echo $TX | jq .height) assertEquals "type=send" '"send"' $(echo $TX | jq .data.type) assertEquals "proper sender" "\"$3\"" $(echo $TX | jq .data.data.inputs[0].address) diff --git a/tests/cli/restart.sh b/tests/cli/restart.sh new file mode 100755 index 000000000000..dfdfe7c547b0 --- /dev/null +++ b/tests/cli/restart.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# these are two globals to control all scripts (can use eg. counter instead) +SERVER_EXE=basecoin +CLIENT_EXE=basecli + +oneTimeSetUp() { + # these are passed in as args + BASE_DIR=$HOME/.basecoin_test_restart + CHAIN_ID=restart-chain + + rm -rf $BASE_DIR 2>/dev/null + mkdir -p $BASE_DIR + + # set up client - make sure you use the proper prefix if you set + # a custom CLIENT_EXE + export BC_HOME=${BASE_DIR}/client + prepareClient + + # start basecoin server (with counter) + initServer $BASE_DIR $CHAIN_ID 3456 + if [ $? != 0 ]; then return 1; fi + + initClient $CHAIN_ID 34567 + + echo "...Testing may begin!" + echo + echo + echo +} + +oneTimeTearDown() { + echo + echo + stopServer $PID_SERVER +} + +test00PreRestart() { + SENDER=$(getAddr $RICH) + RECV=$(getAddr $POOR) + + RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH 2>/dev/null) + txSucceeded $? "$RES" + TX=`echo $RES | cut -d: -f2-` + HASH=$(echo $TX | jq .hash | tr -d \") + TX_HEIGHT=$(echo $TX | jq .height) + + checkAccount $SENDER "1" "9007199254740000" + checkAccount $RECV "0" "992" + + # make sure tx is indexed + checkSendTx $HASH $TX_HEIGHT $SENDER "992" + +} + + +test01OnRestart() { + SENDER=$(getAddr $RICH) + RECV=$(getAddr $POOR) + + RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=10000mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null) + txSucceeded $? "$RES" + if [ $? != 0 ]; then echo "can't make tx!"; return 1; fi + + TX=`echo $RES | cut -d: -f2-` + HASH=$(echo $TX | jq .hash | tr -d \") + TX_HEIGHT=$(echo $TX | jq .height) + + # wait til we have quite a few blocks... like at least 20, + # so the query command won't just wait for the next eg. 7 blocks to verify the result + echo "waiting to generate lots of blocks..." + sleep 20 + echo "done waiting!" + + # last minute tx just at the block cut-off... + RES=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=20000mycoin --sequence=3 --to=$RECV --name=$RICH 2>/dev/null) + txSucceeded $? "$RES" + if [ $? != 0 ]; then echo "can't make second tx!"; return 1; fi + + # now we do a restart... + stopServer $PID_SERVER + startServer $BASE_DIR/server $BASE_DIR/${SERVER_EXE}.log + if [ $? != 0 ]; then echo "can't restart server!"; return 1; fi + + # make sure queries still work properly, with all 3 tx now executed + checkAccount $SENDER "3" "9007199254710000" + checkAccount $RECV "0" "30992" + + # make sure tx is indexed + checkSendTx $HASH $TX_HEIGHT $SENDER "10000" + + # for double-check of logs + if [ -n "$DEBUG" ]; then + cat $BASE_DIR/${SERVER_EXE}.log; + fi +} + + +# load and run these tests with shunit2! +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory + +# load common helpers +. $DIR/common.sh + +. $DIR/shunit2 + From 0fc0a6232342feecec61ce99148648ca0e2a78e5 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 20 Jun 2017 13:52:32 +0200 Subject: [PATCH 2/5] Added restart cli test to Makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9013b038067c..786771d58001 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ test_cli: tests/cli/shunit2 # sudo apt-get install jq @./tests/cli/basictx.sh @./tests/cli/counter.sh + @./tests/cli/restart.sh @./tests/cli/ibc.sh get_vendor_deps: tools From f249748ce12bb9486a7662f82a2c975d40b1d70d Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 21 Jun 2017 16:10:59 +0200 Subject: [PATCH 3/5] Update to latest merkleeyes:fix-restart-height branch --- glide.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glide.lock b/glide.lock index 8b96e92922f5..79207b4f95c3 100644 --- a/glide.lock +++ b/glide.lock @@ -139,7 +139,7 @@ imports: - commands/txs - proofs - name: github.com/tendermint/merkleeyes - version: feb2c3fadac8221f96fbfce65a63af034327f972 + version: 5df9e851e1af64b4fbc7ecab89a9735010ed30fa subpackages: - app - client From 0b81676067eea411911a0897d442e28ec98bac46 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 21 Jun 2017 12:15:11 -0400 Subject: [PATCH 4/5] abci handshake --- app/app.go | 14 +++++++++++--- tests/cli/restart.sh | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index 27a3b9c98acf..6f54782ff7a8 100644 --- a/app/app.go +++ b/app/app.go @@ -8,7 +8,7 @@ import ( abci "github.com/tendermint/abci/types" wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" - . "github.com/tendermint/tmlibs/common" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" sm "github.com/tendermint/basecoin/state" @@ -53,7 +53,15 @@ func (app *Basecoin) GetState() *sm.State { // ABCI::Info func (app *Basecoin) Info() abci.ResponseInfo { - return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version.Version)} + resp, err := app.eyesCli.InfoSync() + if err != nil { + cmn.PanicCrisis(err) + } + return abci.ResponseInfo{ + Data: cmn.Fmt("Basecoin v%v", version.Version), + LastBlockHeight: resp.LastBlockHeight, + LastBlockAppHash: resp.LastBlockAppHash, + } } func (app *Basecoin) RegisterPlugin(plugin types.Plugin) { @@ -172,7 +180,7 @@ func (app *Basecoin) Commit() (res abci.Result) { app.cacheState = app.state.CacheWrap() if res.IsErr() { - PanicSanity("Error getting hash: " + res.Error()) + cmn.PanicSanity("Error getting hash: " + res.Error()) } return res } diff --git a/tests/cli/restart.sh b/tests/cli/restart.sh index dfdfe7c547b0..09187594e39a 100755 --- a/tests/cli/restart.sh +++ b/tests/cli/restart.sh @@ -69,7 +69,7 @@ test01OnRestart() { # wait til we have quite a few blocks... like at least 20, # so the query command won't just wait for the next eg. 7 blocks to verify the result echo "waiting to generate lots of blocks..." - sleep 20 + sleep 5 echo "done waiting!" # last minute tx just at the block cut-off... From 682f9ecc87f76ca2695d36a32a103452788c9cf4 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 21 Jun 2017 18:50:36 +0200 Subject: [PATCH 5/5] Cleanup after rebase --- tests/cli/common.sh | 9 +-------- tests/cli/restart.sh | 34 +++++++--------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/tests/cli/common.sh b/tests/cli/common.sh index 12ca5d5a6fc7..4ceacd22269b 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -77,7 +77,7 @@ initServer() { return $? } -# usage: startServer SERVE_DIR SERVER_LOG +# XXX Ex Usage: startServer $SERVE_DIR $SERVER_LOG startServer() { ${SERVER_EXE} start --home=$1 >>$2 2>&1 & sleep 5 @@ -90,13 +90,6 @@ startServer() { fi } -# XXX Ex Usage: stopServer $PID_SERVER -stopServer() { - echo "stopping $SERVER_EXE test server..." - kill -9 $1 >/dev/null 2>&1 - sleep 1 -} - # XXX Ex Usage1: initClient $CHAINID # XXX Ex Usage2: initClient $CHAINID $PORTPREFIX # Desc: Initialize the client program diff --git a/tests/cli/restart.sh b/tests/cli/restart.sh index 09187594e39a..90ce98e94ef0 100755 --- a/tests/cli/restart.sh +++ b/tests/cli/restart.sh @@ -3,36 +3,16 @@ # these are two globals to control all scripts (can use eg. counter instead) SERVER_EXE=basecoin CLIENT_EXE=basecli +ACCOUNTS=(jae ethan bucky rigel igor) +RICH=${ACCOUNTS[0]} +POOR=${ACCOUNTS[4]} oneTimeSetUp() { - # these are passed in as args - BASE_DIR=$HOME/.basecoin_test_restart - CHAIN_ID=restart-chain - - rm -rf $BASE_DIR 2>/dev/null - mkdir -p $BASE_DIR - - # set up client - make sure you use the proper prefix if you set - # a custom CLIENT_EXE - export BC_HOME=${BASE_DIR}/client - prepareClient - - # start basecoin server (with counter) - initServer $BASE_DIR $CHAIN_ID 3456 - if [ $? != 0 ]; then return 1; fi - - initClient $CHAIN_ID 34567 - - echo "...Testing may begin!" - echo - echo - echo + quickSetup .basecoin_test_restart restart-chain } oneTimeTearDown() { - echo - echo - stopServer $PID_SERVER + quickTearDown } test00PreRestart() { @@ -53,7 +33,6 @@ test00PreRestart() { } - test01OnRestart() { SENDER=$(getAddr $RICH) RECV=$(getAddr $POOR) @@ -78,11 +57,12 @@ test01OnRestart() { if [ $? != 0 ]; then echo "can't make second tx!"; return 1; fi # now we do a restart... - stopServer $PID_SERVER + quickTearDown startServer $BASE_DIR/server $BASE_DIR/${SERVER_EXE}.log if [ $? != 0 ]; then echo "can't restart server!"; return 1; fi # make sure queries still work properly, with all 3 tx now executed + echo "Checking state after restart..." checkAccount $SENDER "3" "9007199254710000" checkAccount $RECV "0" "30992"