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

fix: not to throw error when no txs in block #982

Merged
merged 2 commits into from
Apr 19, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/collection) [\#960](https://github.com/Finschia/finschia-sdk/pull/960) Fix default next class ids of x/collection
* (x/collection) [\#961](https://github.com/Finschia/finschia-sdk/pull/961) Do not loop enum in x/collection
* (x/collection,token) [\#957](https://github.com/Finschia/finschia-sdk/pull/957) Refactor queries of x/collection and x/token
* (x/auth) [\#982](https://github.com/Finschia/finschia-sdk/pull/957) Fix not to emit error when no txs in block while querying `GetBlockWithTxs`

### Removed
* (x/collection,token) [\#966](https://github.com/Finschia/finschia-sdk/pull/966) Remove legacy events on x/collection and x/token
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s tx2Server) GetBlockWithTxs(ctx context.Context, req *tx2types.GetBlockWi
blockTxs := block.Data.Txs
blockTxsLn := uint64(len(blockTxs))
txs := make([]*txtypes.Tx, 0, limit)
if offset >= blockTxsLn {
if offset >= blockTxsLn && blockTxsLn != 0 {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("out of range: cannot paginate %d txs with offset %d and limit %d", blockTxsLn, offset, limit)
}
decodeTxAt := func(i uint64) error {
Expand Down
20 changes: 12 additions & 8 deletions x/auth/tx2/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ func (s IntegrationTestSuite) TestGetBlockWithTxs_GRPC() {
req *tx2.GetBlockWithTxsRequest
expErr bool
expErrMsg string
expTxsLen int
}{
{"nil request", nil, true, "request cannot be nil"},
{"empty request", &tx2.GetBlockWithTxsRequest{}, true, "height must not be less than 1 or greater than the current height"},
{"bad height", &tx2.GetBlockWithTxsRequest{Height: 99999999}, true, "height must not be less than 1 or greater than the current height"},
{"bad pagination", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 1000, Limit: 100}}, true, "out of range"},
{"good request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight}, false, ""},
{"with pagination request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 0, Limit: 1}}, false, ""},
{"page all request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 0, Limit: 100}}, false, ""},
{"nil request", nil, true, "request cannot be nil", 0},
{"empty request", &tx2.GetBlockWithTxsRequest{}, true, "height must not be less than 1 or greater than the current height", 0},
{"bad height", &tx2.GetBlockWithTxsRequest{Height: 99999999}, true, "height must not be less than 1 or greater than the current height", 0},
{"bad pagination", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 1000, Limit: 100}}, true, "out of range", 0},
{"good request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight}, false, "", 1},
{"with pagination request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 0, Limit: 1}}, false, "", 1},
{"page all request", &tx2.GetBlockWithTxsRequest{Height: s.txHeight, Pagination: &query.PageRequest{Offset: 0, Limit: 100}}, false, "", 1},
{"block with 0 tx", &tx2.GetBlockWithTxsRequest{Height: s.txHeight - 1, Pagination: &query.PageRequest{Offset: 0, Limit: 100}}, false, "", 0},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
Expand All @@ -117,7 +119,9 @@ func (s IntegrationTestSuite) TestGetBlockWithTxs_GRPC() {
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)
s.Require().Equal("foobar", grpcRes.Txs[0].Body.Memo)
if tc.expTxsLen > 0 {
s.Require().Equal("foobar", grpcRes.Txs[0].Body.Memo)
}
s.Require().Equal(grpcRes.Block.Header.Height, tc.req.Height)
if tc.req.Pagination != nil {
s.Require().LessOrEqual(len(grpcRes.Txs), int(tc.req.Pagination.Limit))
Expand Down