From 204149920e045ebd9db778c36cdece6311a6e3f5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 13 Jul 2023 16:24:36 +0200 Subject: [PATCH 01/10] feat(gov): autocli query support --- CHANGELOG.md | 6 + x/gov/autocli.go | 76 ++++ x/gov/client/cli/query.go | 632 +-------------------------------- x/gov/client/cli/query_test.go | 408 --------------------- x/gov/keeper/grpc_query.go | 5 - x/gov/module.go | 5 - 6 files changed, 94 insertions(+), 1038 deletions(-) delete mode 100644 x/gov/client/cli/query_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 06833ef15560..907622d2b4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## CLI Breaking Changes +* (all) Query pagination flags have been renamed with the migration to AutoCLI: + * `--limit` -> `--page-limit` + * `--offset` -> `--page-offset` + * `--count-total` -> `--page-count-total` + * `--reverse` -> `--page-reverse` +* (x/gov) []() In ` query gov proposals` the proposal status flag have renamed from `--status` to `--proposal-status`. Additonally, that flags now uses the ENUM values: `PROPOSAL_STATUS_DEPOSIT_PERIOD`, `PROPOSAL_STATUS_VOTING_PERIOD`, `PROPOSAL_STATUS_PASSED`, `PROPOSAL_STATUS_REJECTED`, `PROPOSAL_STATUS_FAILED`. * (x/bank) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) With the migration to AutoCLI some bank commands have been split in two: * Use `denoms-metadata` for querying all denom metadata and `denom-metadata` for querying a specific denom metadata. * Use `total-supply` (or `total`) for querying the total supply and `total-supply-of` for querying the supply of a specific denom. diff --git a/x/gov/autocli.go b/x/gov/autocli.go index 3b53657f79e7..a72be2d09435 100644 --- a/x/gov/autocli.go +++ b/x/gov/autocli.go @@ -1,9 +1,12 @@ package gov import ( + "fmt" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" govv1 "cosmossdk.io/api/cosmos/gov/v1" govv1beta1 "cosmossdk.io/api/cosmos/gov/v1beta1" + "github.com/cosmos/cosmos-sdk/version" ) // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. @@ -11,6 +14,79 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { return &autocliv1.ModuleOptions{ Tx: &autocliv1.ServiceCommandDescriptor{ Service: govv1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Query the parameters of the governance process", + Long: "Query the parameters of the governance process. Specify specific param types (voting|tallying|deposit) to filter results.", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "params_type", Optional: true}, + }, + }, + { + RpcMethod: "Proposals", + Use: "proposals", + Short: "Query proposals with optional filters", + Example: fmt.Sprintf("%[1]s query gov proposals --depositor cosmos1...\n%[1]s query gov proposals --voter cosmos1...\n%[1]s query gov proposals --proposal-status (PROPOSAL_STATUS_DEPOSIT_PERIOD|PROPOSAL_STATUS_VOTING_PERIOD|PROPOSAL_STATUS_PASSED|PROPOSAL_STATUS_REJECTED|PROPOSAL_STATUS_FAILED)", version.AppName), + }, + { + RpcMethod: "Proposal", + Use: "proposal [proposal-id]", + Short: "Query details of a single proposal", + Example: fmt.Sprintf("%s query gov proposal 1", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + }, + }, + { + RpcMethod: "Vote", + Use: "vote [proposal-id] [voter-addr]", + Short: "Query details of a single vote", + Example: fmt.Sprintf("%s query gov vote 1 cosmos1...", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + {ProtoField: "voter"}, + }, + }, + { + RpcMethod: "Votes", + Use: "votes [proposal-id]", + Short: "Query votes of a single proposal", + Example: fmt.Sprintf("%s query gov votes 1", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + }, + }, + { + RpcMethod: "Deposit", + Use: "deposit [proposal-id] [depositer-addr]", + Short: "Query details of a deposit", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + {ProtoField: "depositor"}, + }, + }, + { + RpcMethod: "Deposits", + Use: "deposits [proposal-id]", + Short: "Query deposits on a proposal", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + }, + }, + { + RpcMethod: "TallyResult", + Use: "tally [proposal-id]", + Short: "Query the tally of a proposal vote", + Example: fmt.Sprintf("%s query gov tally 1", version.AppName), + }, + { + RpcMethod: "Constitution", + Use: "constitution", + Short: "Query the current chain constitution", + }, + }, // map v1beta1 as a sub-command SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ "v1beta1": {Service: govv1beta1.Msg_ServiceDesc.ServiceName}, diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index bbcf5fd9652e..6aa77f2242c7 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -1,25 +1,25 @@ package cli import ( - "errors" "fmt" "strconv" - "strings" - - "github.com/spf13/cobra" "cosmossdk.io/core/address" + "github.com/spf13/cobra" "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" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) -// GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(ac address.Codec) *cobra.Command { +// GetCustomQueryCmd returns the cli query commands for this module +// These commands do not rely on gRPC and cannot be autogenerated + +// TODO(@julienrbrt) https://github.com/cosmos/cosmos-sdk/issues/16836 + +func GetCustomQueryCmd(ac address.Codec) *cobra.Command { // Group gov queries under a subcommand govQueryCmd := &cobra.Command{ Use: types.ModuleName, @@ -30,606 +30,20 @@ func GetQueryCmd(ac address.Codec) *cobra.Command { } govQueryCmd.AddCommand( - GetCmdQueryProposal(), - GetCmdQueryProposals(ac), - GetCmdQueryVote(ac), - GetCmdQueryVotes(), - GetCmdQueryParams(), - GetCmdQueryParam(), GetCmdQueryProposer(), - GetCmdQueryDeposit(), - GetCmdQueryDeposits(), - GetCmdQueryTally(), - GetCmdConstitution(), ) return govQueryCmd } -// GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "proposal [proposal-id]", - Args: cobra.ExactArgs(1), - Short: "Query details of a single proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details for a proposal. You can find the -proposal-id by running "%s query gov proposals". - -Example: -$ %s query gov proposal 1 -`, - version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) - } - - // Query the proposal - res, err := queryClient.Proposal( - cmd.Context(), - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return err - } - - return clientCtx.PrintProto(res.Proposal) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryProposals implements a query proposals command. Command to Get -// Proposals Information. -func GetCmdQueryProposals(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "proposals", - Short: "Query proposals with optional filters", - Long: strings.TrimSpace( - fmt.Sprintf(`Query for a all paginated proposals that match optional filters: - -Example: -$ %s query gov proposals --depositor cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -$ %s query gov proposals --voter cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -$ %s query gov proposals --status (DepositPeriod|VotingPeriod|Passed|Rejected) -$ %s query gov proposals --page=2 --limit=100 -`, - version.AppName, version.AppName, version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - bechDepositorAddr, _ := cmd.Flags().GetString(flagDepositor) - bechVoterAddr, _ := cmd.Flags().GetString(flagVoter) - strProposalStatus, _ := cmd.Flags().GetString(flagStatus) - - var proposalStatus v1.ProposalStatus - - if len(bechDepositorAddr) != 0 { - _, err := ac.StringToBytes(bechDepositorAddr) - if err != nil { - return err - } - } - - if len(bechVoterAddr) != 0 { - _, err := ac.StringToBytes(bechVoterAddr) - if err != nil { - return err - } - } - - if len(strProposalStatus) != 0 { - proposalStatus1, err := v1.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus)) - proposalStatus = proposalStatus1 - if err != nil { - return err - } - } - - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.Proposals( - cmd.Context(), - &v1.QueryProposalsRequest{ - ProposalStatus: proposalStatus, - Voter: bechVoterAddr, - Depositor: bechDepositorAddr, - Pagination: pageReq, - }, - ) - if err != nil { - return err - } - - if len(res.GetProposals()) == 0 { - return errors.New("no proposals found") - } - - return clientCtx.PrintProto(res) - }, - } - - cmd.Flags().String(flagDepositor, "", "(optional) filter by proposals deposited on by depositor") - cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted") - cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status, status: deposit_period/voting_period/passed/rejected") - flags.AddPaginationFlagsToCmd(cmd, "proposals") - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryVote implements the query proposal vote command. Command to Get a -// Vote Information. -func GetCmdQueryVote(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "vote [proposal-id] [voter-addr]", - Args: cobra.ExactArgs(2), - Short: "Query details of a single vote", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details for a single vote on a proposal given its identifier. - -Example: -$ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) - } - - // check to see if the proposal is in the store - ctx := cmd.Context() - _, err = queryClient.Proposal( - ctx, - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) - } - - voterAddr, err := ac.StringToBytes(args[1]) - if err != nil { - return err - } - - res, err := queryClient.Vote( - ctx, - &v1.QueryVoteRequest{ProposalId: proposalID, Voter: args[1]}, - ) - if err != nil { - return err - } - - vote := res.GetVote() - if vote.Empty() { - params := v1.NewQueryVoteParams(proposalID, voterAddr) - resByTxQuery, err := gcutils.QueryVoteByTxQuery(clientCtx, params) - if err != nil { - return err - } - - if err := clientCtx.Codec.UnmarshalJSON(resByTxQuery, vote); err != nil { - return err - } - } - - return clientCtx.PrintProto(res.Vote) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryVotes implements the command to query for proposal votes. -func GetCmdQueryVotes() *cobra.Command { - cmd := &cobra.Command{ - Use: "votes [proposal-id]", - Args: cobra.ExactArgs(1), - Short: "Query votes on a proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Query vote details for a single proposal by its identifier. - -Example: -$ %[1]s query gov votes 1 -$ %[1]s query gov votes 1 --page=2 --limit=100 -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) - } - - // check to see if the proposal is in the store - ctx := cmd.Context() - proposalRes, err := queryClient.Proposal( - ctx, - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) - } - - propStatus := proposalRes.GetProposal().Status - if !(propStatus == v1.StatusVotingPeriod || propStatus == v1.StatusDepositPeriod) { - page, _ := cmd.Flags().GetInt(flags.FlagPage) - limit, _ := cmd.Flags().GetInt(flags.FlagLimit) - - params := v1.NewQueryProposalVotesParams(proposalID, page, limit) - resByTxQuery, err := gcutils.QueryVotesByTxQuery(clientCtx, params) - if err != nil { - return err - } - - var votes v1.Votes - // TODO migrate to use JSONCodec (implement MarshalJSONArray - // or wrap lists of proto.Message in some other message) - clientCtx.LegacyAmino.MustUnmarshalJSON(resByTxQuery, &votes) - return clientCtx.PrintObjectLegacy(votes) - - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.Votes( - ctx, - &v1.QueryVotesRequest{ProposalId: proposalID, Pagination: pageReq}, - ) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddPaginationFlagsToCmd(cmd, "votes") - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryDeposit implements the query proposal deposit command. Command to -// get a specific Deposit Information. -func GetCmdQueryDeposit() *cobra.Command { - cmd := &cobra.Command{ - Use: "deposit [proposal-id] [depositer-addr]", - Args: cobra.ExactArgs(2), - Short: "Query details of a deposit", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details for a single proposal deposit on a proposal by its identifier. - -Example: -$ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) - } - - // check to see if the proposal is in the store - ctx := cmd.Context() - _, err = queryClient.Proposal( - ctx, - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) - } - - res, err := queryClient.Deposit( - ctx, - &v1.QueryDepositRequest{ProposalId: proposalID, Depositor: args[1]}, - ) - if err != nil { - return err - } - - return clientCtx.PrintProto(res.Deposit) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryDeposits implements the command to query for proposal deposits. -func GetCmdQueryDeposits() *cobra.Command { - cmd := &cobra.Command{ - Use: "deposits [proposal-id]", - Args: cobra.ExactArgs(1), - Short: "Query deposits on a proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Query details for all deposits on a proposal. -You can find the proposal-id by running "%s query gov proposals". - -Example: -$ %s query gov deposits 1 -`, - version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) - } - - // check to see if the proposal is in the store - ctx := cmd.Context() - _, err = queryClient.Proposal( - ctx, - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.Deposits( - ctx, - &v1.QueryDepositsRequest{ProposalId: proposalID, Pagination: pageReq}, - ) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddPaginationFlagsToCmd(cmd, "deposits") - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryTally implements the command to query for proposal tally result. -func GetCmdQueryTally() *cobra.Command { - cmd := &cobra.Command{ - Use: "tally [proposal-id]", - Args: cobra.ExactArgs(1), - Short: "Get the tally of a proposal vote", - Long: strings.TrimSpace( - fmt.Sprintf(`Query tally of votes on a proposal. You can find -the proposal-id by running "%s query gov proposals". - -Example: -$ %s query gov tally 1 -`, - version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) - } - - // check to see if the proposal is in the store - ctx := cmd.Context() - _, err = queryClient.Proposal( - ctx, - &v1.QueryProposalRequest{ProposalId: proposalID}, - ) - if err != nil { - return fmt.Errorf("failed to fetch proposal-id %d: %w", proposalID, err) - } - - // Query store - res, err := queryClient.TallyResult( - ctx, - &v1.QueryTallyResultRequest{ProposalId: proposalID}, - ) - if err != nil { - return err - } - - return clientCtx.PrintProto(res.Tally) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryParams implements the query params command. -// -//nolint:staticcheck // this function contains deprecated commands that we need. -func GetCmdQueryParams() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Query the parameters of the governance process", - Long: strings.TrimSpace( - fmt.Sprintf(`Query the all the parameters for the governance process. - -Example: -$ %s query gov params -`, - version.AppName, - ), - ), - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // Query store for all 3 params - ctx := cmd.Context() - - res, err := queryClient.Params( - ctx, - &v1.QueryParamsRequest{ParamsType: "deposit"}, - ) - if err != nil { - return err - } - - vp := v1.NewVotingParams(res.Params.VotingPeriod) - res.VotingParams = &vp - - tp := v1.NewTallyParams(res.Params.Quorum, res.Params.Threshold, res.Params.VetoThreshold) - res.TallyParams = &tp - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQueryParam implements the query param command. -func GetCmdQueryParam() *cobra.Command { - cmd := &cobra.Command{ - Use: "param [param-type]", - Args: cobra.ExactArgs(1), - Short: "Query the parameters (voting|tallying|deposit) of the governance process", - Long: strings.TrimSpace( - fmt.Sprintf(`Query the all the parameters for the governance process. -Example: -$ %s query gov param voting -$ %s query gov param tallying -$ %s query gov param deposit -`, - version.AppName, version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - // Query store - res, err := queryClient.Params( - cmd.Context(), - &v1.QueryParamsRequest{ParamsType: args[0]}, - ) - if err != nil { - return err - } - - var out fmt.Stringer - //nolint:staticcheck // this switch statement contains deprecated commands that we need. - switch args[0] { - case "voting": - out = res.GetVotingParams() - case "tallying": - out = res.GetTallyParams() - case "deposit": - out = res.GetDepositParams() - default: - return fmt.Errorf("argument must be one of (voting|tallying|deposit), was %s", args[0]) - } - - return clientCtx.PrintObjectLegacy(out) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - // 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: strings.TrimSpace( - fmt.Sprintf(`Query which address proposed a proposal with a given ID. - -Example: -$ %s query gov proposer 1 -`, - version.AppName, - ), - ), + 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 { @@ -655,25 +69,3 @@ $ %s query gov proposer 1 return cmd } - -func GetCmdConstitution() *cobra.Command { - return &cobra.Command{ - Use: "constitution", - Short: "Get the constitution", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - queryClient := v1.NewQueryClient(clientCtx) - - resp, err := queryClient.Constitution(cmd.Context(), &v1.QueryConstitutionRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(resp) - }, - } -} diff --git a/x/gov/client/cli/query_test.go b/x/gov/client/cli/query_test.go deleted file mode 100644 index f3e4d66557dd..000000000000 --- a/x/gov/client/cli/query_test.go +++ /dev/null @@ -1,408 +0,0 @@ -package cli_test - -import ( - "fmt" - "strings" - - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" - "github.com/cosmos/cosmos-sdk/testutil" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" -) - -func (s *CLITestSuite) TestCmdParams() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "json output", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - "--output=json", - }, - { - "text output", - []string{fmt.Sprintf("--%s=text", flags.FlagOutput)}, - "--output=text", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryParams() - cmd.SetArgs(tc.args) - - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdParam() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "voting params", - []string{ - "voting", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `voting --output=json`, - }, - { - "tally params", - []string{ - "tallying", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `tallying --output=json`, - }, - { - "deposit params", - []string{ - "deposit", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `deposit --output=json`, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryParam() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdProposer() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "without proposal id", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "--output=json", - }, - { - "with proposal id", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "1 --output=json", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposer() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdTally() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "without proposal id", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "--output=json", - }, - { - "with proposal id (json output)", - []string{ - "2", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "2 --output=json", - }, - { - "with proposal id (text output)", - []string{ - "1", - fmt.Sprintf("--%s=text", flags.FlagOutput), - }, - "1 --output=text", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryTally() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdGetProposal() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get proposal with json response", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "1 --output=json", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposal() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdGetProposals() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get proposals as json response", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "--output=json", - }, - { - "get proposals with invalid status", - []string{ - "--status=unknown", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "--status=unknown --output=json", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposals(address.NewBech32Codec("cosmos")) - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdQueryDeposits() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get deposits", - []string{ - "10", - }, - "10", - }, - { - "get deposits(json output)", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "1 --output=json", - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryDeposits() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdQueryDeposit() { - val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get deposit with no depositer", - []string{ - "1", - }, - "1", - }, - { - "get deposit with wrong deposit address", - []string{ - "1", - "wrong address", - }, - "1 wrong address", - }, - { - "get deposit (valid req)", - []string{ - "1", - val[0].Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - fmt.Sprintf("1 %s --output=json", val[0].Address.String()), - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryDeposit() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdQueryVotes() { - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get votes with no proposal id", - []string{}, - "", - }, - { - "get votes of a proposal", - []string{ - "10", - }, - "10", - }, - { - "get votes of a proposal (json output)", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - "1 --output=json", - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryVotes() - cmd.SetArgs(tc.args) - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - }) - } -} - -func (s *CLITestSuite) TestCmdQueryVote() { - val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - - testCases := []struct { - name string - args []string - expCmdOutput string - }{ - { - "get vote of a proposal", - []string{ - "10", - val[0].Address.String(), - }, - fmt.Sprintf("10 %s", val[0].Address.String()), - }, - { - "get vote by wrong voter", - []string{ - "1", - "wrong address", - }, - "1 wrong address", - }, - { - "get vote of a proposal (json output)", - []string{ - "1", - val[0].Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - fmt.Sprintf("1 %s --output=json", val[0].Address.String()), - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryVote(address.NewBech32Codec("cosmos")) - cmd.SetArgs(tc.args) - - if len(tc.args) != 0 { - s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) - } - }) - } -} - -func (s *CLITestSuite) TestCmdGetConstitution() { - testCases := []struct { - name string - expOutput string - }{ - { - name: "get constitution", - expOutput: "constitution", - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdConstitution() - out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, []string{}) - s.Require().NoError(err) - s.Require().Contains(out.String(), tc.expOutput) - }) - } -} diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index a4b4a035140a..69f3c3d274da 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -179,11 +179,6 @@ func (q queryServer) Params(ctx context.Context, req *v1.QueryParamsRequest) (*v case v1.ParamTallying: tallyParams := v1.NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold) response.TallyParams = &tallyParams - - default: - return nil, status.Errorf(codes.InvalidArgument, - "%s is not a valid parameter type", req.ParamsType) - } response.Params = ¶ms diff --git a/x/gov/module.go b/x/gov/module.go index c67a9b06e3ef..146672ac9c28 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -109,11 +109,6 @@ func getProposalCLIHandlers(handlers []govclient.ProposalHandler) []*cobra.Comma return proposalCLIHandlers } -// GetQueryCmd returns the root query command for the gov module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(ab.ac) -} - // RegisterInterfaces implements InterfaceModule.RegisterInterfaces func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { v1.RegisterInterfaces(registry) From 56d48b9da4e2a16c3a6dde5a751e36e0a259b6a6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 13 Jul 2023 16:27:56 +0200 Subject: [PATCH 02/10] updates --- CHANGELOG.md | 2 +- tests/e2e/gov/query.go | 502 ----------------------------------------- 2 files changed, 1 insertion(+), 503 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 907622d2b4ed..58b7ae3b1817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,7 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `--offset` -> `--page-offset` * `--count-total` -> `--page-count-total` * `--reverse` -> `--page-reverse` -* (x/gov) []() In ` query gov proposals` the proposal status flag have renamed from `--status` to `--proposal-status`. Additonally, that flags now uses the ENUM values: `PROPOSAL_STATUS_DEPOSIT_PERIOD`, `PROPOSAL_STATUS_VOTING_PERIOD`, `PROPOSAL_STATUS_PASSED`, `PROPOSAL_STATUS_REJECTED`, `PROPOSAL_STATUS_FAILED`. +* (x/gov) [#16987](https://github.com/cosmos/cosmos-sdk/pull/16987) In ` query gov proposals` the proposal status flag have renamed from `--status` to `--proposal-status`. Additonally, that flags now uses the ENUM values: `PROPOSAL_STATUS_DEPOSIT_PERIOD`, `PROPOSAL_STATUS_VOTING_PERIOD`, `PROPOSAL_STATUS_PASSED`, `PROPOSAL_STATUS_REJECTED`, `PROPOSAL_STATUS_FAILED`. * (x/bank) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) With the migration to AutoCLI some bank commands have been split in two: * Use `denoms-metadata` for querying all denom metadata and `denom-metadata` for querying a specific denom metadata. * Use `total-supply` (or `total`) for querying the total supply and `total-supply-of` for querying the supply of a specific denom. diff --git a/tests/e2e/gov/query.go b/tests/e2e/gov/query.go index f6002129a462..40e3d3aa27a9 100644 --- a/tests/e2e/gov/query.go +++ b/tests/e2e/gov/query.go @@ -4,131 +4,11 @@ import ( "fmt" "strings" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) -func (s *E2ETestSuite) TestCmdParams() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectedOutput string - }{ - { - "json output", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - `{"voting_params":{"voting_period":"172800s"},"deposit_params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s"},"tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s","voting_period":"172800s","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","min_initial_deposit_ratio":"0.000000000000000000","proposal_cancel_ratio":"0.500000000000000000","proposal_cancel_dest":"","expedited_voting_period":"86400s","expedited_threshold":"0.667000000000000000","expedited_min_deposit":[{"denom":"stake","amount":"50000000"}],"burn_vote_quorum":false,"burn_proposal_deposit_prevote":false,"burn_vote_veto":true}}`, - }, - { - "text output", - []string{}, - ` -deposit_params: - max_deposit_period: 172800s - min_deposit: - - amount: "10000000" - denom: stake -params: - burn_proposal_deposit_prevote: false - burn_vote_quorum: false - burn_vote_veto: true - expedited_min_deposit: - - amount: "50000000" - denom: stake - expedited_threshold: "0.667000000000000000" - expedited_voting_period: 86400s - max_deposit_period: 172800s - min_deposit: - - amount: "10000000" - denom: stake - min_initial_deposit_ratio: "0.000000000000000000" - proposal_cancel_dest: "" - proposal_cancel_ratio: "0.500000000000000000" - quorum: "0.334000000000000000" - threshold: "0.500000000000000000" - veto_threshold: "0.334000000000000000" - voting_period: 172800s -tally_params: - quorum: "0.334000000000000000" - threshold: "0.500000000000000000" - veto_threshold: "0.334000000000000000" -voting_params: - voting_period: 172800s - `, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryParams() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - s.Require().NoError(err) - s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String())) - }) - } -} - -func (s *E2ETestSuite) TestCmdParam() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectedOutput string - }{ - { - "voting params", - []string{ - "voting", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `{"voting_period":"172800000000000"}`, - }, - { - "tally params", - []string{ - "tallying", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"}`, - }, - { - "deposit params", - []string{ - "deposit", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800000000000"}`, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryParam() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - s.Require().NoError(err) - s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String())) - }) - } -} - func (s *E2ETestSuite) TestCmdProposer() { val := s.network.Validators[0] @@ -174,385 +54,3 @@ func (s *E2ETestSuite) TestCmdProposer() { }) } } - -func (s *E2ETestSuite) TestCmdTally() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - expectedOutput v1.TallyResult - }{ - { - "without proposal id", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - true, - v1.TallyResult{}, - }, - { - "json output", - []string{ - "2", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - v1.NewTallyResult(math.NewInt(0), math.NewInt(0), math.NewInt(0), math.NewInt(0)), - }, - { - "json output", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - v1.NewTallyResult(s.cfg.BondedTokens, math.NewInt(0), math.NewInt(0), math.NewInt(0)), - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryTally() - clientCtx := val.ClientCtx - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - var tally v1.TallyResult - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &tally), out.String()) - s.Require().Equal(tally, tc.expectedOutput) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdGetProposal() { - val := s.network.Validators[0] - - title := "Text Proposal 1" - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "get non existing proposal", - []string{ - "10", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - true, - }, - { - "get proposal with json response", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposal() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - var proposal v1.Proposal - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposal), out.String()) - s.Require().Equal(title, proposal.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdGetProposals() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "get proposals as json response", - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - }, - { - "get proposals with invalid status", - []string{ - "--status=unknown", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - true, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryProposals(address.NewBech32Codec("cosmos")) - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - var proposals v1.QueryProposalsResponse - - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &proposals), out.String()) - s.Require().Greater(len(proposals.Proposals), 0) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdQueryDeposits() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "get deposits of non existing proposal", - []string{ - "10", - }, - true, - }, - { - "get deposits(valid req)", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryDeposits() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - - var deposits v1.QueryDepositsResponse - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposits), out.String()) - s.Require().Len(deposits.Deposits, 1) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdQueryDeposit() { - val := s.network.Validators[0] - depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens) - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "get deposit with no depositer", - []string{ - "1", - }, - true, - }, - { - "get deposit with wrong deposit address", - []string{ - "1", - "wrong address", - }, - true, - }, - { - "get deposit (valid req)", - []string{ - "1", - val.Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryDeposit() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - - var deposit v1.Deposit - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &deposit), out.String()) - s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Amount).String()) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdQueryVotes() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "get votes with no proposal id", - []string{}, - true, - }, - { - "get votes of non existed proposal", - []string{ - "10", - }, - true, - }, - { - "vote for invalid proposal", - []string{ - "1", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryVotes() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - - var votes v1.QueryVotesResponse - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &votes), out.String()) - s.Require().Len(votes.Votes, 1) - } - }) - } -} - -func (s *E2ETestSuite) TestCmdQueryVote() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - expVoteOptions v1.WeightedVoteOptions - }{ - { - "get vote of non existing proposal", - []string{ - "10", - val.Address.String(), - }, - true, - v1.NewNonSplitVoteOption(v1.OptionYes), - }, - { - "get vote by wrong voter", - []string{ - "1", - "wrong address", - }, - true, - v1.NewNonSplitVoteOption(v1.OptionYes), - }, - { - "vote for valid proposal", - []string{ - "1", - val.Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - v1.NewNonSplitVoteOption(v1.OptionYes), - }, - { - "split vote for valid proposal", - []string{ - "3", - val.Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - v1.WeightedVoteOptions{ - &v1.WeightedVoteOption{Option: v1.OptionYes, Weight: math.LegacyNewDecWithPrec(60, 2).String()}, - &v1.WeightedVoteOption{Option: v1.OptionNo, Weight: math.LegacyNewDecWithPrec(30, 2).String()}, - &v1.WeightedVoteOption{Option: v1.OptionAbstain, Weight: math.LegacyNewDecWithPrec(5, 2).String()}, - &v1.WeightedVoteOption{Option: v1.OptionNoWithVeto, Weight: math.LegacyNewDecWithPrec(5, 2).String()}, - }, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryVote(address.NewBech32Codec("cosmos")) - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - - var vote v1.Vote - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &vote), out.String()) - s.Require().Equal(len(vote.Options), len(tc.expVoteOptions)) - for i, option := range tc.expVoteOptions { - s.Require().Equal(option.Option, vote.Options[i].Option) - s.Require().Equal(option.Weight, vote.Options[i].Weight) - } - } - }) - } -} From ab5177ef3ad5a03756d16e52ffd49e5286829f32 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 13 Jul 2023 16:43:01 +0200 Subject: [PATCH 03/10] updates --- x/gov/keeper/grpc_query.go | 4 ++++ x/gov/keeper/grpc_query_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index 69f3c3d274da..a2acc2f41282 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -179,6 +179,10 @@ func (q queryServer) Params(ctx context.Context, req *v1.QueryParamsRequest) (*v case v1.ParamTallying: tallyParams := v1.NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold) response.TallyParams = &tallyParams + default: + if len(req.ParamsType) > 0 { + return nil, status.Errorf(codes.InvalidArgument, "unknown params type: %s", req.ParamsType) + } } response.Params = ¶ms diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 4ed4d5e8cccc..2d64ef576d15 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -836,7 +836,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() { func() { req = &v1.QueryParamsRequest{} }, - false, + true, }, { "deposit params request", From 1eba9a3ea8d89d19d9e9313e60cd7007d08111c1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 13 Jul 2023 18:02:24 +0200 Subject: [PATCH 04/10] updates --- tests/e2e/gov/deposits.go | 72 ++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/tests/e2e/gov/deposits.go b/tests/e2e/gov/deposits.go index 61353beaaf0a..1694775429c5 100644 --- a/tests/e2e/gov/deposits.go +++ b/tests/e2e/gov/deposits.go @@ -9,10 +9,7 @@ import ( "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" @@ -59,14 +56,12 @@ func (s *DepositTestSuite) submitProposal(val *network.Validator, initialDeposit s.Require().NoError(s.network.WaitForNextBlock()) // query proposals, return the last's id - cmd := cli.GetCmdQueryProposals(address.NewBech32Codec("cosmos")) - args := []string{fmt.Sprintf("--%s=json", flags.FlagOutput)} - res, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + res, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress)) s.Require().NoError(err) - var proposals v1.QueryProposalsResponse - err = s.cfg.Codec.UnmarshalJSON(res.Bytes(), &proposals) + err = s.cfg.Codec.UnmarshalJSON(res, &proposals) s.Require().NoError(err) + s.Require().GreaterOrEqual(len(proposals.Proposals), 1) return proposals.Proposals[len(proposals.Proposals)-1].Id } @@ -93,14 +88,14 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { // query deposit deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) - s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount) + s.Require().Equal(depositAmount, sdk.Coins(deposit.Amount).String()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") s.Require().NotNil(deposits) s.Require().Len(deposits.Deposits, 1) // verify initial deposit - s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), depositAmount) + s.Require().Equal(depositAmount, sdk.Coins(deposits.Deposits[0].Amount).String()) } func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { @@ -114,14 +109,14 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { // query deposit deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) - s.Require().Equal(sdk.Coins(deposit.Amount).String(), depositAmount.String()) + s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Amount).String()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") s.Require().NotNil(deposits) s.Require().Len(deposits.Deposits, 1) // verify initial deposit - s.Require().Equal(sdk.Coins(deposits.Deposits[0].Amount).String(), depositAmount.String()) + s.Require().Equal(depositAmount.String(), sdk.Coins(deposits.Deposits[0].Amount).String()) } func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { @@ -132,24 +127,27 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { id := s.submitProposal(val, depositAmount, "TestQueryProposalAfterVotingPeriod") proposalID := strconv.FormatUint(id, 10) - args := []string{fmt.Sprintf("--%s=json", flags.FlagOutput)} - cmd := cli.GetCmdQueryProposals(address.NewBech32Codec("cosmos")) - _, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals", val.APIAddress)) + s.Require().NoError(err) + var proposals v1.QueryProposalsResponse + err = s.cfg.Codec.UnmarshalJSON(resp, &proposals) s.Require().NoError(err) + s.Require().GreaterOrEqual(len(proposals.Proposals), 1) // query proposal - args = []string{proposalID, fmt.Sprintf("--%s=json", flags.FlagOutput)} - cmd = cli.GetCmdQueryProposal() - _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, proposalID)) + s.Require().NoError(err) + var proposal v1.QueryProposalResponse + err = s.cfg.Codec.UnmarshalJSON(resp, &proposal) s.Require().NoError(err) // waiting for deposit and voting period to end - time.Sleep(25 * time.Second) + time.Sleep(22 * time.Second) // query proposal - _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - s.Require().Error(err) - s.Require().Contains(err.Error(), fmt.Sprintf("proposal %s doesn't exist", proposalID)) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, proposalID)) + s.Require().NoError(err) + s.Require().Contains(string(resp), fmt.Sprintf("proposal %s doesn't exist", proposalID)) // query deposits deposits := s.queryDeposits(val, proposalID, true, "proposal 3 doesn't exist") @@ -157,19 +155,11 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { } func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositsResponse { - args := []string{proposalID, fmt.Sprintf("--%s=json", flags.FlagOutput)} var depositsRes *v1.QueryDepositsResponse - cmd := cli.GetCmdQueryDeposits() - - var ( - out testutil.BufferWriter - err error - ) - - err = s.network.RetryForBlocks(func() error { - out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) + err := s.network.RetryForBlocks(func() error { + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, proposalID)) if err == nil { - err = val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositsRes) + err = val.ClientCtx.LegacyAmino.UnmarshalJSON(resp, &depositsRes) return err } return err @@ -186,16 +176,14 @@ func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID stri } func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.Deposit { - args := []string{proposalID, val.Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)} var depositRes *v1.Deposit - cmd := cli.GetCmdQueryDeposit() - var ( - out testutil.BufferWriter - err error - ) + err := s.network.RetryForBlocks(func() error { + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, proposalID, val.Address.String())) + if err == nil { + err = val.ClientCtx.LegacyAmino.UnmarshalJSON(resp, &depositRes) + return err + } - err = s.network.RetryForBlocks(func() error { - out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) return err }, 3) @@ -204,8 +192,8 @@ func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID strin s.Require().Contains(err.Error(), message) return nil } + s.Require().NoError(err) - s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(out.Bytes(), &depositRes)) return depositRes } From 5440c391a688926016f1def95fd2c9688cd2e322 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 00:29:50 +0200 Subject: [PATCH 05/10] updates --- x/circuit/go.mod | 2 +- x/circuit/go.sum | 4 ++-- x/evidence/go.mod | 2 +- x/evidence/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 60af1396608a..58fc887fc59f 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -12,7 +12,7 @@ require ( cosmossdk.io/store v1.0.0-alpha.1 github.com/cockroachdb/errors v1.10.0 github.com/cometbft/cometbft v0.38.0-rc2 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f github.com/cosmos/gogoproto v1.4.10 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 diff --git a/x/circuit/go.sum b/x/circuit/go.sum index c5a37a5e1391..8a9c9530cc67 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -168,8 +168,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0 github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5 h1:6s31oUkdv9/uEuCIQ/eUXxOOhfJ6gAHbX/9C2mollhY= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5/go.mod h1:LME6v5XztqVK7/1uTQj/G6ZJdosJEz24rKaPYk+WbqI= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f h1:Gbk5m5fb7/W013mOFWrXJ4XVqModmrZAJ/9hhdMDNs4= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f/go.mod h1:zhOSfCxf4bY9XMqZDthyyCu1DrDYbgn9oZjxTkaVAbM= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index b7d34fd8863d..9aec743ce233 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/store v1.0.0-alpha.1 github.com/cometbft/cometbft v0.38.0-rc2 github.com/cosmos/cosmos-proto v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f github.com/cosmos/gogoproto v1.4.10 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 80d8dd39b249..b72f1bd7d4be 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -175,8 +175,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0 github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5 h1:6s31oUkdv9/uEuCIQ/eUXxOOhfJ6gAHbX/9C2mollhY= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713152238-de8d95cc44b5/go.mod h1:LME6v5XztqVK7/1uTQj/G6ZJdosJEz24rKaPYk+WbqI= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f h1:Gbk5m5fb7/W013mOFWrXJ4XVqModmrZAJ/9hhdMDNs4= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230713190037-6a0ab4fd167f/go.mod h1:zhOSfCxf4bY9XMqZDthyyCu1DrDYbgn9oZjxTkaVAbM= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= From 285cebf3fbcec8b2bb3219166aaef7faf240643a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 01:16:55 +0200 Subject: [PATCH 06/10] updates --- tests/e2e/auth/suite.go | 1 - tests/e2e/gov/deposits.go | 52 +++++++++++++++++---------------------- x/gov/client/cli/query.go | 5 ++-- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 1951dabd7f4d..e9cedd1491e6 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -992,7 +992,6 @@ func (s *E2ETestSuite) TestCLIMultisign() { var balRes banktypes.QueryAllBalancesResponse err = s.network.RetryForBlocks(func() error { resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr)) - s.Require().NoError(err) if err != nil { return err } diff --git a/tests/e2e/gov/deposits.go b/tests/e2e/gov/deposits.go index 1694775429c5..ee291abae27f 100644 --- a/tests/e2e/gov/deposits.go +++ b/tests/e2e/gov/deposits.go @@ -88,7 +88,7 @@ func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() { // query deposit deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) - s.Require().Equal(depositAmount, sdk.Coins(deposit.Amount).String()) + s.Require().Equal(depositAmount, sdk.Coins(deposit.Deposit.Amount).String()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") @@ -109,7 +109,7 @@ func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() { // query deposit deposit := s.queryDeposit(val, proposalID, false, "") s.Require().NotNil(deposit) - s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Amount).String()) + s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Deposit.Amount).String()) // query deposits deposits := s.queryDeposits(val, proposalID, false, "") @@ -142,7 +142,7 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { s.Require().NoError(err) // waiting for deposit and voting period to end - time.Sleep(22 * time.Second) + time.Sleep(25 * time.Second) // query proposal resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s", val.APIAddress, proposalID)) @@ -150,50 +150,42 @@ func (s *DepositTestSuite) TestQueryProposalAfterVotingPeriod() { s.Require().Contains(string(resp), fmt.Sprintf("proposal %s doesn't exist", proposalID)) // query deposits - deposits := s.queryDeposits(val, proposalID, true, "proposal 3 doesn't exist") - s.Require().Nil(deposits) + deposits := s.queryDeposits(val, proposalID, false, "") + s.Require().Len(deposits.Deposits, 0) } func (s *DepositTestSuite) queryDeposits(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositsResponse { - var depositsRes *v1.QueryDepositsResponse - err := s.network.RetryForBlocks(func() error { - resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, proposalID)) - if err == nil { - err = val.ClientCtx.LegacyAmino.UnmarshalJSON(resp, &depositsRes) - return err - } - return err - }, 3) + s.Require().NoError(s.network.WaitForNextBlock()) + + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits", val.APIAddress, proposalID)) + s.Require().NoError(err) if exceptErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), message) + s.Require().Contains(string(resp), message) return nil } + var depositsRes v1.QueryDepositsResponse + err = val.ClientCtx.Codec.UnmarshalJSON(resp, &depositsRes) s.Require().NoError(err) - return depositsRes + + return &depositsRes } -func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.Deposit { - var depositRes *v1.Deposit - err := s.network.RetryForBlocks(func() error { - resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, proposalID, val.Address.String())) - if err == nil { - err = val.ClientCtx.LegacyAmino.UnmarshalJSON(resp, &depositRes) - return err - } +func (s *DepositTestSuite) queryDeposit(val *network.Validator, proposalID string, exceptErr bool, message string) *v1.QueryDepositResponse { + s.Require().NoError(s.network.WaitForNextBlock()) - return err - }, 3) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/gov/v1/proposals/%s/deposits/%s", val.APIAddress, proposalID, val.Address.String())) + s.Require().NoError(err) if exceptErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), message) + s.Require().Contains(string(resp), message) return nil } + var depositRes v1.QueryDepositResponse + err = val.ClientCtx.Codec.UnmarshalJSON(resp, &depositRes) s.Require().NoError(err) - return depositRes + return &depositRes } diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 6aa77f2242c7..d8b4b35f02fc 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -4,9 +4,10 @@ import ( "fmt" "strconv" - "cosmossdk.io/core/address" "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" @@ -16,9 +17,7 @@ import ( // GetCustomQueryCmd returns the cli query commands for this module // These commands do not rely on gRPC and cannot be autogenerated - // TODO(@julienrbrt) https://github.com/cosmos/cosmos-sdk/issues/16836 - func GetCustomQueryCmd(ac address.Codec) *cobra.Command { // Group gov queries under a subcommand govQueryCmd := &cobra.Command{ From c0e52684954a3fd143be664842cdb0e894fde1e1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 01:21:49 +0200 Subject: [PATCH 07/10] updates --- x/gov/autocli.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/gov/autocli.go b/x/gov/autocli.go index a72be2d09435..c81220564419 100644 --- a/x/gov/autocli.go +++ b/x/gov/autocli.go @@ -12,8 +12,8 @@ import ( // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { return &autocliv1.ModuleOptions{ - Tx: &autocliv1.ServiceCommandDescriptor{ - Service: govv1.Msg_ServiceDesc.ServiceName, + Query: &autocliv1.ServiceCommandDescriptor{ + Service: govv1.Query_ServiceDesc.ServiceName, RpcCommandOptions: []*autocliv1.RpcCommandOptions{ { RpcMethod: "Params", @@ -89,14 +89,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { }, // map v1beta1 as a sub-command SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - "v1beta1": {Service: govv1beta1.Msg_ServiceDesc.ServiceName}, + "v1beta1": {Service: govv1beta1.Query_ServiceDesc.ServiceName}, }, }, - Query: &autocliv1.ServiceCommandDescriptor{ - Service: govv1.Query_ServiceDesc.ServiceName, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: govv1.Msg_ServiceDesc.ServiceName, // map v1beta1 as a sub-command SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - "v1beta1": {Service: govv1beta1.Query_ServiceDesc.ServiceName}, + "v1beta1": {Service: govv1beta1.Msg_ServiceDesc.ServiceName}, }, }, } From 37f39927116d0af79a63d5ef35681e5bc14d3250 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 09:39:41 +0200 Subject: [PATCH 08/10] fix lint --- x/gov/autocli.go | 1 + x/gov/keeper/grpc_query_test.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/x/gov/autocli.go b/x/gov/autocli.go index c81220564419..43f5574b83c3 100644 --- a/x/gov/autocli.go +++ b/x/gov/autocli.go @@ -6,6 +6,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" govv1 "cosmossdk.io/api/cosmos/gov/v1" govv1beta1 "cosmossdk.io/api/cosmos/gov/v1beta1" + "github.com/cosmos/cosmos-sdk/version" ) diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 5acd4354a051..18c9a78b841f 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -896,7 +896,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryParams() { expPass bool }{ { - "empty request", + "empty request (valid and returns all params)", func() { req = &v1.QueryParamsRequest{} }, @@ -984,11 +984,11 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryParams() { expPass bool }{ { - "empty request", + "empty request (valid and returns all params)", func() { req = &v1beta1.QueryParamsRequest{} }, - false, + true, }, { "deposit params request", From 1d0a6824ffd634c3fc5c5ed71c018ff469f07f92 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 10:03:18 +0200 Subject: [PATCH 09/10] updates --- x/gov/autocli.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/gov/autocli.go b/x/gov/autocli.go index 43f5574b83c3..dbd6b0b750c3 100644 --- a/x/gov/autocli.go +++ b/x/gov/autocli.go @@ -81,6 +81,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Use: "tally [proposal-id]", Short: "Query the tally of a proposal vote", Example: fmt.Sprintf("%s query gov tally 1", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "proposal_id"}, + }, }, { RpcMethod: "Constitution", From 64b01b926f3ea9117d2aaf0de31d2b1b6b9116e6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 10:33:58 +0200 Subject: [PATCH 10/10] updates --- x/gov/keeper/grpc_query.go | 4 ++++ x/gov/keeper/grpc_query_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index 2341b1b98260..77afbbffce12 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -376,6 +376,10 @@ func (q legacyQueryServer) Params(ctx context.Context, req *v1beta1.QueryParamsR response := &v1beta1.QueryParamsResponse{} + if resp.DepositParams == nil && resp.VotingParams == nil && resp.TallyParams == nil { + return nil, status.Errorf(codes.InvalidArgument, "%s is not a valid parameter type", req.ParamsType) + } + if resp.DepositParams != nil { minDeposit := sdk.NewCoins(resp.DepositParams.MinDeposit...) response.DepositParams = v1beta1.NewDepositParams(minDeposit, *resp.DepositParams.MaxDepositPeriod) diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 18c9a78b841f..0620e8863f0f 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -984,11 +984,11 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryParams() { expPass bool }{ { - "empty request (valid and returns all params)", + "empty request", func() { req = &v1beta1.QueryParamsRequest{} }, - true, + false, }, { "deposit params request",