Update docs
This commit is contained in:
@ -1,79 +1,61 @@
|
||||
const EnumerableSet = artifacts.require('$EnumerableSet');
|
||||
const { ethers } = require('hardhat');
|
||||
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 { shouldBehaveLikeSet } = require('./EnumerableSet.behavior');
|
||||
|
||||
const getMethods = ms => {
|
||||
const getMethods = (mock, fnSigs) => {
|
||||
return mapValues(
|
||||
ms,
|
||||
m =>
|
||||
(self, ...args) =>
|
||||
self.methods[m](0, ...args),
|
||||
fnSigs,
|
||||
fnSig =>
|
||||
(...args) =>
|
||||
mock.getFunction(fnSig)(0, ...args),
|
||||
);
|
||||
};
|
||||
|
||||
// Get the name of the library. In the transpiled code it will be EnumerableSetUpgradeable.
|
||||
const library = EnumerableSet._json.contractName.replace(/^\$/, '');
|
||||
async function fixture() {
|
||||
const mock = await ethers.deployContract('$EnumerableSet');
|
||||
|
||||
contract('EnumerableSet', function (accounts) {
|
||||
const env = Object.fromEntries(
|
||||
TYPES.map(({ name, type }) => [
|
||||
type,
|
||||
{
|
||||
values: Array.from({ length: 3 }, generators[type]),
|
||||
methods: getMethods(mock, {
|
||||
add: `$add(uint256,${type})`,
|
||||
remove: `$remove(uint256,${type})`,
|
||||
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}`,
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
return { mock, env };
|
||||
}
|
||||
|
||||
describe('EnumerableSet', function () {
|
||||
beforeEach(async function () {
|
||||
this.set = await EnumerableSet.new();
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
// Bytes32Set
|
||||
describe('EnumerableBytes32Set', function () {
|
||||
shouldBehaveLikeSet(
|
||||
['0xdeadbeef', '0x0123456789', '0x42424242'].map(e => e.padEnd(66, '0')),
|
||||
getMethods({
|
||||
add: '$add(uint256,bytes32)',
|
||||
remove: '$remove(uint256,bytes32)',
|
||||
contains: '$contains(uint256,bytes32)',
|
||||
length: `$length_${library}_Bytes32Set(uint256)`,
|
||||
at: `$at_${library}_Bytes32Set(uint256,uint256)`,
|
||||
values: `$values_${library}_Bytes32Set(uint256)`,
|
||||
}),
|
||||
{
|
||||
addReturn: `return$add_${library}_Bytes32Set_bytes32`,
|
||||
removeReturn: `return$remove_${library}_Bytes32Set_bytes32`,
|
||||
},
|
||||
);
|
||||
});
|
||||
for (const { type } of TYPES) {
|
||||
describe(type, function () {
|
||||
beforeEach(function () {
|
||||
Object.assign(this, this.env[type]);
|
||||
[this.valueA, this.valueB, this.valueC] = this.values;
|
||||
});
|
||||
|
||||
// AddressSet
|
||||
describe('EnumerableAddressSet', function () {
|
||||
shouldBehaveLikeSet(
|
||||
accounts,
|
||||
getMethods({
|
||||
add: '$add(uint256,address)',
|
||||
remove: '$remove(uint256,address)',
|
||||
contains: '$contains(uint256,address)',
|
||||
length: `$length_${library}_AddressSet(uint256)`,
|
||||
at: `$at_${library}_AddressSet(uint256,uint256)`,
|
||||
values: `$values_${library}_AddressSet(uint256)`,
|
||||
}),
|
||||
{
|
||||
addReturn: `return$add_${library}_AddressSet_address`,
|
||||
removeReturn: `return$remove_${library}_AddressSet_address`,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// UintSet
|
||||
describe('EnumerableUintSet', function () {
|
||||
shouldBehaveLikeSet(
|
||||
[1234, 5678, 9101112].map(e => web3.utils.toBN(e)),
|
||||
getMethods({
|
||||
add: '$add(uint256,uint256)',
|
||||
remove: '$remove(uint256,uint256)',
|
||||
contains: '$contains(uint256,uint256)',
|
||||
length: `$length_${library}_UintSet(uint256)`,
|
||||
at: `$at_${library}_UintSet(uint256,uint256)`,
|
||||
values: `$values_${library}_UintSet(uint256)`,
|
||||
}),
|
||||
{
|
||||
addReturn: `return$add_${library}_UintSet_uint256`,
|
||||
removeReturn: `return$remove_${library}_UintSet_uint256`,
|
||||
},
|
||||
);
|
||||
});
|
||||
shouldBehaveLikeSet();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user