plutus-pab-1.2.0.0
Safe Haskell None
Language Haskell2010

Plutus.PAB.Simulator

Synopsis

Documentation

Run with user-defined contracts

type SimulatorContractHandler t = forall effs. ( Member ( Error PABError ) effs, Member ( LogMsg ( PABMultiAgentMsg t)) effs) => Eff ( ContractEffect t ': effs) ~> Eff effs Source #

A handler for the ContractEffect of t that can run contracts in a simulated environment.

mkSimulatorHandlers Source #

Arguments

:: forall t. ( Pretty ( ContractDef t), HasDefinitions ( ContractDef t))
=> Params
-> SimulatorContractHandler t

Making calls to the contract (see handleContractTest for an example)

-> SimulatorEffectHandlers t

Build EffectHandlers for running a contract in the simulator.

addWallet :: forall t. Simulation t (Wallet, PaymentPubKeyHash) Source #

Create a new wallet with a random key, give it some funds and add it to the list of simulated wallets.

addWalletWith :: forall t. Maybe Ada -> Simulation t (Wallet, PaymentPubKeyHash) Source #

Create a new wallet with a random key, give it provided funds and add it to the list of simulated wallets.

Logging

logString :: forall t effs. Member ( LogMsg ( PABMultiAgentMsg t)) effs => String -> Eff effs () Source #

Log some output to the console

Agent actions

payToWallet :: forall t. Wallet -> Wallet -> Value -> Simulation t CardanoTx Source #

Make a payment from one wallet to another

payToPaymentPublicKeyHash :: forall t. Wallet -> PaymentPubKeyHash -> Value -> Simulation t CardanoTx Source #

Make a payment from one wallet to a public key address

activateContract :: forall t. PABContract t => Wallet -> ContractDef t -> Simulation t ContractInstanceId Source #

Start a new instance of a contract

callEndpointOnInstance :: forall a t. ToJSON a => ContractInstanceId -> String -> a -> Simulation t ( Maybe NotificationError) Source #

Call a named endpoint on a contract instance

data Activity Source #

Whether the contract instance is still waiting for an event.

Constructors

Active
Stopped

Instance was stopped before all requests were handled

Done ( Maybe Value )

Instance finished, possibly with an error

Control actions

Querying the state

instanceState :: forall t. Wallet -> ContractInstanceId -> Simulation t ( State t) Source #

Get the current state of the contract instance.

observableState :: forall t. ContractInstanceId -> Simulation t ( STM Value ) Source #

An STM transaction that returns the observable state of the contract instance.

waitForState :: forall t a. ( Value -> Maybe a) -> ContractInstanceId -> Simulation t a Source #

Wait until the observable state of the instance matches a predicate.

waitForInstanceState :: forall t. ( InstanceState -> STM ( Maybe ContractActivityStatus)) -> ContractInstanceId -> Simulation t ContractActivityStatus Source #

activeEndpoints :: forall t. ContractInstanceId -> Simulation t ( STM [ OpenEndpoint ]) Source #

The list of endpoints that are currently open

waitForEndpoint :: forall t. ContractInstanceId -> String -> Simulation t () Source #

Wait until the endpoint becomes active.

waitForTxStatusChange :: forall t. TxId -> Simulation t TxStatus Source #

Wait until the status of the transaction changes

waitForTxOutStatusChange :: forall t. TxOutRef -> Simulation t TxOutStatus Source #

Wait until the status of the transaction changes

waitUntilSlot :: forall t. Slot -> Simulation t () Source #

Wait until the target slot number has been reached

waitNSlots :: forall t. Int -> Simulation t () Source #

Wait for the given number of slots.

activeContracts :: forall t. Simulation t ( Set ContractInstanceId ) Source #

The set of all active contracts.

finalResult :: forall t. ContractInstanceId -> Simulation t ( STM ( Maybe Value )) Source #

The final result of the instance (waits until it is available)

waitUntilFinished :: forall t. ContractInstanceId -> Simulation t ( Maybe Value ) Source #

Wait until the contract is done, then return the error (if any)

valueAt :: forall t. CardanoAddress -> Simulation t Value Source #

The total value currently at an address

valueAtSTM :: forall t. CardanoAddress -> Simulation t ( STM Value ) Source #

The total value currently at an address

walletFees :: forall t. Wallet -> Simulation t Lovelace Source #

The fees paid by the wallet.

blockchain :: forall t. Simulation t Blockchain Source #

The entire chain (newest transactions first)

currentBalances :: forall t. Simulation t ( Map Entity Value ) Source #

Retrieve the balances of all the entities in the simulator.

logBalances :: forall t effs. Member ( LogMsg ( PABMultiAgentMsg t)) effs => Map Entity Value -> Eff effs () Source #

Write the balances out to the log.

Transaction counts

txCounts :: forall t. Simulation t TxCounts Source #

Get the TxCounts of the emulated blockchain

txCountsSTM :: forall t. Simulation t ( STM TxCounts ) Source #

Get an STM transaction with the TxCounts of the emulated blockchain

waitForValidatedTxCount :: forall t. Int -> Simulation t () Source #

Wait until at least the given number of valid transactions are on the simulated blockchain.