Skip to content

Commit

Permalink
Merge PR cosmos#2266: Fix CLI commands JSON output
Browse files Browse the repository at this point in the history
When running with --json, commands should produce
correctly JSON-encoded output.
  • Loading branch information
alessio authored and cwgoes committed Sep 8, 2018
1 parent c800bc7 commit f68e5a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ BUG FIXES

* Gaia CLI (`gaiacli`)
* [cli] [\#1997](https://github.com/cosmos/cosmos-sdk/issues/1997) Handle panics gracefully when `gaiacli stake {delegation,unbond}` fail to unmarshal delegation.
* [cli] [\#2265](https://github.com/cosmos/cosmos-sdk/issues/2265) Fix JSON formatting of the `gaiacli send` command.

* Gaia

Expand Down
4 changes: 2 additions & 2 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ func (ctx CLIContext) ensureBroadcastTx(txBytes []byte) error {
type toJSON struct {
Height int64
TxHash string
Response string
Response abci.ResponseDeliverTx
}

if ctx.Logger != nil {
resJSON := toJSON{res.Height, res.Hash.String(), fmt.Sprintf("%+v", res.DeliverTx)}
resJSON := toJSON{res.Height, res.Hash.String(), res.DeliverTx}
bz, err := ctx.Codec.MarshalJSON(resJSON)
if err != nil {
return err
Expand Down
12 changes: 11 additions & 1 deletion cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"

Expand Down Expand Up @@ -112,8 +113,17 @@ func TestGaiaCLIGasAuto(t *testing.T) {
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())

// Enable auto gas
success = executeWrite(t, fmt.Sprintf("gaiacli send %v --gas=0 --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
success, stdout, _ := executeWriteRetStdStreams(t, fmt.Sprintf("gaiacli send %v --json --gas=0 --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
require.True(t, success)
// check that gas wanted == gas used
cdc := app.MakeCodec()
jsonOutput := struct {
Height int64
TxHash string
Response abci.ResponseDeliverTx
}{}
require.Nil(t, cdc.UnmarshalJSON([]byte(stdout), &jsonOutput))
require.Equal(t, jsonOutput.Response.GasWanted, jsonOutput.Response.GasUsed)
tests.WaitForNextNBlocksTM(2, port)
// Check state has changed accordingly
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
Expand Down

0 comments on commit f68e5a7

Please sign in to comment.