Files
openzeppelin-contracts/test/helpers/shouldFail.js
Nicolás Venturo f0e12d5301 ether and shouldFail tests (#1513)
* Added ether tests.

* Added shouldFail base function and tests.

* Updated test descriptions.

* Reduced gas limit on out-of-gas tests.
2018-11-27 17:20:21 -03:00

38 lines
822 B
JavaScript

const should = require('chai')
.should();
async function shouldFailWithMessage (promise, message) {
try {
await promise;
} catch (error) {
if (message) {
error.message.should.include(message, `Wrong failure type, expected '${message}'`);
}
return;
}
should.fail('Expected 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');
}
async function shouldFail (promise) {
await shouldFailWithMessage(promise);
}
shouldFail.reverting = reverting;
shouldFail.throwing = throwing;
shouldFail.outOfGas = outOfGas;
module.exports = shouldFail;