Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
/ cosmos-sdk Public archive
forked from cosmos/cosmos-sdk

Commit

Permalink
fix: x/group pagination from CLI (cosmos#14923)
Browse files Browse the repository at this point in the history
  • Loading branch information
atheeshp authored and tsenart committed Apr 12, 2023
1 parent 8b2120e commit 2ffbd6e
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 2 deletions.
124 changes: 123 additions & 1 deletion tests/e2e/group/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,24 @@ func (s *E2ETestSuite) TestQueryGroupsByMembers() {
0,
[]*group.GroupInfo{},
},
{
"expect one group (request with pagination)",
[]string{
members.Members[0].Member.Address,
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=1",
},
false,
"",
1,
groups.Groups,
},
{
"expect one group",
[]string{members.Members[0].Member.Address, fmt.Sprintf("--%s=json", flags.FlagOutput)},
[]string{
members.Members[0].Member.Address,
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
false,
"",
1,
Expand Down Expand Up @@ -233,6 +248,27 @@ func (s *E2ETestSuite) TestQueryGroupMembers() {
},
},
},
{
"members found (request with pagination)",
[]string{
strconv.FormatUint(s.group.Id, 10),
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=1",
},
false,
"",
0,
[]*group.GroupMember{
{
GroupId: s.group.Id,
Member: &group.Member{
Address: val.Address.String(),
Weight: "3",
Metadata: validMetadata,
},
},
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -299,6 +335,20 @@ func (s *E2ETestSuite) TestQueryGroupsByAdmin() {
s.group,
},
},
{
"found groups (request with pagination)",
[]string{
val.Address.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.GroupInfo{
s.group,
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -427,6 +477,21 @@ func (s *E2ETestSuite) TestQueryGroupPoliciesByGroup() {
s.groupPolicies[5],
},
},
{
"found group policies (request with pagination)",
[]string{
strconv.FormatUint(s.group.Id, 10),
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.GroupPolicyInfo{
s.groupPolicies[0],
s.groupPolicies[1],
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -503,6 +568,21 @@ func (s *E2ETestSuite) TestQueryGroupPoliciesByAdmin() {
s.groupPolicies[5],
},
},
{
"found group policies (request with pagination)",
[]string{
val.Address.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.GroupPolicyInfo{
s.groupPolicies[0],
s.groupPolicies[1],
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -617,6 +697,20 @@ func (s *E2ETestSuite) TestQueryProposalsByGroupPolicy() {
s.proposal,
},
},
{
"found proposals (request with pagination)",
[]string{
s.groupPolicies[0].Address,
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.Proposal{
s.proposal,
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -723,6 +817,20 @@ func (s *E2ETestSuite) TestQueryVotesByProposal() {
s.vote,
},
},
{
"found votes (request with pagination)",
[]string{
"1",
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.Vote{
s.vote,
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -786,6 +894,20 @@ func (s *E2ETestSuite) TestQueryVotesByVoter() {
s.vote,
},
},
{
"found votes (request with pagination)",
[]string{
val.Address.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
"--limit=2",
},
false,
"",
0,
[]*group.Vote{
s.vote,
},
},
}

for _, tc := range testCases {
Expand Down
16 changes: 15 additions & 1 deletion x/group/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ func QueryGroupsByMemberCmd() *cobra.Command {
return err
}

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

queryClient := group.NewQueryClient(clientCtx)
res, err := queryClient.GroupsByMember(cmd.Context(), &group.QueryGroupsByMemberRequest{
Address: args[0],
Address: args[0],
Pagination: pageReq,
})
if err != nil {
return err
Expand Down Expand Up @@ -171,6 +177,7 @@ func QueryGroupMembersCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "group-members")

return cmd
}
Expand Down Expand Up @@ -207,6 +214,7 @@ func QueryGroupsByAdminCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "groups-by-admin")

return cmd
}
Expand Down Expand Up @@ -248,6 +256,7 @@ func QueryGroupPoliciesByGroupCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "groups-policies-by-group")

return cmd
}
Expand Down Expand Up @@ -284,6 +293,7 @@ func QueryGroupPoliciesByAdminCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "group-policies-by-admin")

return cmd
}
Expand Down Expand Up @@ -355,6 +365,7 @@ func QueryProposalsByGroupPolicyCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "proposals-by-group-policy")

return cmd
}
Expand Down Expand Up @@ -432,6 +443,7 @@ func QueryVotesByProposalCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "votes-by-proposal")

return cmd
}
Expand Down Expand Up @@ -503,10 +515,12 @@ func QueryVotesByVoterCmd() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "votes-by-voter")

return cmd
}

// QueryGroupsCmd creates a CLI command for Query/Groups.
func QueryGroupsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "groups",
Expand Down

0 comments on commit 2ffbd6e

Please sign in to comment.