Remove chai-as-promised (#1116)
* Test: Remove chai-as-promised calls * Test/Helpers: expectThrow accepts optional message * NPM: Remove chai-as-promised * Contracts/DestructibleMock: Fix lint
This commit is contained in:
committed by
Nicolás Venturo
parent
afe9113b18
commit
e6c15b34da
@ -1,21 +1,30 @@
|
||||
async function expectThrow (promise) {
|
||||
async function expectThrow (promise, message) {
|
||||
try {
|
||||
await promise;
|
||||
} catch (error) {
|
||||
// TODO: Check jump destination to destinguish between a throw
|
||||
// and an actual invalid jump.
|
||||
const invalidOpcode = error.message.search('invalid opcode') >= 0;
|
||||
// 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.)
|
||||
const outOfGas = error.message.search('out of gas') >= 0;
|
||||
const revert = error.message.search('revert') >= 0;
|
||||
assert(
|
||||
invalidOpcode || outOfGas || revert,
|
||||
'Expected throw, got \'' + error + '\' instead',
|
||||
);
|
||||
return;
|
||||
// Message is an optional parameter here
|
||||
if (message) {
|
||||
assert(
|
||||
error.message.search(message) >= 0,
|
||||
'Expected \'' + message + '\', got \'' + error + '\' instead',
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
// TODO: Check jump destination to destinguish between a throw
|
||||
// and an actual invalid jump.
|
||||
const invalidOpcode = error.message.search('invalid opcode') >= 0;
|
||||
// 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.)
|
||||
const outOfGas = error.message.search('out of gas') >= 0;
|
||||
const revert = error.message.search('revert') >= 0;
|
||||
assert(
|
||||
invalidOpcode || outOfGas || revert,
|
||||
'Expected throw, got \'' + error + '\' instead',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert.fail('Expected throw not received');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user