-
Notifications
You must be signed in to change notification settings - Fork 20
/
PauseModule.test.js
94 lines (81 loc) · 3.25 KB
/
PauseModule.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
88
89
90
91
92
93
94
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers')
const { PAUSER_ROLE } = require('../utils')
const { should } = require('chai').should()
const CMTAT = artifacts.require('CMTAT')
contract('PauseModule', function ([_, owner, address1, address2, address3]) {
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('Pause', function () {
it('can be paused by the owner', async function () {
({ logs: this.logs } = await this.cmtat.pause({ from: owner }))
})
it('emits a Paused event', function () {
expectEvent.inLogs(this.logs, 'Paused', { account: owner })
})
it('can be paused by the anyone having pauser role', async function () {
await this.cmtat.grantRole(PAUSER_ROLE, address1, { from: owner })
await this.cmtat.pause({ from: address1 })
})
it('reverts when calling from non-owner', async function () {
await expectRevert(
this.cmtat.pause({ from: address1 }),
'AccessControl: account ' +
address1.toLowerCase() +
' is missing role ' +
PAUSER_ROLE
)
})
it('can be unpaused by the owner', async function () {
await this.cmtat.pause({ from: owner });
({ logs: this.logs } = await this.cmtat.unpause({ from: owner }))
})
it('emits a Unpaused event', function () {
expectEvent.inLogs(this.logs, 'Unpaused', { account: owner })
})
it('can be paused by the anyone having pauser role', async function () {
await this.cmtat.pause({ from: owner })
await this.cmtat.grantRole(PAUSER_ROLE, address1, { from: owner })
await this.cmtat.unpause({ from: address1 })
})
it('reverts when calling from non-owner', async function () {
await this.cmtat.pause({ from: owner })
await expectRevert(
this.cmtat.unpause({ from: address1 }),
'AccessControl: account ' +
address1.toLowerCase() +
' is missing role ' +
PAUSER_ROLE
)
})
it('reverts if address1 transfers tokens to address2 when paused', async function () {
await this.cmtat.pause({ from: owner });
(
await this.cmtat.detectTransferRestriction(address1, address2, 10)
).should.be.bignumber.equal('1');
(await this.cmtat.messageForTransferRestriction(1)).should.equal(
'All transfers paused'
)
await expectRevert(
this.cmtat.transfer(address2, 10, { from: address1 }),
'CMTAT: token transfer while paused'
)
})
it('reverts if address3 transfers tokens from address1 to address2 when paused', async function () {
// Define allowance
await this.cmtat.approve(address3, 20, { from: address1 })
await this.cmtat.pause({ from: owner });
(
await this.cmtat.detectTransferRestriction(address1, address2, 10)
).should.be.bignumber.equal('1');
(await this.cmtat.messageForTransferRestriction(1)).should.equal(
'All transfers paused'
)
await expectRevert(
this.cmtat.transferFrom(address1, address2, 10, { from: address3 }),
'CMTAT: token transfer while paused'
)
})
})
})