diff --git a/CHANGELOG.md b/CHANGELOG.md index 9199b9888e..38b54c34cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/auth/tx2/service.go b/x/auth/tx2/service.go index 24f53f34a3..67de6f505a 100644 --- a/x/auth/tx2/service.go +++ b/x/auth/tx2/service.go @@ -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 { diff --git a/x/auth/tx2/service_test.go b/x/auth/tx2/service_test.go index 24a73a2396..4e9e945a79 100644 --- a/x/auth/tx2/service_test.go +++ b/x/auth/tx2/service_test.go @@ -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() { @@ -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))