Pausable.test.js 2.2 KB

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