Skip to content

Commit

Permalink
x/gov: Dont return an error if pagination parameters are wrong
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry <[email protected]>
  • Loading branch information
dshulyak committed Dec 18, 2019
1 parent 8a6ded8 commit 1caad87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
5 changes: 3 additions & 2 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ func QueryVotesByTxQuery(cliCtx context.CLIContext, params types.QueryProposalVo
}
start, end := client.Paginate(len(votes), params.Page, params.Limit, 100)
if start < 0 || end < 0 {
return nil, fmt.Errorf("invalid page (%d) or range is out of bounds (limit %d)", params.Page, params.Limit)
votes = []types.Vote{}
} else {
votes = votes[start:end]
}
votes = votes[start:end]
if cliCtx.Indent {
return cliCtx.Codec.MarshalJSONIndent(votes, "", " ")
}
Expand Down
12 changes: 1 addition & 11 deletions x/gov/client/utils/query_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package utils

import (
"errors"
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -33,7 +31,7 @@ func makeQuerier(txs []sdk.Tx) TxQuerier {
return func(cliCtx context.CLIContext, events []string, page, limit int) (*sdk.SearchTxsResult, error) {
start, end := client.Paginate(len(txs), page, limit, 100)
if start < 0 || end < 0 {
return nil, errors.New("unexpected error in test")
return nil, nil
}
rst := &sdk.SearchTxsResult{
TotalCount: len(txs),
Expand All @@ -55,7 +53,6 @@ func TestGetPaginatedVotes(t *testing.T) {
page, limit int
txs []sdk.Tx
votes []types.Vote
err error
}
acc1 := make(sdk.AccAddress, 20)
acc1[0] = 1
Expand Down Expand Up @@ -107,26 +104,19 @@ func TestGetPaginatedVotes(t *testing.T) {
description: "InvalidPage",
page: -1,
txs: []sdk.Tx{txMock{acc1, 1}},
err: fmt.Errorf("invalid page (%d) or range is out of bounds (limit %d)", -1, 0),
},
{
description: "OutOfBounds",
page: 2,
limit: 10,
txs: []sdk.Tx{txMock{acc1, 1}},
err: fmt.Errorf("invalid page (%d) or range is out of bounds (limit %d)", 2, 10),
},
} {
tc := tc
t.Run(tc.description, func(t *testing.T) {
ctx := context.CLIContext{}.WithCodec(codec.New())
params := types.NewQueryProposalVotesParams(0, tc.page, tc.limit)
votesData, err := QueryVotesByTxQuery(ctx, params, makeQuerier(tc.txs))
if tc.err != nil {
require.NotNil(t, err)
require.EqualError(t, tc.err, err.Error())
return
}
require.NoError(t, err)
votes := []types.Vote{}
require.NoError(t, ctx.Codec.UnmarshalJSON(votesData, &votes))
Expand Down

0 comments on commit 1caad87

Please sign in to comment.