TokenTimelock.test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const { latestTime } = require('../../helpers/latestTime');
  2. const { increaseTimeTo, duration } = require('../../helpers/increaseTime');
  3. const { expectThrow } = require('../../helpers/expectThrow');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. const ERC20Mintable = artifacts.require('ERC20Mintable');
  9. const TokenTimelock = artifacts.require('TokenTimelock');
  10. contract('TokenTimelock', function ([_, owner, beneficiary]) {
  11. const amount = new BigNumber(100);
  12. context('with token', function () {
  13. beforeEach(async function () {
  14. this.token = await ERC20Mintable.new({ from: owner });
  15. });
  16. it('rejects a release time in the past', async function () {
  17. const pastReleaseTime = (await latestTime()) - duration.years(1);
  18. await expectThrow(
  19. TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime)
  20. );
  21. });
  22. context('once deployed', function () {
  23. beforeEach(async function () {
  24. this.releaseTime = (await latestTime()) + duration.years(1);
  25. this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime);
  26. await this.token.mint(this.timelock.address, amount, { from: owner });
  27. });
  28. it('cannot be released before time limit', async function () {
  29. await expectThrow(this.timelock.release());
  30. });
  31. it('cannot be released just before time limit', async function () {
  32. await increaseTimeTo(this.releaseTime - duration.seconds(3));
  33. await expectThrow(this.timelock.release());
  34. });
  35. it('can be released just after limit', async function () {
  36. await increaseTimeTo(this.releaseTime + duration.seconds(1));
  37. await this.timelock.release();
  38. (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
  39. });
  40. it('can be released after time limit', async function () {
  41. await increaseTimeTo(this.releaseTime + duration.years(1));
  42. await this.timelock.release();
  43. (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
  44. });
  45. it('cannot be released twice', async function () {
  46. await increaseTimeTo(this.releaseTime + duration.years(1));
  47. await this.timelock.release();
  48. await expectThrow(this.timelock.release());
  49. (await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
  50. });
  51. });
  52. });
  53. });