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

Fix shouldFail.reverting.withMessage on non-Ganache #25

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
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

## 0.4.0 (unreleased)
* Fix `shouldFail.reverting.withMessage` on non-Ganache chains. ([#25](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/25)

## 0.3.1 (2019-04-01)
* Add support for environments using `web3-provider-engine`. ([#24](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/24))

Expand Down
18 changes: 13 additions & 5 deletions src/shouldFail.js
Expand Up @@ -36,13 +36,21 @@ async function withMessage (promise, message) {
// https://github.com/trufflesuite/ganache-core/releases/tag/v2.2.0
const nodeInfo = await web3.eth.getNodeInfo();
const matches = /TestRPC\/v([0-9.]+)\/ethereum-js/.exec(nodeInfo);
if (1 in matches && semver.satisfies(matches[1], '>=2.2.0')) {
return shouldFailWithMessage(promise, message);
} else {
// Otherwise, warn users and skip reason check.
const warn = function (msg) {
console.log(`${colors.white.bgBlack('openzeppelin-test-helpers')} ${colors.black.bgYellow('WARN')} \
shouldFail.reverting.withMessage: current version of Ganache (${matches[1]}) doesn't return revert reason.`);
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);
} 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);
} else {
// actually perform revert reason check.
return shouldFailWithMessage(promise, message);
}
}

Expand Down