From d4fb6d4ebe003104722021542a7c3800bda7c69d Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 7 Nov 2018 15:03:00 -0800 Subject: [PATCH 1/9] Reorganize CLI command structure. Fixes #2575 --- client/rpc/root.go | 10 +-- client/rpc/status.go | 3 +- client/tx/root.go | 9 --- cmd/gaia/cmd/gaiacli/main.go | 93 +++------------------------ cmd/gaia/cmd/gaiacli/query.go | 81 +++++++++++++++++++++++ cmd/gaia/cmd/gaiacli/tx.go | 83 ++++++++++++++++++++++++ examples/basecoin/cmd/basecli/main.go | 12 ++-- examples/democoin/cmd/democli/main.go | 13 ++-- 8 files changed, 193 insertions(+), 111 deletions(-) create mode 100644 cmd/gaia/cmd/gaiacli/query.go create mode 100644 cmd/gaia/cmd/gaiacli/tx.go diff --git a/client/rpc/root.go b/client/rpc/root.go index 74c5a69a2ed2..6ef33e0e3abf 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -22,15 +22,7 @@ func todoNotImplemented(_ *cobra.Command, _ []string) error { return errors.New("todo: Command not yet implemented") } -// AddCommands adds a number of rpc-related subcommands -func AddCommands(cmd *cobra.Command) { - cmd.AddCommand( - initClientCommand(), - statusCommand(), - ) -} - -func initClientCommand() *cobra.Command { +func InitClientCommand() *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize light client", diff --git a/client/rpc/status.go b/client/rpc/status.go index 68716f3a0b75..0f81fc9c6f00 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -14,7 +14,8 @@ import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" ) -func statusCommand() *cobra.Command { +// StatusCommand returns the status of the network +func StatusCommand() *cobra.Command { cmd := &cobra.Command{ Use: "status", Short: "Query remote node for status", diff --git a/client/tx/root.go b/client/tx/root.go index 0f237b59677e..5cd7eca0b8aa 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -2,20 +2,11 @@ package tx import ( "github.com/gorilla/mux" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" ) -// AddCommands adds a number of tx-query related subcommands -func AddCommands(cmd *cobra.Command, cdc *codec.Codec) { - cmd.AddCommand( - SearchTxCmd(cdc), - QueryTxCmd(cdc), - ) -} - // register REST routes func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET") diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 212a67021404..e4ba7ec65970 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -13,18 +13,10 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/rpc" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" - bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" - distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli" - govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" - stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" - _ "github.com/cosmos/cosmos-sdk/client/lcd/statik" ) @@ -40,7 +32,7 @@ const ( var ( rootCmd = &cobra.Command{ Use: "gaiacli", - Short: "Gaia light-client", + Short: "Command line interface for interacting with gaiad", } ) @@ -57,90 +49,23 @@ func main() { // TODO: setup keybase, viper object, etc. to be passed into // the below functions and eliminate global vars, like we do // with the cdc - rootCmd.AddCommand(client.ConfigCmd()) - - // add standard rpc commands - rpc.AddCommands(rootCmd) - - //Add query commands - queryCmd := &cobra.Command{ - Use: "query", - Aliases: []string{"q"}, - Short: "Querying subcommands", - } - queryCmd.AddCommand( - rpc.BlockCommand(), - rpc.ValidatorCommand(), - ) - tx.AddCommands(queryCmd, cdc) - queryCmd.AddCommand(client.LineBreak) - queryCmd.AddCommand(client.GetCommands( - authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)), - stakecmd.GetCmdQueryDelegation(storeStake, cdc), - stakecmd.GetCmdQueryDelegations(storeStake, cdc), - stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc), - stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc), - stakecmd.GetCmdQueryRedelegation(storeStake, cdc), - stakecmd.GetCmdQueryRedelegations(storeStake, cdc), - stakecmd.GetCmdQueryValidator(storeStake, cdc), - stakecmd.GetCmdQueryValidators(storeStake, cdc), - stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc), - stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), - stakecmd.GetCmdQueryParams(storeStake, cdc), - stakecmd.GetCmdQueryPool(storeStake, cdc), - govcmd.GetCmdQueryProposal(storeGov, cdc), - govcmd.GetCmdQueryProposals(storeGov, cdc), - govcmd.GetCmdQueryVote(storeGov, cdc), - govcmd.GetCmdQueryVotes(storeGov, cdc), - govcmd.GetCmdQueryDeposit(storeGov, cdc), - govcmd.GetCmdQueryDeposits(storeGov, cdc), - slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc), - )...) - - //Add query commands - txCmd := &cobra.Command{ - Use: "tx", - Short: "Transactions subcommands", - } - //Add auth and bank commands - txCmd.AddCommand( - client.PostCommands( - bankcmd.GetBroadcastCommand(cdc), - authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)), - )...) - txCmd.AddCommand(client.LineBreak) - - txCmd.AddCommand( - client.PostCommands( - stakecmd.GetCmdCreateValidator(cdc), - stakecmd.GetCmdEditValidator(cdc), - stakecmd.GetCmdDelegate(cdc), - stakecmd.GetCmdRedelegate(storeStake, cdc), - stakecmd.GetCmdUnbond(storeStake, cdc), - distrcmd.GetCmdWithdrawRewards(cdc), - distrcmd.GetCmdSetWithdrawAddr(cdc), - govcmd.GetCmdDeposit(cdc), - bankcmd.SendTxCmd(cdc), - govcmd.GetCmdSubmitProposal(cdc), - slashingcmd.GetCmdUnjail(cdc), - govcmd.GetCmdVote(cdc), - )...) + // Consturct Root Command rootCmd.AddCommand( - queryCmd, - txCmd, + rpc.InitClientCommand(), + rpc.StatusCommand(), + client.ConfigCmd(), + queryCmd(cdc), + txCmd(cdc), + client.LineBreak, lcd.ServeCommand(cdc), client.LineBreak, - ) - - // add proxy, version and key info - rootCmd.AddCommand( keys.Commands(), client.LineBreak, version.VersionCmd, ) - // prepare and add flags + // Add flags and prefix all env exposed with GA executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome) err := initConfig(rootCmd) if err != nil { diff --git a/cmd/gaia/cmd/gaiacli/query.go b/cmd/gaia/cmd/gaiacli/query.go new file mode 100644 index 000000000000..be3138a35a7c --- /dev/null +++ b/cmd/gaia/cmd/gaiacli/query.go @@ -0,0 +1,81 @@ +package main + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" + stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" + amino "github.com/tendermint/go-amino" +) + +func queryCmd(cdc *amino.Codec) *cobra.Command { + //Add query commands + queryCmd := &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Querying subcommands", + } + + // Group staking queries under a subcommand + stakeQueryCmd := &cobra.Command{ + Use: "stake", + Short: "Querying commands for staking module", + } + + stakeQueryCmd.AddCommand(client.GetCommands( + stakecmd.GetCmdQueryDelegation(storeStake, cdc), + stakecmd.GetCmdQueryDelegations(storeStake, cdc), + stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc), + stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc), + stakecmd.GetCmdQueryRedelegation(storeStake, cdc), + stakecmd.GetCmdQueryRedelegations(storeStake, cdc), + stakecmd.GetCmdQueryValidator(storeStake, cdc), + stakecmd.GetCmdQueryValidators(storeStake, cdc), + stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc), + stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), + stakecmd.GetCmdQueryParams(storeStake, cdc), + stakecmd.GetCmdQueryPool(storeStake, cdc))...) + + // Group gov queries under a subcommand + govQueryCmd := &cobra.Command{ + Use: "gov", + Short: "Querying commands for gov module", + } + + govQueryCmd.AddCommand(client.GetCommands( + govcmd.GetCmdQueryProposal(storeGov, cdc), + govcmd.GetCmdQueryProposals(storeGov, cdc), + govcmd.GetCmdQueryVote(storeGov, cdc), + govcmd.GetCmdQueryVotes(storeGov, cdc), + govcmd.GetCmdQueryDeposit(storeGov, cdc), + govcmd.GetCmdQueryDeposits(storeGov, cdc))...) + + // Group slashing queries under a subcommand + slashingQueryCmd := &cobra.Command{ + Use: "slashing", + Short: "Querying commands for slashing module", + } + + slashingQueryCmd.AddCommand(client.GetCommands( + slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc))...) + + // Query commcmmand sturcture + queryCmd.AddCommand( + rpc.BlockCommand(), + rpc.ValidatorCommand(), + tx.SearchTxCmd(cdc), + tx.QueryTxCmd(cdc), + client.LineBreak, + authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)), + stakeQueryCmd, + govQueryCmd, + slashingQueryCmd, + ) + + return queryCmd +} diff --git a/cmd/gaia/cmd/gaiacli/tx.go b/cmd/gaia/cmd/gaiacli/tx.go new file mode 100644 index 000000000000..892e6ae7c45d --- /dev/null +++ b/cmd/gaia/cmd/gaiacli/tx.go @@ -0,0 +1,83 @@ +package main + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" + distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli" + govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" + stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" + amino "github.com/tendermint/go-amino" +) + +func txCmd(cdc *amino.Codec) *cobra.Command { + //Add transaction generation commands + txCmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", + } + + stakeTxCmd := &cobra.Command{ + Use: "stake", + Short: "Stake Transactions subcommands", + } + + stakeTxCmd.AddCommand(client.PostCommands( + stakecmd.GetCmdCreateValidator(cdc), + stakecmd.GetCmdEditValidator(cdc), + stakecmd.GetCmdDelegate(cdc), + stakecmd.GetCmdRedelegate(storeStake, cdc), + stakecmd.GetCmdUnbond(storeStake, cdc), + )...) + + distTxCmd := &cobra.Command{ + Use: "dist", + Short: "Distribution Transactions subcommands", + } + + distTxCmd.AddCommand(client.PostCommands( + distrcmd.GetCmdWithdrawRewards(cdc), + distrcmd.GetCmdSetWithdrawAddr(cdc), + )...) + + govTxCmd := &cobra.Command{ + Use: "gov", + Short: "Governance Transactions subcommands", + } + + govTxCmd.AddCommand(client.PostCommands( + govcmd.GetCmdDeposit(cdc), + govcmd.GetCmdVote(cdc), + govcmd.GetCmdSubmitProposal(cdc), + )...) + + slashingTxCmd := &cobra.Command{ + Use: "slashing", + Short: "Slashing Transactions subcommands", + } + + slashingTxCmd.AddCommand(client.PostCommands( + slashingcmd.GetCmdUnjail(cdc), + )...) + + txCmd.AddCommand( + //Add auth and bank commands + client.PostCommands( + bankcmd.SendTxCmd(cdc), + bankcmd.GetBroadcastCommand(cdc), + authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)), + )...) + + txCmd.AddCommand( + client.LineBreak, + stakeTxCmd, + distTxCmd, + govTxCmd, + slashingTxCmd, + ) + + return txCmd +} diff --git a/examples/basecoin/cmd/basecli/main.go b/examples/basecoin/cmd/basecli/main.go index 1732e82eb916..4ebd1bef8476 100644 --- a/examples/basecoin/cmd/basecli/main.go +++ b/examples/basecoin/cmd/basecli/main.go @@ -39,10 +39,14 @@ func main() { // with the cdc. // add standard rpc, and tx commands - rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) + rootCmd.AddCommand( + rpc.InitClientCommand(), + rpc.StatusCommand(), + client.LineBreak, + tx.SearchTxCmd(cdc), + tx.QueryTxCmd(cdc), + client.LineBreak, + ) // add query/post commands (custom to binary) rootCmd.AddCommand( diff --git a/examples/democoin/cmd/democli/main.go b/examples/democoin/cmd/democli/main.go index 6bb2da868083..4121fa30b5e3 100644 --- a/examples/democoin/cmd/democli/main.go +++ b/examples/democoin/cmd/democli/main.go @@ -52,10 +52,15 @@ func main() { // with the cdc // add standard rpc, and tx commands - rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) + + rootCmd.AddCommand( + rpc.InitClientCommand(), + rpc.StatusCommand(), + client.LineBreak, + tx.SearchTxCmd(cdc), + tx.QueryTxCmd(cdc), + client.LineBreak, + ) // add query/post commands (custom to binary) // start with commands common to basecoin From c20e383d7fd970e6ce6101af907dbc1c031ba88a Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 7 Nov 2018 15:35:12 -0800 Subject: [PATCH 2/9] Fix missing flags issue --- cmd/gaia/cmd/gaiacli/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/cmd/gaiacli/query.go b/cmd/gaia/cmd/gaiacli/query.go index be3138a35a7c..b3d7a43093bb 100644 --- a/cmd/gaia/cmd/gaiacli/query.go +++ b/cmd/gaia/cmd/gaiacli/query.go @@ -71,7 +71,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { tx.SearchTxCmd(cdc), tx.QueryTxCmd(cdc), client.LineBreak, - authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)), + client.GetCommands(authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)))[0], stakeQueryCmd, govQueryCmd, slashingQueryCmd, From cade5f552c3a4306368aa25141d5a799aa5a1fed Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 7 Nov 2018 15:38:30 -0800 Subject: [PATCH 3/9] Address linting issues --- client/rpc/root.go | 1 + cmd/gaia/cmd/gaiacli/query.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/rpc/root.go b/client/rpc/root.go index 6ef33e0e3abf..7bdcd8cd8486 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -22,6 +22,7 @@ func todoNotImplemented(_ *cobra.Command, _ []string) error { return errors.New("todo: Command not yet implemented") } +// InitClientCommand initializes client commands func InitClientCommand() *cobra.Command { cmd := &cobra.Command{ Use: "init", diff --git a/cmd/gaia/cmd/gaiacli/query.go b/cmd/gaia/cmd/gaiacli/query.go index b3d7a43093bb..91734a825914 100644 --- a/cmd/gaia/cmd/gaiacli/query.go +++ b/cmd/gaia/cmd/gaiacli/query.go @@ -64,7 +64,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { slashingQueryCmd.AddCommand(client.GetCommands( slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc))...) - // Query commcmmand sturcture + // Query commcmmand structure queryCmd.AddCommand( rpc.BlockCommand(), rpc.ValidatorCommand(), From 0ab5d7639bc93b4d7ab73f8b88d19544aef58aa5 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 7 Nov 2018 16:42:34 -0800 Subject: [PATCH 4/9] Fix gobash CLI testing --- client/config.go | 21 ++++++++------- cmd/gaia/cli_test/cli_test.go | 49 ++++++++++++++++------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/client/config.go b/client/config.go index a1d38a016ff2..784ae0590be2 100644 --- a/client/config.go +++ b/client/config.go @@ -3,20 +3,20 @@ package client import ( "bufio" "fmt" + "io/ioutil" + "os" + "path" + "github.com/cosmos/cosmos-sdk/types" "github.com/mitchellh/go-homedir" "github.com/pelletier/go-toml" "github.com/spf13/cobra" - "io/ioutil" - "os" - "path" ) type cliConfig struct { Home string `toml:"home"` ChainID string `toml:"chain_id"` TrustNode bool `toml:"trust_node"` - Encoding string `toml:"encoding"` Output string `toml:"output"` Node string `toml:"node"` Trace bool `toml:"trace"` @@ -41,23 +41,25 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { } stdin := BufferStdin() + gaiaCLIHome, err := handleGaiaCLIHome(home, stdin) if err != nil { return err } + node, err := handleNode(stdin) if err != nil { return err } + trustNode, err := handleTrustNode(stdin) if err != nil { return err } - encoding := "btc" - output := "text" - var chainID string - chainID, err = types.DefaultChainID() + // var chainID string + chainID, err := types.DefaultChainID() + if err != nil { fmt.Println("Couldn't populate ChainID, so using an empty one.") } @@ -66,8 +68,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { Home: gaiaCLIHome, ChainID: chainID, TrustNode: trustNode, - Encoding: encoding, - Output: output, + Output: "text", Node: node, Trace: false, } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index bc9151200c43..2d482350a96f 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -236,7 +236,7 @@ func TestGaiaCLICreateValidator(t *testing.T) { initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewDec(100)) // Delegate tx on GaiaAppGenState // create validator - cvStr := fmt.Sprintf("gaiacli tx create-validator %v", flags) + cvStr := fmt.Sprintf("gaiacli tx stake create-validator %v", flags) cvStr += fmt.Sprintf(" --from=%s", "bar") cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey) cvStr += fmt.Sprintf(" --amount=%v", "2steak") @@ -267,12 +267,12 @@ func TestGaiaCLICreateValidator(t *testing.T) { barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags)) require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc) - validator := executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags)) + validator := executeGetValidator(t, fmt.Sprintf("gaiacli query stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags)) require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr)) require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens)) // unbond a single share - unbondStr := fmt.Sprintf("gaiacli tx unbond begin %v", flags) + unbondStr := fmt.Sprintf("gaiacli tx stake unbond begin %v", flags) unbondStr += fmt.Sprintf(" --from=%s", "bar") unbondStr += fmt.Sprintf(" --validator=%s", sdk.ValAddress(barAddr)) unbondStr += fmt.Sprintf(" --shares-amount=%v", "1") @@ -285,19 +285,19 @@ func TestGaiaCLICreateValidator(t *testing.T) { barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %v %v", barCech, flags)) require.Equal(t, int64(9), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc) */ - validator = executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags)) + validator = executeGetValidator(t, fmt.Sprintf("gaiacli query stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags)) require.Equal(t, "1.0000000000", validator.Tokens.String()) validatorUbds := executeGetValidatorUnbondingDelegations(t, - fmt.Sprintf("gaiacli query unbonding-delegations-from %s --output=json %v", + fmt.Sprintf("gaiacli query stake unbonding-delegations-from %s --output=json %v", sdk.ValAddress(barAddr), flags)) require.Len(t, validatorUbds, 1) require.Equal(t, "1", validatorUbds[0].Balance.Amount.String()) - params := executeGetParams(t, fmt.Sprintf("gaiacli query parameters --output=json %v", flags)) + params := executeGetParams(t, fmt.Sprintf("gaiacli query stake parameters --output=json %v", flags)) require.True(t, defaultParams.Equal(params)) - pool := executeGetPool(t, fmt.Sprintf("gaiacli query pool --output=json %v", flags)) + pool := executeGetPool(t, fmt.Sprintf("gaiacli query stake pool --output=json %v", flags)) require.Equal(t, initialPool.BondedTokens, pool.BondedTokens) } @@ -317,11 +317,11 @@ func TestGaiaCLISubmitProposal(t *testing.T) { fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64()) - proposalsQuery, _ := tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals %v", flags), "") + proposalsQuery, _ := tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals %v", flags), "") require.Equal(t, "No matching proposals found", proposalsQuery) // submit a test proposal - spStr := fmt.Sprintf("gaiacli tx submit-proposal %v", flags) + spStr := fmt.Sprintf("gaiacli tx gov submit-proposal %v", flags) spStr += fmt.Sprintf(" --from=%s", "foo") spStr += fmt.Sprintf(" --deposit=%s", "5steak") spStr += fmt.Sprintf(" --type=%s", "Text") @@ -348,19 +348,19 @@ func TestGaiaCLISubmitProposal(t *testing.T) { fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64()) - proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli query proposal --proposal-id=1 --output=json %v", flags)) + proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli query gov proposal --proposal-id=1 --output=json %v", flags)) require.Equal(t, uint64(1), proposal1.GetProposalID()) require.Equal(t, gov.StatusDepositPeriod, proposal1.GetStatus()) - proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals %v", flags), "") + proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals %v", flags), "") require.Equal(t, " 1 - Test", proposalsQuery) deposit := executeGetDeposit(t, - fmt.Sprintf("gaiacli query deposit --proposal-id=1 --depositer=%s --output=json %v", + fmt.Sprintf("gaiacli query gov deposit --proposal-id=1 --depositer=%s --output=json %v", fooAddr, flags)) require.Equal(t, int64(5), deposit.Amount.AmountOf("steak").Int64()) - depositStr := fmt.Sprintf("gaiacli tx deposit %v", flags) + depositStr := fmt.Sprintf("gaiacli tx gov deposit %v", flags) depositStr += fmt.Sprintf(" --from=%s", "foo") depositStr += fmt.Sprintf(" --deposit=%s", "10steak") depositStr += fmt.Sprintf(" --proposal-id=%s", "1") @@ -380,22 +380,22 @@ func TestGaiaCLISubmitProposal(t *testing.T) { // test query deposit deposits := executeGetDeposits(t, - fmt.Sprintf("gaiacli query deposits --proposal-id=1 --output=json %v", flags)) + fmt.Sprintf("gaiacli query gov deposits --proposal-id=1 --output=json %v", flags)) require.Len(t, deposits, 1) require.Equal(t, int64(15), deposits[0].Amount.AmountOf("steak").Int64()) deposit = executeGetDeposit(t, - fmt.Sprintf("gaiacli query deposit --proposal-id=1 --depositer=%s --output=json %v", + fmt.Sprintf("gaiacli query gov deposit --proposal-id=1 --depositer=%s --output=json %v", fooAddr, flags)) require.Equal(t, int64(15), deposit.Amount.AmountOf("steak").Int64()) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64()) - proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli query proposal --proposal-id=1 --output=json %v", flags)) + proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli query gov proposal --proposal-id=1 --output=json %v", flags)) require.Equal(t, uint64(1), proposal1.GetProposalID()) require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus()) - voteStr := fmt.Sprintf("gaiacli tx vote %v", flags) + voteStr := fmt.Sprintf("gaiacli tx gov vote %v", flags) voteStr += fmt.Sprintf(" --from=%s", "foo") voteStr += fmt.Sprintf(" --proposal-id=%s", "1") voteStr += fmt.Sprintf(" --option=%s", "Yes") @@ -413,23 +413,23 @@ func TestGaiaCLISubmitProposal(t *testing.T) { executeWrite(t, voteStr, app.DefaultKeyPass) tests.WaitForNextNBlocksTM(2, port) - vote := executeGetVote(t, fmt.Sprintf("gaiacli query vote --proposal-id=1 --voter=%s --output=json %v", fooAddr, flags)) + vote := executeGetVote(t, fmt.Sprintf("gaiacli query gov vote --proposal-id=1 --voter=%s --output=json %v", fooAddr, flags)) require.Equal(t, uint64(1), vote.ProposalID) require.Equal(t, gov.OptionYes, vote.Option) - votes := executeGetVotes(t, fmt.Sprintf("gaiacli query votes --proposal-id=1 --output=json %v", flags)) + votes := executeGetVotes(t, fmt.Sprintf("gaiacli query gov votes --proposal-id=1 --output=json %v", flags)) require.Len(t, votes, 1) require.Equal(t, uint64(1), votes[0].ProposalID) require.Equal(t, gov.OptionYes, votes[0].Option) - proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --status=DepositPeriod %v", flags), "") + proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --status=DepositPeriod %v", flags), "") require.Equal(t, "No matching proposals found", proposalsQuery) - proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --status=VotingPeriod %v", flags), "") + proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --status=VotingPeriod %v", flags), "") require.Equal(t, " 1 - Test", proposalsQuery) // submit a second test proposal - spStr = fmt.Sprintf("gaiacli tx submit-proposal %v", flags) + spStr = fmt.Sprintf("gaiacli tx gov submit-proposal %v", flags) spStr += fmt.Sprintf(" --from=%s", "foo") spStr += fmt.Sprintf(" --deposit=%s", "5steak") spStr += fmt.Sprintf(" --type=%s", "Text") @@ -439,7 +439,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { executeWrite(t, spStr, app.DefaultKeyPass) tests.WaitForNextNBlocksTM(2, port) - proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --limit=1 %v", flags), "") + proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --limit=1 %v", flags), "") require.Equal(t, " 2 - Apples", proposalsQuery) } @@ -552,7 +552,6 @@ func TestGaiaCLIConfig(t *testing.T) { config, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml")) require.NoError(t, err) expectedConfig := fmt.Sprintf(`chain_id = "%s" -encoding = "btc" home = "%s" node = "%s" output = "text" @@ -570,8 +569,6 @@ trust_node = true executeWrite(t, "gaiacli config", gaiacliHome, node, "y") // ensure it works without an initialized gaiad state - expectedConfig = fmt.Sprintf(`chain_id = "" -encoding = "btc" home = "%s" node = "%s" output = "text" From 1aae086f49da70d70d075a74de6ec77777645c89 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Wed, 7 Nov 2018 16:48:55 -0800 Subject: [PATCH 5/9] Fix typo --- cmd/gaia/cli_test/cli_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 2d482350a96f..73331c6eded9 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -569,6 +569,7 @@ trust_node = true executeWrite(t, "gaiacli config", gaiacliHome, node, "y") // ensure it works without an initialized gaiad state + expectedConfig = fmt.Sprintf(`chain_id = "" home = "%s" node = "%s" output = "text" From 8f4c7df0336108a849acb1fdb09ed77674db5294 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Thu, 8 Nov 2018 08:24:34 -0800 Subject: [PATCH 6/9] Address PR comments --- client/config.go | 1 - cmd/gaia/cmd/gaiacli/query.go | 6 +++--- cmd/gaia/cmd/gaiacli/tx.go | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/config.go b/client/config.go index 784ae0590be2..b7661063877b 100644 --- a/client/config.go +++ b/client/config.go @@ -57,7 +57,6 @@ func runConfigCmd(cmd *cobra.Command, args []string) error { return err } - // var chainID string chainID, err := types.DefaultChainID() if err != nil { diff --git a/cmd/gaia/cmd/gaiacli/query.go b/cmd/gaia/cmd/gaiacli/query.go index 91734a825914..051d9427ae56 100644 --- a/cmd/gaia/cmd/gaiacli/query.go +++ b/cmd/gaia/cmd/gaiacli/query.go @@ -24,7 +24,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { // Group staking queries under a subcommand stakeQueryCmd := &cobra.Command{ Use: "stake", - Short: "Querying commands for staking module", + Short: "Querying commands for the staking module", } stakeQueryCmd.AddCommand(client.GetCommands( @@ -44,7 +44,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { // Group gov queries under a subcommand govQueryCmd := &cobra.Command{ Use: "gov", - Short: "Querying commands for gov module", + Short: "Querying commands for the governance module", } govQueryCmd.AddCommand(client.GetCommands( @@ -58,7 +58,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { // Group slashing queries under a subcommand slashingQueryCmd := &cobra.Command{ Use: "slashing", - Short: "Querying commands for slashing module", + Short: "Querying commands for the slashing module", } slashingQueryCmd.AddCommand(client.GetCommands( diff --git a/cmd/gaia/cmd/gaiacli/tx.go b/cmd/gaia/cmd/gaiacli/tx.go index 892e6ae7c45d..fa0abc4ad8c3 100644 --- a/cmd/gaia/cmd/gaiacli/tx.go +++ b/cmd/gaia/cmd/gaiacli/tx.go @@ -22,7 +22,7 @@ func txCmd(cdc *amino.Codec) *cobra.Command { stakeTxCmd := &cobra.Command{ Use: "stake", - Short: "Stake Transactions subcommands", + Short: "Staking transaction subcommands", } stakeTxCmd.AddCommand(client.PostCommands( @@ -35,7 +35,7 @@ func txCmd(cdc *amino.Codec) *cobra.Command { distTxCmd := &cobra.Command{ Use: "dist", - Short: "Distribution Transactions subcommands", + Short: "Distribution transactions subcommands", } distTxCmd.AddCommand(client.PostCommands( @@ -45,7 +45,7 @@ func txCmd(cdc *amino.Codec) *cobra.Command { govTxCmd := &cobra.Command{ Use: "gov", - Short: "Governance Transactions subcommands", + Short: "Governance transactions subcommands", } govTxCmd.AddCommand(client.PostCommands( @@ -56,7 +56,7 @@ func txCmd(cdc *amino.Codec) *cobra.Command { slashingTxCmd := &cobra.Command{ Use: "slashing", - Short: "Slashing Transactions subcommands", + Short: "Slashing transactions subcommands", } slashingTxCmd.AddCommand(client.PostCommands( From 0ff12bb57a719d77da60b5ef1455406936e8acea Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Thu, 8 Nov 2018 08:25:18 -0800 Subject: [PATCH 7/9] Update cmd/gaia/cmd/gaiacli/main.go Co-Authored-By: jackzampolin --- cmd/gaia/cmd/gaiacli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index e4ba7ec65970..de99b0fc8fac 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -50,7 +50,7 @@ func main() { // the below functions and eliminate global vars, like we do // with the cdc - // Consturct Root Command + // Construct Root Command rootCmd.AddCommand( rpc.InitClientCommand(), rpc.StatusCommand(), From 6c261eec66fd1dbd4955becdd46c96cf4d97e9ab Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Thu, 8 Nov 2018 13:39:37 -0800 Subject: [PATCH 8/9] PENDING --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index 8b2044ea29ee..26a0ec776999 100644 --- a/PENDING.md +++ b/PENDING.md @@ -5,6 +5,7 @@ BREAKING CHANGES * Gaia REST API (`gaiacli advanced rest-server`) * Gaia CLI (`gaiacli`) + * [cli] [\#2728](https://github.com/cosmos/cosmos-sdk/pull/2728) Seperate `tx` and `query` subcommands by module * Gaia * [gaiad init] \#2602 New genesis workflow From 17c119dff7cea6175ec3b749f05866a3cee788d2 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Tue, 13 Nov 2018 08:27:42 -0800 Subject: [PATCH 9/9] Fix failing test --- cmd/gaia/cli_test/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index ae12714e45c7..f6fb6381ec47 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -392,7 +392,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) - require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64()) + require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64()) proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli query gov proposal --proposal-id=1 --output=json %v", flags)) require.Equal(t, uint64(1), proposal1.GetProposalID()) require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus())