FinalizableCrowdsale.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import moment from 'moment'
  2. import advanceToBlock from './helpers/advanceToBlock'
  3. import increaseTime from './helpers/increaseTime'
  4. import latestTime from './helpers/latestTime'
  5. import EVMThrow from './helpers/EVMThrow'
  6. const BigNumber = web3.BigNumber
  7. const should = require('chai')
  8. .use(require('chai-as-promised'))
  9. .use(require('chai-bignumber')(BigNumber))
  10. .should()
  11. const FinalizableCrowdsale = artifacts.require('./helpers/FinalizableCrowdsaleImpl.sol')
  12. const MintableToken = artifacts.require('MintableToken')
  13. contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
  14. const rate = new BigNumber(1000)
  15. before(async function() {
  16. //Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
  17. await advanceToBlock(web3.eth.getBlock('latest').number + 1)
  18. })
  19. beforeEach(async function () {
  20. this.startTime = latestTime().unix() + moment.duration(1, 'week').asSeconds();
  21. this.endTime = latestTime().unix() + moment.duration(2, 'week').asSeconds();
  22. this.crowdsale = await FinalizableCrowdsale.new(this.startTime, this.endTime, rate, wallet, {from: owner})
  23. this.token = MintableToken.at(await this.crowdsale.token())
  24. })
  25. it('cannot be finalized before ending', async function () {
  26. await this.crowdsale.finalize({from: owner}).should.be.rejectedWith(EVMThrow)
  27. })
  28. it('cannot be finalized by third party after ending', async function () {
  29. await increaseTime(moment.duration(2.1, 'week'))
  30. await this.crowdsale.finalize({from: thirdparty}).should.be.rejectedWith(EVMThrow)
  31. })
  32. it('can be finalized by owner after ending', async function () {
  33. await increaseTime(moment.duration(2.1, 'week'))
  34. await this.crowdsale.finalize({from: owner}).should.be.fulfilled
  35. })
  36. it('cannot be finalized twice', async function () {
  37. await increaseTime(moment.duration(2.1, 'week'))
  38. await this.crowdsale.finalize({from: owner})
  39. await this.crowdsale.finalize({from: owner}).should.be.rejectedWith(EVMThrow)
  40. })
  41. it('logs finalized', async function () {
  42. await increaseTime(moment.duration(2.1, 'week'))
  43. const {logs} = await this.crowdsale.finalize({from: owner})
  44. const event = logs.find(e => e.event === 'Finalized')
  45. should.exist(event)
  46. })
  47. it('finishes minting of token', async function () {
  48. await increaseTime(moment.duration(2.1, 'week'))
  49. await this.crowdsale.finalize({from: owner})
  50. const finished = await this.token.mintingFinished()
  51. finished.should.equal(true)
  52. })
  53. })