TokenTimelock.test.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import latestTime from './helpers/latestTime';
  2. import { increaseTimeTo, duration } from './helpers/increaseTime';
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-as-promised'))
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. const MintableToken = artifacts.require('MintableToken');
  9. const TokenTimelock = artifacts.require('TokenTimelock');
  10. contract('TokenTimelock', function ([_, owner, beneficiary]) {
  11. const amount = new BigNumber(100);
  12. beforeEach(async function () {
  13. this.token = await MintableToken.new({ from: owner });
  14. this.releaseTime = latestTime() + duration.years(1);
  15. this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime);
  16. await this.token.mint(this.timelock.address, amount, { from: owner });
  17. });
  18. it('cannot be released before time limit', async function () {
  19. await this.timelock.release().should.be.rejected;
  20. });
  21. it('cannot be released just before time limit', async function () {
  22. await increaseTimeTo(this.releaseTime - duration.seconds(3));
  23. await this.timelock.release().should.be.rejected;
  24. });
  25. it('can be released just after limit', async function () {
  26. await increaseTimeTo(this.releaseTime + duration.seconds(1));
  27. await this.timelock.release().should.be.fulfilled;
  28. const balance = await this.token.balanceOf(beneficiary);
  29. balance.should.be.bignumber.equal(amount);
  30. });
  31. it('can be released after time limit', async function () {
  32. await increaseTimeTo(this.releaseTime + duration.years(1));
  33. await this.timelock.release().should.be.fulfilled;
  34. const balance = await this.token.balanceOf(beneficiary);
  35. balance.should.be.bignumber.equal(amount);
  36. });
  37. it('cannot be released twice', async function () {
  38. await increaseTimeTo(this.releaseTime + duration.years(1));
  39. await this.timelock.release().should.be.fulfilled;
  40. await this.timelock.release().should.be.rejected;
  41. const balance = await this.token.balanceOf(beneficiary);
  42. balance.should.be.bignumber.equal(amount);
  43. });
  44. });