Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: #106 wrong height on restart #129

Merged
merged 5 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions tests/cli/common.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -73,14 +73,20 @@ initServer() {
fi

echo "Starting ${SERVER_EXE} server..."
${SERVER_EXE} start --home=$SERVE_DIR >>$SERVER_LOG 2>&1 &
startServer $SERVE_DIR $SERVER_LOG
return $?
}

# XXX Ex 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
}

Expand Down Expand Up @@ -121,7 +127,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 $?
Expand All @@ -145,6 +155,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)
Expand Down
86 changes: 86 additions & 0 deletions tests/cli/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# 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() {
quickSetup .basecoin_test_restart restart-chain
}

oneTimeTearDown() {
quickTearDown
}

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 5
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...
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"

# 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