Bounties-Network/StandardBounties

Testing failed transactions

naterush opened this issue · 0 comments

I could be totally off-the-mark here (ignore me if so), but I think that how you're testing for transactions that throw errors isn't properly checking the transactions fail.

For example:
https://github.com/ConsenSys/StandardBounties/blob/c56c66328b230e72b37e2b18caa69fe4a185df9d/test/standardBountyWithProxy.js#L53

Consider the case where the transaction does not fail. Thus, the try statement executes without throwing an error, and the catch statement never runs. In this case, the test would pass (as there are no failed asserts) even though the transaction did not throw as we expected it to.

There are two simple fixes, I think:

  • Add a let errorThrown = false before each try statement, then in the catch statement set errorThrown = true, and then have an assert.isTrue(errorThrown) (or whatever the syntax is 💯 ) right after the end of the catch.
  • Change your util to take a promisified transaction, wait for the promise to resolve, and assert that the transaction failed, as above (essentially, move the try/catch to a helper).