From ee4c51bb366c7950f9b3183b80d1698176ef16e1 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 20 Nov 2018 14:13:05 +0100 Subject: [PATCH] update cli tests --- client/tx/search.go | 22 ++++++++++++++++------ cmd/gaia/cli_test/cli_test.go | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/client/tx/search.go b/client/tx/search.go index 66989b42d..7a9942714 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -35,16 +35,15 @@ passed to the --tags option. To match any transaction, use the --any option. For example: -$ gaiacli tendermint txs --tag test1,test2 +$ gaiacli query txs --tag test1,test2 will match any transaction tagged with both test1,test2. To match a transaction tagged with either test1 or test2, use: -$ gaiacli tendermint txs --tag test1,test2 --any +$ gaiacli query txs --tag test1,test2 --any `), RunE: func(cmd *cobra.Command, args []string) error { tags := viper.GetStringSlice(flagTags) - cliCtx := context.NewCLIContext().WithCodec(cdc) txs, err := searchTxs(cliCtx, cdc, tags) @@ -140,13 +139,14 @@ func FormatTxResults(cdc *codec.Codec, res []*ctypes.ResultTx) ([]Info, error) { func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var tags []string + var txs []Info err := r.ParseForm() if err != nil { utils.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not parse query parameters", err.Error())) return } if len(r.Form) == 0 { - utils.PostProcessResponse(w, cdc, "[]", cliCtx.Indent) + utils.PostProcessResponse(w, cdc, txs, cliCtx.Indent) return } @@ -166,13 +166,23 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http. } key = strings.TrimRight(key, "_bech32") - value = sdk.AccAddress(bz).String() + if prefix == sdk.Bech32PrefixAccAddr { + value = sdk.AccAddress(bz).String() + } else if prefix == sdk.Bech32PrefixValAddr { + value = sdk.ValAddress(bz).String() + } else { + utils.WriteErrorResponse(w, http.StatusBadRequest, + sdk.ErrInvalidAddress(fmt.Sprintf("invalid bech32 prefix '%s'", prefix)).Error(), + ) + return + } + } tag := fmt.Sprintf("%s='%s'", key, value) tags = append(tags, tag) } - txs, err := searchTxs(cliCtx, cdc, tags) + txs, err = searchTxs(cliCtx, cdc, tags) if err != nil { utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 874c2a29a..e52bbe663 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" @@ -354,6 +355,10 @@ func TestGaiaCLISubmitProposal(t *testing.T) { executeWrite(t, spStr, app.DefaultKeyPass) tests.WaitForNextNBlocksTM(2, port) + // Test query txs + // txs := executeGetTxs(t, fmt.Sprintf("gaiacli query txs --tag action=submit-proposal,proposer=%s %v", fooAddr, flags)) + // require.Len(t, txs, 1) + fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64()) @@ -728,6 +733,18 @@ func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount { return acc } +//___________________________________________________________________________________ +// txs + +func executeGetTxs(t *testing.T, cmdStr string) []tx.Info { + out, _ := tests.ExecuteT(t, cmdStr, "") + var txs []tx.Info + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &txs) + require.NoError(t, err, "out %v\n, err %v", out, err) + return txs +} + //___________________________________________________________________________________ // stake