Replaced assertJump, assertRevert and expectThrow with shouldFail. (#1363)
* Replaced assertJump, assertRevert and expectThrow with shouldFail. * Fixed linter errors. * Fixed typo. * Made the helpers async.
This commit is contained in:
31
test/helpers/shouldFail.js
Normal file
31
test/helpers/shouldFail.js
Normal file
@ -0,0 +1,31 @@
|
||||
const should = require('chai')
|
||||
.should();
|
||||
|
||||
async function shouldFailWithMessage (promise, message) {
|
||||
try {
|
||||
await promise;
|
||||
} catch (error) {
|
||||
error.message.should.include(message, 'Wrong failure type');
|
||||
return;
|
||||
}
|
||||
|
||||
should.fail(`Expected '${message}' failure not received`);
|
||||
}
|
||||
|
||||
async function reverting (promise) {
|
||||
await shouldFailWithMessage(promise, 'revert');
|
||||
}
|
||||
|
||||
async function throwing (promise) {
|
||||
await shouldFailWithMessage(promise, 'invalid opcode');
|
||||
}
|
||||
|
||||
async function outOfGas (promise) {
|
||||
await shouldFailWithMessage(promise, 'out of gas');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
reverting,
|
||||
throwing,
|
||||
outOfGas,
|
||||
};
|
||||
Reference in New Issue
Block a user