Pausable.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const { assertRevert } = require('../helpers/assertRevert');
  2. const PausableMock = artifacts.require('PausableMock');
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. contract('Pausable', function () {
  8. beforeEach(async function () {
  9. this.Pausable = await PausableMock.new();
  10. });
  11. it('can perform normal process in non-pause', async function () {
  12. const count0 = await this.Pausable.count();
  13. count0.should.be.bignumber.equal(0);
  14. await this.Pausable.normalProcess();
  15. const count1 = await this.Pausable.count();
  16. count1.should.be.bignumber.equal(1);
  17. });
  18. it('can not perform normal process in pause', async function () {
  19. await this.Pausable.pause();
  20. const count0 = await this.Pausable.count();
  21. count0.should.be.bignumber.equal(0);
  22. await assertRevert(this.Pausable.normalProcess());
  23. const count1 = await this.Pausable.count();
  24. count1.should.be.bignumber.equal(0);
  25. });
  26. it('can not take drastic measure in non-pause', async function () {
  27. await assertRevert(this.Pausable.drasticMeasure());
  28. const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken();
  29. drasticMeasureTaken.should.be.false;
  30. });
  31. it('can take a drastic measure in a pause', async function () {
  32. await this.Pausable.pause();
  33. await this.Pausable.drasticMeasure();
  34. const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken();
  35. drasticMeasureTaken.should.be.true;
  36. });
  37. it('should resume allowing normal process after pause is over', async function () {
  38. await this.Pausable.pause();
  39. await this.Pausable.unpause();
  40. await this.Pausable.normalProcess();
  41. const count0 = await this.Pausable.count();
  42. count0.should.be.bignumber.equal(1);
  43. });
  44. it('should prevent drastic measure after pause is over', async function () {
  45. await this.Pausable.pause();
  46. await this.Pausable.unpause();
  47. await assertRevert(this.Pausable.drasticMeasure());
  48. const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken();
  49. drasticMeasureTaken.should.be.false;
  50. });
  51. });