Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/{gov,params,upgrade,distribution} CLI: In-Process test & use grpc query service #6664

Merged
merged 28 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5128147
refactor CLI to use grpc query service
amaury1093 Jul 9, 2020
6acad21
In process CLI for gov
amaury1093 Jul 10, 2020
a5971cb
ReadQueryCommandFlags
amaury1093 Jul 10, 2020
14b5036
gov tx
amaury1093 Jul 10, 2020
f7349d6
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 10, 2020
eb73cbd
Fix compiler errors
amaury1093 Jul 10, 2020
8a22b96
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 13, 2020
adac5e1
Formatting
amaury1093 Jul 13, 2020
05f47f5
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 15, 2020
b1fa4e3
x/distribution: use gRPC query
amaury1093 Jul 15, 2020
1012219
Consistent
amaury1093 Jul 15, 2020
4e53b36
Fix x/distrib test
amaury1093 Jul 15, 2020
8ed2fd7
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 16, 2020
94e37d0
Update x/gov
amaury1093 Jul 16, 2020
a4f391a
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 16, 2020
439990e
Add ReadQueryCommandFlags
amaury1093 Jul 16, 2020
d078b57
Fix lint
amaury1093 Jul 16, 2020
ac7790c
Revert x/params
amaury1093 Jul 16, 2020
5296f58
x/params use grpc query
amaury1093 Jul 16, 2020
fbb02ae
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 16, 2020
0c3f42a
Fix tests
amaury1093 Jul 16, 2020
49903f0
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 17, 2020
eaffb1a
Use page request
amaury1093 Jul 17, 2020
b40b391
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 17, 2020
5f50a1e
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 20, 2020
cacf3b7
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 20, 2020
bda7a4e
Merge branch 'master' into am-cli-params-distrib
amaury1093 Jul 20, 2020
96dff3e
Merge branch 'master' into am-cli-params-distrib
mergify[bot] Jul 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use page request
  • Loading branch information
amaury1093 committed Jul 17, 2020
commit eaffb1af84d342a5efb04ddb953c0124a54a329f
10 changes: 9 additions & 1 deletion x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq
return fmt.Errorf("end-height %s not a valid uint, please input a valid end-height", args[2])
}

pageReq := client.ReadPageRequest(cmd.Flags())

res, err := queryClient.ValidatorSlashes(
context.Background(),
&types.QueryValidatorSlashesRequest{ValidatorAddress: validatorAddr, StartingHeight: startHeight, EndingHeight: endHeight},
&types.QueryValidatorSlashesRequest{
ValidatorAddress: validatorAddr,
StartingHeight: startHeight,
EndingHeight: endHeight,
Req: pageReq,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't catch this before but page parameters should not be called req. I would just use page or something like that. This can be fixed separate from this PR but it should be addressed before release. /cc @sahith-narahari @anilcse @atheeshp

},
)
if err != nil {
return err
Expand All @@ -204,6 +211,7 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "validator slashes")
return cmd
}

Expand Down
51 changes: 36 additions & 15 deletions x/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -137,13 +136,15 @@ $ %s query gov proposals --page=2 --limit=100
}
queryClient := types.NewQueryClient(clientCtx)

pageReq := client.ReadPageRequest(cmd.Flags())

res, err := queryClient.Proposals(
context.Background(),
&types.QueryProposalsRequest{
ProposalStatus: proposalStatus,
Voter: voterAddr,
Depositor: depositorAddr,
Req: &query.PageRequest{},
Req: pageReq,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

},
)
if err != nil {
Expand All @@ -161,6 +162,7 @@ $ %s query gov proposals --page=2 --limit=100
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
Expand Down Expand Up @@ -297,9 +299,11 @@ $ %[1]s query gov votes 1 --page=2 --limit=100

}

pageReq := client.ReadPageRequest(cmd.Flags())

res, err := queryClient.Votes(
context.Background(),
&types.QueryVotesRequest{ProposalId: proposalID, Req: &query.PageRequest{}},
&types.QueryVotesRequest{ProposalId: proposalID, Req: pageReq},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

)
if err != nil {
return err
Expand All @@ -310,6 +314,10 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
},
}

// Deprecated, remove line when removing FlagPage altogether.
cmd.Flags().Int(flags.FlagPage, 1, "pagination page of proposals to to query for")

flags.AddPaginationFlagsToCmd(cmd, "votes")
flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -438,9 +446,11 @@ $ %s query gov deposits 1
return clientCtx.PrintOutput(dep)
}

