Files
openzeppelin-contracts/test/drafts/ERC1820Implementer.test.js
Nicolás Venturo 308a4c9907 Draft EIP 1820 (#1677)
* Add barebones EIP1820 support.

* Update openzeppelin-test-helpers dependency to have ERC1820 support.

* Add tests for ERC1820.

* Improve inline documentation.

* Add changelog entry.

* Update test-helpers, refactor tests to use new helpers.

* Rename ERC1820 to ERC1820Implementer.

* Improve implementer docstring.

* Remove _implementsInterfaceForAddress.

* update openzeppelin-test-helpers to 0.2.0

* Update contracts/drafts/ERC1820Implementer.sol

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Fix how solidity coverage is run to allow for free events.

* Fix coverage testing script.
2019-03-19 15:13:55 -03:00

62 lines
2.5 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, anyone]) {
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(
this.registry.setInterfaceImplementer(
implementee, this.interfaceA, this.implementer.address, { from: implementee }
)
);
});
});
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, anyone))
.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);
});
});
});