cooked-validators-4.0.0
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

Constructors

Test 

Fields

data MockChainSt Source #

Slightly more concrete version of UtxoState, used to actually run the simulation.

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.

Instances

Instances details
Semigroup UtxoState Source # 
Instance details

Defined in Cooked.MockChain.UtxoState

PrettyCooked UtxoState Source #

Pretty print a UtxoState. Print the known wallets first, then unknown pubkeys, then scripts.

Instance details

Defined in Cooked.Pretty.Cooked

Eq UtxoState Source # 
Instance details

Defined in Cooked.MockChain.UtxoState

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

Defined in Cooked.Pretty.Cooked

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

Defined in Cooked.Pretty.Cooked

data MockChainError Source #

The errors that can be produced by the MockChainT monad

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

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

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

Contains methods needed for 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.

validatorFromHash :: ValidatorHash -> m (Maybe (Versioned Validator)) 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

(MonadTrans t, MonadBlockChainBalancing m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainBalancing (AsTrans t 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

class MonadBlockChainBalancing m => MonadBlockChainWithoutValidation m where Source #

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.

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

(MonadTrans t, MonadBlockChainWithoutValidation m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainWithoutValidation (AsTrans t 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

class MonadBlockChainWithoutValidation m => MonadBlockChain m where Source #

The main abstraction of the blockchain.

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. In MockChainT, this means:

  • deletes the consumed outputs from mcstIndex
  • adds the produced outputs to msctIndex
  • deletes the consumed datums from mcstDatums
  • adds the produced datums to mcstDatums
  • adds the validators on outputs to the mcstValidators.

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

newtype MockChainT m a Source #

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

Monad m => MonadWriter [MockChainLogEntry] (MockChainT m) Source # 
Instance details

Defined in Cooked.MockChain.Direct

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

pattern MCLogSubmittedTxSkel :: SkelContext -> TxSkel -> MockChainLogEntry Source #

Logging a Skeleton as it is submitted by the user.

pattern MCLogAdjustedTxSkel :: SkelContext -> 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 :: Redeemer -> TxOutRef -> ScriptHash -> MockChainLogEntry Source #

Logging the automatic addition of a reference script

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 => prop -> prop -> prop infixr 3 Source #

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

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

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, Fee, Maybe (Collaterals, 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 (Fee, Fee) 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 #

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

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 #

Try 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 validatorFromHash 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 #

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

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

All validators which protect transaction inputs

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

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

txSkelHashedData :: MonadBlockChainBalancing m => TxSkel -> m (Map DatumHash Datum) Source #

Looks up and resolves the hashed datums on UTxOs the transaction consumes or references, which will be needed by the transaction body.

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

Looks up the data on UTxOs the transaction consumes and returns their hashes. This corresponds to the keys of what should be removed from the stored datums in our mockchain. There can be duplicates, which is expected.

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.

toTxSkelOutWithMinAda :: Params -> TxSkelOut -> Either GenerateTxError TxSkelOut Source #

This transforms an output into another output which necessarily contains at least the minimal required ada. If the previous quantity of ada was sufficient, it remains unchanged. This requires an iterative process, as adding ada into an output can potentially increase its size and thus make it require more minimal ada (although this remains to be witnessed in practice). This approach was inspired by https://github.com/input-output-hk/plutus-apps/blob/8706e6c7c525b4973a7b6d2ed7c9d0ef9cd4ef46/plutus-ledger/src/Ledger/Index.hs#L124

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

This transforms a skeleton by replacing all its TxSkelOut by their updated variants with their minimal amount of required ada. Any error raised in the transformation process is transformed into an MCEGenerationError

getTxSkelOutMinAda :: Params -> TxSkelOut -> Either GenerateTxError Integer Source #

This provides the minimum amount of ada required in a given TxSkelOut. As we need to transform our output into a Cardano output to compute this value, this function can fail.

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.

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

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

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.

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 TxInfo-TxOut.

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

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

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

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

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

Search all TxInfo-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 failing monadic "lookup" on every output.

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

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

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

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

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

A vanilla output only possesses an ada-only value and does not have a staking credential, a datum or a reference script. A vanilla UTxO is a perfect candidate to be used for fee, balancing or collateral.

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

holdsInState :: Address -> UtxoState -> Value Source #

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

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

runMockChainTRaw :: Monad m => MockChainSt -> MockChainT m a -> m (MockChainReturn a MockChainSt) Source #

Executes a MockChainT from some initial state; does not convert the MockChainSt into a UtxoState.

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

Executes a MockChainT from an initial state set up with the given initial value distribution. Similar to runMockChainT, uses the default environment. Returns a UtxoState instead of a MockChainSt. If you need the later, use runMockChainTRaw

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

Executes a MockChainT from the canonical initial state and environment. The canonical environment uses the default SlotConfig and Cooked.Wallet.wallet 1 as the sole wallet signing transactions.

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

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

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.

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

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

A test template with no particular requirement on the trace

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

Appending an initial distribution to a test

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

Appending printing options to a test

withJournalPred :: IsProp prop => Test a prop -> ([MockChainLogEntry] -> prop) -> Test a prop Source #

Appending a predicate over the log to a test. This will be used both in case of success or failure of the trace.

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

Appending a predicate over the return value and state, which will be used in case of success of the trace.

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

Appending a predicate over the return value, which will be used in case of success of the trace.

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

Appending a predicate over the return state, which will be used in case of success of the trace.

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

Appending a predicate over an error which uses the printing options, which will be used in case of failure of the trace.

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

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

This takes a test and transforms it into an actual test case in prop.

testSucceeds :: IsProp prop => StagedMockChain a -> prop Source #

Ensure that all results produced by the staged mockchain succeed, starting from the default initial distribution

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

Ensure that all results produced by the staged mockchain fail

isPhase1Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #

A property to ensure a phase 1 failure

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

A test that succeeds when the trace results in a phase 1 failure

isPhase2Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop Source #

A property to ensure a phase 2 failure

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

A test that succeeds when the trace results in a phase 2 failure

isPhase1FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #

Same as isPhase1Failure with an added predicate on the text error

testFailsInPhase1WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #

Same as testFailsInPhase1 with an added predicate on the text error

isPhase2FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop Source #

Same as isPhase2Failure with an added predicate over the text error

testFailsInPhase2WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop Source #

Same as testFailsInPhase2 with an added predicate over the text error