PausableCrowdsale.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const { BN, shouldFail } = require('openzeppelin-test-helpers');
  2. const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl');
  3. const SimpleToken = artifacts.require('SimpleToken');
  4. contract('PausableCrowdsale', function ([_, pauser, wallet, other]) {
  5. const rate = new BN(1);
  6. const value = new BN(1);
  7. beforeEach(async function () {
  8. const from = pauser;
  9. this.token = await SimpleToken.new({ from });
  10. this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from });
  11. await this.token.transfer(this.crowdsale.address, value.muln(2), { from });
  12. });
  13. it('purchases work', async function () {
  14. await this.crowdsale.sendTransaction({ from: other, value });
  15. await this.crowdsale.buyTokens(other, { from: other, value });
  16. });
  17. context('after pause', function () {
  18. beforeEach(async function () {
  19. await this.crowdsale.pause({ from: pauser });
  20. });
  21. it('purchases do not work', async function () {
  22. await shouldFail.reverting.withMessage(this.crowdsale.sendTransaction({ from: other, value }),
  23. 'Pausable: paused'
  24. );
  25. await shouldFail.reverting.withMessage(this.crowdsale.buyTokens(other, { from: other, value }),
  26. 'Pausable: paused'
  27. );
  28. });
  29. context('after unpause', function () {
  30. beforeEach(async function () {
  31. await this.crowdsale.unpause({ from: pauser });
  32. });
  33. it('purchases work', async function () {
  34. await this.crowdsale.sendTransaction({ from: other, value });
  35. await this.crowdsale.buyTokens(other, { from: other, value });
  36. });
  37. });
  38. });
  39. });