TokenTimelock.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 moment from 'moment'
  7. import latestTime from './helpers/latestTime'
  8. import increaseTime from './helpers/increaseTime'
  9. const MintableToken = artifacts.require('MintableToken')
  10. const TokenTimelock = artifacts.require('TokenTimelock')
  11. contract('TokenTimelock', function ([_, owner, beneficiary]) {
  12. const amount = new BigNumber(100)
  13. beforeEach(async function () {
  14. this.token = await MintableToken.new({from: owner})
  15. this.releaseTime = latestTime().add(1, 'year').unix()
  16. this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime)
  17. await this.token.mint(this.timelock.address, amount, {from: owner})
  18. })
  19. it('cannot be released before time limit', async function () {
  20. await this.timelock.release().should.be.rejected
  21. })
  22. it('cannot be released just before time limit', async function () {
  23. await increaseTime(moment.duration(0.99, 'year'))
  24. await this.timelock.release().should.be.rejected
  25. })
  26. it('can be released just after limit', async function () {
  27. await increaseTime(moment.duration(1.01, 'year'))
  28. await this.timelock.release().should.be.fulfilled
  29. const balance = await this.token.balanceOf(beneficiary)
  30. balance.should.be.bignumber.equal(amount)
  31. })
  32. it('can be released after time limit', async function () {
  33. await increaseTime(moment.duration(2, 'year'))
  34. await this.timelock.release().should.be.fulfilled
  35. const balance = await this.token.balanceOf(beneficiary)
  36. balance.should.be.bignumber.equal(amount)
  37. })
  38. it('cannot be released twice', async function () {
  39. await increaseTime(moment.duration(2, 'year'))
  40. await this.timelock.release().should.be.fulfilled
  41. await this.timelock.release().should.be.rejected
  42. const balance = await this.token.balanceOf(beneficiary)
  43. balance.should.be.bignumber.equal(amount)
  44. })
  45. })