Add paginated version of EnumerableSet.values() and EnumerableMap.keys() (#5713)

Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
Hadrien Croubois
2025-06-04 09:33:00 +02:00
committed by GitHub
parent f45e9158b7
commit d20b9e30bd
10 changed files with 472 additions and 4 deletions

View File

@ -191,6 +191,22 @@ function shouldBehaveLikeMap() {
});
});
});
it('keys (full & paginated)', async function () {
const keys = [this.keyA, this.keyB, this.keyC];
await this.methods.set(this.keyA, this.valueA);
await this.methods.set(this.keyB, this.valueB);
await this.methods.set(this.keyC, this.valueC);
// get all values
expect([...(await this.methods.keys())]).to.deep.equal(keys);
// try pagination
for (const begin of [0, 1, 2, 3, 4])
for (const end of [0, 1, 2, 3, 4]) {
expect([...(await this.methods.keysPage(begin, end))]).to.deep.equal(keys.slice(begin, end));
}
});
}
module.exports = {

View File

@ -34,6 +34,7 @@ async function fixture() {
length: `$length_EnumerableMap_${name}(uint256)`,
at: `$at_EnumerableMap_${name}(uint256,uint256)`,
keys: `$keys_EnumerableMap_${name}(uint256)`,
keysPage: `$keys_EnumerableMap_${name}(uint256,uint256,uint256)`,
}
: {
set: `$set(uint256,${key.type},${value.type})`,
@ -45,6 +46,7 @@ async function fixture() {
length: `$length_EnumerableMap_${name}(uint256)`,
at: `$at_EnumerableMap_${name}(uint256,uint256)`,
keys: `$keys_EnumerableMap_${name}(uint256)`,
keysPage: `$keys_EnumerableMap_${name}(uint256,uint256,uint256)`,
},
fnSig =>
(...args) =>

View File

@ -152,6 +152,22 @@ function shouldBehaveLikeSet() {
await expectMembersMatch(this.methods, [this.valueA]);
});
});
it('values (full & paginated)', async function () {
const values = [this.valueA, this.valueB, this.valueC];
await this.methods.add(this.valueA);
await this.methods.add(this.valueB);
await this.methods.add(this.valueC);
// get all values
expect([...(await this.methods.values())]).to.deep.equal(values);
// try pagination
for (const begin of [0, 1, 2, 3, 4])
for (const end of [0, 1, 2, 3, 4]) {
expect([...(await this.methods.valuesPage(begin, end))]).to.deep.equal(values.slice(begin, end));
}
});
}
module.exports = {

View File

@ -35,6 +35,7 @@ async function fixture() {
length: `$length_EnumerableSet_${name}(uint256)`,
at: `$at_EnumerableSet_${name}(uint256,uint256)`,
values: `$values_EnumerableSet_${name}(uint256)`,
valuesPage: `$values_EnumerableSet_${name}(uint256,uint256,uint256)`,
}),
events: {
addReturn: `return$add_EnumerableSet_${name}_${value.type.replace(/[[\]]/g, '_')}`,