Merge pull request #129 from tendermint/bugfix/106-wrong-height-on-restart
WIP: #106 wrong height on restart
This commit is contained in:
commit
4ed03aceed
1
Makefile
1
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
|
||||
|
||||
14
app/app.go
14
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
|
||||
}
|
||||
|
||||
2
glide.lock
generated
2
glide.lock
generated
@ -139,7 +139,7 @@ imports:
|
||||
- commands/txs
|
||||
- proofs
|
||||
- name: github.com/tendermint/merkleeyes
|
||||
version: feb2c3fadac8221f96fbfce65a63af034327f972
|
||||
version: 5df9e851e1af64b4fbc7ecab89a9735010ed30fa
|
||||
subpackages:
|
||||
- app
|
||||
- client
|
||||
|
||||
@ -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,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
|
||||
}
|
||||
|
||||
@ -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 $?
|
||||
@ -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)
|
||||
|
||||
86
tests/cli/restart.sh
Executable file
86
tests/cli/restart.sh
Executable file
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user