cooked-validators-4.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain.Testing

Description

This modules provides primitives to run tests over mockchain executions and to give expectation on the result of these runs.

Synopsis

Common interface between HUnit and QuickCheck

class IsProp prop where Source #

IsProp is a common interface for HUnit and QuickCheck tests. It abstracts uses of Assertion and Property for (IsProp prop) => prop, then provide instances for both HU.Asserton and QC.Property.

Minimal complete definition

testCounterexample, testConjoin, testDisjoin

Methods

testCounterexample :: String -> prop -> prop Source #

Displays the string to the user in case of failure

testConjoin :: [prop] -> prop Source #

Conjunction of a number of results

testDisjoin :: [prop] -> prop Source #

Disjunction of a number of results

testFailure :: prop Source #

Flags a failure

testSuccess :: prop Source #

Flags a success

testFailureMsg :: String -> prop Source #

Flags a failure with a message

testBool :: IsProp prop => Bool -> prop Source #

testAll :: IsProp prop => (a -> prop) -> [a] -> prop Source #

(.==.) :: (IsProp prop, Eq a) => a -> a -> prop infix 4 Source #

(.&&.) :: IsProp prop => prop -> prop -> prop infixr 3 Source #

(.||.) :: IsProp prop => prop -> prop -> prop infixr 2 Source #

assertionToMaybe :: Assertion -> IO (Maybe HUnitFailure) Source #

Catches a HUnit test failure, if the test fails.

forAll :: Show a => Gen a -> (a -> Property) -> Property Source #

Here we provide our own universsal quantifier instead of forAll, so we can monomorphize it to returning a Property

Extra HUnit assertions

assertSubset :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #

Asserts whether a set is a subset of another one, both given as lists.

assertSameSets :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #

Asserts whether 2 sets are equal, both given as lists.

Testing mockchain traces

data Test a prop Source #

Data structure to test a mockchain trace

Constructors

Test 

Fields

mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop Source #

A test template which expects a success from a trace

mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #

A test template which expects a failure from a trace

emptyTest :: IsProp prop => StagedMockChain a -> Test a prop Source #

A test template with no particular requirement on the trace

withInitDist :: IsProp prop => Test a prop -> InitialDistribution -> Test a prop Source #

Appending an initial distribution to a test

withPrettyOpts :: IsProp prop => Test a prop -> PrettyCookedOpts -> Test a prop Source #

Appending printing options to a test

withJournalPred :: IsProp prop => Test a prop -> ([MockChainLogEntry] -> prop) -> Test a prop Source #

Appending a predicate over the log to a test. This will be used both in case of success or failure of the trace.

withValueAndStatePred :: IsProp prop => Test a prop -> (a -> UtxoState -> prop) -> Test a prop Source #

Appending a predicate over the return value and state, which will be used in case of success of the trace.

withValuePred :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop Source #

Appending a predicate over the return value, which will be used in case of success of the trace.

withStatePred :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop Source #

Appending a predicate over the return state, which will be used in case of success of the trace.

withPrettyAndErrorPred :: IsProp prop => Test a prop -> (PrettyCookedOpts -> MockChainError -> prop) -> Test a prop Source #

Appending a predicate over an error which uses the printing options, which will be used in case of failure of the trace.

withErrorPred :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop Source #

testToProp :: IsProp prop => Test a prop -> prop Source #

This takes a test and transforms it into an actual test case in prop.

testSucceeds :: IsProp prop => StagedMockChain a -> prop Source #

Ensure that all results produced by the staged mockchain succeed, starting from the default initial distribution

testFails :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #

Ensure that all results produced by the staged mockchain fail

isPhase1Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #

A property to ensure a phase 1 failure

testFailsInPhase1 :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #

A test that succeeds when the trace results in a phase 1 failure

isPhase2Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #

A property to ensure a phase 2 failure

testFailsInPhase2 :: (IsProp prop, Show a) => StagedMockChain a -> prop Source #

A test that succeeds when the trace results in a phase 2 failure

isPhase1FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #

Same as isPhase1Failure with an added predicate on the text error

testFailsInPhase1WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #

Same as testFailsInPhase1 with an added predicate on the text error

isPhase2FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #

Same as isPhase2Failure with an added predicate over the text error

testFailsInPhase2WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #

Same as testFailsInPhase2 with an added predicate over the text error