PausableCrowdsale.test.js 1.5 KB

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