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

Restrict pagination on all-state-query #1619

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@
SilenceUsage: true,
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "contract state")
cmd.Flags().String(flags.FlagPageKey, "", "pagination page-key of contract state to query for")
cmd.Flags().Uint64(flags.FlagLimit, 100, "pagination limit of contract state to query for")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

cmd.Flags().Bool(flags.FlagReverse, false, "results are sorted in descending order")

Check warning on line 373 in x/wasm/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/query.go#L371-L373

Added lines #L371 - L373 were not covered by tests

return cmd
}

Expand Down
4 changes: 4 additions & 0 deletions x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func (q GrpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if req.Pagination != nil &&
(req.Pagination.Offset != 0 || req.Pagination.CountTotal) {
return nil, status.Error(codes.InvalidArgument, "offset and count queries not supported anymore")
}
contractAddr, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, err
Expand Down
15 changes: 10 additions & 5 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ func TestQueryAllContractState(t *testing.T) {
Offset: 1,
},
},
expModelContains: []types.Model{
{Key: []byte("foo"), Value: []byte(`"bar"`)},
},
expModelContainsNot: []types.Model{
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
expErr: status.Error(codes.InvalidArgument, "offset and count queries not supported anymore"),
},
"with pagination count": {
srcQuery: &types.QueryAllContractStateRequest{
Address: contractAddr.String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

nice test 👍

Pagination: &query.PageRequest{
CountTotal: true,
},
},
expErr: status.Error(codes.InvalidArgument, "offset and count queries not supported anymore"),
},
"with pagination limit": {
srcQuery: &types.QueryAllContractStateRequest{
Expand Down Expand Up @@ -108,6 +112,7 @@ func TestQueryAllContractState(t *testing.T) {
require.Equal(t, spec.expErr.Error(), err.Error())
return
}
require.NoError(t, err)
for _, exp := range spec.expModelContains {
assert.Contains(t, got.Models, exp)
}
Expand Down