FinalizableCrowdsale.test.js 1.8 KB

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