Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utility functions for unit testing.
Synopsis
- type ContractReturn st = (Either MichelsonFailed ([Operation], Value st), InterpreterState)
- type ContractPropValidator st prop = ContractReturn st -> prop
- contractProp :: (IsoValue param, IsoValue storage, ToT param ~ cp, ToT storage ~ st, ParameterScope cp) => FullContract cp st -> ContractPropValidator st prop -> ContractEnv -> param -> storage -> prop
- contractPropVal :: ParameterScope cp => FullContract cp st -> ContractPropValidator st prop -> ContractEnv -> Value cp -> Value st -> prop
- contractHasEntryPoints :: Contract -> Map EpName Type -> Bool
- matchContractEntryPoints :: HasCallStack => Contract -> Map EpName Type -> Either (NonEmpty (EpName, Type)) ()
- mkEntrypointsMap :: Type -> Map EpName Type
- hasEp :: T -> (EpName, Type) -> Bool
- validateSuccess :: HasCallStack => ContractPropValidator st Expectation
- validateStorageIs :: IsoValue st => st -> ContractPropValidator (ToT st) Assertion
- validateMichelsonFailsWith :: (IsoValue v, Typeable (ToT v), SingI (ToT v)) => v -> ContractPropValidator st Expectation
Documentation
type ContractReturn st = (Either MichelsonFailed ([Operation], Value st), InterpreterState) Source #
type ContractPropValidator st prop = ContractReturn st -> prop Source #
Type for contract execution validation.
It's a function which is supplied with contract execution output (failure or new storage with operation list).
Function returns a property which type is designated by type variable prop
and might be Property
or Expectation
or anything else relevant.
contractProp :: (IsoValue param, IsoValue storage, ToT param ~ cp, ToT storage ~ st, ParameterScope cp) => FullContract cp st -> ContractPropValidator st prop -> ContractEnv -> param -> storage -> prop Source #
ContractCode's property tester against given input. Takes contract environment, initial storage and parameter, interprets contract on this input and invokes validation function.
contractPropVal :: ParameterScope cp => FullContract cp st -> ContractPropValidator st prop -> ContractEnv -> Value cp -> Value st -> prop Source #
Version of contractProp
which takes Val
as arguments instead
of regular Haskell values.
This function assumes that contract has no explicit default entrypoints and you always have to construct parameter manually; if you need to test contract calling specific entrypoints, use integrational testing defined by Michelson.Test.Integrational module.
contractHasEntryPoints :: Contract -> Map EpName Type -> Bool Source #
Check whether the given set of entrypoints is present in contract.
matchContractEntryPoints :: HasCallStack => Contract -> Map EpName Type -> Either (NonEmpty (EpName, Type)) () Source #
Match the given contract with provided set of entrypoints, return left if some entrypoints were not found.
mkEntrypointsMap :: Type -> Map EpName Type Source #
Given an untyped type, extract a map that maps entrypoint names to the their parameter types. If there are duplicate entrypoints in the given Type then the duplicate entrypoints at a deeper nesting level will get overwritten with the ones that are on top.
validateSuccess :: HasCallStack => ContractPropValidator st Expectation Source #
ContractPropValidator
that expects a successful termination.
validateStorageIs :: IsoValue st => st -> ContractPropValidator (ToT st) Assertion Source #
ContractPropValidator
that expects contract execution to
succeed and update storage to a particular constant value.
validateMichelsonFailsWith :: (IsoValue v, Typeable (ToT v), SingI (ToT v)) => v -> ContractPropValidator st Expectation Source #
ContractPropValidator
that expects a given failure.