FinalizableCrowdsale.test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { advanceBlock } from './helpers/advanceToBlock';
  2. import { increaseTimeTo, duration } from './helpers/increaseTime';
  3. import latestTime from './helpers/latestTime';
  4. import EVMRevert from './helpers/EVMRevert';
  5. const BigNumber = web3.BigNumber;
  6. const should = require('chai')
  7. .use(require('chai-as-promised'))
  8. .use(require('chai-bignumber')(BigNumber))
  9. .should();
  10. const FinalizableCrowdsale = artifacts.require('mocks/FinalizableCrowdsaleImpl.sol');
  11. const MintableToken = artifacts.require('MintableToken');
  12. contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
  13. const rate = new BigNumber(1000);
  14. before(async function () {
  15. // Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
  16. await advanceBlock();
  17. });
  18. beforeEach(async function () {
  19. this.startTime = latestTime() + duration.weeks(1);
  20. this.endTime = this.startTime + duration.weeks(1);
  21. this.afterEndTime = this.endTime + duration.seconds(1);
  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(EVMRevert);
  27. });
  28. it('cannot be finalized by third party after ending', async function () {
  29. await increaseTimeTo(this.afterEndTime);
  30. await this.crowdsale.finalize({ from: thirdparty }).should.be.rejectedWith(EVMRevert);
  31. });
  32. it('can be finalized by owner after ending', async function () {
  33. await increaseTimeTo(this.afterEndTime);
  34. await this.crowdsale.finalize({ from: owner }).should.be.fulfilled;
  35. });
  36. it('cannot be finalized twice', async function () {
  37. await increaseTimeTo(this.afterEndTime);
  38. await this.crowdsale.finalize({ from: owner });
  39. await this.crowdsale.finalize({ from: owner }).should.be.rejectedWith(EVMRevert);
  40. });
  41. it('logs finalized', async function () {
  42. await increaseTimeTo(this.afterEndTime);
  43. const { logs } = await this.crowdsale.finalize({ from: owner });
  44. const event = logs.find(e => e.event === 'Finalized');
  45. should.exist(event);
  46. });
  47. });