Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class HasSymbolics a where
- getAllSymbolics :: a -> SymCollectionIndex
- newtype BaseType a = BaseType a
- class GenericHasSymbolics f where
- genericGetAllSymbolics :: f k -> SymCollectionIndex
- class (Typeable state, Show state, HasActions state) => ContractModel state where
- data Action state
- arbitraryAction :: ModelState state -> Gen (Action state)
- actionName :: Action state -> String
- waitProbability :: ModelState state -> Double
- arbitraryWaitInterval :: ModelState state -> Gen SlotNo
- initialState :: state
- precondition :: ModelState state -> Action state -> Bool
- nextReactiveState :: SlotNo -> Spec state ()
- nextState :: Action state -> Spec state ()
- shrinkAction :: ModelState state -> Action state -> [Action state]
- restricted :: Action state -> Bool
- createsSymbolics :: ContractModel state => ModelState state -> Action state -> Bool
- wait :: ContractModel state => Integer -> Spec state ()
- waitUntil :: ContractModel state => SlotNo -> Spec state ()
- contractAction :: ContractModel state => ModelState state -> Action state -> Action (ModelState state) SymIndex
- data Actions s = Actions_ [String] (Smart [Act s])
- pattern ContractAction :: Bool -> Action state -> Action (ModelState state) SymIndex
- pattern WaitUntil :: SlotNo -> Action (ModelState state) ()
- pattern Observation :: String -> (SymbolicSemantics -> ChainState -> Bool) -> Action (ModelState state) ()
- pattern Actions :: [Act s] -> Actions s
- data Act s
- = Bind { }
- | NoBind { }
- | ActWaitUntil (Var ()) SlotNo
- | ActObservation (Var ()) String (SymbolicSemantics -> ChainState -> Bool)
- mapActions :: (Action s -> Action s') -> Actions s -> Actions s'
- isBind :: Act s -> Bool
- toStateModelActions :: ContractModel state => Actions state -> Actions (ModelState state)
- fromStateModelActions :: Actions (ModelState s) -> Actions s
- dummyModelState :: state -> ModelState state
- stateAfter :: ContractModel state => Actions state -> ModelState state
- annotatedStateAfter :: ContractModel state => Actions state -> Annotated (ModelState state)
- asserts :: ModelState state -> Property
Documentation
class HasSymbolics a where Source #
Nothing
getAllSymbolics :: a -> SymCollectionIndex Source #
default getAllSymbolics :: (Generic a, GenericHasSymbolics (Rep a)) => a -> SymCollectionIndex Source #
Instances
BaseType a |
Instances
HasSymbolics (BaseType a) Source # | |
Defined in Test.QuickCheck.ContractModel.Internal.Model getAllSymbolics :: BaseType a -> SymCollectionIndex Source # |
class GenericHasSymbolics f where Source #
genericGetAllSymbolics :: f k -> SymCollectionIndex Source #
Instances
class (Typeable state, Show state, HasActions state) => ContractModel state where Source #
A ContractModel
instance captures everything that is needed to generate and run tests of a
contract or set of contracts. It specifies among other things
- what operations are supported by the contract (
Action
), - when they are valid (
precondition
), - how to generate random actions (
arbitraryAction
), - how the operations affect the state (
nextState
), and - how to run the operations in the emulator (
perform
)
The type of actions that are supported by the contract. An action usually represents a single
callEndpoint
or a transfer of tokens, but it can be anything
that can be interpreted in the EmulatorTrace
monad.
arbitraryAction :: ModelState state -> Gen (Action state) Source #
Given the current model state, provide a QuickCheck generator for a random next action.
This is used in the Arbitrary
instance for Actions
s as well as by anyAction
and
anyActions
.
actionName :: Action state -> String Source #
The name of an Action, used to report statistics.
waitProbability :: ModelState state -> Double Source #
The probability that we will generate a WaitUntil
in a given state
arbitraryWaitInterval :: ModelState state -> Gen SlotNo Source #
Control the distribution of how long WaitUntil
waits
initialState :: state Source #
The initial state, before any actions have been performed.
precondition :: ModelState state -> Action state -> Bool Source #
The precondition
function decides if a given action is valid in a given state. Typically
actions generated by arbitraryAction
will satisfy the precondition, but if they don't
they will be discarded and another action will be generated. More importantly, the
preconditions are used when shrinking (see shrinkAction
) to ensure that shrunk test cases
still make sense.
If an explicit action
in a DL
scenario violates the precondition an error is raised.
nextReactiveState :: SlotNo -> Spec state () Source #
nextReactiveState
is run every time the model wait
s for a slot to be reached. This
can be used to model reactive components of off-chain code.
nextState :: Action state -> Spec state () Source #
This is where the model logic is defined. Given an action, nextState
specifies the
effects running that action has on the model state. It runs in the Spec
monad, which is a
state monad over the ModelState
.
shrinkAction :: ModelState state -> Action state -> [Action state] Source #
When a test involving random sequences of actions fails, the framework tries to find a
minimal failing test case by shrinking the original failure. Action sequences are shrunk by
removing individual actions, or by replacing an action by one of the (simpler) actions
returned by shrinkAction
.
See shrink
for more information on shrinking.
restricted :: Action state -> Bool Source #
createsSymbolics :: ContractModel state => ModelState state -> Action state -> Bool Source #
Check if a given action creates new symbolic tokens in a given ModelState
wait :: ContractModel state => Integer -> Spec state () Source #
Wait the given number of slots. Updates the currentSlot
of the model state.
waitUntil :: ContractModel state => SlotNo -> Spec state () Source #
Wait until the given slot. Has no effect if currentSlot
is greater than the given slot.
contractAction :: ContractModel state => ModelState state -> Action state -> Action (ModelState state) SymIndex Source #
Instances
ContractModel state => Show (Actions state) Source # | |
ContractModel s => Arbitrary (Actions s) Source # | |
pattern ContractAction :: Bool -> Action state -> Action (ModelState state) SymIndex Source #
pattern WaitUntil :: SlotNo -> Action (ModelState state) () Source #
pattern Observation :: String -> (SymbolicSemantics -> ChainState -> Bool) -> Action (ModelState state) () Source #
Bind | |
NoBind | |
ActWaitUntil (Var ()) SlotNo | |
ActObservation (Var ()) String (SymbolicSemantics -> ChainState -> Bool) |
Instances
ContractModel s => Eq (Act s) Source # | |
ContractModel state => Show (Act state) Source # | |
toStateModelActions :: ContractModel state => Actions state -> Actions (ModelState state) Source #
fromStateModelActions :: Actions (ModelState s) -> Actions s Source #
dummyModelState :: state -> ModelState state Source #
stateAfter :: ContractModel state => Actions state -> ModelState state Source #
annotatedStateAfter :: ContractModel state => Actions state -> Annotated (ModelState state) Source #
asserts :: ModelState state -> Property Source #
Orphan instances
HasVariables Quantity Source # | |
getAllVariables :: Quantity -> Set (Any Var) | |
HasVariables Value Source # | |
getAllVariables :: Value -> Set (Any Var) | |
ContractModel state => StateModel (ModelState state) Source # | |
data Action (ModelState state) a actionName :: Action (ModelState state) a -> String arbitraryAction :: VarContext -> ModelState state -> Gen (Any (Action (ModelState state))) shrinkAction :: Typeable a => VarContext -> ModelState state -> Action (ModelState state) a -> [Any (Action (ModelState state))] initialState :: ModelState state nextState :: Typeable a => ModelState state -> Action (ModelState state) a -> Var a -> ModelState state precondition :: ModelState state -> Action (ModelState state) a -> Bool | |
HasVariables (AddressInEra Era) Source # | |
getAllVariables :: AddressInEra Era -> Set (Any Var) | |
ContractModel state => Eq (Action (ModelState state) a) Source # | |
(==) :: Action (ModelState state) a -> Action (ModelState state) a -> Bool Source # (/=) :: Action (ModelState state) a -> Action (ModelState state) a -> Bool Source # | |
ContractModel state => Show (Action (ModelState state) a) Source # | |
HasVariables (Action state) => HasVariables (Action (ModelState state) a) Source # | |
getAllVariables :: Action (ModelState state) a -> Set (Any Var) |