-
Notifications
You must be signed in to change notification settings - Fork 0
/
vesting.ts
151 lines (122 loc) · 4.02 KB
/
vesting.ts
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { ethers } from 'hardhat'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from 'chai'
import {
burnAddress,
checkBalance,
grantRole,
initVesting,
revokeRole,
testWithdraw
} from './helpers/vesting-helpers'
import { IERC20, ERC20Token__factory } from '../typechain'
const { parseEther } = ethers.utils
describe('Vesting test', async () => {
let owner: SignerWithAddress
let user: SignerWithAddress
let token: IERC20
let amount = parseEther('200')
before(async () => {
let signers = await ethers.getSigners()
owner = signers[0]
user = signers[1]
token = await new ERC20Token__factory(owner).deploy(
parseEther('1000000')
)
})
afterEach(async () => {
let userConnection = token.connect(user)
let userBalance = await userConnection.balanceOf(user.address)
await (await userConnection.transfer(burnAddress(), userBalance)).wait()
})
it('should not init if edge < now', async () => {
await expect(
initVesting(token, owner, user, amount, 1, -2),
'edge before now'
).to.be.reverted
})
it('should not init if edge > end', async () => {
await expect(
initVesting(token, owner, user, amount, 1, 0, 2),
'edge after end'
).to.be.reverted
})
it('should not revoke WITHDRAW_ROLE from beneficiary', async () => {
let { vesting } = await initVesting(token, owner, user, amount, 1)
await expect(
revokeRole(vesting, 'WITHDRAW_ROLE', user),
'revoke withdraw from beneficiary'
).to.be.reverted
})
it('should revoke WITHDRAW_ROLE from owner', async () => {
let { vesting } = await initVesting(token, owner, user, amount, 1)
await expect(
grantRole(vesting, 'WITHDRAW_ROLE', owner),
'granting WITHDRAW_ROLE to owner'
).to.not.be.reverted
await expect(
revokeRole(vesting, 'WITHDRAW_ROLE', owner),
'revoking WITHDRAW_ROLE from owner'
).to.not.be.reverted
})
it('should not withdraw before edge', async () => {
let { vesting, now, cliffAmount } = await initVesting(
token,
owner,
user,
amount,
1
)
await expect(
testWithdraw(vesting, now++, cliffAmount),
'withdrawn before edge'
).to.be.reverted
await testWithdraw(vesting, now, cliffAmount)
await checkBalance(token, user, amount)
})
it('should withdraw in order', async () => {
let { vesting, now, cliffAmount } = await initVesting(
token,
owner,
user,
amount,
4
)
now++
await testWithdraw(vesting, now++, cliffAmount)
await testWithdraw(vesting, now++, cliffAmount)
await testWithdraw(vesting, now++, cliffAmount)
await testWithdraw(vesting, now++, cliffAmount)
await checkBalance(token, user, amount)
})
it('should withdraw skipping', async () => {
let { vesting, now, cliffAmount } = await initVesting(
token,
owner,
user,
amount,
3
)
now += 2
await testWithdraw(vesting, now++, cliffAmount, false)
await testWithdraw(vesting, now++, cliffAmount, false)
// fail to withdraw if all is withdrawn
await expect(
testWithdraw(vesting, now++, cliffAmount, false),
'withdrawn after end'
).to.be.reverted
await checkBalance(token, user, amount)
})
it('should withdraw past end', async () => {
let { vesting, now, cliffAmount } = await initVesting(
token,
owner,
user,
amount,
2
)
now += 2
await testWithdraw(vesting, now, cliffAmount, false)
await checkBalance(token, user, amount)
})
})