pageReq := client.ReadPageRequest(cmd.Flags())

res, err := queryClient.Deposits(
context.Background(),
&types.QueryDepositsRequest{ProposalId: proposalID, Req: &query.PageRequest{}},
&types.QueryDepositsRequest{ProposalId: proposalID, Req: pageReq},
)
if err != nil {
return err
Expand All @@ -450,6 +460,7 @@ $ %s query gov deposits 1
},
}

flags.AddPaginationFlagsToCmd(cmd, "deposits")
flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -533,28 +544,38 @@ $ %s query gov params
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

tp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/tallying", types.QuerierRoute), nil)
// Query store for all 3 params
votingRes, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{ParamsType: "voting"},
)
if err != nil {
return err
}
dp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/deposit", types.QuerierRoute), nil)

tallyRes, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{ParamsType: "tallying"},
)
if err != nil {
return err
}
vp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/voting", types.QuerierRoute), nil)

depositRes, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{ParamsType: "deposit"},
)
if err != nil {
return err
}

var tallyParams types.TallyParams
clientCtx.JSONMarshaler.MustUnmarshalJSON(tp, &tallyParams)
var depositParams types.DepositParams
clientCtx.JSONMarshaler.MustUnmarshalJSON(dp, &depositParams)
var votingParams types.VotingParams
clientCtx.JSONMarshaler.MustUnmarshalJSON(vp, &votingParams)

return clientCtx.PrintOutput(types.NewParams(votingParams, tallyParams, depositParams))
return clientCtx.PrintOutput(types.NewParams(
votingRes.GetVotingParams(),
tallyRes.GetTallyParams(),
depositRes.GetDepositParams(),
))
},
}

Expand Down
9 changes: 4 additions & 5 deletions x/upgrade/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func GetCurrentPlanCmd() *cobra.Command {
}
queryClient := types.NewQueryClient(clientCtx)

params := types.NewQueryCurrentPlanRequest()
res, err := queryClient.CurrentPlan(context.Background(), params)
params := types.QueryCurrentPlanRequest{}
res, err := queryClient.CurrentPlan(context.Background(), &params)
if err != nil {
return err
}
Expand Down Expand Up @@ -77,9 +77,8 @@ func GetAppliedPlanCmd() *cobra.Command {
}
queryClient := types.NewQueryClient(clientCtx)

name := args[0]
params := types.NewQueryAppliedPlanRequest(name)
res, err := queryClient.AppliedPlan(context.Background(), params)
params := types.QueryAppliedPlanRequest{Name: args[0]}
res, err := queryClient.AppliedPlan(context.Background(), &params)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *htt
return func(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]

params := types.NewQueryAppliedPlanRequest(name)
params := types.QueryAppliedPlanRequest{Name: name}
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
if rest.CheckBadRequestError(w, err) {
return
Expand Down
8 changes: 4 additions & 4 deletions x/upgrade/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() {
{
"without current upgrade plan",
func() {
req = types.NewQueryCurrentPlanRequest()
req = &types.QueryCurrentPlanRequest{}
expResponse = types.QueryCurrentPlanResponse{}
},
true,
Expand All @@ -57,7 +57,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() {
plan := types.Plan{Name: "test-plan", Height: 5}
suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan)

req = types.NewQueryCurrentPlanRequest()
req = &types.QueryCurrentPlanRequest{}
expResponse = types.QueryCurrentPlanResponse{Plan: &plan}
},
true,
Expand Down Expand Up @@ -97,7 +97,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() {
{
"with non-existent upgrade plan",
func() {
req = types.NewQueryAppliedPlanRequest("foo")
req = &types.QueryAppliedPlanRequest{Name: "foo"}
},
true,
},
Expand All @@ -114,7 +114,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() {
suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan) {})
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan)

req = types.NewQueryAppliedPlanRequest(planName)
req = &types.QueryAppliedPlanRequest{Name: planName}
},
true,
},
Expand Down
10 changes: 0 additions & 10 deletions x/upgrade/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,3 @@ const (
QueryCurrent = "current"
QueryApplied = "applied"
)

// NewQueryCurrentPlanRequest creates a new instance of QueryCurrentPlanRequest.
func NewQueryCurrentPlanRequest() *QueryCurrentPlanRequest {
return &QueryCurrentPlanRequest{}
}

// NewQueryAppliedPlanRequest creates a new instance of QueryAppliedPlanRequest.
func NewQueryAppliedPlanRequest(name string) *QueryAppliedPlanRequest {
return &QueryAppliedPlanRequest{Name: name}
}