Skip to content

Commit

Permalink
fix: x/group pagination from CLI (#14923)
Browse files Browse the repository at this point in the history
(cherry picked from commit fd7bbd7)

# Conflicts:
#	x/group/client/cli/query.go
  • Loading branch information
atheeshp authored and mergify[bot] committed Feb 6, 2023
1 parent 0c0c6a9 commit 997c082
Show file tree
Hide file tree
Showing 2 changed files with 175 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 @@ -184,6 +199,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 @@ -250,6 +286,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 @@ -378,6 +428,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 @@ -454,6 +519,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 @@ -568,6 +648,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 @@ -674,6 +768,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 @@ -737,6 +845,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
53 changes: 52 additions & 1 deletion x/group/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,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 @@ -170,6 +176,7 @@ func QueryGroupMembersCmd() *cobra.Command {
}

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

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

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

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

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

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

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

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

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

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

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

return cmd
}
Expand Down Expand Up @@ -502,6 +514,45 @@ func QueryVotesByVoterCmd() *cobra.Command {
}

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

return cmd
}
<<<<<<< HEAD
=======

// QueryGroupsCmd creates a CLI command for Query/Groups.
func QueryGroupsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "groups",
Short: "Query for groups present in the state",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

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

queryClient := group.NewQueryClient(clientCtx)

res, err := queryClient.Groups(cmd.Context(), &group.QueryGroupsRequest{
Pagination: pageReq,
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

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

return cmd
}
>>>>>>> fd7bbd7e8 (fix: `x/group` pagination from CLI (#14923))

0 comments on commit 997c082

Please sign in to comment.