Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve expectRevert output #59

Merged
merged 5 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/expectRevert.js
Expand Up @@ -2,13 +2,19 @@ const { web3 } = require('./setup');

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

async function expectException (promise, expectedError) {
try {
await promise;
} catch (error) {
if (error.message.indexOf(expectedError) === -1) {
throw Error(`Wrong failure type, expected '${expectedError}' and got '${error.message}'`);
const actualError = error.message.replace('Returned error: VM Exception while processing transaction: ', '');
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');
frangio marked this conversation as resolved.
Show resolved Hide resolved
}
return;
}
expect.fail();
Expand Down