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

shouldFail.reverting.withMessage fails if no error string is provided #28

Merged
merged 2 commits into from Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

## 0.4.0 (unreleased)
* Fix `shouldFail.reverting.withMessage` on non-Ganache chains. ([#25](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/25)
* `shouldFail.reverting.withMessage` fails if no error string is provided. ([#28](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/28)

## 0.3.2 (2019-04-10)
* Update ERC1820Registry address. ([#26](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/26))
Expand Down
13 changes: 10 additions & 3 deletions src/shouldFail.js
Expand Up @@ -8,6 +8,8 @@ async function shouldFailWithMessage (promise, message) {
} catch (error) {
if (message) {
expect(error.message).to.include(message, `Wrong failure type, expected '${message}'`);
} else {
expect.fail('Message not provided');
}
return;
}
Expand All @@ -28,7 +30,12 @@ async function outOfGas (promise) {
}

async function shouldFail (promise) {
await shouldFailWithMessage(promise);
try {
await promise;
} catch (error) {
return;
}
expect.fail('Failure not received');
}

async function withMessage (promise, message) {
Expand All @@ -43,11 +50,11 @@ shouldFail.reverting.withMessage: ` + msg);
if (matches === null || !(1 in matches)) {
// warn users and skip reason check.
warn('revert reason checking only supported on Ganache>=2.2.0');
return shouldFailWithMessage(promise);
return shouldFail(promise);
} else if (!semver.satisfies(matches[1], '>=2.2.0')) {
// warn users and skip reason check.
warn(`current version of Ganache (${matches[1]}) doesn't return revert reason.`);
return shouldFailWithMessage(promise);
return shouldFail(promise);
} else {
// actually perform revert reason check.
return shouldFailWithMessage(promise, message);
Expand Down
4 changes: 4 additions & 0 deletions test/src/shouldFail.test.js
Expand Up @@ -73,6 +73,10 @@ describe('shouldFail', function () {
await assertFailure(shouldFail.reverting.withMessage(this.failer.failWithRevertReason(), 'Wrong reason'));
});

it('rejects if no reason string passed', async function () {
await assertFailure(shouldFail.reverting.withMessage(this.failer.failWithRevertReason()));
});

it('accepts require() revert with an expected reason', async function () {
await shouldFail.reverting.withMessage(this.failer.failRequirementWithReason(), 'Unsatisfied');
});
Expand Down