PausableCrowdsale.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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(this.crowdsale.sendTransaction({ from: other, value }));
  23. await shouldFail.reverting(this.crowdsale.buyTokens(other, { from: other, value }));
  24. });
  25. context('after unpause', function () {
  26. beforeEach(async function () {
  27. await this.crowdsale.unpause({ from: pauser });
  28. });
  29. it('purchases work', async function () {
  30. await this.crowdsale.sendTransaction({ from: other, value });
  31. await this.crowdsale.buyTokens(other, { from: other, value });
  32. });
  33. });
  34. });
  35. });