Skip to content

Commit

Permalink
use AssertionError instead assert.fail, add message confirmation to a…
Browse files Browse the repository at this point in the history
…ssertFailure
  • Loading branch information
dotrungkien committed Jun 28, 2019
1 parent d431f14 commit 59aee75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/expectRevert.js
Expand Up @@ -2,15 +2,19 @@ const { web3 } = require('./setup');

const colors = require('ansi-colors');
const semver = require('semver');
const assert = require('assert');
const AssertionError = require('assert').AssertionError;

async function expectException (promise, expectedError) {
try {
await promise;
} catch (error) {
if (error.message.indexOf(expectedError) === -1) {
const actualError = error.message.replace('Returned error: VM Exception while processing transaction: ', '');
assert.fail(`Wrong failure type, expected '${expectedError}' and got '${actualError}'`);
throw new AssertionError({
message: 'Wrong failure type',
expected: expectedError,
actual: actualError
});
}
return;
}
Expand Down
4 changes: 4 additions & 0 deletions test/helpers/assertFailure.js
@@ -1,9 +1,13 @@
const { expect } = require('chai');
const AssertionError = require('assert').AssertionError;

async function assertFailure (promise) {
try {
await promise;
} catch (error) {
if (error instanceof AssertionError) {
expect(error.message).to.equal('Wrong failure type');
}
return;
}
expect.fail();
Expand Down

0 comments on commit 59aee75

Please sign in to comment.