Replace all asserts with chai.should (#1183)

* Moving towards chai.should.

* Fixed failing tests.

* Fixed linter errors.

* Revert package-lock.json changes.

* Fixed failing tests.

* s/eq/equal

* Addressed review comment
This commit is contained in:
Nicolás Venturo
2018-08-10 19:03:04 -03:00
committed by Francisco Giordano
parent a2e7103869
commit ac91af9a6a
41 changed files with 396 additions and 297 deletions

View File

@ -1,32 +1,26 @@
const should = require('chai')
.should();
async function expectThrow (promise, message) {
try {
await promise;
} catch (error) {
// Message is an optional parameter here
if (message) {
assert(
error.message.search(message) >= 0,
'Expected \'' + message + '\', got \'' + error + '\' instead',
);
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.
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',
);
error.message.should.match(/[invalid opcode|out of gas|revert]/, 'Expected throw, got \'' + error + '\' instead');
return;
}
}
assert.fail('Expected throw not received');
should.fail('Expected throw not received');
}
module.exports = {