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 { expect } = require('chai');
|
||||||
|
|
||||||
|
const INVALID_ID = '0xffffffff';
|
||||||
const INTERFACES = {
|
const INTERFACES = {
|
||||||
ERC165: ['supportsInterface(bytes4)'],
|
ERC165: ['supportsInterface(bytes4)'],
|
||||||
ERC721: [
|
ERC721: [
|
||||||
@ -111,19 +112,31 @@ function shouldSupportInterfaces(interfaces = []) {
|
|||||||
this.contractUnderTest = this.mock || this.token || this.holder || this.accessControl;
|
this.contractUnderTest = this.mock || this.token || this.holder || this.accessControl;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supportsInterface uses less than 30k gas', async function () {
|
describe('when the interfaceId is supported', 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 = INTERFACE_IDS[k] ?? k;
|
||||||
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.be.lte(30000);
|
expect(await this.contractUnderTest.supportsInterface.estimateGas(interfaceId)).to.be.lte(30000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('all interfaces are reported as supported', 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 = INTERFACE_IDS[k] ?? k;
|
||||||
expect(await this.contractUnderTest.supportsInterface(interfaceId)).to.equal(true, `does not support ${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 () {
|
it('all interface functions are in ABI', async function () {
|
||||||
for (const k of interfaces) {
|
for (const k of interfaces) {
|
||||||
|
|||||||
Reference in New Issue
Block a user