Pausable.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. (await this.Pausable.count()).should.be.bignumber.equal(0);
  13. await this.Pausable.normalProcess();
  14. (await this.Pausable.count()).should.be.bignumber.equal(1);
  15. });
  16. it('can not perform normal process in pause', async function () {
  17. await this.Pausable.pause();
  18. (await this.Pausable.count()).should.be.bignumber.equal(0);
  19. await assertRevert(this.Pausable.normalProcess());
  20. (await this.Pausable.count()).should.be.bignumber.equal(0);
  21. });
  22. it('can not take drastic measure in non-pause', async function () {
  23. await assertRevert(this.Pausable.drasticMeasure());
  24. (await this.Pausable.drasticMeasureTaken()).should.equal(false);
  25. });
  26. it('can take a drastic measure in a pause', async function () {
  27. await this.Pausable.pause();
  28. await this.Pausable.drasticMeasure();
  29. (await this.Pausable.drasticMeasureTaken()).should.equal(true);
  30. });
  31. it('should resume allowing normal process after pause is over', async function () {
  32. await this.Pausable.pause();
  33. await this.Pausable.unpause();
  34. await this.Pausable.normalProcess();
  35. (await this.Pausable.count()).should.be.bignumber.equal(1);
  36. });
  37. it('should prevent drastic measure after pause is over', async function () {
  38. await this.Pausable.pause();
  39. await this.Pausable.unpause();
  40. await assertRevert(this.Pausable.drasticMeasure());
  41. (await this.Pausable.drasticMeasureTaken()).should.equal(false);
  42. });
  43. });