Co-authored-by: beer-1 <147697694+beer-1@users.noreply.github.com> Co-authored-by: Facundo <facundomedica@gmail.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
beer-1
Facundo
Julien Robert
parent
d975e0160c
commit
711d86a691
@@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
* [#20939](https://github.com/cosmos/cosmos-sdk/pull/20939) Fix collection reverse iterator to include `pagination.key` in the result.
|
||||
|
||||
## [v0.50.8](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.8) - 2024-07-15
|
||||
|
||||
## Features
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user