shouldFail.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const shouldFail = require('../shouldFail');
  2. const BigNumber = web3.BigNumber;
  3. const should = require('chai')
  4. .use(require('chai-bignumber')(BigNumber))
  5. .should();
  6. const Failer = artifacts.require('Failer');
  7. async function assertFailure (promise) {
  8. try {
  9. await promise;
  10. } catch (error) {
  11. return;
  12. }
  13. should.fail();
  14. }
  15. describe('shouldFail', function () {
  16. beforeEach(async function () {
  17. this.failer = await Failer.new();
  18. });
  19. describe('shouldFail', function () {
  20. it('rejects if no failure occurs', async function () {
  21. await assertFailure(shouldFail(this.failer.dontFail()));
  22. });
  23. it('accepts a revert', async function () {
  24. await shouldFail(this.failer.failWithRevert());
  25. });
  26. it('accepts a throw', async function () {
  27. await shouldFail(this.failer.failWithThrow());
  28. });
  29. it('accepts an out of gas', async function () {
  30. await shouldFail(this.failer.failWithOutOfGas({ gas: 2000000 }));
  31. });
  32. });
  33. describe('reverting', function () {
  34. it('rejects if no failure occurs', async function () {
  35. await assertFailure(shouldFail.reverting(this.failer.dontFail()));
  36. });
  37. it('accepts a revert', async function () {
  38. await shouldFail.reverting(this.failer.failWithRevert());
  39. });
  40. it('rejects a throw', async function () {
  41. await assertFailure(shouldFail.reverting(this.failer.failWithThrow()));
  42. });
  43. it('rejects an outOfGas', async function () {
  44. await assertFailure(shouldFail.reverting(this.failer.failWithOutOfGas({ gas: 2000000 })));
  45. });
  46. });
  47. describe('throwing', function () {
  48. it('rejects if no failure occurs', async function () {
  49. await assertFailure(shouldFail.throwing(this.failer.dontFail()));
  50. });
  51. it('accepts a throw', async function () {
  52. await shouldFail.throwing(this.failer.failWithThrow());
  53. });
  54. it('rejects a throw', async function () {
  55. await assertFailure(shouldFail.throwing(this.failer.failWithRevert()));
  56. });
  57. it('rejects an outOfGas', async function () {
  58. await assertFailure(shouldFail.throwing(this.failer.failWithOutOfGas({ gas: 2000000 })));
  59. });
  60. });
  61. describe('outOfGas', function () {
  62. it('rejects if no failure occurs', async function () {
  63. await assertFailure(shouldFail.outOfGas(this.failer.dontFail()));
  64. });
  65. it('accepts an out of gas', async function () {
  66. await shouldFail.outOfGas(this.failer.failWithOutOfGas({ gas: 2000000 }));
  67. });
  68. it('rejects a revert', async function () {
  69. await assertFailure(shouldFail.outOfGas(this.failer.failWithRevert()));
  70. });
  71. it('rejects a throw', async function () {
  72. await assertFailure(shouldFail.outOfGas(this.failer.failWithThrow()));
  73. });
  74. });
  75. });