Skip to content

OpenZeppelin Test Helpers v0.4.0

Compare
Choose a tag to compare
@nventuro nventuro released this 27 May 15:52
· 142 commits to master since this release

This release includes a revamped expectRevert helper, configurability for using outside of Truffle, and more!

When we first took these helpers out of openzeppelin-solidity, our main concern was the quality of the API. We had collected these functions over time and they had been written by multiple contributors, so they lacked a cohesive structure, making them sometimes a bit unwieldy. Things are starting to take shape, and with this release we feel one step closer to v1.0! 🌟

Testing revert reasons

We've reworked shouldFail, our module used to test transaction promises that throw an exception. It is now called expectRevert. There are two main reasons behind this change:

  • A minor one: we're leaving behind should style and going for expect. (See openzeppelin-solidity#1678. Help welcome!)
  • We want to encourage developers to use revert reasons in their contracts, and to assert in their tests the precise reason a transaction is expected to fail. Because of this, the default helper expectRevert receives both a promise and a mandatory expected error message. (It's also possible to expect an unspecified revert with expectRevert.unspecified.) We even found some hidden errors in our own tests after we started using this new version.

There's a handy guide in the changelog explaining how to migrate from shouldFail to expectRevert: How to upgrade from v0.3.

Configurability

Some of the helpers need to use a web3.js instance. Until now, this instance was taken from the global variable web3 found in a Truffle testing environment. We've now added to possibility to manually specify an instance, which allows using the helpers in other environments. Check out the instructions in the readme!

Changelog

For a complete list of changes, take a look at the changelog.