You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
970 B
28 lines
970 B
const should = require('chai')
|
|
.should();
|
|
|
|
async function expectThrow (promise, message) {
|
|
try {
|
|
await promise;
|
|
} catch (error) {
|
|
// Message is an optional parameter here
|
|
if (message) {
|
|
error.message.should.include(message, 'Expected \'' + message + '\', got \'' + error + '\' instead');
|
|
return;
|
|
} else {
|
|
// TODO: Check jump destination to destinguish between a throw
|
|
// and an actual invalid jump.
|
|
// TODO: When we contract A calls contract B, and B throws, instead
|
|
// of an 'invalid jump', we get an 'out of gas' error. How do
|
|
// we distinguish this from an actual out of gas event? (The
|
|
// ganache log actually show an 'invalid jump' event.)
|
|
error.message.should.match(/[invalid opcode|out of gas|revert]/, 'Expected throw, got \'' + error + '\' instead');
|
|
return;
|
|
}
|
|
}
|
|
should.fail('Expected throw not received');
|
|
}
|
|
|
|
module.exports = {
|
|
expectThrow,
|
|
};
|
|
|