Skip to content

Commit

Permalink
fix: x/group pagination from CLI (backport #14923) (#14926)
Browse files Browse the repository at this point in the history
Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: atheesh <atheesh@vitwit.com>
  • Loading branch information
4 people authored Feb 6, 2023
1 parent 0c0c6a9 commit 6ed270d
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (cli) [#14919](https://github.com/cosmos/cosmos-sdk/pull/#14919) Fix never assigned error when write validators.
* (cli) [#14919](https://github.com/cosmos/cosmos-sdk/pull/14919) Fix never assigned error when write validators.
* (x/group) [#14923](https://github.com/cosmos/cosmos-sdk/pull/14923) Fix error while using pagination in `x/group` from CLI

## [v0.47.0-rc2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0-rc2) - 2023-01-31

Expand Down
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
15 changes: 14 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,7 @@ func QueryVotesByVoterCmd() *cobra.Command {
}

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

return cmd
}

0 comments on commit 6ed270d

Please sign in to comment.