diff --git a/CHANGELOG.md b/CHANGELOG.md index a723523623..2e56167821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add a `shutdown-grace` flag for waiting a given time before exit. +### Improvements + +* (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve ` q gov proposer` by querying directly a proposal instead of tx events. It is an alias of `q gov proposal` as the proposer is a field of the proposal. + ## [v0.50.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.1) - 2023-11-07 > v0.50.0 has been retracted due to a mistake in tagging the release. Please use v0.50.1 instead. diff --git a/tests/e2e/gov/query.go b/tests/e2e/gov/query.go deleted file mode 100644 index a600649d67..0000000000 --- a/tests/e2e/gov/query.go +++ /dev/null @@ -1,56 +0,0 @@ -package gov - -import ( - "fmt" - "strings" - - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" -) - -func (s *E2ETestSuite) TestCmdProposer() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - expectedOutput string - }{ - { - "without proposal id", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - true, - ``, - }, - { - "json output", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - fmt.Sprintf("{\"proposal_id\":%d,\"proposer\":\"%s\"}", 1, val.Address.String()), - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposer() - clientCtx := val.ClientCtx - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String())) - } - }) - } -} diff --git a/x/gov/autocli.go b/x/gov/autocli.go index 86edefa256..05764633b9 100644 --- a/x/gov/autocli.go +++ b/x/gov/autocli.go @@ -33,6 +33,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { { RpcMethod: "Proposal", Use: "proposal [proposal-id]", + Alias: []string{"proposer"}, Short: "Query details of a single proposal", Example: fmt.Sprintf("%s query gov proposal 1", version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go deleted file mode 100644 index a6c1538c0a..0000000000 --- a/x/gov/client/cli/query.go +++ /dev/null @@ -1,74 +0,0 @@ -package cli - -import ( - "encoding/json" - "fmt" - "strconv" - - "github.com/spf13/cobra" - - "cosmossdk.io/core/address" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/version" - gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" - "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -// GetCustomQueryCmd returns the cli query commands for this module -// These commands do not rely on gRPC and cannot be autogenerated -func GetCustomQueryCmd(ac address.Codec) *cobra.Command { - // Group gov queries under a subcommand - govQueryCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the gov module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - govQueryCmd.AddCommand( - GetCmdQueryProposer(), - ) - - return govQueryCmd -} - -// GetCmdQueryProposer implements the query proposer command. -func GetCmdQueryProposer() *cobra.Command { - cmd := &cobra.Command{ - Use: "proposer [proposal-id]", - Args: cobra.ExactArgs(1), - Short: "Query the proposer of a governance proposal", - Long: "Query which address proposed a proposal with a given ID", - Example: fmt.Sprintf("%s query gov proposer 1", version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - // validate that the proposalID is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s is not a valid uint", args[0]) - } - - prop, err := gcutils.QueryProposerByTxQuery(clientCtx, proposalID) - if err != nil { - return err - } - - output, err := json.Marshal(prop) - if err != nil { - return err - } - return clientCtx.PrintRaw(output) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index 6ee7ca4a65..a567f3b03a 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -161,6 +161,7 @@ func QueryVoteByTxQuery(clientCtx client.Context, params v1.QueryVoteParams) ([] } // QueryProposerByTxQuery will query for a proposer of a governance proposal by ID. +// Deprecated: Should not be used, as not always accurate. It will be removed in v0.51. func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Proposer, error) { q := fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID) searchResult, err := authtx.QueryTxsByEvents(clientCtx, defaultPage, defaultLimit, q, "") diff --git a/x/gov/module.go b/x/gov/module.go index a30b718ca1..dc84dd9bca 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -107,12 +107,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd(legacyProposalCLIHandlers) } -// GetQueryCmd returns the custom query commands for the gov modules. -// This command will be enhanced by AutoCLI as defined in the AutoCLIOptions() method. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetCustomQueryCmd(ab.ac) -} - func getProposalCLIHandlers(handlers []govclient.ProposalHandler) []*cobra.Command { proposalCLIHandlers := make([]*cobra.Command, 0, len(handlers)) for _, proposalHandler := range handlers {