TokenVesting.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const BigNumber = web3.BigNumber
  2. require('chai')
  3. .use(require('chai-as-promised'))
  4. .use(require('chai-bignumber')(BigNumber))
  5. .should();
  6. import EVMThrow from './helpers/EVMThrow'
  7. import latestTime from './helpers/latestTime';
  8. import {increaseTimeTo, duration} from './helpers/increaseTime';
  9. const MintableToken = artifacts.require('MintableToken');
  10. const TokenVesting = artifacts.require('TokenVesting');
  11. contract('TokenVesting', function ([_, owner, beneficiary]) {
  12. const amount = new BigNumber(1000);
  13. beforeEach(async function () {
  14. this.token = await MintableToken.new({ from: owner });
  15. this.cliff = latestTime() + duration.years(1);
  16. this.end = latestTime() + duration.years(2);
  17. this.vesting = await TokenVesting.new(beneficiary, this.cliff, this.end, { from: owner });
  18. this.start = latestTime(); // gets the timestamp at construction
  19. await this.token.mint(this.vesting.address, amount, { from: owner });
  20. });
  21. it('cannot be released before cliff', async function () {
  22. await this.vesting.release(this.token.address).should.be.rejectedWith(EVMThrow);
  23. });
  24. it('can be released after cliff', async function () {
  25. await increaseTimeTo(this.cliff + duration.weeks(1));
  26. await this.vesting.release(this.token.address).should.be.fulfilled;
  27. });
  28. it('should release proper amount after cliff', async function () {
  29. await increaseTimeTo(this.cliff);
  30. const { receipt } = await this.vesting.release(this.token.address);
  31. const releaseTime = web3.eth.getBlock(receipt.blockNumber).timestamp;
  32. const balance = await this.token.balanceOf(beneficiary);
  33. balance.should.bignumber.equal(amount.mul(releaseTime - this.start).div(this.end - this.start).floor());
  34. });
  35. it('should have released all after end', async function () {
  36. await increaseTimeTo(this.end);
  37. await this.vesting.release(this.token.address);
  38. const balance = await this.token.balanceOf(beneficiary);
  39. balance.should.bignumber.equal(amount);
  40. });
  41. });