Add paginated version of EnumerableSet.values() and EnumerableMap.keys() (#5713)
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
@ -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 = {
|
||||
|
||||
@ -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) =>
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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, '_')}`,
|
||||
|
||||
Reference in New Issue
Block a user