Testing failed transactions
naterush opened this issue · 0 comments
naterush commented
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.
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 eachtry
statement, then in the catch statement seterrorThrown = true
, and then have anassert.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).