Wrong Failure Type When Expecting Revert using openzeppelin-test-helpers

I have a function that accepts a string of data as an argument and a corresponding unit test that uses shouldFail in the event the string argument is missing when the function is called:

await shouldFail(contractInstance.functionName({from: wallet1, value: donation}))

This unit test works correctly. However, when I test manually on Ropsten the transaction does not fail, but instead is successful.

Consequently, I’ve tried to introduce a require statement in the function to cause a revert if the string argument is missing:

require(bytes(_stringArgument).length > 0);

And I change the unit test to await shouldFail.reverting(contractInstance.functionName({from: wallet1, value: donation}))

Now when I run the test I get the following error: AssertionError: Wrong failure type, expected 'revert': expected 'invalid string value (arg="_encryptedData", coderType="string"

Any thoughts on the best way to cause a revert if the string argument is missing when the function is called?

Thanks in advance!! :slight_smile:

1 Like

The assertion error most likely indicates that a revert message was expected (“invalid string value…”) but was not given in the require-/revert-statement.

However, if you would post your code it would help us more to help you in your actual case :slight_smile:

2 Likes

Hi @dougiebuckets how did you get on with your testing?

If @itinance reply answered your question can you mark it as the solution, otherwise please post your code so the community can help you further.

We had to update the unit test to include the empty string in order for it to revert:

await shouldFail.reverting(contractInstance.functionName("", {from: wallet1, value: donation}))

If we don’t include the empty string, only shouldFail will work:

await shouldFail(contractInstance.functionName({from: wallet1, value: donation}))

1 Like

@dougiebuckets test-helpers is still in active development, and we’re iterating over the API to make usage seamless. The exact issue you describe is one of the ones we’ve tackled in v0.4, so I’d encourage you to upgrade to that version! We’ve included a handy migration guide for users that were running v0.3.

2 Likes

Awesome! Thanks so much, @nventuro.

1 Like