-
Notifications
You must be signed in to change notification settings - Fork 20
/
EnforcementModule.test.js
87 lines (76 loc) · 3.06 KB
/
EnforcementModule.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers')
const { should } = require('chai').should()
const { ENFORCER_ROLE } = require('../utils')
const CMTAT = artifacts.require('CMTAT')
contract(
'EnforcementModule',
function ([_, owner, address1, address2, address3, fakeRuleEngine]) {
beforeEach(async function () {
this.cmtat = await CMTAT.new(_, { from: owner })
await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner })
})
context('Freeze', function () {
beforeEach(async function () {
await this.cmtat.mint(address1, 50, { from: owner })
})
it('can freeze an account as the owner', async function () {
(await this.cmtat.frozen(address1)).should.equal(false);
({ logs: this.logs } = await this.cmtat.freeze(address1, {
from: owner
}));
(await this.cmtat.frozen(address1)).should.equal(true)
})
it('emits a Freeze event', function () {
expectEvent.inLogs(this.logs, 'Freeze', {
enforcer: owner,
owner: address1
})
})
it('can freeze an account as anyone with the enforcer role', async function () {
await this.cmtat.grantRole(ENFORCER_ROLE, address3, { from: owner });
(await this.cmtat.frozen(address1)).should.equal(false)
await this.cmtat.freeze(address1, { from: address3 });
(await this.cmtat.frozen(address1)).should.equal(true)
})
it('can unfreeze an account as the owner', async function () {
await this.cmtat.freeze(address1, { from: owner });
(await this.cmtat.frozen(address1)).should.equal(true);
({ logs: this.logs } = await this.cmtat.unfreeze(address1, {
from: owner
}));
(await this.cmtat.frozen(address1)).should.equal(false)
})
it('can unfreeze an account as anyone with the enforcer role', async function () {
await this.cmtat.freeze(address1, { from: owner });
(await this.cmtat.frozen(address1)).should.equal(true)
await this.cmtat.grantRole(ENFORCER_ROLE, address3, { from: owner })
await this.cmtat.unfreeze(address1, { from: address3 });
(await this.cmtat.frozen(address1)).should.equal(false)
})
it('emits an Unfreeze event', function () {
expectEvent.inLogs(this.logs, 'Unfreeze', {
enforcer: owner,
owner: address1
})
})
it('reverts when freezing from non-enforcer', async function () {
await expectRevert(
this.cmtat.freeze(address1, { from: address3 }),
'AccessControl: account ' +
address3.toLowerCase() +
' is missing role ' +
ENFORCER_ROLE
)
})
it('reverts when unfreezing from non-enforcer', async function () {
await expectRevert(
this.cmtat.unfreeze(address1, { from: address3 }),
'AccessControl: account ' +
address3.toLowerCase() +
' is missing role ' +
ENFORCER_ROLE
)
})
})
}
)