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 MockChainState Source #

The state used to run the simulation in Direct

Constructors

MockChainState 

Fields

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 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

The balancing wallet does not have enough funds

MCEMissingBalancingWallet String

The balancing wallet is required but missing

MCENoSuitableCollateral Integer Integer Value

No suitable collateral could be associated with a skeleton

MCEToCardanoError String ToCardanoError

Translating a skeleton element to its Cardano counterpart failed

MCEWrongReferenceScriptError TxOutRef ScriptHash (Maybe ScriptHash)

The required reference script is missing from a witness utxo

MCEUnknownOutRef TxOutRef

A UTxO is missing from the mockchain state

MCEPastSlot Slot Slot

A jump in time would result in a past slot

MCEUnsupportedFeature String

An attempt to invoke an unsupported feature has been made

FailWith String

Used to provide MonadFail instances.

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.

Minimal complete definition

getParams, utxosAt, txOutByRef, logEvent

Methods

getParams :: m Params Source #

Returns the emulator parameters, including protocol parameters

utxosAt :: ToAddress a => a -> m [(TxOutRef, TxSkelOut)] Source #

Returns a list of all UTxOs at a certain address.

txOutByRef :: TxOutRef -> m (Maybe TxSkelOut) 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 blockchain, 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, TxSkelOut)] Source #

Returns a list of all currently known outputs.

setParams :: Params -> m () Source #

Updates parameters

waitNSlots :: Integral i => i -> m Slot Source #

Wait a certain amount of slot. Throws MCEPastSlot if the input integer is negative. Returns the slot after jumping in time.

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.

setConstitutionScript :: ToVersioned Script s => s -> m () Source #

Sets the current script to act as the official constitution script

getConstitutionScript :: m (Maybe (Versioned Script)) Source #

Gets the current official constitution script

registerStakingCred :: ToCredential c => c -> Integer -> Integer -> m () Source #

