expectThrow.js 772 B

1234567891011121314151617181920
  1. export default async 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. // testrpc log actually show an 'invalid jump' event.)
  12. const outOfGas = error.message.search('out of gas') >= 0;
  13. assert(
  14. invalidOpcode || outOfGas,
  15. "Expected throw, got '" + error + "' instead",
  16. );
  17. return;
  18. }
  19. assert.fail('Expected throw not received');
  20. };