|
|
|
@ -19,12 +19,11 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { |
|
|
|
|
beforeEach(async function () { |
|
|
|
|
this.token = await MintableToken.new({ from: owner }); |
|
|
|
|
|
|
|
|
|
this.cliff = latestTime() + duration.years(1); |
|
|
|
|
this.end = latestTime() + duration.years(2); |
|
|
|
|
this.start = latestTime() + duration.minutes(1); // +1 minute so it starts after contract instantiation
|
|
|
|
|
this.cliff = duration.years(1); |
|
|
|
|
this.duration = duration.years(2); |
|
|
|
|
|
|
|
|
|
this.vesting = await TokenVesting.new(beneficiary, this.cliff, this.end, true, { from: owner }); |
|
|
|
|
|
|
|
|
|
this.start = latestTime(); // gets the timestamp at construction
|
|
|
|
|
this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner }); |
|
|
|
|
|
|
|
|
|
await this.token.mint(this.vesting.address, amount, { from: owner }); |
|
|
|
|
}); |
|
|
|
@ -34,55 +33,55 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('can be released after cliff', async function () { |
|
|
|
|
await increaseTimeTo(this.cliff + duration.weeks(1)); |
|
|
|
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(1)); |
|
|
|
|
await this.vesting.release(this.token.address).should.be.fulfilled; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should release proper amount after cliff', async function () { |
|
|
|
|
await increaseTimeTo(this.cliff); |
|
|
|
|
await increaseTimeTo(this.start + this.cliff); |
|
|
|
|
|
|
|
|
|
const { receipt } = await this.vesting.release(this.token.address); |
|
|
|
|
const releaseTime = web3.eth.getBlock(receipt.blockNumber).timestamp; |
|
|
|
|
|
|
|
|
|
const balance = await this.token.balanceOf(beneficiary); |
|
|
|
|
balance.should.bignumber.equal(amount.mul(releaseTime - this.start).div(this.end - this.start).floor()); |
|
|
|
|
balance.should.bignumber.equal(amount.mul(releaseTime - this.start).div(this.duration).floor()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should linearly release tokens during vesting period', async function () { |
|
|
|
|
const duration = this.end - this.cliff; |
|
|
|
|
const vestingPeriod = this.duration - this.cliff; |
|
|
|
|
const checkpoints = 4; |
|
|
|
|
|
|
|
|
|
for (let i = 1; i <= checkpoints; i++) { |
|
|
|
|
const now = this.cliff + i * (duration / checkpoints); |
|
|
|
|
const now = this.start + this.cliff + i * (vestingPeriod / checkpoints); |
|
|
|
|
await increaseTimeTo(now); |
|
|
|
|
|
|
|
|
|
await this.vesting.release(this.token.address); |
|
|
|
|
const balance = await this.token.balanceOf(beneficiary); |
|
|
|
|
const expectedVesting = amount.mul(now - this.start).div(this.end - this.start).floor(); |
|
|
|
|
const expectedVesting = amount.mul(now - this.start).div(this.duration).floor(); |
|
|
|
|
|
|
|
|
|
balance.should.bignumber.equal(expectedVesting); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should have released all after end', async function () { |
|
|
|
|
await increaseTimeTo(this.end); |
|
|
|
|
await increaseTimeTo(this.start + this.duration); |
|
|
|
|
await this.vesting.release(this.token.address); |
|
|
|
|
const balance = await this.token.balanceOf(beneficiary); |
|
|
|
|
balance.should.bignumber.equal(amount); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should be revoked by owner if revocable is set', async function () { |
|
|
|
|
const vesting = await TokenVesting.new(beneficiary, this.cliff, this.end, true, { from: owner } ); |
|
|
|
|
const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner } ); |
|
|
|
|
await vesting.revoke(this.token.address, { from: owner }).should.be.fulfilled; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should fail to be revoked by owner if revocable not set', async function () { |
|
|
|
|
const vesting = await TokenVesting.new(beneficiary, this.cliff, this.end, false, { from: owner } ); |
|
|
|
|
const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, false, { from: owner } ); |
|
|
|
|
await vesting.revoke(this.token.address, { from: owner }).should.be.rejectedWith(EVMThrow); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should return the non-vested tokens when revoked by owner', async function () { |
|
|
|
|
await increaseTimeTo(this.cliff + duration.weeks(1)); |
|
|
|
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(1)); |
|
|
|
|
await this.vesting.release(this.token.address); |
|
|
|
|
|
|
|
|
|
const vested = await this.vesting.vestedAmount(this.token.address); |
|
|
|
@ -95,7 +94,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should keep the vested tokens when revoked by owner', async function () { |
|
|
|
|
await increaseTimeTo(this.cliff + duration.weeks(1)); |
|
|
|
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(1)); |
|
|
|
|
await this.vesting.release(this.token.address); |
|
|
|
|
|
|
|
|
|
const vested = await this.vesting.vestedAmount(this.token.address); |
|
|
|
|