expectThrow.js 882 B

12345678910111213141516171819202122232425
  1. async function expectThrow (promise) {
  2. try {
  3. await promise;
  4. } catch (error) {
  5. // TODO: Check jump destination to destinguish between a throw
  6. // and an actual invalid jump.
  7. const invalidOpcode = error.message.search('invalid opcode') >= 0;
  8. // TODO: When we contract A calls contract B, and B throws, instead
  9. // of an 'invalid jump', we get an 'out of gas' error. How do
  10. // we distinguish this from an actual out of gas event? (The
  11. // ganache log actually show an 'invalid jump' event.)
  12. const outOfGas = error.message.search('out of gas') >= 0;
  13. const revert = error.message.search('revert') >= 0;
  14. assert(
  15. invalidOpcode || outOfGas || revert,
  16. 'Expected throw, got \'' + error + '\' instead',
  17. );
  18. return;
  19. }
  20. assert.fail('Expected throw not received');
  21. }
  22. module.exports = {
  23. expectThrow,
  24. };