Registers a staking credential with a given reward and deposit

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. It writes a MockChainBook, updates and reads from a MockChainState and throws possible MockChainErrors.

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 MockChainState (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 -> UtxoState -> 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

type StateProp prop = PrettyCookedOpts -> UtxoState -> prop Source #

Type of properties over the UtxoState

pattern MCLogSubmittedTxSkel :: TxSkel -> MockChainLogEntry Source #

Logging a Skeleton as it is submitted by the user.

pattern MCLogAdjustedTxSkel :: 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 -> Integer -> MockChainLogEntry Source #

Logging the successful validation of a new transaction, with its id and number of produced outputs.

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

currentSlot :: MonadBlockChainWithoutValidation m => m Slot Source #

Returns the current slot number

awaitSlot :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m Slot Source #

Wait for a certain slot, or throws an error if the slot is already past

(.==.) :: (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.

mockChainState0From :: MonadBlockChainBalancing m => InitialDistribution -> m MockChainState Source #

This creates the initial MockChainState from an initial distribution by submitting an initial transaction with the appropriate content. The genesis key hash has been taken from https://github.com/input-output-hk/cardano-node/blob/543b267d75d3d448e1940f9ec04b42bd01bbb16b/cardano-api/test/Test/Cardano/Api/Genesis.hs#L60

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 => Integer -> m (Integer, Integer) Source #

This computes the minimum and maximum possible fee a transaction can cost based on the current protocol parameters and its number of scripts.

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

Returns the closed ms interval corresponding to the current slot

utxosFromCardanoTx :: MonadBlockChainBalancing m => CardanoTx -> m [(TxOutRef, TxSkelOut)] 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.

unsafeTxOutByRef :: MonadBlockChainBalancing m => TxOutRef -> m TxSkelOut Source #

Same as txOutByRef but throws an error in case of missing utxo. Use this when you know the utxo is present, or when you want an error to be throw when it's not.

typedDatumFromTxOutRef :: (DatumConstrs 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

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

Return the slot that contains the given time. See slotToMSRange 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.

waitNMSFromSlotLowerBound :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m Slot Source #

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

waitNMSFromSlotUpperBound :: (MonadBlockChainWithoutValidation m, Integral i) => i -> 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

slotToMSRange :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m (POSIXTime, POSIXTime) Source #

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

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

and

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

and

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

txSkelInputValidators :: MonadBlockChainBalancing m => TxSkel -> m [Versioned Validator] Source #

Returns all validators which guard transaction inputs

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

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

lookupUtxos :: MonadBlockChainBalancing m => [TxOutRef] -> m (Map TxOutRef TxSkelOut) 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.

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

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

unsafeOutputDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m OutputDatum Source #

Same as outputDatumFromTxOutRef but throws an error when the utxo is missing

unsafeDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m TxSkelOutDatum Source #

Same as datumFromTxOutRef but throws an error when the utxo is missing

unsafeTypedDatumFromTxOutRef :: (DatumConstrs a, MonadBlockChainBalancing m) => TxOutRef -> m (Maybe a) Source #

Like typedDatumFromTxOutRef but throws an error when the utxo is missing

unsafeValueFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m Value Source #

Same as valueFromTxOutRef but throws an error when the utxo is missing

txSkelAllScripts :: MonadBlockChainBalancing m => TxSkel -> m [Versioned Script] Source #

Returns all scripts involved in this TxSkel

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] 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 TxSkelOut Source #

Search all currently known TxOutRefs together with their corresponding TxOut.

utxosOwnedBySearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut Source #

Search all TxOutRefs at a certain address, together with their TxOut. This will attempt to cast the owner of the TxSkelOut to addr so be careful how you use it.

utxosFromCardanoTxSearch :: MonadBlockChainBalancing m => CardanoTx -> UtxoSearch m TxSkelOut Source #

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

txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxSkelOut 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 TxSkelOut -> (Value -> Bool) -> UtxoSearch m TxSkelOut Source #

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

filterWithOnlyAda :: Monad m => UtxoSearch m TxSkelOut -> UtxoSearch m TxSkelOut Source #

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

filterWithNotOnlyAda :: Monad m => UtxoSearch m TxSkelOut -> UtxoSearch m TxSkelOut Source #

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

onlyValueOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut 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 TxSkelOut 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

referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m TxSkelOut Source #

Searches for all outputs containing a given script as reference script

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

Same as filterWithPure but inverses the predicate

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

utxoPayloadDatum :: UtxoPayload -> Maybe (DatumContent, Bool) Source #

The optional datum stored in this UTxO and whether it is hashed (True) or inline (False)

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

mcrValue :: MockChainReturn a -> Either MockChainError a Source #

The returned value of the run

mcrOutputs :: MockChainReturn a -> Map TxOutRef (TxSkelOut, Bool) Source #

All the outputs used throughout the run

mcrUtxoState :: MockChainReturn a -> UtxoState Source #

The resulting UtxoState of the run

mcrJournal :: MockChainReturn a -> [MockChainLogEntry] Source #

The log entries emitted during the run

mcrAliases :: MockChainReturn a -> Map BuiltinByteString String Source #

The aliases defined during the run

runMockChainT :: Monad m => MockChainT m a -> m (MockChainReturn a) 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, Show a) => 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 :: Show a => 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 => 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.

withStateProp :: IsProp prop => Test a prop -> StateProp prop -> Test a prop Source #

Appends a requirements over the resulting UtxoState, 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

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 => StagedMockChain a -> Test a prop Source #

A test template which expects a Phase 2 failure

mustFailInPhase2WithMsgTest :: IsProp prop => String -> StagedMockChain a -> Test a prop Source #

A test template which expects a specific phase 2 error message

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

A test template which expects a Phase 1 failure

mustFailInPhase1WithMsgTest :: IsProp prop => 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 => Integer -> StagedMockChain a -> Test a prop Source #

A test template which expects a certain number of unsuccessful outcomes