quickcheck-contractmodel-0.1.4.1
Safe HaskellNone
LanguageHaskell2010

Test.QuickCheck.ContractModel.Internal.Model

Synopsis

Documentation

class HasSymbolics a where Source #

Minimal complete definition

Nothing

Instances

Instances details
HasSymbolics Char Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolics Int Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolics Integer Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

(Generic a, GenericHasSymbolics (Rep a)) => HasSymbolics a Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolics Quantity Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolics Value Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolics (BaseType a) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

(HasSymbolics k, HasSymbolics v) => HasSymbolics (Map k v) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

HasSymbolicRep t => HasSymbolics (Symbolic t) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

newtype BaseType a Source #

Constructors

BaseType a 

Instances

Instances details
HasSymbolics (BaseType a) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

class GenericHasSymbolics f where Source #

Instances

Instances details
GenericHasSymbolics (U1 :: k -> Type) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

genericGetAllSymbolics :: forall (k0 :: k1). U1 k0 -> SymCollectionIndex Source #

(GenericHasSymbolics f, GenericHasSymbolics g) => GenericHasSymbolics (f :+: g :: k -> Type) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

genericGetAllSymbolics :: forall (k0 :: k1). (f :+: g) k0 -> SymCollectionIndex Source #

(GenericHasSymbolics f, GenericHasSymbolics g) => GenericHasSymbolics (f :*: g :: k -> Type) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

genericGetAllSymbolics :: forall (k0 :: k1). (f :*: g) k0 -> SymCollectionIndex Source #

HasSymbolics c => GenericHasSymbolics (K1 i c :: k -> Type) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

genericGetAllSymbolics :: forall (k0 :: k1). K1 i c k0 -> SymCollectionIndex Source #

GenericHasSymbolics f => GenericHasSymbolics (M1 i c f :: k -> Type) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

genericGetAllSymbolics :: forall (k0 :: k1). M1 i c f k0 -> SymCollectionIndex Source #

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)

Minimal complete definition

arbitraryAction, initialState, nextState

Associated Types

data Action state Source #

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.

Methods

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 Actionss 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 waits 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 #

data Actions s Source #

Constructors

Actions_ [String] (Smart [Act s]) 

Instances

Instances details
ContractModel state => Show (Actions state) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

showsPrec :: Int -> Actions state -> ShowS Source #

show :: Actions state -> String Source #

showList :: [Actions state] -> ShowS Source #

ContractModel s => Arbitrary (Actions s) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

arbitrary :: Gen (Actions s)

shrink :: Actions s -> [Actions s]

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 #

pattern Actions :: [Act s] -> Actions s Source #

data Act s Source #

Constructors

Bind 

Fields

NoBind 

Fields

ActWaitUntil (Var ()) SlotNo 
ActObservation (Var ()) String (SymbolicSemantics -> ChainState -> Bool) 

Instances

Instances details
ContractModel s => Eq (Act s) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

(==) :: Act s -> Act s -> Bool Source #

(/=) :: Act s -> Act s -> Bool Source #

ContractModel state => Show (Act state) Source # 
Instance details

Defined in Test.QuickCheck.ContractModel.Internal.Model

Methods

showsPrec :: Int -> Act state -> ShowS Source #

show :: Act state -> String Source #

showList :: [Act state] -> ShowS Source #

mapActions :: (Action s -> Action s') -> Actions s -> Actions s' Source #

toStateModelActions :: ContractModel state => Actions state -> Actions (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 # 
Instance details

Methods

getAllVariables :: Quantity -> Set (Any Var)

HasVariables Value Source # 
Instance details

Methods

getAllVariables :: Value -> Set (Any Var)

ContractModel state => StateModel (ModelState state) Source # 
Instance details

Associated Types

data Action (ModelState state) a

Methods

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 # 
Instance details

Methods

getAllVariables :: AddressInEra Era -> Set (Any Var)

ContractModel state => Eq (Action (ModelState state) a) Source # 
Instance details

Methods

(==) :: 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 # 
Instance details

Methods

showsPrec :: Int -> Action (ModelState state) a -> ShowS Source #

show :: Action (ModelState state) a -> String Source #

showList :: [Action (ModelState state) a] -> ShowS Source #

HasVariables (Action state) => HasVariables (Action (ModelState state) a) Source # 
Instance details

Methods

getAllVariables :: Action (ModelState state) a -> Set (Any Var)