|
|
@ -92,8 +92,10 @@ const SIGNATURES = { |
|
|
|
|
|
|
|
|
|
|
|
const INTERFACE_IDS = mapValues(SIGNATURES, interfaceId); |
|
|
|
const INTERFACE_IDS = mapValues(SIGNATURES, interfaceId); |
|
|
|
|
|
|
|
|
|
|
|
function shouldSupportInterfaces(interfaces = []) { |
|
|
|
function shouldSupportInterfaces(interfaces = [], signatures = SIGNATURES) { |
|
|
|
interfaces.unshift('ERC165'); |
|
|
|
interfaces.unshift('ERC165'); |
|
|
|
|
|
|
|
signatures.ERC165 = SIGNATURES.ERC165; |
|
|
|
|
|
|
|
const interfaceIds = mapValues(signatures, interfaceId, ([name]) => interfaces.includes(name)); |
|
|
|
|
|
|
|
|
|
|
|
describe('ERC165', function () { |
|
|
|
describe('ERC165', function () { |
|
|
|
beforeEach(function () { |
|
|
|
beforeEach(function () { |
|
|
@ -103,14 +105,14 @@ function shouldSupportInterfaces(interfaces = []) { |
|
|
|
describe('when the interfaceId is supported', function () { |
|
|
|
describe('when the interfaceId is supported', function () { |
|
|
|
it('uses less than 30k gas', async function () { |
|
|
|
it('uses less than 30k gas', async function () { |
|
|
|
for (const k of interfaces) { |
|
|
|
for (const k of interfaces) { |
|
|
|
const interfaceId = INTERFACE_IDS[k] ?? k; |
|
|
|
const interfaceId = interfaceIds[k] ?? k; |
|
|
|
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.lte(30_000n); |
|
|
|
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.lte(30_000n); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns true', async function () { |
|
|
|
it('returns true', async function () { |
|
|
|
for (const k of interfaces) { |
|
|
|
for (const k of interfaces) { |
|
|
|
const interfaceId = INTERFACE_IDS[k] ?? k; |
|
|
|
const interfaceId = interfaceIds[k] ?? k; |
|
|
|
expect(await this.contractUnderTest.supportsInterface(interfaceId), `does not support ${k}`).to.be.true; |
|
|
|
expect(await this.contractUnderTest.supportsInterface(interfaceId), `does not support ${k}`).to.be.true; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -129,10 +131,10 @@ function shouldSupportInterfaces(interfaces = []) { |
|
|
|
it('all interface functions are in ABI', async function () { |
|
|
|
it('all interface functions are in ABI', async function () { |
|
|
|
for (const k of interfaces) { |
|
|
|
for (const k of interfaces) { |
|
|
|
// skip interfaces for which we don't have a function list
|
|
|
|
// skip interfaces for which we don't have a function list
|
|
|
|
if (SIGNATURES[k] === undefined) continue; |
|
|
|
if (signatures[k] === undefined) continue; |
|
|
|
|
|
|
|
|
|
|
|
// Check the presence of each function in the contract's interface
|
|
|
|
// Check the presence of each function in the contract's interface
|
|
|
|
for (const fnSig of SIGNATURES[k]) { |
|
|
|
for (const fnSig of signatures[k]) { |
|
|
|
expect(this.contractUnderTest.interface.hasFunction(fnSig), `did not find ${fnSig}`).to.be.true; |
|
|
|
expect(this.contractUnderTest.interface.hasFunction(fnSig), `did not find ${fnSig}`).to.be.true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -141,5 +143,7 @@ function shouldSupportInterfaces(interfaces = []) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
|
|
|
|
SIGNATURES, |
|
|
|
|
|
|
|
INTERFACE_IDS, |
|
|
|
shouldSupportInterfaces, |
|
|
|
shouldSupportInterfaces, |
|
|
|
}; |
|
|
|
}; |
|
|
|