TokenTimelock.test.js 2.6 KB

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