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: include pagination.key at reverse mode (backport #20939) #20954

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test.
* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test.
* [#20939](https://github.com/cosmos/cosmos-sdk/pull/20939) Fix collection reverse iterator to include `pagination.key` in the result.

## [v0.50.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.7) - 2024-06-04

Expand Down
10 changes: 5 additions & 5 deletions types/query/collections_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ func encodeCollKey[K, V any, C Collection[K, V]](coll C, key K) ([]byte, error)
func getCollIter[K, V any, C Collection[K, V]](ctx context.Context, coll C, prefix, start []byte, reverse bool) (collections.Iterator[K, V], error) {
// TODO: maybe can be simplified
if reverse {
var end []byte
if prefix != nil {
start = storetypes.PrefixEndBytes(append(prefix, start...))
end = prefix
}
// if we are in reverse mode, we need to increase the start key
// to include the start key in the iteration.
start = storetypes.PrefixEndBytes(append(prefix, start...))
end := prefix

return coll.IterateRaw(ctx, end, start, collections.OrderDescending)
}
var end []byte
Expand Down
10 changes: 10 additions & 0 deletions types/query/collections_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func TestCollectionPagination(t *testing.T) {
},
expResults: createResults(299, 200),
},
"with key and reverse": {
req: &PageRequest{
Key: encodeKey(199),
Reverse: true,
},
expResp: &PageResponse{
NextKey: encodeKey(99),
},
expResults: createResults(199, 100),
},
"with offset and count total": {
req: &PageRequest{
Offset: 50,
Expand Down
Loading