mirror of openzeppelin-contracts
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.
openzeppelin-contracts/test/helpers/shouldFail.js

32 lines
635 B

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,
};