cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.MockChain

Description

This module centralizes everything related to our mockchain, while hiding elements related to logs and inner state.

Synopsis

Documentation

data Test a prop Source #

Data structure to test a mockchain trace. a is the return typed of the tested trace, prop is the domain in which the properties live. This is not enforced here, but it will often be assumed that prop satisfies IsProp.

Constructors

Test 

Fields

type MockChain = MockChainT Identity Source #

Our MockChain naturally instantiate the inner monad with Identity

data MockChainSt Source #

The state used to run the simulation in Direct

Instances

Instances details
Show MockChainSt Source # 
Instance details

Defined in Cooked.MockChain.MockChainSt

Default MockChainSt Source # 
Instance details

Defined in Cooked.MockChain.MockChainSt

Methods

def :: MockChainSt #

Eq MockChainSt Source # 
Instance details

Defined in Cooked.MockChain.MockChainSt

Monad m => MonadState MockChainSt (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

type UtxoSearch m a = ListT m (TxOutRef, a) Source #

If a UTxO is a TxOutRef with some additional information, this type captures a "stream" of UTxOs.

data UtxoState Source #

A description of who owns what in a blockchain. Owners are addresses and they each own a UtxoPayloadSet.

data GenerateTxError Source #

Errors that can arise during transaction generation

Constructors

ToCardanoError String ToCardanoError

Error when translating a skeleton element to its Cardano counterpart

TxBodyError String TxBodyError

Error when generating a Cardano transaction body

GenerateTxErrorGeneral String

Other generation error

data MockChainError Source #

Errors that can be produced by the blockchain

Constructors

MCEValidationError ValidationPhase ValidationError

Validation errors, either in Phase 1 or Phase 2

MCEUnbalanceable Wallet Value TxSkel

Thrown when the balancing wallet does not have enough funds

MCENoSuitableCollateral Integer Integer Value

Thrown when not enough collateral are provided. Built upon the fee, the percentage and the expected minimal collateral value.

MCEGenerationError GenerateTxError

Thrown when an error occured during transaction generation

MCEUnknownOutRefError String TxOutRef

Thrown when an output reference is missing from the mockchain state

MCEUnknownValidator String ValidatorHash

Same as MCEUnknownOutRefError for validators.

MCEUnknownDatum String DatumHash

Same as MCEUnknownOutRefError for datums.

FailWith String

Used to provide MonadFail instances.

Instances

Instances details
Show MockChainError Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

PrettyCooked MockChainError Source # 
Instance details

Defined in Cooked.Pretty.MockChain

Eq MockChainError Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

MonadError MockChainError StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Monad m => MonadError MockChainError (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

(MonadTransControl t, MonadError MockChainError m, Monad (t m)) => MonadError MockChainError (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

throwError :: MockChainError -> AsTrans t m a #

catchError :: AsTrans t m a -> (MockChainError -> AsTrans t m a) -> AsTrans t m a #

Show a => PrettyCooked (MockChainReturn a UtxoState) Source # 
Instance details

Defined in Cooked.Pretty.MockChain

class (MonadFail m, MonadError MockChainError m) => MonadBlockChainBalancing m where Source #

This is the first layer of our blockchain, which provides the minimal subset of primitives required to perform balancing.

Methods

getParams :: m Params Source #

Returns the emulator parameters, including protocol parameters

utxosAt :: Address -> m [(TxOutRef, TxOut)] Source #

Returns a list of all UTxOs at a certain address.

datumFromHash :: DatumHash -> m (Maybe Datum) Source #

Returns the datum with the given hash if present.

scriptFromHash :: ScriptHash -> m (Maybe (Versioned Script)) Source #

Returns the full validator corresponding to hash, if that validator owns something or if it is stored in the reference script field of some UTxO.

txOutByRef :: TxOutRef -> m (Maybe TxOut) Source #

Returns an output given a reference to it

Instances

Instances details
MonadBlockChainBalancing StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Monad m => MonadBlockChainBalancing (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

MonadBlockChainBalancing m => MonadBlockChainBalancing (ListT m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

MonadBlockChainBalancing m => MonadBlockChainBalancing (ReaderT r m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

MonadBlockChainBalancing m => MonadBlockChainBalancing (StateT s m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(Monoid w, MonadBlockChainBalancing m) => MonadBlockChainBalancing (WriterT w m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(MonadTrans t, MonadBlockChainBalancing m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainBalancing (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

class MonadBlockChainBalancing m => MonadBlockChainWithoutValidation m where Source #

This is the second layer of our block, which provides all the other blockchain primitives not needed for balancing, except transaction validation. This layers is the one where Tweaks are plugged to.

Methods

allUtxos :: m [(TxOutRef, TxOut)] Source #

Returns a list of all currently known outputs.

setParams :: Params -> m () Source #

Updates parameters

currentSlot :: m Slot Source #

Returns the current slot number

awaitSlot :: Slot -> m Slot Source #

Waits until the current slot becomes greater or equal to the given slot, and returns the current slot after waiting.

Note that it might not wait for anything if the current slot is large enough.

define :: ToHash a => String -> a -> m a Source #

Binds a hashable quantity of type a to a variable in the mockchain, while registering its alias for printing purposes.

Instances

Instances details
MonadBlockChainWithoutValidation StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Monad m => MonadBlockChainWithoutValidation (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (ListT m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (ReaderT r m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (StateT s m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(Monoid w, MonadBlockChainWithoutValidation m) => MonadBlockChainWithoutValidation (WriterT w m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(MonadTrans t, MonadBlockChainWithoutValidation m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainWithoutValidation (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

class MonadBlockChainWithoutValidation m => MonadBlockChain m where Source #

The final layer of our blockchain, adding transaction validation to the mix. This is the only primitive that actually modifies the ledger state.

Methods

validateTxSkel :: TxSkel -> m CardanoTx Source #

Generates, balances and validates a transaction from a skeleton. It returns the validated transaction and updates the state of the blockchain.

newtype AsTrans t (m :: Type -> Type) a Source #

A newtype wrapper to be used with '-XDerivingVia' to derive instances of MonadBlockChain for any MonadTransControl.

For example, to derive 'MonadBlockChain m => MonadBlockChain (ReaderT r m)', you'd write

deriving via (AsTrans (ReaderT r) m) instance MonadBlockChain m => MonadBlockChain (ReaderT r m)

and avoid the trouble of defining all the class methods yourself.

Constructors

AsTrans 

Fields

Instances

Instances details
(MonadTransControl t, MonadError MockChainError m, Monad (t m)) => MonadError MockChainError (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

throwError :: MockChainError -> AsTrans t m a #

catchError :: AsTrans t m a -> (MockChainError -> AsTrans t m a) -> AsTrans t m a #

MonadTransControl t => MonadTransControl (AsTrans t) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Associated Types

type StT (AsTrans t) a #

Methods

liftWith :: Monad m => (Run (AsTrans t) -> m a) -> AsTrans t m a #

restoreT :: Monad m => m (StT (AsTrans t) a) -> AsTrans t m a #

MonadTrans t => MonadTrans (AsTrans t) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

lift :: Monad m => m a -> AsTrans t m a #

(MonadTrans t, MonadFail m, Monad (t m)) => MonadFail (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

fail :: String -> AsTrans t m a #

Applicative (t m) => Applicative (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

pure :: a -> AsTrans t m a #

(<*>) :: AsTrans t m (a -> b) -> AsTrans t m a -> AsTrans t m b #

liftA2 :: (a -> b -> c) -> AsTrans t m a -> AsTrans t m b -> AsTrans t m c #

(*>) :: AsTrans t m a -> AsTrans t m b -> AsTrans t m b #

(<*) :: AsTrans t m a -> AsTrans t m b -> AsTrans t m a #

Functor (t m) => Functor (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

fmap :: (a -> b) -> AsTrans t m a -> AsTrans t m b #

(<$) :: a -> AsTrans t m b -> AsTrans t m a #

Monad (t m) => Monad (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

Methods

(>>=) :: AsTrans t m a -> (a -> AsTrans t m b) -> AsTrans t m b #

(>>) :: AsTrans t m a -> AsTrans t m b -> AsTrans t m b #

return :: a -> AsTrans t m a #

(MonadTrans t, MonadBlockChain m, MonadBlockChainWithoutValidation (AsTrans t m)) => MonadBlockChain (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(MonadTrans t, MonadBlockChainBalancing m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainBalancing (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

(MonadTrans t, MonadBlockChainWithoutValidation m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainWithoutValidation (AsTrans t m) Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

type StT (AsTrans t) a Source # 
Instance details

Defined in Cooked.MockChain.BlockChain

type StT (AsTrans t) a = StT t a

data MockChainBook Source #

This represents elements that can be emitted throughout a MockChain run. These elements are either log entries corresponding to internal events worth logging, or aliases for hashables corresponding to elements users wishes to be properly displayed when printed with PrettyCooked

Constructors

MockChainBook 

Fields

type MonadModalBlockChain m = (MonadBlockChain m, MonadModal m, Modification m ~ UntypedTweak InterpMockChain) Source #

A modal mock chain is a mock chain that allows us to use LTL modifications with Tweaks

class IsProp prop where Source #

IsProp is a common interface for HUnit and QuickCheck tests. It abstracts uses of Assertion and Property for (IsProp prop) => prop, then provide instances for both HU.Asserton and QC.Property.

Minimal complete definition

testCounterexample, testConjoin, testDisjoin

Methods

testCounterexample :: String -> prop -> prop Source #

Displays the string to the user in case of failure

testConjoin :: [prop] -> prop Source #

Conjunction of a number of results

testDisjoin :: [prop] -> prop Source #

Disjunction of a number of results

testFailure :: prop Source #

Flags a failure

testSuccess :: prop Source #

Flags a success

testFailureMsg :: String -> prop Source #

Flags a failure with a message

newtype MockChainT m a Source #

A MockChainT builds up a stack of monads on top of a given monad m to reflect the requirements of the simulation.

Instances

Instances details
MonadFail StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Methods

fail :: String -> StagedMockChain a #

Alternative StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChain StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChainBalancing StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadBlockChainWithoutValidation StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

MonadTrans MockChainT Source # 
Instance details

Defined in Cooked.MockChain.Direct

Methods

lift :: Monad m => m a -> MockChainT m a #

MonadError MockChainError StagedMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

Monad m => MonadError MockChainError (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Monad m => MonadState MockChainSt (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Monad m => MonadWriter MockChainBook (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Monad m => MonadFail (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Methods

fail :: String -> MockChainT m a #

(Monad m, Alternative m) => Alternative (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Methods

empty :: MockChainT m a #

(<|>) :: MockChainT m a -> MockChainT m a -> MockChainT m a #

some :: MockChainT m a -> MockChainT m [a] #

many :: MockChainT m a -> MockChainT m [a] #

Monad m => Applicative (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Methods

pure :: a -> MockChainT m a #

(<*>) :: MockChainT m (a -> b) -> MockChainT m a -> MockChainT m b #

liftA2 :: (a -> b -> c) -> MockChainT m a -> MockChainT m b -> MockChainT m c #

(*>) :: MockChainT m a -> MockChainT m b -> MockChainT m b #

(<*) :: MockChainT m a -> MockChainT m b -> MockChainT m a #

Functor m => Functor (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Methods

fmap :: (a -> b) -> MockChainT m a -> MockChainT m b #

(<$) :: a -> MockChainT m b -> MockChainT m a #

Monad m => Monad (MockChainT m) Source #

Custom monad instance made to increase the slot count automatically

Instance details

Defined in Cooked.MockChain.Direct

Methods

(>>=) :: MockChainT m a -> (a -> MockChainT m b) -> MockChainT m b #

(>>) :: MockChainT m a -> MockChainT m b -> MockChainT m b #

return :: a -> MockChainT m a #

MonadPlus m => MonadPlus (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Staged

Methods

mzero :: MockChainT m a #

mplus :: MockChainT m a -> MockChainT m a -> MockChainT m a #

Monad m => MonadBlockChain (MockChainT m) Source #

Most of the logic of the direct emulation happens here

Instance details

Defined in Cooked.MockChain.Direct

Monad m => MonadBlockChainBalancing (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

Monad m => MonadBlockChainWithoutValidation (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

InterpLtl (UntypedTweak InterpMockChain) MockChainBuiltin InterpMockChain Source # 
Instance details

Defined in Cooked.MockChain.Staged

type FailureProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> MockChainError -> prop Source #

Type of properties over failures

type SuccessProp a prop = PrettyCookedOpts -> [MockChainLogEntry] -> a -> UtxoState -> prop Source #

Type of properties over successes

type SizeProp prop = Integer -> prop Source #

Type of properties over the number of run outcomes. This does not necessitate a PrettyCookedOpts as parameter as an Integer does not contain anything significant that can be pretty printed.

type JournalProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop Source #

Type of properties over the mockchain journal

pattern MCLogSubmittedTxSkel :: Map TxOutRef TxOut -> Map DatumHash TxSkelOutDatum -> TxSkel -> MockChainLogEntry Source #

Logging a Skeleton as it is submitted by the user.

pattern MCLogAdjustedTxSkel :: Map TxOutRef TxOut -> Map DatumHash TxSkelOutDatum -> TxSkel -> Integer -> Maybe (Set TxOutRef, Wallet) -> MockChainLogEntry Source #

Logging a Skeleton as it has been adjusted by the balancing mechanism, alongside fee, and possible collateral utxos and return collateral wallet.

pattern MCLogNewTx :: TxId -> MockChainLogEntry Source #

Logging the appearance of a new transaction, after a skeleton has been successfully sent for validation.

pattern MCLogDiscardedUtxos :: Integer -> String -> MockChainLogEntry Source #

Logging the fact that utxos provided by the user for balancing have to be discarded for a specific reason.

pattern MCLogUnusedCollaterals :: Either Wallet (Set TxOutRef) -> MockChainLogEntry Source #

Logging the fact that utxos provided as collaterals will not be used because the transaction does not involve scripts. There are 2 cases, depending on whether the user has provided an explicit wallet or a set of utxos to be used as collaterals.

pattern MCLogAddedReferenceScript :: TxSkelRedeemer -> TxOutRef -> ScriptHash -> MockChainLogEntry Source #

Logging the automatic addition of a reference script

pattern MCLogAdjustedTxSkelOut :: TxSkelOut -> Lovelace -> MockChainLogEntry Source #

Logging the automatic adjusment of a min ada amount

(.&&.) :: IsProp prop => prop -> prop -> prop infixr 3 Source #

Conjunction of two props

(.||.) :: IsProp prop => prop -> prop -> prop infixr 2 Source #

Disjunction of two props

forAll :: Show a => Gen a -> (a -> Property) -> Property Source #

Here we provide our own universsal quantifier instead of forAll, so we can monomorphize it to returning a Property

(.==.) :: (IsProp prop, Eq a) => a -> a -> prop infix 4 Source #

Lifts an equality test to a prop

there :: MonadModalBlockChain m => Integer -> Tweak InterpMockChain b -> m a -> m a Source #

Apply a Tweak to the (0-indexed) nth transaction in a given trace. Successful when this transaction exists and can be modified.

everywhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Apply a Tweak to every transaction in a given trace. This is also successful if there are no transactions at all.

somewhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a Source #

Apply a Tweak to some transaction in the given Trace. The tweak must apply at least once.

balanceTxSkel :: MonadBlockChainBalancing m => TxSkel -> m (TxSkel, Integer, Maybe (Set TxOutRef, Wallet)) Source #

This is the main entry point of our balancing mechanism. This function takes a skeleton and returns a (possibly) balanced skeleton alongside the associated fee, collateral inputs and return collateral wallet, which might be empty when no script is involved in the transaction. The options from the skeleton control whether it should be balanced, and how to compute its associated elements.

getMinAndMaxFee :: MonadBlockChainBalancing m => m (Integer, Integer) Source #

This computes the minimum and maximum possible fee a transaction can cost based on the current protocol parameters

currentTime :: MonadBlockChainWithoutValidation m => m (POSIXTime, POSIXTime) Source #

Returns the closed ms interval corresponding to the current slot

utxosFromCardanoTx :: CardanoTx -> [(TxOutRef, TxOut)] Source #

Retrieves the ordered list of outputs of the given CardanoTx.

This is useful when writing endpoints and/or traces to fetch utxos of interest right from the start and avoid querying the chain for them afterwards using allUtxos or similar functions.

typedDatumFromTxOutRef :: (FromData a, MonadBlockChainBalancing m) => TxOutRef -> m (Maybe a) Source #

Like datumFromTxOutRef, but uses fromBuiltinData to attempt to deserialize this datum into a given type

valueFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe Value) Source #

Resolves an TxOutRef and extracts the value it contains

datumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe Datum) Source #

Extracts a potential Datum from a given TxOutRef

resolveDatum :: (IsAbstractOutput out, ToOutputDatum (DatumType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (OwnerType out) Datum (ValueType out) (ReferenceScriptType out))) Source #

Try to resolve the datum on the output: If there's an inline datum, take that; if there's a datum hash, look the corresponding datum up (with datumFromHash), returning Nothing if it can't be found; if there's no datum or hash at all, return Nothing.

resolveTypedDatum :: (IsAbstractOutput out, ToOutputDatum (DatumType out), MonadBlockChainBalancing m, FromData a) => out -> m (Maybe (ConcreteOutput (OwnerType out) a (ValueType out) (ReferenceScriptType out))) Source #

Like resolveDatum, but also tries to use fromBuiltinData to extract a datum of the suitable type.

resolveValidator :: (IsAbstractOutput out, ToCredential (OwnerType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (Versioned Validator) (DatumType out) (ValueType out) (ReferenceScriptType out))) Source #

Tries to resolve the validator that owns an output: If the output is owned by a public key, or if the validator's hash is not known (i.e. if scriptFromHash returns Nothing) return Nothing.

resolveReferenceScript :: (IsAbstractOutput out, ToScriptHash (ReferenceScriptType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) (Versioned Validator))) Source #

Tries to resolve the reference script on an output: If the output has no reference script, or if the reference script's hash is not known (i.e. if scriptFromHash returns Nothing), this function will return Nothing.

getEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot Source #

Return the slot that contains the given time. See slotToTimeInterval for some satisfied equational properties.

awaitEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot Source #

Waits until the current slot becomes greater or equal to the slot containing the given POSIX time. Note that that it might not wait for anything if the current slot is large enough.

awaitDurationFromLowerBound :: MonadBlockChainWithoutValidation m => Integer -> m Slot Source #

Wait a given number of ms from the lower bound of the current slot and returns the current slot after waiting.

awaitDurationFromUpperBound :: MonadBlockChainWithoutValidation m => Integer -> m Slot Source #

Wait a given number of ms from the upper bound of the current slot and returns the current slot after waiting.

slotRangeBefore :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange Source #

The infinite range of slots ending before or at the given time

slotRangeAfter :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange Source #

The infinite range of slots starting after or at the given time

slotToTimeInterval :: MonadBlockChainWithoutValidation m => Slot -> m (POSIXTime, POSIXTime) Source #

Returns the closed ms interval corresponding to the slot with the given number. It holds that

slotToTimeInterval (getEnclosingSlot t) == (a, b)    ==>   a <= t <= b

and

slotToTimeInterval n == (a, b)   ==>   getEnclosingSlot a == n && getEnclosingSlot b == n

and

slotToTimeInterval n == (a, b)   ==>   getEnclosingSlot (a-1) == n-1 && getEnclosingSlot (b+1) == n+1

txSkelInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut) Source #

Resolves all the inputs of a given TxSkel

txSkelReferenceInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut) Source #

Resolves all the reference inputs of a given TxSkel

txSkelInputValidators :: MonadBlockChainBalancing m => TxSkel -> m (Map ValidatorHash (Versioned Validator)) Source #

Returns all validators which protect transaction inputs

txSkelInputValue :: MonadBlockChainBalancing m => TxSkel -> m Value Source #

look up the UTxOs the transaction consumes, and sum their values.

txSkelInputDataAsHashes :: MonadBlockChainBalancing m => TxSkel -> m [DatumHash] Source #

Looks up the data on UTxOs the transaction consumes and returns their hashes.

lookupUtxos :: MonadBlockChainBalancing m => [TxOutRef] -> m (Map TxOutRef TxOut) Source #

Go through all of the TxOutRefs in the list and look them up in the state of the blockchain, throwing an error if one of them cannot be resolved.

validateTxSkel' :: MonadBlockChain m => TxSkel -> m [TxOutRef] Source #

Validates a skeleton, and retuns the ordered list of produced output references

validateTxSkel_ :: MonadBlockChain m => TxSkel -> m () Source #

Validates a skeleton, and erases the outputs

txSkelProposalsDeposit :: MonadBlockChainBalancing m => TxSkel -> m Lovelace Source #

Retrieves the total amount of lovelace deposited in proposals in this skeleton (equal to govActionDeposit times the number of proposals).

govActionDeposit :: MonadBlockChainBalancing m => m Lovelace Source #

Retrieves the required deposit amount for issuing governance actions.

txOutRefToTxSkelOut Source #

Arguments

:: MonadBlockChainBalancing m 
=> TxOutRef

The UTXO to translate

-> Bool

Whether to include the datum in the transaction

-> Bool

Whether to allow further adjustment of the Ada value

-> m TxSkelOut 

This creates a payment from an existing UTXO

txOutRefToTxSkelOut' :: MonadBlockChainBalancing m => TxOutRef -> m TxSkelOut Source #

A default version of txOutRefToTxSkelOut where we both include the datum in the transaction if it was hashed in the TxOut, and allow further ADA adjustment in case changes in the output require it.

defineM :: (MonadBlockChainWithoutValidation m, ToHash a) => String -> m a -> m a Source #

Like define, but binds the result of a monadic computation instead

toTxSkelOutWithMinAda :: MonadBlockChainBalancing m => TxSkelOut -> m TxSkelOut Source #

This transforms an output into another output which contains the minimal required ada. If the previous quantity of ADA was sufficient, it remains unchanged. This can require a few iterations to converge, as the added ADA will increase the size of the UTXO which in turn might need more ADA.

toTxSkelWithMinAda :: MonadBlockChainBalancing m => TxSkel -> m TxSkel Source #

This goes through all the TxSkelOuts of the given skeleton and updates their ada value when requested by the user and required by the protocol parameters.

getTxSkelOutMinAda :: MonadBlockChainBalancing m => TxSkelOut -> m Integer Source #

Compute the required minimal ADA for a given output

interpretAndRunWith :: (forall m. Monad m => MockChainT m a -> m res) -> StagedMockChain a -> [res] Source #

Interprets the staged mockchain then runs the resulting computation with a custom function. This can be used, for example, to supply a custom InitialDistribution by providing runMockChainTFrom.

interpretAndRun :: StagedMockChain a -> [MockChainReturn a UtxoState] Source #

Same as interpretAndRunWith but using runMockChainT as the default way to run the computation.

runTweak :: Tweak InterpMockChain a -> TxSkel -> [MockChainReturn a TxSkel] Source #

Runs a Tweak from a given TxSkel within a mockchain

withTweak :: MonadModalBlockChain m => m x -> Tweak InterpMockChain a -> m x Source #

Apply a Tweak to the next transaction in the given trace. The order of arguments is reversed compared to somewhere and everywhere, because that enables an idiom like

do ...
   endpoint arguments `withTweak` someModification
   ...

where endpoint builds and validates a single transaction depending on the given arguments. Then withTweak says "I want to modify the transaction returned by this endpoint in the following way".

runUtxoSearch :: Monad m => UtxoSearch m a -> m [(TxOutRef, a)] Source #

Given a UTxO search, we can run it to obtain a list of UTxOs.

allUtxosSearch :: MonadBlockChain m => UtxoSearch m TxOut Source #

Search all currently known TxOutRefs together with their corresponding TxOut.

utxosAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxOut Source #

Search all TxOutRefs at a certain address, together with their TxOut.

utxosFromCardanoTxSearch :: Monad m => CardanoTx -> UtxoSearch m TxOut Source #

Search all TxOutRefs of a transaction, together with their TxOut.

txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxOut Source #

Search all TxOuts corresponding to given the list of TxOutRefs. Any TxOutRef that doesn't correspond to a known output will be filtered out.

filterWith :: Monad m => UtxoSearch m a -> (a -> m (Maybe b)) -> UtxoSearch m b Source #

Transform a UtxoSearch by applying a possibly partial monadic transformation on each output in the stream

filterWithPure :: Monad m => UtxoSearch m a -> (a -> Maybe b) -> UtxoSearch m b Source #

Same as filterWith but with a pure transformation

filterWithOptic :: (Is k An_AffineFold, Monad m) => UtxoSearch m a -> Optic' k is a b -> UtxoSearch m b Source #

Some as filterWithPure, but the transformation is taken from an optic

filterWithPred :: Monad m => UtxoSearch m a -> (a -> Bool) -> UtxoSearch m a Source #

Same as filterWithPure but the outputs are selected using a boolean predicate, and not modified

filterWithValuePred :: Monad m => UtxoSearch m TxOut -> (Value -> Bool) -> UtxoSearch m Value Source #

A specific version of filterWithPred where outputs must me of type TxOut and the predicate only relies on their value

filterWithOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value Source #

A specific version of filterWithValuePred when TxOuts are only kept when they contain only ADA

filterWithNotOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value Source #

A specific version of filterWithValuePred when TxOuts are only kept when they contain non-ADA assets

onlyValueOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Value ScriptHash) Source #

Search for UTxOs at a specific address, which only carry address and value information (no datum, staking credential, or reference script).

vanillaOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Lovelace ScriptHash) Source #

Same as onlyValueOutputsAtSearch, but also ensures the returned outputs do not contain non-ADA assets. These "vanilla" outputs are perfect candidates to be used for balancing transaction and attaching collaterals.

filterWithAlways :: Monad m => UtxoSearch m a -> (a -> b) -> UtxoSearch m b Source #

Some as filterWithPure but with a total transformation

scriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput s OutputDatum Value ScriptHash) Source #

Searches for all outputs belonging to a given script

referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput Credential OutputDatum Value ScriptHash) Source #

Searches for all outputs containing a given script as reference script

holdsInState :: ToAddress a => a -> UtxoState -> Value Source #

Total value accessible to what's pointed by the address.

utxoPayloadSet :: UtxoPayloadSet -> [UtxoPayload] Source #

List of UTxOs contained in this UtxoPayloadSet

utxoPayloadTxOutRef :: UtxoPayload -> TxOutRef Source #

The reference of this UTxO

utxoPayloadValue :: UtxoPayload -> Value Source #

The value stored in this UTxO

utxoPayloadSkelOutDatum :: UtxoPayload -> TxSkelOutDatum Source #

The datum stored in this UTxO

utxoPayloadReferenceScript :: UtxoPayload -> Maybe ScriptHash Source #

The optional reference script stored in this UTxO

combineMockChainT :: (forall a. m a -> m a -> m a) -> MockChainT m x -> MockChainT m x -> MockChainT m x Source #

Combines two MockChainT together

mapMockChainT :: (m (MockChainReturn a MockChainSt) -> n (MockChainReturn b MockChainSt)) -> MockChainT m a -> MockChainT n b Source #

Transforms a MockChainT into another one

runMockChainTFrom :: Monad m => InitialDistribution -> MockChainT m a -> m (MockChainReturn a UtxoState) Source #

Runs a MockChainT from an initial MockChainSt built from a given InitialDistribution. Returns a UtxoState.

runMockChainT :: Monad m => MockChainT m a -> m (MockChainReturn a UtxoState) Source #

Executes a MockChainT from the canonical initial state and environment.

testBool :: IsProp prop => Bool -> prop Source #

Turns a boolean into a prop

testAll :: IsProp prop => (a -> prop) -> [a] -> prop Source #

Ensures all elements of a list satisfy a given prop

testAny :: IsProp prop => (a -> prop) -> [a] -> prop Source #

Ensures at least one element of a list satisfy a given prop

assertionToMaybe :: Assertion -> IO (Maybe HUnitFailure) Source #

Catches a HUnit test failure, if the test fails.

assertSubset :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #

Asserts whether a set is a subset of another one, both given as lists.

assertSameSets :: (Show a, Eq a) => [a] -> [a] -> Assertion Source #

Asserts whether 2 sets are equal, both given as lists.

testToProp :: IsProp prop => Test a prop -> prop Source #

This takes a Test and transforms it into an actual test case in prop. This is the main function justifying the existence of Test. This runs the traces, ensures there is the right number of outcomes and, depending on the nature of these outcomes, either calls testFailureProp or testSuccessProp. It also uses the aliases emitted during the mockchain run to pretty print messages when applicable.

testCooked :: String -> Test a Assertion -> TestTree Source #

A convenience helper when using Assertion which allows to replace testCase with testCooked and thus avoid the use of testToProp. Sadly we cannot generalise it with type classes on prop to work for QuichCheck at GHC will never be able to instantiate prop.

mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop Source #

A test template which expects a success from a trace

mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #

A test template which expects a failure from a trace

withInitDist :: Test a prop -> InitialDistribution -> Test a prop Source #

Gives an initial distribution from which the trace will be run

withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop Source #

Gives some pretty options to render test messages

withJournalProp :: IsProp prop => Test a prop -> JournalProp prop -> Test a prop Source #

Appends a requirements over the emitted log, which will need to be satisfied both in case of success or failure of the run.

withSuccessProp :: IsProp prop => Test a prop -> SuccessProp a prop -> Test a prop Source #

Appends a requirement over the resulting value and state of the mockchain run which will need to be satisfied if the run is successful

withResultProp :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop Source #

Same as withSuccessProp but only considers the returning value of the run

withStateProp :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop Source #

Some as withSuccessProp but only considers the returning state of the run

withSizeProp :: IsProp prop => Test a prop -> SizeProp prop -> Test a prop Source #

Appends a requirement over the resulting number of outcomes of the run

withFailureProp :: IsProp prop => Test a prop -> FailureProp prop -> Test a prop Source #

Appends a requirement over the resulting value and state of the mockchain run which will need to be satisfied if the run is successful

withErrorProp :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop Source #

Same as withFailureProp but only considers the returning error of the run

isPhase1Failure :: IsProp prop => FailureProp prop Source #

A property to ensure a phase 1 failure

isPhase2Failure :: IsProp prop => FailureProp prop Source #

A property to ensure a phase 2 failure

isPhase1FailureWithMsg :: IsProp prop => String -> FailureProp prop Source #

Same as isPhase1Failure with an added predicate on the text error

isPhase2FailureWithMsg :: IsProp prop => String -> FailureProp prop Source #

Same as isPhase2Failure with an added predicate over the text error

isOfSize :: IsProp prop => Integer -> SizeProp prop Source #

Ensures the run has an exact given number of outcomes

isAtLeastOfSize :: IsProp prop => Integer -> SizeProp prop Source #

Ensures the run has a minimal number of outcomes

isAtMostOfSize :: IsProp prop => Integer -> SizeProp prop Source #

Ensures the run has a minimal number of outcomes

happened :: IsProp prop => String -> JournalProp prop Source #

Ensures a certain event has been emitted. This uses the constructor's name of the MockChainLogEntry by relying on show being lazy.

didNotHappen :: IsProp prop => String -> JournalProp prop Source #

Ensures a certain event has not been emitted. This uses the constructor's name of the MockChainLogEntry by relying on show being lazy.

isInWallets :: IsProp prop => [(Wallet, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop Source #

Ensures that the given wallets satisfy certain amount requirements over a list of given asset classes in the end of the run

isInWallet :: IsProp prop => (Wallet, AssetClass, Integer) -> SuccessProp a prop Source #

Ensures that a given wallet possesses exactly a certain amount of a given asset class in the end of the run

mustFailInPhase2Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #

A test template which expects a Phase 2 failure

mustFailInPhase2WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop Source #

A test template which expects a specific phase 2 error message

mustFailInPhase1Test :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop Source #

A test template which expects a Phase 1 failure

mustFailInPhase1WithMsgTest :: (IsProp prop, Show a) => String -> StagedMockChain a -> Test a prop Source #

A test template which expects a specific phase 1 error message

mustSucceedWithSizeTest :: IsProp prop => Integer -> StagedMockChain a -> Test a prop Source #

A test template which expects a certain number of successful outcomes

mustFailWithSizeTest :: (IsProp prop, Show a) => Integer -> StagedMockChain a -> Test a prop Source #

A test template which expects a certain number of unsuccessful outcomes