Refactor Morley.Nettest errors types
Clarification and motivation
Right now we have this ADT in Morley.Nettest to model all errors that could occur:
data NettestFailure
= NettestFailedWith
| NettestUnexpectedBalance UnexpectedBalanceArg
| NettestUnexpectedClientSuccess
We should differentiate between two types of exceptions that could happen while running tests:
- Exceptions that happen because the code under test failed (e.g.
transfer
throwsNettestFailedWith
) - Exceptions that happen because an assertion failed (e.g.
expectBalance
throwsNettestUnexpectedBalance
)
Exceptions of type (2) are different from type (1) because they never need to be caught/handled by the test framework user. While it does make sense to say
transfer x y `expectFailure` NettestFailedWith
, it doesn't make sense to say
expectBalance n `expectFailure` NettestUnexpectedBalance x
For this reason, I think they should be modelled separately, instead of being bundled into one single ADT.
Possible solution
data NettestFailure
= NettestFailedWith
expectFailure :: m a -> NettestFailure -> m ()
data UnexpectedBalance = UnexpectedBalance UnexpectedBalanceArg
instance Exception UnexpectedBalance
Acceptance criteria
expectFailure
no longer accepts UnexpectedBalance
or other exceptions thrown exclusively by the test framework when an assertion fails.