* Error handling in ERC20 and ERC721 * Added message string for require. * Fixed solhint errors. * Updated PR as per issue #1709 * changes as per #1709 and openzeppelin forum. * Changes in require statement * Changes in require statement * build pipeline fix * Changes as per @nventuro's comment. * Update revert reason strings. * Fianal update of revert reason strings. * WIP: Updating reason strings in test cases * WIP: Added changes to ERC20 and ERC721 * Fixes linting errors in *.tes.js files * Achieved 100% code coverage * Updated the test cases with shouldFail.reverting.withMessage() * Fix package-lock. * address review comments * fix linter issues * fix remaining revert reasons
63 lines
2.6 KiB
JavaScript
63 lines
2.6 KiB
JavaScript
const { shouldFail, singletons } = require('openzeppelin-test-helpers');
|
|
const { bufferToHex, keccak256 } = require('ethereumjs-util');
|
|
|
|
const ERC1820ImplementerMock = artifacts.require('ERC1820ImplementerMock');
|
|
|
|
contract('ERC1820Implementer', function ([_, registryFunder, implementee, other]) {
|
|
const ERC1820_ACCEPT_MAGIC = bufferToHex(keccak256('ERC1820_ACCEPT_MAGIC'));
|
|
|
|
beforeEach(async function () {
|
|
this.implementer = await ERC1820ImplementerMock.new();
|
|
this.registry = await singletons.ERC1820Registry(registryFunder);
|
|
|
|
this.interfaceA = bufferToHex(keccak256('interfaceA'));
|
|
this.interfaceB = bufferToHex(keccak256('interfaceB'));
|
|
});
|
|
|
|
context('with no registered interfaces', function () {
|
|
it('returns false when interface implementation is queried', async function () {
|
|
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, implementee))
|
|
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
|
});
|
|
|
|
it('reverts when attempting to set as implementer in the registry', async function () {
|
|
await shouldFail.reverting.withMessage(
|
|
this.registry.setInterfaceImplementer(
|
|
implementee, this.interfaceA, this.implementer.address, { from: implementee }
|
|
),
|
|
'Does not implement the interface'
|
|
);
|
|
});
|
|
});
|
|
|
|
context('with registered interfaces', function () {
|
|
beforeEach(async function () {
|
|
await this.implementer.registerInterfaceForAddress(this.interfaceA, implementee);
|
|
});
|
|
|
|
it('returns true when interface implementation is queried', async function () {
|
|
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, implementee))
|
|
.should.equal(ERC1820_ACCEPT_MAGIC);
|
|
});
|
|
|
|
it('returns false when interface implementation for non-supported interfaces is queried', async function () {
|
|
(await this.implementer.canImplementInterfaceForAddress(this.interfaceB, implementee))
|
|
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
|
});
|
|
|
|
it('returns false when interface implementation for non-supported addresses is queried', async function () {
|
|
(await this.implementer.canImplementInterfaceForAddress(this.interfaceA, other))
|
|
.should.not.equal(ERC1820_ACCEPT_MAGIC);
|
|
});
|
|
|
|
it('can be set as an implementer for supported interfaces in the registry', async function () {
|
|
await this.registry.setInterfaceImplementer(
|
|
implementee, this.interfaceA, this.implementer.address, { from: implementee }
|
|
);
|
|
|
|
(await this.registry.getInterfaceImplementer(implementee, this.interfaceA))
|
|
.should.equal(this.implementer.address);
|
|
});
|
|
});
|
|
});
|