Add non-value types in EnumerableSet and EnumerableMap (#5658)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -3,39 +3,42 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { mapValues } = require('../../helpers/iterate');
|
||||
const { generators } = require('../../helpers/random');
|
||||
const { TYPES } = require('../../../scripts/generate/templates/EnumerableSet.opts');
|
||||
const { SET_TYPES } = require('../../../scripts/generate/templates/Enumerable.opts');
|
||||
|
||||
const { shouldBehaveLikeSet } = require('./EnumerableSet.behavior');
|
||||
|
||||
const getMethods = (mock, fnSigs) => {
|
||||
return mapValues(
|
||||
const getMethods = (mock, fnSigs) =>
|
||||
mapValues(
|
||||
fnSigs,
|
||||
fnSig =>
|
||||
(...args) =>
|
||||
mock.getFunction(fnSig)(0, ...args),
|
||||
);
|
||||
};
|
||||
|
||||
async function fixture() {
|
||||
const mock = await ethers.deployContract('$EnumerableSet');
|
||||
|
||||
const env = Object.fromEntries(
|
||||
TYPES.map(({ name, type }) => [
|
||||
type,
|
||||
SET_TYPES.map(({ name, value }) => [
|
||||
name,
|
||||
{
|
||||
values: Array.from({ length: 3 }, generators[type]),
|
||||
value,
|
||||
values: Array.from(
|
||||
{ length: 3 },
|
||||
value.size ? () => Array.from({ length: value.size }, generators[value.base]) : generators[value.type],
|
||||
),
|
||||
methods: getMethods(mock, {
|
||||
add: `$add(uint256,${type})`,
|
||||
remove: `$remove(uint256,${type})`,
|
||||
add: `$add(uint256,${value.type})`,
|
||||
remove: `$remove(uint256,${value.type})`,
|
||||
contains: `$contains(uint256,${value.type})`,
|
||||
clear: `$clear_EnumerableSet_${name}(uint256)`,
|
||||
contains: `$contains(uint256,${type})`,
|
||||
length: `$length_EnumerableSet_${name}(uint256)`,
|
||||
at: `$at_EnumerableSet_${name}(uint256,uint256)`,
|
||||
values: `$values_EnumerableSet_${name}(uint256)`,
|
||||
}),
|
||||
events: {
|
||||
addReturn: `return$add_EnumerableSet_${name}_${type}`,
|
||||
removeReturn: `return$remove_EnumerableSet_${name}_${type}`,
|
||||
addReturn: `return$add_EnumerableSet_${name}_${value.type.replace(/[[\]]/g, '_')}`,
|
||||
removeReturn: `return$remove_EnumerableSet_${name}_${value.type.replace(/[[\]]/g, '_')}`,
|
||||
},
|
||||
},
|
||||
]),
|
||||
@ -49,10 +52,10 @@ describe('EnumerableSet', function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
for (const { type } of TYPES) {
|
||||
describe(type, function () {
|
||||
for (const { name, value } of SET_TYPES) {
|
||||
describe(`${name} (enumerable set of ${value.type})`, function () {
|
||||
beforeEach(function () {
|
||||
Object.assign(this, this.env[type]);
|
||||
Object.assign(this, this.env[name]);
|
||||
[this.valueA, this.valueB, this.valueC] = this.values;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user