Cli now returns errors on non-zero code from DeliverTx

This commit is contained in:
Ethan Frey 2017-07-14 12:47:17 +02:00
parent e5db61a63a
commit 9fd250209e
4 changed files with 31 additions and 3 deletions

View File

@ -9,11 +9,13 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/basecoin"
"github.com/tendermint/light-client/commands"
txcmd "github.com/tendermint/light-client/commands/txs"
cmn "github.com/tendermint/tmlibs/common"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/modules/auth"
"github.com/tendermint/basecoin/modules/base"
"github.com/tendermint/basecoin/modules/coin"
@ -88,11 +90,26 @@ func doSendTx(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err = ValidateResult(bres); err != nil {
return err
}
// Output result
return txcmd.OutputTx(bres)
}
// ValidateResult returns an appropriate error if the server rejected the
// tx in CheckTx or DeliverTx
func ValidateResult(res *ctypes.ResultBroadcastTxCommit) error {
if res.CheckTx.IsErr() {
return fmt.Errorf("CheckTx: (%d): %s", res.CheckTx.Code, res.CheckTx.Log)
}
if res.DeliverTx.IsErr() {
return fmt.Errorf("DeliverTx: (%d): %s", res.DeliverTx.Code, res.DeliverTx.Log)
}
return nil
}
// WrapNonceTx grabs the sequence number from the flag and wraps
// the tx with this nonce. Grabs the permission from the signer,
// as we still only support single sig on the cli

View File

@ -76,6 +76,9 @@ func counterTx(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err = bcmd.ValidateResult(bres); err != nil {
return err
}
// Output result
return txcmd.OutputTx(bres)

View File

@ -66,7 +66,7 @@ test02SendTxWithFee() {
checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10"
# assert replay protection
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH)
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx send --amount=90mycoin --fee=10mycoin --sequence=2 --to=$RECV --name=$RICH 2>/dev/null)
assertFalse "replay: $TX" $?
checkAccount $SENDER "9007199254739900"
checkAccount $RECV "1082"

View File

@ -83,7 +83,9 @@ test03AddCount() {
if assertTrue "Line=${LINENO}, found tx" $?; then
assertEquals "Line=${LINENO}, proper height" $TX_HEIGHT $(echo $TX | jq .height)
assertEquals "Line=${LINENO}, type=sigs/one" '"sigs/one"' $(echo $TX | jq .data.type)
CTX=$(echo $TX | jq .data.data.tx)
NTX=$(echo $TX | jq .data.data.tx)
assertEquals "line=${LINENO}, type=nonce" '"nonce"' $(echo $NTX | jq .type)
CTX=$(echo $NTX | jq .data.tx)
assertEquals "Line=${LINENO}, type=chain/tx" '"chain/tx"' $(echo $CTX | jq .type)
CNTX=$(echo $CTX | jq .data.tx)
assertEquals "Line=${LINENO}, type=cntr/count" '"cntr/count"' $(echo $CNTX | jq .type)
@ -99,6 +101,12 @@ test03AddCount() {
# make sure the account was debited 11
checkAccount $SENDER "9007199254739979"
# 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" $?
checkCounter "2" "17"
checkAccount $SENDER "9007199254739979"
}
# Load common then run these tests with shunit2!