FinalizableCrowdsale.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const expectEvent = require('../helpers/expectEvent');
  2. const time = require('../helpers/time');
  3. const shouldFail = require('../helpers/shouldFail');
  4. const { BigNumber } = require('../helpers/setup');
  5. const FinalizableCrowdsaleImpl = artifacts.require('FinalizableCrowdsaleImpl');
  6. const ERC20 = artifacts.require('ERC20');
  7. contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
  8. const rate = new BigNumber(1000);
  9. before(async function () {
  10. // Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
  11. await time.advanceBlock();
  12. });
  13. beforeEach(async function () {
  14. this.openingTime = (await time.latest()) + time.duration.weeks(1);
  15. this.closingTime = this.openingTime + time.duration.weeks(1);
  16. this.afterClosingTime = this.closingTime + time.duration.seconds(1);
  17. this.token = await ERC20.new();
  18. this.crowdsale = await FinalizableCrowdsaleImpl.new(
  19. this.openingTime, this.closingTime, rate, wallet, this.token.address
  20. );
  21. });
  22. it('cannot be finalized before ending', async function () {
  23. await shouldFail.reverting(this.crowdsale.finalize({ from: anyone }));
  24. });
  25. it('can be finalized by anyone after ending', async function () {
  26. await time.increaseTo(this.afterClosingTime);
  27. await this.crowdsale.finalize({ from: anyone });
  28. });
  29. it('cannot be finalized twice', async function () {
  30. await time.increaseTo(this.afterClosingTime);
  31. await this.crowdsale.finalize({ from: anyone });
  32. await shouldFail.reverting(this.crowdsale.finalize({ from: anyone }));
  33. });
  34. it('logs finalized', async function () {
  35. await time.increaseTo(this.afterClosingTime);
  36. const { logs } = await this.crowdsale.finalize({ from: anyone });
  37. expectEvent.inLogs(logs, 'CrowdsaleFinalized');
  38. });
  39. });