Skip to content

Commit 7472008

Browse files
Transpile 1c1186af1
1 parent 7f46c69 commit 7472008

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

test/helpers/iterate.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ module.exports = {
3030

3131
// ================================================ Object helpers =================================================
3232

33-
// Create a new object by mapping the values through a function, keeping the keys
33+
// Create a new object by mapping the values through a function, keeping the keys. Second function can be used to pre-filter entries
3434
// Example: mapValues({a:1,b:2,c:3}, x => x**2) → {a:1,b:4,c:9}
35-
mapValues: (obj, fn) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn(v)])),
35+
mapValues: (obj, fn, fn2 = () => true) =>
36+
Object.fromEntries(
37+
Object.entries(obj)
38+
.filter(fn2)
39+
.map(([k, v]) => [k, fn(v)]),
40+
),
3641
};

test/utils/introspection/SupportsInterface.behavior.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ const SIGNATURES = {
9292

9393
const INTERFACE_IDS = mapValues(SIGNATURES, interfaceId);
9494

95-
function shouldSupportInterfaces(interfaces = []) {
95+
function shouldSupportInterfaces(interfaces = [], signatures = SIGNATURES) {
9696
interfaces.unshift('ERC165');
97+
signatures.ERC165 = SIGNATURES.ERC165;
98+
const interfaceIds = mapValues(signatures, interfaceId, ([name]) => interfaces.includes(name));
9799

98100
describe('ERC165', function () {
99101
beforeEach(function () {
@@ -103,14 +105,14 @@ function shouldSupportInterfaces(interfaces = []) {
103105
describe('when the interfaceId is supported', function () {
104106
it('uses less than 30k gas', async function () {
105107
for (const k of interfaces) {
106-
const interfaceId = INTERFACE_IDS[k] ?? k;
108+
const interfaceId = interfaceIds[k] ?? k;
107109
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.lte(30_000n);
108110
}
109111
});
110112

111113
it('returns true', async function () {
112114
for (const k of interfaces) {
113-
const interfaceId = INTERFACE_IDS[k] ?? k;
115+
const interfaceId = interfaceIds[k] ?? k;
114116
expect(await this.contractUnderTest.supportsInterface(interfaceId), `does not support ${k}`).to.be.true;
115117
}
116118
});
@@ -129,10 +131,10 @@ function shouldSupportInterfaces(interfaces = []) {
129131
it('all interface functions are in ABI', async function () {
130132
for (const k of interfaces) {
131133
// skip interfaces for which we don't have a function list
132-
if (SIGNATURES[k] === undefined) continue;
134+
if (signatures[k] === undefined) continue;
133135

134136
// Check the presence of each function in the contract's interface
135-
for (const fnSig of SIGNATURES[k]) {
137+
for (const fnSig of signatures[k]) {
136138
expect(this.contractUnderTest.interface.hasFunction(fnSig), `did not find ${fnSig}`).to.be.true;
137139
}
138140
}
@@ -141,5 +143,7 @@ function shouldSupportInterfaces(interfaces = []) {
141143
}
142144

143145
module.exports = {
146+
SIGNATURES,
147+
INTERFACE_IDS,
144148
shouldSupportInterfaces,
145149
};

0 commit comments

Comments
 (0)