PausableCrowdsale.test.js 1.6 KB

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