forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERC1820Implementer.test.js
61 lines (49 loc) · 2.53 KB
/
ERC1820Implementer.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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(
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, 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);
});
});
});