Skip to content

Commit

Permalink
shouldFail.reverting.withMessage fails if no error string is provided (
Browse files Browse the repository at this point in the history
…#28)

* fixes #27

* changelog
  • Loading branch information
Aniket-Engg authored and nventuro committed Apr 24, 2019
1 parent 27ca0bf commit 8a2de42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 8a2de42

Please sign in to comment.