forked from OpenZeppelin/openzeppelin-contracts
/
VestingWallet.behavior.js
70 lines (54 loc) · 2.02 KB
/
VestingWallet.behavior.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
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
function shouldBehaveLikeVesting (beneficiary) {
it('check vesting schedule', async function () {
const args = this.token ? [ this.token.address ] : [];
for (const timestamp of this.schedule) {
expect(await this.mock.vestedAmount(...args, timestamp))
.to.be.bignumber.equal(this.vestingFn(timestamp));
}
});
it('execute vesting schedule', async function () {
const args = this.token ? [ this.token.address ] : [];
let released = web3.utils.toBN(0);
const before = await this.getBalance(beneficiary);
{
const receipt = await this.mock.release(...args);
await expectEvent.inTransaction(
receipt.tx,
this.mock,
this.token ? 'ERC20Released' : 'EtherReleased',
Object.fromEntries(Object.entries({
token: this.token && this.token.address,
amount: '0',
}).filter(x => x.every(Boolean))),
);
await this.checkRelease(receipt, beneficiary, '0');
expect(await this.getBalance(beneficiary)).to.be.bignumber.equal(before);
}
for (const timestamp of this.schedule) {
const vested = this.vestingFn(timestamp);
await new Promise(resolve => web3.currentProvider.send({
method: 'evm_setNextBlockTimestamp',
params: [ timestamp.toNumber() ],
}, resolve));
const receipt = await this.mock.release(...args);
await expectEvent.inTransaction(
receipt.tx,
this.mock,
this.token ? 'ERC20Released' : 'EtherReleased',
Object.fromEntries(Object.entries({
token: this.token && this.token.address,
amount: vested.sub(released),
}).filter(x => x.every(Boolean))),
);
await this.checkRelease(receipt, beneficiary, vested.sub(released));
expect(await this.getBalance(beneficiary))
.to.be.bignumber.equal(before.add(vested));
released = vested;
}
});
}
module.exports = {
shouldBehaveLikeVesting,
};