|
@@ -15,110 +15,134 @@ const TokenVesting = artifacts.require('TokenVesting');
|
|
|
|
|
|
contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|
contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|
const amount = new BigNumber(1000);
|
|
const amount = new BigNumber(1000);
|
|
|
|
+ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
|
|
|
beforeEach(async function () {
|
|
beforeEach(async function () {
|
|
- this.token = await MintableToken.new({ from: owner });
|
|
|
|
-
|
|
|
|
this.start = (await latestTime()) + duration.minutes(1); // +1 minute so it starts after contract instantiation
|
|
this.start = (await latestTime()) + duration.minutes(1); // +1 minute so it starts after contract instantiation
|
|
this.cliff = duration.years(1);
|
|
this.cliff = duration.years(1);
|
|
this.duration = duration.years(2);
|
|
this.duration = duration.years(2);
|
|
|
|
+ });
|
|
|
|
|
|
- this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner });
|
|
|
|
|
|
+ it('rejects a duration shorter than the cliff', async function () {
|
|
|
|
+ const cliff = this.duration;
|
|
|
|
+ const duration = this.cliff;
|
|
|
|
|
|
- await this.token.mint(this.vesting.address, amount, { from: owner });
|
|
|
|
- });
|
|
|
|
|
|
+ cliff.should.be.gt(duration);
|
|
|
|
|
|
- it('cannot be released before cliff', async function () {
|
|
|
|
await expectThrow(
|
|
await expectThrow(
|
|
- this.vesting.release(this.token.address),
|
|
|
|
- EVMRevert,
|
|
|
|
|
|
+ TokenVesting.new(beneficiary, this.start, cliff, duration, true, { from: owner })
|
|
);
|
|
);
|
|
});
|
|
});
|
|
|
|
|
|
- it('can be released after cliff', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
|
|
|
|
- await this.vesting.release(this.token.address);
|
|
|
|
|
|
+ it('requires a valid beneficiary', async function () {
|
|
|
|
+ await expectThrow(
|
|
|
|
+ TokenVesting.new(ZERO_ADDRESS, this.start, this.cliff, this.duration, true, { from: owner })
|
|
|
|
+ );
|
|
});
|
|
});
|
|
|
|
|
|
- it('should release proper amount after cliff', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.cliff);
|
|
|
|
|
|
+ context('once deployed', function () {
|
|
|
|
+ beforeEach(async function () {
|
|
|
|
+ this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner });
|
|
|
|
|
|
- const { receipt } = await this.vesting.release(this.token.address);
|
|
|
|
- const block = await ethGetBlock(receipt.blockNumber);
|
|
|
|
- const releaseTime = block.timestamp;
|
|
|
|
|
|
+ this.token = await MintableToken.new({ from: owner });
|
|
|
|
+ await this.token.mint(this.vesting.address, amount, { from: owner });
|
|
|
|
+ });
|
|
|
|
|
|
- const balance = await this.token.balanceOf(beneficiary);
|
|
|
|
- balance.should.bignumber.eq(amount.mul(releaseTime - this.start).div(this.duration).floor());
|
|
|
|
- });
|
|
|
|
|
|
+ it('cannot be released before cliff', async function () {
|
|
|
|
+ await expectThrow(
|
|
|
|
+ this.vesting.release(this.token.address),
|
|
|
|
+ EVMRevert,
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
|
|
- it('should linearly release tokens during vesting period', async function () {
|
|
|
|
- const vestingPeriod = this.duration - this.cliff;
|
|
|
|
- const checkpoints = 4;
|
|
|
|
|
|
+ it('can be released after cliff', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
|
|
|
|
+ await this.vesting.release(this.token.address);
|
|
|
|
+ });
|
|
|
|
|
|
- for (let i = 1; i <= checkpoints; i++) {
|
|
|
|
- const now = this.start + this.cliff + i * (vestingPeriod / checkpoints);
|
|
|
|
- await increaseTimeTo(now);
|
|
|
|
|
|
+ it('should release proper amount after cliff', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.cliff);
|
|
|
|
+
|
|
|
|
+ const { receipt } = await this.vesting.release(this.token.address);
|
|
|
|
+ const block = await ethGetBlock(receipt.blockNumber);
|
|
|
|
+ const releaseTime = block.timestamp;
|
|
|
|
|
|
- await this.vesting.release(this.token.address);
|
|
|
|
const balance = await this.token.balanceOf(beneficiary);
|
|
const balance = await this.token.balanceOf(beneficiary);
|
|
- const expectedVesting = amount.mul(now - this.start).div(this.duration).floor();
|
|
|
|
|
|
+ balance.should.bignumber.eq(amount.mul(releaseTime - this.start).div(this.duration).floor());
|
|
|
|
+ });
|
|
|
|
|
|
- balance.should.bignumber.eq(expectedVesting);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ it('should linearly release tokens during vesting period', async function () {
|
|
|
|
+ const vestingPeriod = this.duration - this.cliff;
|
|
|
|
+ const checkpoints = 4;
|
|
|
|
|
|
- it('should have released all after end', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.duration);
|
|
|
|
- await this.vesting.release(this.token.address);
|
|
|
|
- const balance = await this.token.balanceOf(beneficiary);
|
|
|
|
- balance.should.bignumber.eq(amount);
|
|
|
|
- });
|
|
|
|
|
|
+ for (let i = 1; i <= checkpoints; i++) {
|
|
|
|
+ const now = this.start + this.cliff + i * (vestingPeriod / checkpoints);
|
|
|
|
+ await increaseTimeTo(now);
|
|
|
|
|
|
- it('should be revoked by owner if revocable is set', async function () {
|
|
|
|
- await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
- });
|
|
|
|
|
|
+ await this.vesting.release(this.token.address);
|
|
|
|
+ const balance = await this.token.balanceOf(beneficiary);
|
|
|
|
+ const expectedVesting = amount.mul(now - this.start).div(this.duration).floor();
|
|
|
|
|
|
- it('should fail to be revoked by owner if revocable not set', async function () {
|
|
|
|
- const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, false, { from: owner });
|
|
|
|
- await expectThrow(
|
|
|
|
- vesting.revoke(this.token.address, { from: owner }),
|
|
|
|
- EVMRevert,
|
|
|
|
- );
|
|
|
|
- });
|
|
|
|
|
|
+ balance.should.bignumber.eq(expectedVesting);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- it('should return the non-vested tokens when revoked by owner', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
|
|
+ it('should have released all after end', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.duration);
|
|
|
|
+ await this.vesting.release(this.token.address);
|
|
|
|
+ const balance = await this.token.balanceOf(beneficiary);
|
|
|
|
+ balance.should.bignumber.eq(amount);
|
|
|
|
+ });
|
|
|
|
|
|
- const vested = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
+ it('should be revoked by owner if revocable is set', async function () {
|
|
|
|
+ await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
+ });
|
|
|
|
|
|
- await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
|
|
+ it('should fail to be revoked by owner if revocable not set', async function () {
|
|
|
|
+ const vesting = await TokenVesting.new(
|
|
|
|
+ beneficiary, this.start, this.cliff, this.duration, false, { from: owner }
|
|
|
|
+ );
|
|
|
|
|
|
- const ownerBalance = await this.token.balanceOf(owner);
|
|
|
|
- ownerBalance.should.bignumber.eq(amount.sub(vested));
|
|
|
|
- });
|
|
|
|
|
|
+ await expectThrow(
|
|
|
|
+ vesting.revoke(this.token.address, { from: owner }),
|
|
|
|
+ EVMRevert,
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
|
|
- it('should keep the vested tokens when revoked by owner', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
|
|
+ it('should return the non-vested tokens when revoked by owner', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
|
|
- const vestedPre = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
+ const vested = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
- await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
|
|
+ await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
|
|
- const vestedPost = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
+ const ownerBalance = await this.token.balanceOf(owner);
|
|
|
|
+ ownerBalance.should.bignumber.eq(amount.sub(vested));
|
|
|
|
+ });
|
|
|
|
|
|
- vestedPre.should.bignumber.eq(vestedPost);
|
|
|
|
- });
|
|
|
|
|
|
+ it('should keep the vested tokens when revoked by owner', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
|
|
- it('should fail to be revoked a second time', async function () {
|
|
|
|
- await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
|
|
+ const vestedPre = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
- await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
+ await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
|
|
- await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
|
|
+ const vestedPost = await this.vesting.vestedAmount(this.token.address);
|
|
|
|
|
|
- await expectThrow(
|
|
|
|
- this.vesting.revoke(this.token.address, { from: owner }),
|
|
|
|
- EVMRevert,
|
|
|
|
- );
|
|
|
|
|
|
+ vestedPre.should.bignumber.eq(vestedPost);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('should fail to be revoked a second time', async function () {
|
|
|
|
+ await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
|
|
|
+
|
|
|
|
+ await this.vesting.vestedAmount(this.token.address);
|
|
|
|
+
|
|
|
|
+ await this.vesting.revoke(this.token.address, { from: owner });
|
|
|
|
+
|
|
|
|
+ await expectThrow(
|
|
|
|
+ this.vesting.revoke(this.token.address, { from: owner }),
|
|
|
|
+ EVMRevert,
|
|
|
|
+ );
|
|
|
|
+ });
|
|
});
|
|
});
|
|
});
|
|
});
|