shouldFail.js 822 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const should = require('chai')
  2. .should();
  3. async function shouldFailWithMessage (promise, message) {
  4. try {
  5. await promise;
  6. } catch (error) {
  7. if (message) {
  8. error.message.should.include(message, `Wrong failure type, expected '${message}'`);
  9. }
  10. return;
  11. }
  12. should.fail('Expected failure not received');
  13. }
  14. async function reverting (promise) {
  15. await shouldFailWithMessage(promise, 'revert');
  16. }
  17. async function throwing (promise) {
  18. await shouldFailWithMessage(promise, 'invalid opcode');
  19. }
  20. async function outOfGas (promise) {
  21. await shouldFailWithMessage(promise, 'out of gas');
  22. }
  23. async function shouldFail (promise) {
  24. await shouldFailWithMessage(promise);
  25. }
  26. shouldFail.reverting = reverting;
  27. shouldFail.throwing = throwing;
  28. shouldFail.outOfGas = outOfGas;
  29. module.exports = shouldFail;