-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrestrictable.js
50 lines (38 loc) · 1.86 KB
/
restrictable.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
/* global artifacts contract it assert */
const { shouldFail, expectEvent } = require('openzeppelin-test-helpers')
const SukuToken = artifacts.require('SukuToken')
contract('Restrictable', (accounts) => {
it('should deploy', async () => {
const tokenInstance = await SukuToken.new(accounts[0])
assert.equal(tokenInstance !== null, true, 'Contract should be deployed')
})
it('should default to restriction enabled and be changeable', async () => {
const tokenInstance = await SukuToken.new(accounts[0])
// Check initial value
let isRestricted = await tokenInstance.isRestrictionEnabled.call()
assert.equal(isRestricted, true, 'Should be restricted by default')
// Let the owner update
await tokenInstance.disableRestrictions({ from: accounts[0] })
// Should now be disabled
isRestricted = await tokenInstance.isRestrictionEnabled.call()
assert.equal(isRestricted, false, 'Should be disabled by admin')
})
it('should only allow owner to update', async () => {
const tokenInstance = await SukuToken.new(accounts[0])
await shouldFail.reverting(tokenInstance.disableRestrictions({ from: accounts[5] }))
await shouldFail.reverting(tokenInstance.disableRestrictions({ from: accounts[6] }))
})
it('should trigger events', async () => {
const tokenInstance = await SukuToken.new(accounts[0])
// Turn it off
let ret = await tokenInstance.disableRestrictions({ from: accounts[0] })
expectEvent.inLogs(ret.logs, 'RestrictionsDisabled', { owner: accounts[0] })
})
it('should fail to be disabled on the second try', async () => {
const tokenInstance = await SukuToken.new(accounts[0])
// First time should succeed
await tokenInstance.disableRestrictions({ from: accounts[0] })
// Second time should fail
await shouldFail.reverting(tokenInstance.disableRestrictions({ from: accounts[0] }))
})
})