Implement ERC165 tests realted to invalidID (#4414)
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
@ -2,6 +2,7 @@ const { makeInterfaceId } = require('@openzeppelin/test-helpers');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
const INVALID_ID = '0xffffffff';
|
||||
const INTERFACES = {
|
||||
ERC165: ['supportsInterface(bytes4)'],
|
||||
ERC721: [
|
||||
@ -111,18 +112,30 @@ function shouldSupportInterfaces(interfaces = []) {
|
||||
this.contractUnderTest = this.mock || this.token || this.holder || this.accessControl;
|
||||
});
|
||||
|
||||
it('supportsInterface uses less than 30k gas', async function () {
|
||||
for (const k of interfaces) {
|
||||
const interfaceId = INTERFACE_IDS[k] ?? k;
|
||||
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.be.lte(30000);
|
||||
}
|
||||
describe('when the interfaceId is supported', function () {
|
||||
it('uses less than 30k gas', async function () {
|
||||
for (const k of interfaces) {
|
||||
const interfaceId = INTERFACE_IDS[k] ?? k;
|
||||
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.be.lte(30000);
|
||||
}
|
||||
});
|
||||
|
||||
it('returns true', async function () {
|
||||
for (const k of interfaces) {
|
||||
const interfaceId = INTERFACE_IDS[k] ?? k;
|
||||
expect(await this.contractUnderTest.supportsInterface(interfaceId)).to.equal(true, `does not support ${k}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('all interfaces are reported as supported', async function () {
|
||||
for (const k of interfaces) {
|
||||
const interfaceId = INTERFACE_IDS[k] ?? k;
|
||||
expect(await this.contractUnderTest.supportsInterface(interfaceId)).to.equal(true, `does not support ${k}`);
|
||||
}
|
||||
describe('when the interfaceId is not supported', function () {
|
||||
it('uses less thank 30k', async function () {
|
||||
expect(await this.contractUnderTest.supportsInterface.estimateGas(INVALID_ID)).to.be.lte(30000);
|
||||
});
|
||||
|
||||
it('returns false', async function () {
|
||||
expect(await this.contractUnderTest.supportsInterface(INVALID_ID)).to.be.equal(false, `supports ${INVALID_ID}`);
|
||||
});
|
||||
});
|
||||
|
||||
it('all interface functions are in ABI', async function () {
|
||||
|
||||
Reference in New Issue
Block a user