cleveland-0.2.1: Testing framework for Morley.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Cleveland.Internal.Actions.ExceptionHandling

Description

Exception handling

Synopsis

Documentation

attempt :: forall e caps m a. (HasCallStack, MonadCleveland caps m, Exception e) => m a -> m (Either e a) Source #

Attempt to run an action and return its result or, if interpretation fails, an error.

catchTransferFailure :: (HasCallStack, MonadCleveland caps m) => m a -> m TransferFailure Source #

Asserts that a transfer should fail, and returns the exception.

expectTransferFailure :: (HasCallStack, MonadCleveland caps m) => TransferFailurePredicate -> m a -> m () Source #

Asserts that a transfer should fail, and runs some TransferFailurePredicates over the exception.

expectTransferFailure (failedWith (constant @MText "NOT_ADMIN")) $
  call contractAddr (Call @"Ep") arg
call contractAddr (Call @"Ep") arg & expectTransferFailure
  ( failedWith (customError #tag 3) &&
    addressIs contractAddr
  )

checkTransferFailure :: (HasCallStack, MonadCleveland caps m) => TransferFailure -> TransferFailurePredicate -> m () Source #

Check whether a given predicate holds for a given TransferFailure.

expectFailedWith :: forall err a caps m. (HasCallStack, MonadCleveland caps m, NiceConstant err) => err -> m a -> m () Source #

Asserts that interpretation of a contract ended with FAILWITH, returning the given constant value.

expectError :: forall err a caps m. (HasCallStack, MonadCleveland caps m, IsError err) => err -> m a -> m () Source #

Asserts that interpretation of a contract ended with FAILWITH, returning the given lorentz error.

expectCustomError :: forall arg a tag caps m. (HasCallStack, MonadCleveland caps m, IsError (CustomError tag), MustHaveErrorArg tag (MText, arg)) => Label tag -> arg -> m a -> m () Source #

Asserts that interpretation of a contract ended with FAILWITH, returning the given custom lorentz error.

expectCustomError_ :: (HasCallStack, MonadCleveland caps m, IsError (CustomError tag), MustHaveErrorArg tag (MText, ())) => Label tag -> m a -> m () Source #

Version of expectCustomError for error with unit argument.

expectCustomErrorNoArg :: (HasCallStack, MonadCleveland caps m, IsError (CustomError tag), MustHaveErrorArg tag MText) => Label tag -> m a -> m () Source #

Version of expectCustomError specialized for expecting NoErrorArgs.

expectNumericError :: forall err a caps m. (HasCallStack, MonadCleveland caps m, IsError err) => ErrorTagMap -> err -> m a -> m () Source #

Asserts that interpretation of a contract ended with FAILWITH, returning the given lorentz numeric error.

clarifyErrors :: forall caps m a. MonadCleveland caps m => Builder -> m a -> m a Source #

Prefix scenario-custom error messages (i.e. CustomTestError either from pure or non-pure implementation), potentially thrown from the given code block.

The prefix will be put at a separate line before the main text, if text is multiline, otherwise it will be separated from the main text with : .

This affects errors produced by functions like failure, assert, @==, etc. Errors related to events in the chain will not be touched.

Example:

for [1..10] \i -> clarifyErrors ("For i=" +| i |+ "") $
  askContract i @@== i * 2