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 27 commits
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
2 changes: 2 additions & 0 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
return keeper.NewQuerier(am.accountKeeper)
}

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(grpc.Server) {}

// InitGenesis performs genesis initialization for the auth module. It returns
Expand Down
2 changes: 2 additions & 0 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type AppModule struct {
accountKeeper types.AccountKeeper
}

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(server grpc.Server) {
types.RegisterQueryServer(server, am.keeper)
}
Expand Down
2 changes: 2 additions & 0 deletions x/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (AppModule) QuerierRoute() string { return "" }
// NewQuerierHandler returns the capability module's Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier { return nil }

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(grpc.Server) {}

// RegisterInvariants registers the capability module's invariants.
Expand Down
2 changes: 2 additions & 0 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (AppModule) QuerierRoute() string { return "" }
// NewQuerierHandler returns no sdk.Querier.
func (AppModule) NewQuerierHandler() sdk.Querier { return nil }

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(grpc.Server) {}

// InitGenesis performs genesis initialization for the crisis module. It returns
Expand Down
129 changes: 52 additions & 77 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"fmt"
"strconv"
"strings"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

Expand Down Expand Up @@ -49,19 +49,14 @@ func GetCmdQueryParams() *cobra.Command {
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams)
res, _, err := clientCtx.QueryWithData(route, nil)
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

var params types.Params
if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, &params); err != nil {
return fmt.Errorf("failed to unmarshal params: %w", err)
}

return clientCtx.PrintOutput(params)
return clientCtx.PrintOutput(res.GetParams())
},
}

Expand Down Expand Up @@ -91,32 +86,22 @@ $ %s query distribution validator-outstanding-rewards cosmosvaloper1lwjmdnks33xw
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

valAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}

params := types.NewQueryValidatorOutstandingRewardsParams(valAddr)
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
validatorAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}

resp, _, err := clientCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorOutstandingRewards),
bz,
res, err := queryClient.ValidatorOutstandingRewards(
context.Background(),
&types.QueryValidatorOutstandingRewardsRequest{ValidatorAddress: validatorAddr},
)
if err != nil {
return err
}

var outstandingRewards types.ValidatorOutstandingRewards
if err := clientCtx.JSONMarshaler.UnmarshalJSON(resp, &outstandingRewards); err != nil {
return err
}

return clientCtx.PrintOutput(outstandingRewards)
return clientCtx.PrintOutput(res.GetRewards())
},
}

Expand Down Expand Up @@ -145,23 +130,22 @@ $ %s query distribution commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9l
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

validatorAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}

res, err := common.QueryValidatorCommission(clientCtx, validatorAddr)
res, err := queryClient.ValidatorCommission(
context.Background(),
&types.QueryValidatorCommissionRequest{ValidatorAddress: validatorAddr},
)
if err != nil {
return err
}

var valCom types.ValidatorAccumulatedCommission
if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, &valCom); err != nil {
return err
}

return clientCtx.PrintOutput(valCom)
return clientCtx.PrintOutput(res.GetCommission())
},
}

Expand Down Expand Up @@ -190,6 +174,7 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

validatorAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
Expand All @@ -206,27 +191,27 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq
return fmt.Errorf("end-height %s not a valid uint, please input a valid end-height", args[2])
}

params := types.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
if err != nil {
return err
}
pageReq := client.ReadPageRequest(cmd.Flags())

res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_slashes", types.QuerierRoute), bz)
res, err := queryClient.ValidatorSlashes(
context.Background(),
&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
}

var slashes []types.ValidatorSlashEvent
if err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &slashes); err != nil {
return fmt.Errorf("failed to unmarshal response: %w", err)
}

return clientCtx.PrintOutput(slashes)
return clientCtx.PrintOutput(res.GetSlashes())
},
}

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

Expand All @@ -252,54 +237,48 @@ $ %s query distribution rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

delegatorAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

// query for rewards from a particular delegation
if len(args) == 2 {
resp, _, err := common.QueryDelegationRewards(clientCtx, args[0], args[1])
validatorAddr, err := sdk.ValAddressFromBech32(args[1])
if err != nil {
return err
}

var result sdk.DecCoins
if err = clientCtx.JSONMarshaler.UnmarshalJSON(resp, &result); err != nil {
return fmt.Errorf("failed to unmarshal response: %w", err)
res, err := queryClient.DelegationRewards(
context.Background(),
&types.QueryDelegationRewardsRequest{DelegatorAddress: delegatorAddr, ValidatorAddress: validatorAddr},
)
if err != nil {
return err
}

return clientCtx.PrintOutput(result)
}

delegatorAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

params := types.NewQueryDelegatorParams(delegatorAddr)
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
return clientCtx.PrintOutput(res.GetRewards())
}

// query for delegator total rewards
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorTotalRewards)
res, _, err := clientCtx.QueryWithData(route, bz)
res, err := queryClient.DelegationTotalRewards(
context.Background(),
&types.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegatorAddr},
)
if err != nil {
return err
}

var result types.QueryDelegatorTotalRewardsResponse
if err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &result); err != nil {
return fmt.Errorf("failed to unmarshal response: %w", err)
}

return clientCtx.PrintOutput(result)
return clientCtx.PrintOutput(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdQueryCommunityPool returns the command for fetching community pool info
// GetCmdQueryCommunityPool returns the command for fetching community pool info.
func GetCmdQueryCommunityPool() *cobra.Command {
cmd := &cobra.Command{
Use: "community-pool",
Expand All @@ -320,18 +299,14 @@ $ %s query distribution community-pool
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", types.QuerierRoute), nil)
res, err := queryClient.CommunityPool(context.Background(), &types.QueryCommunityPoolRequest{})
if err != nil {
return err
}

var result sdk.DecCoins
if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, &result); err != nil {
return err
}

return clientCtx.PrintOutput(result)
return clientCtx.PrintOutput(res.GetPool())
},
}

Expand Down
2 changes: 2 additions & 0 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
return keeper.NewQuerier(am.keeper)
}

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(server grpc.Server) {
types.RegisterQueryServer(server, am.keeper)
}
Expand Down
2 changes: 2 additions & 0 deletions x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
return keeper.NewQuerier(am.keeper)
}

// RegisterQueryService registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterQueryService(grpc.Server) {}

// RegisterInvariants registers the evidence module's invariants.
Expand Down
3 changes: 1 addition & 2 deletions x/gov/client/cli/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil"
)

Expand All @@ -23,7 +22,7 @@ func TestParseSubmitProposalFlags(t *testing.T) {
badJSON, cleanup2 := testutil.WriteToNewTempFile(t, "bad json")
t.Cleanup(cleanup2)

fs := NewCmdSubmitProposal(client.Context{}).Flags()
fs := NewCmdSubmitProposal().Flags()

// nonexistent json
fs.Set(FlagProposal, "fileDoesNotExist")
Expand Down
Loading