Skip to content

Commit 965e28c

Browse files
committed
Restrict pagination on all state query
1 parent 09b5008 commit 965e28c

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

x/wasm/client/cli/query.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ func GetCmdGetContractStateAll() *cobra.Command {
368368
SilenceUsage: true,
369369
}
370370
flags.AddQueryFlagsToCmd(cmd)
371-
flags.AddPaginationFlagsToCmd(cmd, "contract state")
371+
cmd.Flags().String(flags.FlagPageKey, "", "pagination page-key of contract state to query for")
372+
cmd.Flags().Uint64(flags.FlagLimit, 100, "pagination limit of contract state to query for")
373+
cmd.Flags().Bool(flags.FlagReverse, false, "results are sorted in descending order")
374+
372375
return cmd
373376
}
374377

x/wasm/keeper/querier.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func (q GrpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont
117117
if req == nil {
118118
return nil, status.Error(codes.InvalidArgument, "empty request")
119119
}
120+
if req.Pagination != nil &&
121+
(req.Pagination.Offset != 0 || req.Pagination.CountTotal) {
122+
return nil, status.Error(codes.InvalidArgument, "offset and count queries not supported anymore")
123+
}
120124
contractAddr, err := sdk.AccAddressFromBech32(req.Address)
121125
if err != nil {
122126
return nil, err

x/wasm/keeper/querier_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ func TestQueryAllContractState(t *testing.T) {
6464
Offset: 1,
6565
},
6666
},
67-
expModelContains: []types.Model{
68-
{Key: []byte("foo"), Value: []byte(`"bar"`)},
69-
},
70-
expModelContainsNot: []types.Model{
71-
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
67+
expErr: status.Error(codes.InvalidArgument, "offset and count queries not supported anymore"),
68+
},
69+
"with pagination count": {
70+
srcQuery: &types.QueryAllContractStateRequest{
71+
Address: contractAddr.String(),
72+
Pagination: &query.PageRequest{
73+
CountTotal: true,
74+
},
7275
},
76+
expErr: status.Error(codes.InvalidArgument, "offset and count queries not supported anymore"),
7377
},
7478
"with pagination limit": {
7579
srcQuery: &types.QueryAllContractStateRequest{
@@ -108,6 +112,7 @@ func TestQueryAllContractState(t *testing.T) {
108112
require.Equal(t, spec.expErr.Error(), err.Error())
109113
return
110114
}
115+
require.NoError(t, err)
111116
for _, exp := range spec.expModelContains {
112117
assert.Contains(t, got.Models, exp)
113118
}

0 commit comments

Comments
 (0)