shouldFail.js 817 B

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