1

I'm using hardhat with mocha and chai to write tests for a contract. I'm trying to write a test that will expect a function call to be successful (not to revert); the function does not emit any events.

Some combinations I expected to work but did not are: not.to.be.reverted, not.to.be.rejected, to.be.ok, to.be.fulfilled.

What is the recommended way to test for success?

1
  • Did you try .to.not.be.reverted
    – Sky
    May 31 at 8:14

1 Answer 1

1

I just tested it:

.to.not.be.reverted

It raises and error if the transaction reverted, and even returns the reason why:

  1) Access Control Test
   Setup organization
     Call functions that use AccessControl from uncertified Account:
 AssertionError: Expected transaction NOT to be reverted, but it was reverted with "VM Exception while processing transaction: reverted with reason string 'AccessControl: account 0x15d34aaf54267db7d7c367839aaf71a00a2c6a65 is missing role 0xd3879079fee113afaf053f6103cde29a976de27944824d68ae5bbbdb9b498e49'"

Your Answer

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

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