auto-sequencing

This commit is contained in:
rigel rozanski 2017-07-19 00:13:39 -04:00
parent 942506c21a
commit 0a9460dc93
11 changed files with 240 additions and 213 deletions

View File

@ -29,7 +29,7 @@ test_unit:
test_cli: tests/cli/shunit2
# sudo apt-get install jq
./tests/cli/keys.sh
./tests/cli/rpc.sh
#./tests/cli/rpc.sh
./tests/cli/init.sh
./tests/cli/basictx.sh
./tests/cli/counter.sh

View File

@ -15,7 +15,6 @@ var (
errNoOutputs = fmt.Errorf("No Output Coins")
errInvalidAddress = fmt.Errorf("Invalid Address")
errInvalidCoins = fmt.Errorf("Invalid Coins")
errInvalidSequence = fmt.Errorf("Invalid Sequence")
)
var (

View File

@ -6,9 +6,10 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
lc "github.com/tendermint/light-client"
"github.com/tendermint/basecoin"
lcmd "github.com/tendermint/basecoin/client/commands"
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
lc "github.com/tendermint/light-client"
"github.com/tendermint/basecoin/modules/nonce"
"github.com/tendermint/basecoin/stack"
@ -18,28 +19,37 @@ import (
var NonceQueryCmd = &cobra.Command{
Use: "nonce [address]",
Short: "Get details of a nonce sequence number, with proof",
RunE: lcmd.RequireInit(doNonceQuery),
RunE: lcmd.RequireInit(nonceQueryCmd),
}
func doNonceQuery(cmd *cobra.Command, args []string) error {
func nonceQueryCmd(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("Missing required argument [address]")
}
addr := strings.Join(args, ",")
act, err := parseActors(addr)
var signers []basecoin.Actor
signers, err := parseActors(addr)
if err != nil {
return err
}
key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(act))
var seq uint32
proof, err := proofcmd.GetAndParseAppProof(key, &seq)
if lc.IsNoDataErr(err) {
return errors.Errorf("Sequence is empty for address %s ", addr)
} else if err != nil {
seq, proof, err := doNonceQuery(signers)
if err != nil {
return err
}
return proofcmd.OutputProof(seq, proof.BlockHeight())
}
func doNonceQuery(signers []basecoin.Actor) (sequence uint32, proof lc.Proof, err error) {
key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(signers))
proof, err = proofcmd.GetAndParseAppProof(key, &sequence)
if lc.IsNoDataErr(err) {
err = errors.Errorf("Sequence is empty for key %s ", key)
}
return
}

View File

@ -28,15 +28,17 @@ var _ txcmd.Wrapper = NonceWrapper{}
// the tx with this nonce. Grabs the permission from the signer,
// as we still only support single sig on the cli
func (NonceWrapper) Wrap(tx basecoin.Tx) (res basecoin.Tx, err error) {
seq, err := readSequence()
if err != nil {
return res, err
}
signers, err := readNonceKey()
if err != nil {
return res, err
}
seq, err := readSequence(signers)
if err != nil {
return res, err
}
res = nonce.NewTx(seq, signers, tx)
return
}
@ -67,13 +69,28 @@ func parseActors(key string) (signers []basecoin.Actor, err error) {
return
}
func readSequence() (uint32, error) {
// read the sequence from the flag or query for it if flag is -1
func readSequence(signers []basecoin.Actor) (seq uint32, err error) {
//add the nonce tx layer to the tx
seq := viper.GetInt(FlagSequence)
if seq > 0 {
return uint32(seq), nil
seqFlag := viper.GetInt(FlagSequence)
switch {
case seqFlag > 0:
seq = uint32(seqFlag)
case seqFlag == -1:
//autocalculation for default sequence
seq, _, err = doNonceQuery(signers)
if err != nil {
return
}
//increase the sequence by 1!
seq++
default:
err = fmt.Errorf("sequence must be either greater than 0, or -1 for autocalculation")
}
// TODO: try to download from query..
return 0, fmt.Errorf("sequence must be greater than 0")
return
}

View File

@ -21,20 +21,20 @@ test00GetAccount() {
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
assertFalse "requires arg" "${CLIENT_EXE} query account"
assertFalse "line=${LINENO}, requires arg" "${CLIENT_EXE} query account"
checkAccount $SENDER "9007199254740992"
ACCT2=$(${CLIENT_EXE} query account $RECV 2>/dev/null)
assertFalse "has no genesis account" $?
assertFalse "line=${LINENO}, has no genesis account" $?
}
test01SendTx() {
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
assertFalse "missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1"
assertFalse "bad password" "echo foo | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH"
assertFalse "line=${LINENO}, missing dest" "${CLIENT_EXE} tx send --amount=992mycoin --sequence=1"
assertFalse "line=${LINENO}, bad password" "echo foo | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH"
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=992mycoin --sequence=1 --to=$RECV --name=$RICH)
txSucceeded $? "$TX" "$RECV"
HASH=$(echo $TX | jq .hash | tr -d \")
@ -53,7 +53,8 @@ test02SendTxWithFee() {
SENDER=$(getAddr $RICH)
RECV=$(getAddr $POOR)
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH)
# Test to see if the auto-sequencing works, the sequence here should be calculated to be 2
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=-1 --to=$RECV --name=$RICH)
txSucceeded $? "$TX" "$RECV"
HASH=$(echo $TX | jq .hash | tr -d \")
TX_HEIGHT=$(echo $TX | jq .height)
@ -67,7 +68,7 @@ test02SendTxWithFee() {
# assert replay protection
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null)
assertFalse "replay: $TX" $?
assertFalse "line=${LINENO}, replay: $TX" $?
checkAccount $SENDER "9007199254739900"
checkAccount $RECV "1082"
@ -76,7 +77,7 @@ test02SendTxWithFee() {
if [ -n "$DEBUG" ]; then echo $NONCE; echo; fi
# TODO: note that cobra returns error code 0 on parse failure,
# so currently this check passes even if there is no nonce query command
if assertTrue "no nonce query" $?; then
if assertTrue "line=${LINENO}, no nonce query" $?; then
assertEquals "line=${LINENO}, proper nonce" "2" $(echo $NONCE | jq .data)
fi
}

View File

@ -141,7 +141,7 @@ checkAccount() {
# XXX Ex Usage: txSucceeded $? "$TX" "$RECIEVER"
# Desc: Must be called right after the `tx` command, makes sure it got a success response
txSucceeded() {
if (assertTrue "sent tx ($3): $2" $1); then
if (assertTrue "line=${LINENO}, sent tx ($3): $2" $1); then
TX=$2
assertEquals "line=${LINENO}, good check ($3): $TX" "0" $(echo $TX | jq .check_tx.code)
assertEquals "line=${LINENO}, good deliver ($3): $TX" "0" $(echo $TX | jq .deliver_tx.code)
@ -177,7 +177,7 @@ checkSendTx() {
# and that the first input was from this sender for this amount
checkSendFeeTx() {
TX=$(${CLIENT_EXE} query tx $1)
assertTrue "found tx" $?
assertTrue "line=${LINENO}, found tx" $?
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
assertEquals "line=${LINENO}, proper height" $2 $(echo $TX | jq .height)

View File

@ -104,7 +104,7 @@ test03AddCount() {
# make sure we cannot replay the counter, no state change
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --countfee=10mycoin --sequence=2 --name=${RICH} --valid 2>/dev/null)
assertFalse "replay: $TX" $?
assertFalse "line=${LINENO}, replay: $TX" $?
checkCounter "2" "17"
checkAccount $SENDER "9007199254739979"
}

View File

@ -66,21 +66,21 @@ test00GetAccount() {
RECV_1=$(BC_HOME=${CLIENT_1} getAddr $POOR)
export BC_HOME=${CLIENT_1}
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_1 2>/dev/null"
assertFalse "line=${LINENO}, requires arg" "${CLIENT_EXE} query account 2>/dev/null"
assertFalse "line=${LINENO}, has no genesis account" "${CLIENT_EXE} query account $RECV_1 2>/dev/null"
checkAccount $SENDER_1 "0" "9007199254740992"
export BC_HOME=${CLIENT_2}
SENDER_2=$(getAddr $RICH)
RECV_2=$(getAddr $POOR)
assertFalse "requires arg" "${CLIENT_EXE} query account 2>/dev/null"
assertFalse "has no genesis account" "${CLIENT_EXE} query account $RECV_2 2>/dev/null"
assertFalse "line=${LINENO}, requires arg" "${CLIENT_EXE} query account 2>/dev/null"
assertFalse "line=${LINENO}, has no genesis account" "${CLIENT_EXE} query account $RECV_2 2>/dev/null"
checkAccount $SENDER_2 "0" "9007199254740992"
# Make sure that they have different addresses on both chains (they are random keys)
assertNotEquals "sender keys must be different" "$SENDER_1" "$SENDER_2"
assertNotEquals "recipient keys must be different" "$RECV_1" "$RECV_2"
assertNotEquals "line=${LINENO}, sender keys must be different" "$SENDER_1" "$SENDER_2"
assertNotEquals "line=${LINENO}, recipient keys must be different" "$RECV_1" "$RECV_2"
}
test01SendIBCTx() {
@ -105,7 +105,7 @@ test01SendIBCTx() {
# Make sure nothing arrived - yet
waitForBlock ${PORT_1}
assertFalse "no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV"
assertFalse "line=${LINENO}, no relay running" "BC_HOME=${CLIENT_2} ${CLIENT_EXE} query account $RECV"
# Start the relay and wait a few blocks...
# (already sent a tx on chain1, so use higher sequence)

View File

@ -4,103 +4,103 @@ CLIENT_EXE=basecli
SERVER_EXE=basecoin
oneTimeSetUp() {
BASE=~/.bc_init_test
rm -rf "$BASE"
mkdir -p "$BASE"
BASE=~/.bc_init_test
rm -rf "$BASE"
mkdir -p "$BASE"
SERVER="${BASE}/server"
SERVER_LOG="${BASE}/${SERVER_EXE}.log"
SERVER="${BASE}/server"
SERVER_LOG="${BASE}/${SERVER_EXE}.log"
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
${SERVER_EXE} init ${HEX} --home="$SERVER" >> "$SERVER_LOG"
if ! assertTrue $?; then return 1; fi
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
${SERVER_EXE} init ${HEX} --home="$SERVER" >> "$SERVER_LOG"
if ! assertTrue "line=${LINENO}" $?; then return 1; fi
GENESIS_FILE=${SERVER}/genesis.json
CHAIN_ID=$(cat ${GENESIS_FILE} | jq .chain_id | tr -d \")
GENESIS_FILE=${SERVER}/genesis.json
CHAIN_ID=$(cat ${GENESIS_FILE} | jq .chain_id | tr -d \")
printf "starting ${SERVER_EXE}...\n"
${SERVER_EXE} start --home="$SERVER" >> "$SERVER_LOG" 2>&1 &
sleep 5
PID_SERVER=$!
disown
if ! ps $PID_SERVER >/dev/null; then
echo "**STARTUP FAILED**"
cat $SERVER_LOG
return 1
fi
printf "starting ${SERVER_EXE}...\n"
${SERVER_EXE} start --home="$SERVER" >> "$SERVER_LOG" 2>&1 &
sleep 5
PID_SERVER=$!
disown
if ! ps $PID_SERVER >/dev/null; then
echo "**STARTUP FAILED**"
cat $SERVER_LOG
return 1
fi
}
oneTimeTearDown() {
printf "\nstopping ${SERVER_EXE}..."
kill -9 $PID_SERVER >/dev/null 2>&1
sleep 1
printf "\nstopping ${SERVER_EXE}..."
kill -9 $PID_SERVER >/dev/null 2>&1
sleep 1
}
test01goodInit() {
export BCHOME=${BASE}/client-01
assertFalse "ls ${BCHOME} 2>/dev/null >&2"
export BCHOME=${BASE}/client-01
assertFalse "line=${LINENO}" "ls ${BCHOME} 2>/dev/null >&2"
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null
assertTrue "initialized light-client" $?
checkDir $BCHOME 3
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null
assertTrue "line=${LINENO}, initialized light-client" $?
checkDir $BCHOME 3
}
test02badInit() {
export BCHOME=${BASE}/client-02
assertFalse "ls ${BCHOME} 2>/dev/null >&2"
export BCHOME=${BASE}/client-02
assertFalse "line=${LINENO}" "ls ${BCHOME} 2>/dev/null >&2"
# no node where we go
echo y | ${CLIENT_EXE} init --node=tcp://localhost:9999 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "invalid init" $?
# dir there, but empty...
checkDir $BCHOME 0
# no node where we go
echo y | ${CLIENT_EXE} init --node=tcp://localhost:9999 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "line=${LINENO}, invalid init" $?
# dir there, but empty...
checkDir $BCHOME 0
# try with invalid chain id
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="bad-chain-id" > /dev/null 2>&1
assertFalse "invalid init" $?
checkDir $BCHOME 0
# try with invalid chain id
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="bad-chain-id" > /dev/null 2>&1
assertFalse "line=${LINENO}, invalid init" $?
checkDir $BCHOME 0
# reject the response
echo n | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "invalid init" $?
checkDir $BCHOME 0
# reject the response
echo n | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "line=${LINENO}, invalid init" $?
checkDir $BCHOME 0
}
test03noDoubleInit() {
export BCHOME=${BASE}/client-03
assertFalse "ls ${BCHOME} 2>/dev/null >&2"
export BCHOME=${BASE}/client-03
assertFalse "line=${LINENO}" "ls ${BCHOME} 2>/dev/null >&2"
# init properly
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertTrue "initialized light-client" $?
checkDir $BCHOME 3
# init properly
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertTrue "line=${LINENO}, initialized light-client" $?
checkDir $BCHOME 3
# try again, and we get an error
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "warning on re-init" $?
checkDir $BCHOME 3
# try again, and we get an error
echo y | ${CLIENT_EXE} init --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertFalse "line=${LINENO}, warning on re-init" $?
checkDir $BCHOME 3
# unless we --force-reset
echo y | ${CLIENT_EXE} init --force-reset --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertTrue "re-initialized light-client" $?
checkDir $BCHOME 3
# unless we --force-reset
echo y | ${CLIENT_EXE} init --force-reset --node=tcp://localhost:46657 --chain-id="${CHAIN_ID}" > /dev/null 2>&1
assertTrue "line=${LINENO}, re-initialized light-client" $?
checkDir $BCHOME 3
}
test04acceptGenesisFile() {
export BCHOME=${BASE}/client-04
assertFalse "ls ${BCHOME} 2>/dev/null >&2"
export BCHOME=${BASE}/client-04
assertFalse "line=${LINENO}" "ls ${BCHOME} 2>/dev/null >&2"
# init properly
${CLIENT_EXE} init --node=tcp://localhost:46657 --genesis=${GENESIS_FILE} > /dev/null 2>&1
assertTrue "initialized light-client" $?
checkDir $BCHOME 3
# init properly
${CLIENT_EXE} init --node=tcp://localhost:46657 --genesis=${GENESIS_FILE} > /dev/null 2>&1
assertTrue "line=${LINENO}, initialized light-client" $?
checkDir $BCHOME 3
}
# XXX Ex: checkDir $DIR $FILES
# Makes sure directory exists and has the given number of files
checkDir() {
assertTrue "ls ${1} 2>/dev/null >&2"
assertEquals "no files created" "$2" $(ls $1 | wc -l)
assertTrue "line=${LINENO}" "ls ${1} 2>/dev/null >&2"
assertEquals "line=${LINENO}, no files created" "$2" $(ls $1 | wc -l)
}
# load and run these tests with shunit2!

View File

@ -4,24 +4,24 @@ CLIENT_EXE=basecli
oneTimeSetUp() {
PASS=qwertyuiop
export BCHOME=$HOME/.bc_keys_test
${CLIENT_EXE} reset_all
assertTrue $?
PASS=qwertyuiop
export BCHOME=$HOME/.bc_keys_test
${CLIENT_EXE} reset_all
assertTrue "line ${LINENO}" $?
}
newKey(){
assertNotNull "keyname required" "$1"
KEYPASS=${2:-qwertyuiop}
echo $KEYPASS | ${CLIENT_EXE} keys new $1 >/dev/null 2>&1
assertTrue "created $1" $?
assertNotNull "keyname required" "$1"
KEYPASS=${2:-qwertyuiop}
echo $KEYPASS | ${CLIENT_EXE} keys new $1 >/dev/null 2>&1
assertTrue "line ${LINENO}, created $1" $?
}
testMakeKeys() {
USER=demouser
assertFalse "already user $USER" "${CLIENT_EXE} keys get $USER"
newKey $USER
assertTrue "no user $USER" "${CLIENT_EXE} keys get $USER"
USER=demouser
assertFalse "line ${LINENO}, already user $USER" "${CLIENT_EXE} keys get $USER"
newKey $USER
assertTrue "line ${LINENO}, no user $USER" "${CLIENT_EXE} keys get $USER"
}
# load and run these tests with shunit2!

View File

@ -4,125 +4,125 @@ CLIENT_EXE=basecli
SERVER_EXE=basecoin
oneTimeSetUp() {
BASE=~/.bc_init_test
rm -rf "$BASE"
mkdir -p "$BASE"
BASE=~/.bc_init_test
rm -rf "$BASE"
mkdir -p "$BASE"
SERVER="${BASE}/server"
SERVER_LOG="${BASE}/${SERVER_EXE}.log"
SERVER="${BASE}/server"
SERVER_LOG="${BASE}/${SERVER_EXE}.log"
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
${SERVER_EXE} init ${HEX} --home="$SERVER" >> "$SERVER_LOG"
if ! assertTrue $?; then return 1; fi
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
${SERVER_EXE} init ${HEX} --home="$SERVER" >> "$SERVER_LOG"
if ! assertTrue "line=${LINENO}" $?; then return 1; fi
GENESIS_FILE=${SERVER}/genesis.json
CHAIN_ID=$(cat ${GENESIS_FILE} | jq .chain_id | tr -d \")
GENESIS_FILE=${SERVER}/genesis.json
CHAIN_ID=$(cat ${GENESIS_FILE} | jq .chain_id | tr -d \")
printf "starting ${SERVER_EXE}...\n"
${SERVER_EXE} start --home="$SERVER" >> "$SERVER_LOG" 2>&1 &
sleep 5
PID_SERVER=$!
disown
if ! ps $PID_SERVER >/dev/null; then
echo "**STARTUP FAILED**"
cat $SERVER_LOG
return 1
fi
printf "starting ${SERVER_EXE}...\n"
${SERVER_EXE} start --home="$SERVER" >> "$SERVER_LOG" 2>&1 &
sleep 5
PID_SERVER=$!
disown
if ! ps $PID_SERVER >/dev/null; then
echo "**STARTUP FAILED**"
cat $SERVER_LOG
return 1
fi
# this sets the base for all client queries in the tests
export BCHOME=${BASE}/client
${CLIENT_EXE} init --node=tcp://localhost:46657 --genesis=${GENESIS_FILE} > /dev/null 2>&1
if ! assertTrue "initialized light-client" "$?"; then
return 1
fi
# this sets the base for all client queries in the tests
export BCHOME=${BASE}/client
${CLIENT_EXE} init --node=tcp://localhost:46657 --genesis=${GENESIS_FILE} > /dev/null 2>&1
if ! assertTrue "line=${LINENO}, initialized light-client" "$?"; then
return 1
fi
}
oneTimeTearDown() {
printf "\nstopping ${SERVER_EXE}..."
kill -9 $PID_SERVER >/dev/null 2>&1
sleep 1
printf "\nstopping ${SERVER_EXE}..."
kill -9 $PID_SERVER >/dev/null 2>&1
sleep 1
}
test01getInsecure() {
GENESIS=$(${CLIENT_EXE} rpc genesis)
assertTrue "get genesis" "$?"
MYCHAIN=$(echo ${GENESIS} | jq .genesis.chain_id | tr -d \")
assertEquals "genesis chain matches" "${CHAIN_ID}" "${MYCHAIN}"
test01GetInsecure() {
GENESIS=$(${CLIENT_EXE} rpc genesis)
assertTrue "line=${LINENO}, get genesis" "$?"
MYCHAIN=$(echo ${GENESIS} | jq .genesis.chain_id | tr -d \")
assertEquals "line=${LINENO}, genesis chain matches" "${CHAIN_ID}" "${MYCHAIN}"
STATUS=$(${CLIENT_EXE} rpc status)
assertTrue "get status" "$?"
SHEIGHT=$(echo ${STATUS} | jq .latest_block_height)
assertTrue "parsed status" "$?"
assertNotNull "has a height" "${SHEIGHT}"
STATUS=$(${CLIENT_EXE} rpc status)
assertTrue "line=${LINENO}, get status" "$?"
SHEIGHT=$(echo ${STATUS} | jq .latest_block_height)
assertTrue "line=${LINENO}, parsed status" "$?"
assertNotNull "line=${LINENO}, has a height" "${SHEIGHT}"
VALS=$(${CLIENT_EXE} rpc validators)
assertTrue "get validators" "$?"
VHEIGHT=$(echo ${VALS} | jq .block_height)
assertTrue "parsed validators" "$?"
assertTrue "sensible heights: $SHEIGHT / $VHEIGHT" "test $VHEIGHT -ge $SHEIGHT"
VCNT=$(echo ${VALS} | jq '.validators | length')
assertEquals "one validator" "1" "$VCNT"
VALS=$(${CLIENT_EXE} rpc validators)
assertTrue "line=${LINENO}, get validators" "$?"
VHEIGHT=$(echo ${VALS} | jq .block_height)
assertTrue "line=${LINENO}, parsed validators" "$?"
assertTrue "line=${LINENO}, sensible heights: $SHEIGHT / $VHEIGHT" "test $VHEIGHT -ge $SHEIGHT"
VCNT=$(echo ${VALS} | jq '.validators | length')
assertEquals "line=${LINENO}, one validator" "1" "$VCNT"
INFO=$(${CLIENT_EXE} rpc info)
assertTrue "get info" "$?"
DATA=$(echo $INFO | jq .response.data)
assertEquals "basecoin info" '"Basecoin v0.6.1"' "$DATA"
INFO=$(${CLIENT_EXE} rpc info)
assertTrue "line=${LINENO}, get info" "$?"
DATA=$(echo $INFO | jq .response.data)
assertEquals "line=${LINENO}, basecoin info" '"Basecoin v0.6.1"' "$DATA"
}
test02getSecure() {
HEIGHT=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertTrue "get status" "$?"
test02GetSecure() {
HEIGHT=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertTrue "line=${LINENO}, get status" "$?"
# check block produces something reasonable
assertFalse "missing height" "${CLIENT_EXE} rpc block"
BLOCK=$(${CLIENT_EXE} rpc block --height=$HEIGHT)
assertTrue "get block" "$?"
MHEIGHT=$(echo $BLOCK | jq .block_meta.header.height)
assertEquals "meta height" "${HEIGHT}" "${MHEIGHT}"
BHEIGHT=$(echo $BLOCK | jq .block.header.height)
assertEquals "meta height" "${HEIGHT}" "${BHEIGHT}"
# check block produces something reasonable
assertFalse "line=${LINENO}, missing height" "${CLIENT_EXE} rpc block"
BLOCK=$(${CLIENT_EXE} rpc block --height=$HEIGHT)
assertTrue "line=${LINENO}, get block" "$?"
MHEIGHT=$(echo $BLOCK | jq .block_meta.header.height)
assertEquals "line=${LINENO}, meta height" "${HEIGHT}" "${MHEIGHT}"
BHEIGHT=$(echo $BLOCK | jq .block.header.height)
assertEquals "line=${LINENO}, meta height" "${HEIGHT}" "${BHEIGHT}"
# check commit produces something reasonable
assertFalse "missing height" "${CLIENT_EXE} rpc commit"
let "CHEIGHT = $HEIGHT - 1"
COMMIT=$(${CLIENT_EXE} rpc commit --height=$CHEIGHT)
assertTrue "get commit" "$?"
HHEIGHT=$(echo $COMMIT | jq .header.height)
assertEquals "commit height" "${CHEIGHT}" "${HHEIGHT}"
assertEquals "canonical" "true" $(echo $COMMIT | jq .canonical)
BSIG=$(echo $BLOCK | jq .block.last_commit)
CSIG=$(echo $COMMIT | jq .commit)
assertEquals "block and commit" "$BSIG" "$CSIG"
# check commit produces something reasonable
assertFalse "line=${LINENO}, missing height" "${CLIENT_EXE} rpc commit"
let "CHEIGHT = $HEIGHT - 1"
COMMIT=$(${CLIENT_EXE} rpc commit --height=$CHEIGHT)
assertTrue "line=${LINENO}, get commit" "$?"
HHEIGHT=$(echo $COMMIT | jq .header.height)
assertEquals "line=${LINENO}, commit height" "${CHEIGHT}" "${HHEIGHT}"
assertEquals "line=${LINENO}, canonical" "true" $(echo $COMMIT | jq .canonical)
BSIG=$(echo $BLOCK | jq .block.last_commit)
CSIG=$(echo $COMMIT | jq .commit)
assertEquals "line=${LINENO}, block and commit" "$BSIG" "$CSIG"
# now let's get some headers
# assertFalse "missing height" "${CLIENT_EXE} rpc headers"
HEADERS=$(${CLIENT_EXE} rpc headers --min=$CHEIGHT --max=$HEIGHT)
assertTrue "get headers" "$?"
assertEquals "proper height" "$HEIGHT" $(echo $HEADERS | jq '.last_height')
assertEquals "two headers" "2" $(echo $HEADERS | jq '.block_metas | length')
# should we check these headers?
CHEAD=$(echo $COMMIT | jq .header)
# most recent first, so the commit header is second....
HHEAD=$(echo $HEADERS | jq .block_metas[1].header)
assertEquals "commit and header" "$CHEAD" "$HHEAD"
# now let's get some headers
# assertFalse "missing height" "${CLIENT_EXE} rpc headers"
HEADERS=$(${CLIENT_EXE} rpc headers --min=$CHEIGHT --max=$HEIGHT)
assertTrue "line=${LINENO}, get headers" "$?"
assertEquals "line=${LINENO}, proper height" "$HEIGHT" $(echo $HEADERS | jq '.last_height')
assertEquals "line=${LINENO}, two headers" "2" $(echo $HEADERS | jq '.block_metas | length')
# should we check these headers?
CHEAD=$(echo $COMMIT | jq .header)
# most recent first, so the commit header is second....
HHEAD=$(echo $HEADERS | jq .block_metas[1].header)
assertEquals "line=${LINENO}, commit and header" "$CHEAD" "$HHEAD"
}
test03waiting() {
START=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertTrue "get status" "$?"
test03Waiting() {
START=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertTrue "line=${LINENO}, get status" "$?"
let "NEXT = $START + 5"
assertFalse "no args" "${CLIENT_EXE} rpc wait"
assertFalse "too long" "${CLIENT_EXE} rpc wait --height=1234"
assertTrue "normal wait" "${CLIENT_EXE} rpc wait --height=$NEXT"
let "NEXT = $START + 5"
assertFalse "line=${LINENO}, no args" "${CLIENT_EXE} rpc wait"
assertFalse "line=${LINENO}, too long" "${CLIENT_EXE} rpc wait --height=1234"
assertTrue "line=${LINENO}, normal wait" "${CLIENT_EXE} rpc wait --height=$NEXT"
STEP=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertEquals "wait until height" "$NEXT" "$STEP"
STEP=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertEquals "line=${LINENO}, wait until height" "$NEXT" "$STEP"
let "NEXT = $STEP + 3"
assertTrue "${CLIENT_EXE} rpc wait --delta=3"
STEP=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertEquals "wait for delta" "$NEXT" "$STEP"
let "NEXT = $STEP + 3"
assertTrue "line=${LINENO}, ${CLIENT_EXE} rpc wait --delta=3"
STEP=$(${CLIENT_EXE} rpc status | jq .latest_block_height)
assertEquals "line=${LINENO}, wait for delta" "$NEXT" "$STEP"
}
# load and run these tests with shunit2!