shouldFail.js 635 B

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