diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index 1a8118f0dd..2ab581c8bb 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -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 diff --git a/docs/guide/counter/cmd/countercli/commands/counter.go b/docs/guide/counter/cmd/countercli/commands/counter.go index 995ec23f30..a3746b8671 100644 --- a/docs/guide/counter/cmd/countercli/commands/counter.go +++ b/docs/guide/counter/cmd/countercli/commands/counter.go @@ -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) diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index b35dd0be4f..80d5c71f4e 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -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" diff --git a/tests/cli/counter.sh b/tests/cli/counter.sh index 1cd62c03de..4c56eeaf88 100755 --- a/tests/cli/counter.sh +++ b/tests/cli/counter.sh @@ -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!