0

For example, testing for a transaction that reverted or an out of gas error etc.

What is the best practice for writing such tests? Specifically, I am using truffle test framework (mocha/chai).

7
  • You might find this answer useful (disclosure: I wrote it). Commented Sep 7, 2020 at 21:35
  • Actually I did come across that. However I was hoping that something more robust existed in the form of a library that has been vetted and tested by a significant amount of the community. Copying and pasting code like this seems a bit risky even if only for a tiny nuanced error; When money is at stake then it has to be near-perfect. I guess I'll use this if nothing else exists though. Commented Sep 7, 2020 at 21:39
  • 1
    Waffle has Chai matchers for events, reverts, etc. You can use it in conjunction with Truflfe.
    – Morten
    Commented Sep 7, 2020 at 21:44
  • @Morten This is great thanks! Why not post it as an answer? Commented Sep 7, 2020 at 21:48
  • Risky? That argument is relevant when dealing with on-chain code (Solidity), not off-chain code. Commented Sep 8, 2020 at 6:27

1 Answer 1

2

You can use Waffle's built-in Chai matchers to test for events, reverts, etc. It works with Truffle and Mocha out of the box, and supports any network provider with history support (like Ganache, BuidlerVM). You can find documentation here:

There are also experimental Jest matchers if you're looking to use Jest instead of Mocha and Chai.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.