FinalizableCrowdsale.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import advanceToBlock from './helpers/advanceToBlock'
  2. import EVMThrow from './helpers/EVMThrow'
  3. const BigNumber = web3.BigNumber
  4. const should = require('chai')
  5. .use(require('chai-as-promised'))
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should()
  8. const FinalizableCrowdsale = artifacts.require('./helpers/FinalizableCrowdsaleImpl.sol')
  9. const MintableToken = artifacts.require('MintableToken')
  10. contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
  11. const rate = new BigNumber(1000)
  12. beforeEach(async function () {
  13. this.startBlock = web3.eth.blockNumber + 10
  14. this.endBlock = web3.eth.blockNumber + 20
  15. this.crowdsale = await FinalizableCrowdsale.new(this.startBlock, this.endBlock, rate, wallet, {from: owner})
  16. this.token = MintableToken.at(await this.crowdsale.token())
  17. })
  18. it('cannot be finalized before ending', async function () {
  19. await this.crowdsale.finalize({from: owner}).should.be.rejectedWith(EVMThrow)
  20. })
  21. it('cannot be finalized by third party after ending', async function () {
  22. await advanceToBlock(this.endBlock)
  23. await this.crowdsale.finalize({from: thirdparty}).should.be.rejectedWith(EVMThrow)
  24. })
  25. it('can be finalized by owner after ending', async function () {
  26. await advanceToBlock(this.endBlock)
  27. await this.crowdsale.finalize({from: owner}).should.be.fulfilled
  28. })
  29. it('cannot be finalized twice', async function () {
  30. await advanceToBlock(this.endBlock + 1)
  31. await this.crowdsale.finalize({from: owner})
  32. await this.crowdsale.finalize({from: owner}).should.be.rejectedWith(EVMThrow)
  33. })
  34. it('logs finalized', async function () {
  35. await advanceToBlock(this.endBlock)
  36. const {logs} = await this.crowdsale.finalize({from: owner})
  37. const event = logs.find(e => e.event === 'Finalized')
  38. should.exist(event)
  39. })
  40. it('finishes minting of token', async function () {
  41. await advanceToBlock(this.endBlock)
  42. await this.crowdsale.finalize({from: owner})
  43. const finished = await this.token.mintingFinished()
  44. finished.should.equal(true)
  45. })
  46. })