Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module centralizes everything related to our mockchain, while hiding elements related to logs and inner state.
Synopsis
- data Test a prop = Test {
- testTrace :: StagedMockChain a
- testInitDist :: InitialDistribution
- testErrorProp :: PrettyCookedOpts -> MockChainError -> [MockChainLogEntry] -> prop
- testResultProp :: PrettyCookedOpts -> a -> UtxoState -> [MockChainLogEntry] -> prop
- testPrettyOpts :: PrettyCookedOpts
- type MockChain = MockChainT Identity
- data MockChainSt = MockChainSt {}
- type UtxoSearch m a = ListT m (TxOutRef, a)
- data UtxoState
- data MockChainError
- = MCEValidationError ValidationPhase ValidationError
- | MCEUnbalanceable Wallet Value TxSkel
- | MCENoSuitableCollateral Integer Integer Value
- | MCEGenerationError GenerateTxError
- | MCEUnknownOutRefError String TxOutRef
- | MCEUnknownValidator String ValidatorHash
- | MCEUnknownDatum String DatumHash
- | FailWith String
- class (MonadFail m, MonadError MockChainError m) => MonadBlockChainBalancing m where
- getParams :: m Params
- utxosAt :: Address -> m [(TxOutRef, TxOut)]
- datumFromHash :: DatumHash -> m (Maybe Datum)
- validatorFromHash :: ValidatorHash -> m (Maybe (Versioned Validator))
- txOutByRef :: TxOutRef -> m (Maybe TxOut)
- class MonadBlockChainBalancing m => MonadBlockChainWithoutValidation m where
- class MonadBlockChainWithoutValidation m => MonadBlockChain m where
- validateTxSkel :: TxSkel -> m CardanoTx
- newtype AsTrans t (m :: Type -> Type) a = AsTrans {
- getTrans :: t m a
- newtype MockChainT m a = MockChainT {
- unMockChain :: StateT MockChainSt (ExceptT MockChainError (WriterT [MockChainLogEntry] m)) a
- type MonadModalBlockChain m = (MonadBlockChain m, MonadModal m, Modification m ~ UntypedTweak InterpMockChain)
- class IsProp prop where
- testCounterexample :: String -> prop -> prop
- testConjoin :: [prop] -> prop
- testDisjoin :: [prop] -> prop
- testFailure :: prop
- testSuccess :: prop
- testFailureMsg :: String -> prop
- pattern MCLogSubmittedTxSkel :: SkelContext -> TxSkel -> MockChainLogEntry
- pattern MCLogAdjustedTxSkel :: SkelContext -> TxSkel -> Integer -> Maybe (Set TxOutRef, Wallet) -> MockChainLogEntry
- pattern MCLogNewTx :: TxId -> MockChainLogEntry
- pattern MCLogDiscardedUtxos :: Integer -> String -> MockChainLogEntry
- pattern MCLogUnusedCollaterals :: Either Wallet (Set TxOutRef) -> MockChainLogEntry
- pattern MCLogAddedReferenceScript :: Redeemer -> TxOutRef -> ScriptHash -> MockChainLogEntry
- forAll :: Show a => Gen a -> (a -> Property) -> Property
- (.&&.) :: IsProp prop => prop -> prop -> prop
- (.||.) :: IsProp prop => prop -> prop -> prop
- (.==.) :: (IsProp prop, Eq a) => a -> a -> prop
- everywhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- somewhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- mockChainSt0From :: InitialDistribution -> MockChainSt
- balanceTxSkel :: MonadBlockChainBalancing m => TxSkel -> m (TxSkel, Fee, Maybe (Collaterals, Wallet))
- getMinAndMaxFee :: MonadBlockChainBalancing m => m (Fee, Fee)
- estimateTxSkelFee :: MonadBlockChainBalancing m => TxSkel -> Fee -> Maybe (Collaterals, Wallet) -> m Fee
- currentTime :: MonadBlockChainWithoutValidation m => m (POSIXTime, POSIXTime)
- waitNSlots :: MonadBlockChainWithoutValidation m => Integer -> m Slot
- utxosFromCardanoTx :: CardanoTx -> [(TxOutRef, TxOut)]
- typedDatumFromTxOutRef :: (FromData a, MonadBlockChainWithoutValidation m) => TxOutRef -> m (Maybe a)
- valueFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe Value)
- outputDatumFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe OutputDatum)
- datumFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe Datum)
- resolveDatum :: (IsAbstractOutput out, ToOutputDatum (DatumType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (OwnerType out) Datum (ValueType out) (ReferenceScriptType out)))
- resolveTypedDatum :: (IsAbstractOutput out, ToOutputDatum (DatumType out), MonadBlockChainBalancing m, FromData a) => out -> m (Maybe (ConcreteOutput (OwnerType out) a (ValueType out) (ReferenceScriptType out)))
- resolveValidator :: (IsAbstractOutput out, ToCredential (OwnerType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (Versioned Validator) (DatumType out) (ValueType out) (ReferenceScriptType out)))
- resolveReferenceScript :: (IsAbstractOutput out, ToScriptHash (ReferenceScriptType out), MonadBlockChainBalancing m) => out -> m (Maybe (ConcreteOutput (OwnerType out) (DatumType out) (ValueType out) (Versioned Validator)))
- getEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot
- awaitEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot
- awaitDurationFromLowerBound :: MonadBlockChainWithoutValidation m => Integer -> m Slot
- awaitDurationFromUpperBound :: MonadBlockChainWithoutValidation m => Integer -> m Slot
- slotRangeBefore :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange
- slotRangeAfter :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange
- slotToTimeInterval :: MonadBlockChainWithoutValidation m => Slot -> m (POSIXTime, POSIXTime)
- txSkelInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut)
- txSkelReferenceInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut)
- txSkelInputValidators :: MonadBlockChainBalancing m => TxSkel -> m (Map ValidatorHash (Versioned Validator))
- txSkelInputValue :: MonadBlockChainBalancing m => TxSkel -> m Value
- txSkelHashedData :: MonadBlockChainBalancing m => TxSkel -> m (Map DatumHash Datum)
- txSkelInputDataAsHashes :: MonadBlockChainBalancing m => TxSkel -> m [DatumHash]
- lookupUtxos :: MonadBlockChainBalancing m => [TxOutRef] -> m (Map TxOutRef TxOut)
- validateTxSkel' :: MonadBlockChain m => TxSkel -> m [TxOutRef]
- validateTxSkel_ :: MonadBlockChain m => TxSkel -> m ()
- txSkelProposalsDeposit :: MonadBlockChainBalancing m => TxSkel -> m Lovelace
- govActionDeposit :: MonadBlockChainBalancing m => m Lovelace
- toTxSkelOutWithMinAda :: Params -> TxSkelOut -> Either GenerateTxError TxSkelOut
- toTxSkelWithMinAda :: MonadBlockChainBalancing m => TxSkel -> m TxSkel
- getTxSkelOutMinAda :: Params -> TxSkelOut -> Either GenerateTxError Integer
- interpretAndRunWith :: (forall m. Monad m => MockChainT m a -> m res) -> StagedMockChain a -> [res]
- interpretAndRun :: StagedMockChain a -> [MockChainReturn a UtxoState]
- runTweakFrom :: MockChainSt -> Tweak InterpMockChain a -> TxSkel -> [MockChainReturn a TxSkel]
- runTweak :: Tweak InterpMockChain a -> TxSkel -> [MockChainReturn a TxSkel]
- withTweak :: MonadModalBlockChain m => m x -> Tweak InterpMockChain a -> m x
- there :: MonadModalBlockChain m => Integer -> Tweak InterpMockChain b -> m a -> m a
- runUtxoSearch :: Monad m => UtxoSearch m a -> m [(TxOutRef, a)]
- allUtxosSearch :: MonadBlockChain m => UtxoSearch m TxOut
- utxosAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxOut
- utxosFromCardanoTxSearch :: Monad m => CardanoTx -> UtxoSearch m TxOut
- txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxOut
- filterWith :: Monad m => UtxoSearch m a -> (a -> m (Maybe b)) -> UtxoSearch m b
- filterWithPure :: Monad m => UtxoSearch m a -> (a -> Maybe b) -> UtxoSearch m b
- filterWithOptic :: (Is k An_AffineFold, Monad m) => UtxoSearch m a -> Optic' k is a b -> UtxoSearch m b
- filterWithPred :: Monad m => UtxoSearch m a -> (a -> Bool) -> UtxoSearch m a
- filterWithValuePred :: Monad m => UtxoSearch m TxOut -> (Value -> Bool) -> UtxoSearch m Value
- filterWithOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value
- filterWithNotOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value
- onlyValueOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Value ScriptHash)
- vanillaOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m (ConcreteOutput Credential () Ada ScriptHash)
- filterWithAlways :: Monad m => UtxoSearch m a -> (a -> b) -> UtxoSearch m b
- scriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput s OutputDatum Value ScriptHash)
- referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput Credential OutputDatum Value ScriptHash)
- holdsInState :: Address -> UtxoState -> Value
- utxoPayloadSet :: UtxoPayloadSet -> [UtxoPayload]
- utxoPayloadTxOutRef :: UtxoPayload -> TxOutRef
- utxoPayloadValue :: UtxoPayload -> Value
- utxoPayloadSkelOutDatum :: UtxoPayload -> TxSkelOutDatum
- utxoPayloadReferenceScript :: UtxoPayload -> Maybe ScriptHash
- combineMockChainT :: Monad m => (forall a. m a -> m a -> m a) -> MockChainT m x -> MockChainT m x -> MockChainT m x
- mapMockChainT :: (m (MockChainReturn a MockChainSt) -> n (MockChainReturn b MockChainSt)) -> MockChainT m a -> MockChainT n b
- runMockChainTRaw :: Monad m => MockChainSt -> MockChainT m a -> m (MockChainReturn a MockChainSt)
- runMockChainTFrom :: Monad m => InitialDistribution -> MockChainT m a -> m (MockChainReturn a UtxoState)
- runMockChainT :: Monad m => MockChainT m a -> m (MockChainReturn a UtxoState)
- runMockChainRaw :: MockChain a -> MockChainReturn a MockChainSt
- runMockChainFrom :: InitialDistribution -> MockChain a -> MockChainReturn a UtxoState
- runMockChain :: MockChain a -> MockChainReturn a UtxoState
- testBool :: IsProp prop => Bool -> prop
- testAll :: IsProp prop => (a -> prop) -> [a] -> prop
- assertionToMaybe :: Assertion -> IO (Maybe HUnitFailure)
- assertSubset :: (Show a, Eq a) => [a] -> [a] -> Assertion
- assertSameSets :: (Show a, Eq a) => [a] -> [a] -> Assertion
- mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailTest :: (IsProp prop, Show a) => StagedMockChain a -> Test a prop
- emptyTest :: IsProp prop => StagedMockChain a -> Test a prop
- withInitDist :: IsProp prop => Test a prop -> InitialDistribution -> Test a prop
- withPrettyOpts :: IsProp prop => Test a prop -> PrettyCookedOpts -> Test a prop
- withJournalPred :: IsProp prop => Test a prop -> ([MockChainLogEntry] -> prop) -> Test a prop
- withValueAndStatePred :: IsProp prop => Test a prop -> (a -> UtxoState -> prop) -> Test a prop
- withValuePred :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop
- withStatePred :: IsProp prop => Test a prop -> (UtxoState -> prop) -> Test a prop
- withPrettyAndErrorPred :: IsProp prop => Test a prop -> (PrettyCookedOpts -> MockChainError -> prop) -> Test a prop
- withErrorPred :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop
- testToProp :: IsProp prop => Test a prop -> prop
- testSucceeds :: IsProp prop => StagedMockChain a -> prop
- testFails :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase1Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase1 :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase2Failure :: IsProp prop => PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase2 :: (IsProp prop, Show a) => StagedMockChain a -> prop
- isPhase1FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase1WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop
- isPhase2FailureWithMsg :: IsProp prop => (String -> Bool) -> PrettyCookedOpts -> MockChainError -> prop
- testFailsInPhase2WithMsg :: (IsProp prop, Show a) => (String -> Bool) -> StagedMockChain a -> prop
Documentation
Data structure to test a mockchain trace
Test | |
|
type MockChain = MockChainT Identity Source #
data MockChainSt Source #
Slightly more concrete version of UtxoState
, used to actually run the
simulation.
Instances
Show MockChainSt Source # | |
Defined in Cooked.MockChain.MockChainSt showsPrec :: Int -> MockChainSt -> ShowS # show :: MockChainSt -> String # showList :: [MockChainSt] -> ShowS # | |
Default MockChainSt Source # | |
Defined in Cooked.MockChain.MockChainSt def :: MockChainSt # | |
Eq MockChainSt Source # | |
Defined in Cooked.MockChain.MockChainSt (==) :: MockChainSt -> MockChainSt -> Bool # (/=) :: MockChainSt -> MockChainSt -> Bool # | |
Monad m => MonadState MockChainSt (MockChainT m) Source # | |
Defined in Cooked.MockChain.Direct get :: MockChainT m MockChainSt # put :: MockChainSt -> MockChainT m () # state :: (MockChainSt -> (a, MockChainSt)) -> MockChainT m a # |
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.
A description of who owns what in a blockchain. Owners are addresses and
they each own a UtxoPayloadSet
.
Instances
Semigroup UtxoState Source # | |
PrettyCooked UtxoState Source # | Pretty print a |
Defined in Cooked.Pretty.Cooked prettyCooked :: UtxoState -> DocCooked Source # prettyCookedOpt :: PrettyCookedOpts -> UtxoState -> DocCooked Source # | |
Eq UtxoState Source # | |
Show a => PrettyCooked (MockChainReturn a UtxoState) Source # | |
Defined in Cooked.Pretty.Cooked | |
Show a => PrettyCooked (a, UtxoState) Source # | |
Defined in Cooked.Pretty.Cooked prettyCooked :: (a, UtxoState) -> DocCooked Source # prettyCookedOpt :: PrettyCookedOpts -> (a, UtxoState) -> DocCooked Source # |
data MockChainError Source #
The errors that can be produced by the MockChainT
monad
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 |
MCEUnknownDatum String DatumHash | Same as |
FailWith String | Used to provide |
Instances
class (MonadFail m, MonadError MockChainError m) => MonadBlockChainBalancing m where Source #
Contains methods needed for balancing.
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
class MonadBlockChainBalancing m => MonadBlockChainWithoutValidation m where Source #
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
MonadBlockChainWithoutValidation StagedMockChain Source # | |
Defined in Cooked.MockChain.Staged allUtxos :: StagedMockChain [(TxOutRef, TxOut)] Source # setParams :: Params -> StagedMockChain () Source # | |
Monad m => MonadBlockChainWithoutValidation (MockChainT m) Source # | |
Defined in Cooked.MockChain.Direct allUtxos :: MockChainT m [(TxOutRef, TxOut)] Source # setParams :: Params -> MockChainT m () Source # currentSlot :: MockChainT m Slot Source # | |
MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (ListT m) Source # | |
(MonadTrans t, MonadBlockChainWithoutValidation m, Monad (t m), MonadError MockChainError (AsTrans t m)) => MonadBlockChainWithoutValidation (AsTrans t m) Source # | |
MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (ReaderT r m) Source # | |
MonadBlockChainWithoutValidation m => MonadBlockChainWithoutValidation (StateT s m) Source # | |
(Monoid w, MonadBlockChainWithoutValidation m) => MonadBlockChainWithoutValidation (WriterT w m) Source # | |
class MonadBlockChainWithoutValidation m => MonadBlockChain m where Source #
The main abstraction of the blockchain.
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
.
Instances
MonadBlockChain StagedMockChain Source # | |
Defined in Cooked.MockChain.Staged | |
Monad m => MonadBlockChain (MockChainT m) Source # | |
Defined in Cooked.MockChain.Direct validateTxSkel :: TxSkel -> MockChainT m CardanoTx Source # | |
MonadBlockChain m => MonadBlockChain (ListT m) Source # | |
Defined in Cooked.MockChain.BlockChain | |
(MonadTrans t, MonadBlockChain m, MonadBlockChainWithoutValidation (AsTrans t m)) => MonadBlockChain (AsTrans t m) Source # | |
Defined in Cooked.MockChain.BlockChain | |
MonadBlockChain m => MonadBlockChain (ReaderT r m) Source # | |
Defined in Cooked.MockChain.BlockChain | |
MonadBlockChain m => MonadBlockChain (StateT s m) Source # | |
Defined in Cooked.MockChain.BlockChain | |
(Monoid w, MonadBlockChain m) => MonadBlockChain (WriterT w m) Source # | |
Defined in Cooked.MockChain.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.
Instances
newtype MockChainT m a Source #
MockChainT | |
|
Instances
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 Tweak
s
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
.
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
Instances
IsProp Property Source # | QuickCheck instance of |
Defined in Cooked.MockChain.Testing testCounterexample :: String -> Property -> Property Source # testConjoin :: [Property] -> Property Source # testDisjoin :: [Property] -> Property Source # testFailure :: Property Source # testSuccess :: Property Source # testFailureMsg :: String -> Property Source # | |
IsProp Assertion Source # | HUnit instance of |
Defined in Cooked.MockChain.Testing testCounterexample :: String -> Assertion -> Assertion Source # testConjoin :: [Assertion] -> Assertion Source # testDisjoin :: [Assertion] -> Assertion Source # testFailure :: Assertion Source # testSuccess :: Assertion Source # testFailureMsg :: String -> Assertion Source # |
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
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
estimateTxSkelFee :: MonadBlockChainBalancing m => TxSkel -> Fee -> Maybe (Collaterals, Wallet) -> m Fee Source #
This function is essentially a copy of https://github.com/input-output-hk/plutus-apps/blob/d4255f05477fd8477ee9673e850ebb9ebb8c9657/plutus-ledger/src/Ledger/Fee.hs#L19
currentTime :: MonadBlockChainWithoutValidation m => m (POSIXTime, POSIXTime) Source #
Returns the closed ms interval corresponding to the current slot
waitNSlots :: MonadBlockChainWithoutValidation m => Integer -> m Slot Source #
Moves n slots fowards
typedDatumFromTxOutRef :: (FromData a, MonadBlockChainWithoutValidation m) => TxOutRef -> m (Maybe a) Source #
valueFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe Value) Source #
outputDatumFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe OutputDatum) Source #
datumFromTxOutRef :: MonadBlockChainWithoutValidation m => TxOutRef -> m (Maybe Datum) Source #
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
txSkelInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut) Source #
txSkelReferenceInputUtxos :: MonadBlockChainBalancing m => TxSkel -> m (Map TxOutRef TxOut) Source #
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 TxOutRef
s 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
.
interpretAndRun :: StagedMockChain a -> [MockChainReturn a UtxoState] Source #
runTweakFrom :: MockChainSt -> 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 TxOutRef
s together with their corresponding
TxInfo
-TxOut
.
utxosAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxOut Source #
Search all TxOutRef
s at a certain address, together with their
TxInfo
-TxOut
.
utxosFromCardanoTxSearch :: Monad m => CardanoTx -> UtxoSearch m TxOut Source #
Search all TxOutRef
s of a transaction, together with their
TxInfo
-TxOut
.
txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxOut Source #
Search all TxInfo
-TxOut
s corresponding to given the list of
TxOutRef
s. 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 #
filterWithOptic :: (Is k An_AffineFold, Monad m) => UtxoSearch m a -> Optic' k is a b -> UtxoSearch m b Source #
filterWithPred :: Monad m => UtxoSearch m a -> (a -> Bool) -> UtxoSearch m a Source #
filterWithValuePred :: Monad m => UtxoSearch m TxOut -> (Value -> Bool) -> UtxoSearch m Value Source #
filterWithOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value Source #
filterWithNotOnlyAda :: Monad m => UtxoSearch m TxOut -> UtxoSearch m Value 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 #
scriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput s OutputDatum Value ScriptHash) Source #
referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m (ConcreteOutput Credential OutputDatum Value ScriptHash) Source #
holdsInState :: Address -> UtxoState -> Value Source #
Total value accessible to what's pointed by the address.
utxoPayloadSet :: UtxoPayloadSet -> [UtxoPayload] Source #
utxoPayloadValue :: UtxoPayload -> Value Source #
combineMockChainT :: Monad m => (forall a. m a -> m a -> m a) -> MockChainT m x -> MockChainT m x -> MockChainT m x Source #
mapMockChainT :: (m (MockChainReturn a MockChainSt) -> n (MockChainReturn b MockChainSt)) -> MockChainT m a -> MockChainT n b 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.
runMockChainRaw :: MockChain a -> MockChainReturn a MockChainSt Source #
See runMockChainTRaw
runMockChainFrom :: InitialDistribution -> MockChain a -> MockChainReturn a UtxoState Source #
runMockChain :: MockChain a -> MockChainReturn a UtxoState Source #
See runMockChainT
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