plutus-contract-1.2.0.0
Safe HaskellNone
LanguageHaskell2010

Plutus.Trace.Emulator

Synopsis

Documentation

data ContractHandle w s e Source #

A reference to a running contract in the emulator.

data ContractInstanceTag Source #

A user-defined tag for a contract instance. Used to find the instance's log messages in the emulator log.

Instances

Instances details
Eq ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Ord ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Show ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

IsString ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Generic ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Associated Types

type Rep ContractInstanceTag :: Type -> Type Source #

FromJSON ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Methods

parseJSON :: Value -> Parser ContractInstanceTag

parseJSONList :: Value -> Parser [ContractInstanceTag]

ToJSON ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Pretty ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Methods

pretty :: ContractInstanceTag -> Doc ann

prettyList :: [ContractInstanceTag] -> Doc ann

type Rep ContractInstanceTag Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

type Rep ContractInstanceTag = D1 ('MetaData "ContractInstanceTag" "Plutus.Trace.Emulator.Types" "plutus-contract-1.2.0.0-FH8LC9wh7UV4Nmv68NHXrC" 'False) (C1 ('MetaCons "ContractInstanceTag" 'PrefixI 'True) (S1 ('MetaSel ('Just "unContractInstanceTag") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "shortContractInstanceTag") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

type ContractConstraints s = (Forall (Output s) Unconstrained1, Forall (Input s) Unconstrained1, AllUniqueLabels (Input s), AllUniqueLabels (Output s), Forall (Input s) FromJSON, Forall (Input s) ToJSON, Forall (Output s) FromJSON, Forall (Output s) ToJSON) Source #

Constructing Traces

assert :: forall effs. Member Assert effs => String -> (EmulatorState -> Bool) -> Eff effs () Source #

activateContract :: forall (contract :: Type -> Row Type -> Type -> Type -> Type) (s :: Row Type) e w a. (IsContract contract, ContractConstraints s, Show e, FromJSON e, ToJSON e, ToJSON w, Monoid w, FromJSON w) => forall effs. Member StartContract effs => Wallet -> contract w s e a -> ContractInstanceTag -> Eff effs (ContractHandle w s e) Source #

activateContractWallet :: forall contract w s e effs. (IsContract contract, ContractConstraints s, Show e, ToJSON e, FromJSON e, ToJSON w, FromJSON w, Member StartContract effs, Monoid w) => Wallet -> contract w s e () -> Eff effs (ContractHandle w s e) Source #

Like activateContract, but using walletInstanceTag for the tag.

walletInstanceTag :: Wallet -> ContractInstanceTag Source #

The ContractInstanceTag for the contract instance of a wallet. See note [Wallet contract instances]

callEndpoint :: forall l ep w s e effs. (ToJSON ep, ContractConstraints s, HasEndpoint l ep s, Member RunContract effs) => ContractHandle w s e -> ep -> Eff effs () Source #

Call an endpoint on a contract instance.

getContractState :: forall w (s :: Row Type) e. (ContractConstraints s, FromJSON e, FromJSON w, ToJSON w) => forall effs. Member RunContract effs => ContractHandle w s e -> Eff effs (ContractInstanceState w s e ()) Source #

observableState :: forall w s e effs. (Member RunContract effs, ContractConstraints s, FromJSON e, FromJSON w, ToJSON w) => ContractHandle w s e -> Eff effs w Source #

Get the observable state w of a contract instance.

activeEndpoints :: forall w s e effs. (Member RunContract effs, ContractConstraints s, FromJSON e, FromJSON w, ToJSON w) => ContractHandle w s e -> Eff effs [ActiveEndpoint] Source #

Get the active endpoints of a contract instance.

liftWallet :: forall a. forall effs. Member EmulatedWalletAPI effs => Wallet -> Eff ('(:) WalletEffect ('(:) (Error WalletAPIError) ('(:) (LogMsg Text) ('(:) (LogMsg RequestHandlerLogMsg) ('[] :: [Type -> Type]))))) a -> Eff effs a Source #

payToWallet :: forall effs. Member EmulatedWalletAPI effs => Wallet -> Wallet -> Value -> Eff effs TxId Source #

Make a payment from one wallet to another

nextSlot :: Member Waiting effs => Eff effs Slot Source #

Wait until the beginning of the next slot, returning the new slot number.

waitUntilSlot :: forall effs. Member Waiting effs => Slot -> Eff effs Slot Source #

waitUntilTime :: Member Waiting effs => POSIXTime -> Eff effs POSIXTime Source #

Wait until the slot where the given time falls into and return latest time we know has passed.

waitNSlots :: forall effs. Member Waiting effs => Natural -> Eff effs Slot Source #

Wait for a number of slots

waitNMilliSeconds :: forall effs. Member Waiting effs => DiffMilliSeconds -> Eff effs Slot Source #

Convert the given n milliseconds to a number of slots to wait.

Note: Currently, if n < length of a slot, then waitNMilliSeconds has no effect.

freezeContractInstance :: forall effs. Member EmulatorControl effs => ContractInstanceId -> Eff effs () Source #

thawContractInstance :: forall effs. Member EmulatorControl effs => ContractInstanceId -> Eff effs () Source #

Inspecting the chain state

setSigningProcess :: forall effs. Member EmulatorControl effs => Wallet -> Maybe SigningProcess -> Eff effs () Source #

chainState :: forall effs. Member EmulatorControl effs => Eff effs ChainState Source #

getSlotConfig :: forall effs. Member EmulatorControl effs => Eff effs SlotConfig Source #

chainNewestFirst :: Lens' ChainState Blockchain #

txPool :: Lens' ChainState TxPool #

index :: Lens' ChainState UtxoIndex #

chainCurrentSlot :: Lens' ChainState Slot #

Inspecting the agent states

agentState :: forall effs. Member EmulatorControl effs => Wallet -> Eff effs WalletState Source #

ownPaymentPrivateKey :: WalletState -> PaymentPrivateKey Source #

Throwing errors

throwError :: forall e (effs :: [Type -> Type]) a. Member (Error e) effs => e -> Eff effs a #

data EmulatorRuntimeError Source #

Instances

Instances details
Eq EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Show EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Generic EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Associated Types

type Rep EmulatorRuntimeError :: Type -> Type Source #

FromJSON EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Methods

parseJSON :: Value -> Parser EmulatorRuntimeError

parseJSONList :: Value -> Parser [EmulatorRuntimeError]

ToJSON EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Pretty EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Methods

pretty :: EmulatorRuntimeError -> Doc ann

prettyList :: [EmulatorRuntimeError] -> Doc ann

type Rep EmulatorRuntimeError Source # 
Instance details

Defined in Plutus.Trace.Emulator.Types

Running traces

data EmulatorConfig Source #

Constructors

EmulatorConfig 

Fields

  • _initialChainState :: InitialChainState

    State of the blockchain at the beginning of the simulation. Can be given as a map of funds to wallets, or as a block of transactions.

  • _params :: Params

    Set the protocol parameters, network ID and slot configuration for the emulator.

runEmulatorStream :: forall effs a. EmulatorConfig -> EmulatorTrace a -> Stream (Of (LogMessage EmulatorEvent)) (Eff effs) (Either EmulatorErr a, EmulatorState) Source #

Run a 'Trace Emulator', streaming the log messages as they arrive

data TraceConfig Source #

Options for how to set up and print the trace.

Constructors

TraceConfig 

Fields

Instances

Instances details
Default TraceConfig Source # 
Instance details

Defined in Plutus.Trace.Emulator

Methods

def :: TraceConfig

traceConfigShowEventExample :: LogMessage EmulatorEvent -> Maybe String Source #

Some example of how to configure the traceConfigShowEvent.

runEmulatorTrace :: TraceConfig -> EmulatorConfig -> EmulatorTrace a -> ([LogMessage EmulatorEvent], Either EmulatorErr a, EmulatorState) Source #

Run an emulator trace to completion, returning a tuple of the final state of the emulator, the events, and any error, if any.

data PrintEffect r where Source #

A very simple effect for interpreting the output printing done by the trace printing functions:

Constructors

PrintLn :: String -> PrintEffect () 

runEmulatorTraceEff :: forall effs. Member PrintEffect effs => TraceConfig -> EmulatorConfig -> EmulatorTrace () -> Eff effs () Source #

Run the emulator trace returning an effect that can be evaluated by interpreting the PrintEffects.

runEmulatorTraceIO :: EmulatorTrace () -> IO () Source #

Runs the trace with runEmulatorTrace, with default configuration that prints a selection of events to stdout.

Example:

>>> runEmulatorTraceIO (void $ Trace.waitNSlots 1)

runEmulatorTraceIO' :: TraceConfig -> EmulatorConfig -> EmulatorTrace () -> IO () Source #

Deprecated: Renamed to runEmulatorTraceIOWithConfig

Interpreter

interpretEmulatorTrace :: forall effs a. (Member MultiAgentEffect effs, Member MultiAgentControlEffect effs, Member (Error EmulatorRuntimeError) effs, Member ChainControlEffect effs, Member (LogMsg EmulatorEvent') effs, Member (State EmulatorState) effs) => EmulatorConfig -> EmulatorTrace a -> Eff effs (Maybe a) Source #

Interpret a 'Trace Emulator' action in the multi agent and emulated blockchain effects.