FinalizableCrowdsale.test.js 1.7 KB

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