Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Cooked.MockChain
Description
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
- testSizeProp :: SizeProp prop
- testFailureProp :: FailureProp prop
- testSuccessProp :: SuccessProp a prop
- testPrettyOpts :: PrettyCookedOpts
- type MockChain = MockChainT Identity
- data MockChainState = MockChainState {}
- type UtxoSearch m a = ListT m (TxOutRef, a)
- data MockChainError
- = MCEValidationError ValidationPhase ValidationError
- | MCEUnbalanceable Wallet Value
- | MCEMissingBalancingWallet String
- | MCENoSuitableCollateral Integer Integer Value
- | MCEToCardanoError String ToCardanoError
- | MCEWrongReferenceScriptError TxOutRef ScriptHash (Maybe ScriptHash)
- | MCEUnknownOutRef TxOutRef
- | MCEPastSlot Slot Slot
- | MCEUnsupportedFeature String
- | FailWith String
- class (MonadFail m, MonadError MockChainError m) => MonadBlockChainBalancing m where
- class MonadBlockChainBalancing m => MonadBlockChainWithoutValidation m where
- allUtxos :: m [(TxOutRef, TxSkelOut)]
- setParams :: Params -> m ()
- waitNSlots :: Integral i => i -> m Slot
- define :: ToHash a => String -> a -> m a
- setConstitutionScript :: ToVersioned Script s => s -> m ()
- getConstitutionScript :: m (Maybe (Versioned Script))
- registerStakingCred :: ToCredential c => c -> Integer -> Integer -> m ()
- class MonadBlockChainWithoutValidation m => MonadBlockChain m where
- validateTxSkel :: TxSkel -> m CardanoTx
- newtype AsTrans t (m :: Type -> Type) a = AsTrans {
- getTrans :: t m a
- data MockChainBook = MockChainBook {}
- 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
- newtype MockChainT m a = MockChainT {}
- type FailureProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> MockChainError -> UtxoState -> prop
- type SuccessProp a prop = PrettyCookedOpts -> [MockChainLogEntry] -> a -> UtxoState -> prop
- type SizeProp prop = Integer -> prop
- type JournalProp prop = PrettyCookedOpts -> [MockChainLogEntry] -> prop
- type StateProp prop = PrettyCookedOpts -> UtxoState -> prop
- pattern MCLogSubmittedTxSkel :: TxSkel -> MockChainLogEntry
- pattern MCLogAdjustedTxSkel :: TxSkel -> Integer -> Maybe (Set TxOutRef, Wallet) -> MockChainLogEntry
- pattern MCLogNewTx :: TxId -> Integer -> MockChainLogEntry
- pattern MCLogDiscardedUtxos :: Integer -> String -> MockChainLogEntry
- pattern MCLogUnusedCollaterals :: Either Wallet (Set TxOutRef) -> MockChainLogEntry
- pattern MCLogAddedReferenceScript :: TxSkelRedeemer -> TxOutRef -> ScriptHash -> MockChainLogEntry
- pattern MCLogAdjustedTxSkelOut :: TxSkelOut -> Lovelace -> MockChainLogEntry
- (.&&.) :: IsProp prop => prop -> prop -> prop
- (.||.) :: IsProp prop => prop -> prop -> prop
- forAll :: Show a => Gen a -> (a -> Property) -> Property
- currentSlot :: MonadBlockChainWithoutValidation m => m Slot
- awaitSlot :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m Slot
- (.==.) :: (IsProp prop, Eq a) => a -> a -> prop
- there :: MonadModalBlockChain m => Integer -> Tweak InterpMockChain b -> m a -> m a
- everywhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- somewhere :: MonadModalBlockChain m => Tweak InterpMockChain b -> m a -> m a
- mockChainState0From :: MonadBlockChainBalancing m => InitialDistribution -> m MockChainState
- balanceTxSkel :: MonadBlockChainBalancing m => TxSkel -> m (TxSkel, Integer, Maybe (Set TxOutRef, Wallet))
- getMinAndMaxFee :: MonadBlockChainBalancing m => Integer -> m (Integer, Integer)
- estimateTxSkelFee :: MonadBlockChainBalancing m => TxSkel -> Integer -> Maybe (Set TxOutRef, Wallet) -> m Integer
- currentMSRange :: MonadBlockChainWithoutValidation m => m (POSIXTime, POSIXTime)
- utxosFromCardanoTx :: MonadBlockChainBalancing m => CardanoTx -> m [(TxOutRef, TxSkelOut)]
- unsafeTxOutByRef :: MonadBlockChainBalancing m => TxOutRef -> m TxSkelOut
- typedDatumFromTxOutRef :: (DatumConstrs a, MonadBlockChainBalancing m) => TxOutRef -> m (Maybe a)
- valueFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe Value)
- outputDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe OutputDatum)
- datumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe TxSkelOutDatum)
- getEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot
- awaitEnclosingSlot :: MonadBlockChainWithoutValidation m => POSIXTime -> m Slot
- waitNMSFromSlotLowerBound :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m Slot
- waitNMSFromSlotUpperBound :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m Slot
- slotRangeBefore :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange
- slotRangeAfter :: MonadBlockChainWithoutValidation m => POSIXTime -> m SlotRange
- slotToMSRange :: (MonadBlockChainWithoutValidation m, Integral i) => i -> m (POSIXTime, POSIXTime)
- txSkelInputValidators :: MonadBlockChainBalancing m => TxSkel -> m [Versioned Validator]
- txSkelInputValue :: MonadBlockChainBalancing m => TxSkel -> m Value
- lookupUtxos :: MonadBlockChainBalancing m => [TxOutRef] -> m (Map TxOutRef TxSkelOut)
- validateTxSkel' :: MonadBlockChain m => TxSkel -> m [TxOutRef]
- validateTxSkel_ :: MonadBlockChain m => TxSkel -> m ()
- txSkelProposalsDeposit :: MonadBlockChainBalancing m => TxSkel -> m Lovelace
- govActionDeposit :: MonadBlockChainBalancing m => m Lovelace
- defineM :: (MonadBlockChainWithoutValidation m, ToHash a) => String -> m a -> m a
- unsafeOutputDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m OutputDatum
- unsafeDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m TxSkelOutDatum
- unsafeTypedDatumFromTxOutRef :: (DatumConstrs a, MonadBlockChainBalancing m) => TxOutRef -> m (Maybe a)
- unsafeValueFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m Value
- txSkelAllScripts :: MonadBlockChainBalancing m => TxSkel -> m [Versioned Script]
- toTxSkelOutWithMinAda :: MonadBlockChainBalancing m => TxSkelOut -> m TxSkelOut
- toTxSkelWithMinAda :: MonadBlockChainBalancing m => TxSkel -> m TxSkel
- getTxSkelOutMinAda :: MonadBlockChainBalancing m => TxSkelOut -> m Integer
- interpretAndRunWith :: (forall m. Monad m => MockChainT m a -> m res) -> StagedMockChain a -> [res]
- interpretAndRun :: StagedMockChain a -> [MockChainReturn a]
- runTweakFrom :: InitialDistribution -> 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
- runUtxoSearch :: Monad m => UtxoSearch m a -> m [(TxOutRef, a)]
- allUtxosSearch :: MonadBlockChain m => UtxoSearch m TxSkelOut
- utxosOwnedBySearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut
- utxosFromCardanoTxSearch :: MonadBlockChainBalancing m => CardanoTx -> UtxoSearch m TxSkelOut
- txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxSkelOut
- 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 TxSkelOut -> (Value -> Bool) -> UtxoSearch m TxSkelOut
- filterWithOnlyAda :: Monad m => UtxoSearch m TxSkelOut -> UtxoSearch m TxSkelOut
- filterWithNotOnlyAda :: Monad m => UtxoSearch m TxSkelOut -> UtxoSearch m TxSkelOut
- onlyValueOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut
- vanillaOutputsAtSearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut
- filterWithAlways :: Monad m => UtxoSearch m a -> (a -> b) -> UtxoSearch m b
- referenceScriptOutputsSearch :: (MonadBlockChain m, ToScriptHash s) => s -> UtxoSearch m TxSkelOut
- filterWithPureRev :: Monad m => UtxoSearch m a -> (a -> Maybe b) -> UtxoSearch m a
- holdsInState :: ToAddress a => a -> UtxoState -> Value
- utxoPayloadSet :: UtxoPayloadSet -> [UtxoPayload]
- utxoPayloadTxOutRef :: UtxoPayload -> TxOutRef
- utxoPayloadValue :: UtxoPayload -> Value
- utxoPayloadDatum :: UtxoPayload -> Maybe (DatumContent, Bool)
- utxoPayloadReferenceScript :: UtxoPayload -> Maybe ScriptHash
- combineMockChainT :: (forall a. m a -> m a -> m a) -> MockChainT m x -> MockChainT m x -> MockChainT m x
- mcrValue :: MockChainReturn a -> Either MockChainError a
- mcrOutputs :: MockChainReturn a -> Map TxOutRef (TxSkelOut, Bool)
- mcrUtxoState :: MockChainReturn a -> UtxoState
- mcrJournal :: MockChainReturn a -> [MockChainLogEntry]
- mcrAliases :: MockChainReturn a -> Map BuiltinByteString String
- runMockChainTRaw :: Monad m => MockChainT m a -> m (MockChainReturn a)
- runMockChainTFrom :: Monad m => InitialDistribution -> MockChainT m a -> m (MockChainReturn a)
- runMockChainT :: Monad m => MockChainT m a -> m (MockChainReturn a)
- runMockChainFrom :: InitialDistribution -> MockChain a -> MockChainReturn a
- runMockChain :: MockChain a -> MockChainReturn a
- testBool :: IsProp prop => Bool -> prop
- testAll :: IsProp prop => (a -> prop) -> [a] -> prop
- testAny :: 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
- testToProp :: (IsProp prop, Show a) => Test a prop -> prop
- testCooked :: Show a => String -> Test a Assertion -> TestTree
- testCookedQC :: Show a => String -> Test a Property -> TestTree
- mustSucceedTest :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailTest :: IsProp prop => StagedMockChain a -> Test a prop
- withInitDist :: Test a prop -> InitialDistribution -> Test a prop
- withPrettyOpts :: Test a prop -> PrettyCookedOpts -> Test a prop
- withJournalProp :: IsProp prop => Test a prop -> JournalProp prop -> Test a prop
- withStateProp :: IsProp prop => Test a prop -> StateProp prop -> Test a prop
- withSuccessProp :: IsProp prop => Test a prop -> SuccessProp a prop -> Test a prop
- withResultProp :: IsProp prop => Test a prop -> (a -> prop) -> Test a prop
- withSizeProp :: IsProp prop => Test a prop -> SizeProp prop -> Test a prop
- withFailureProp :: IsProp prop => Test a prop -> FailureProp prop -> Test a prop
- withErrorProp :: IsProp prop => Test a prop -> (MockChainError -> prop) -> Test a prop
- isPhase1Failure :: IsProp prop => FailureProp prop
- isPhase2Failure :: IsProp prop => FailureProp prop
- isPhase1FailureWithMsg :: IsProp prop => String -> FailureProp prop
- isPhase2FailureWithMsg :: IsProp prop => String -> FailureProp prop
- isOfSize :: IsProp prop => Integer -> SizeProp prop
- isAtLeastOfSize :: IsProp prop => Integer -> SizeProp prop
- isAtMostOfSize :: IsProp prop => Integer -> SizeProp prop
- happened :: IsProp prop => String -> JournalProp prop
- didNotHappen :: IsProp prop => String -> JournalProp prop
- isInWallets :: IsProp prop => [(Wallet, [(AssetClass, Integer -> Bool)])] -> SuccessProp a prop
- isInWallet :: IsProp prop => (Wallet, AssetClass, Integer) -> SuccessProp a prop
- mustFailInPhase2Test :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailInPhase2WithMsgTest :: IsProp prop => String -> StagedMockChain a -> Test a prop
- mustFailInPhase1Test :: IsProp prop => StagedMockChain a -> Test a prop
- mustFailInPhase1WithMsgTest :: IsProp prop => String -> StagedMockChain a -> Test a prop
- mustSucceedWithSizeTest :: IsProp prop => Integer -> StagedMockChain a -> Test a prop
- mustFailWithSizeTest :: IsProp prop => Integer -> StagedMockChain a -> Test a prop
Documentation
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 #
data MockChainState Source #
The state used to run the simulation in Direct
Constructors
MockChainState | |
Fields
|
Instances
Show MockChainState Source # | |
Defined in Cooked.MockChain.MockChainState Methods showsPrec :: Int -> MockChainState -> ShowS # show :: MockChainState -> String # showList :: [MockChainState] -> ShowS # | |
Default MockChainState Source # | |
Defined in Cooked.MockChain.MockChainState Methods def :: MockChainState # | |
Monad m => MonadState MockChainState (MockChainT m) Source # | |
Defined in Cooked.MockChain.Direct Methods get :: MockChainT m MockChainState # put :: MockChainState -> MockChainT m () # state :: (MockChainState -> (a, MockChainState)) -> 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.
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 |
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
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
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
Tweak
s 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
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.
Instances
MonadBlockChain StagedMockChain Source # | |
Defined in Cooked.MockChain.Staged Methods validateTxSkel :: TxSkel -> StagedMockChain CardanoTx Source # | |
Monad m => MonadBlockChain (MockChainT m) Source # | Most of the logic of the direct emulation happens here |
Defined in Cooked.MockChain.Direct Methods validateTxSkel :: TxSkel -> MockChainT m CardanoTx Source # | |
MonadBlockChain m => MonadBlockChain (ListT 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 | |
(MonadTrans t, MonadBlockChain m, MonadBlockChainWithoutValidation (AsTrans t m)) => MonadBlockChain (AsTrans t 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
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
|
Instances
Monoid MockChainBook Source # | |
Defined in Cooked.MockChain.Direct Methods mempty :: MockChainBook # mappend :: MockChainBook -> MockChainBook -> MockChainBook # mconcat :: [MockChainBook] -> MockChainBook # | |
Semigroup MockChainBook Source # | |
Defined in Cooked.MockChain.Direct Methods (<>) :: MockChainBook -> MockChainBook -> MockChainBook # sconcat :: NonEmpty MockChainBook -> MockChainBook # stimes :: Integral b => b -> MockChainBook -> MockChainBook # | |
Monad m => MonadWriter MockChainBook (MockChainT m) Source # | |
Defined in Cooked.MockChain.Direct Methods writer :: (a, MockChainBook) -> MockChainT m a # tell :: MockChainBook -> MockChainT m () # listen :: MockChainT m a -> MockChainT m (a, MockChainBook) # pass :: MockChainT m (a, MockChainBook -> MockChainBook) -> MockChainT m a # |
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
.
Minimal complete definition
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
Instances
IsProp Property Source # | QuickCheck instance of |
Defined in Cooked.MockChain.Testing Methods 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 Methods testCounterexample :: String -> Assertion -> Assertion Source # testConjoin :: [Assertion] -> Assertion Source # testDisjoin :: [Assertion] -> Assertion Source # testFailure :: Assertion Source # testSuccess :: Assertion Source # testFailureMsg :: String -> Assertion Source # |
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
MockChainError
s.
Constructors
MockChainT | |
Fields |
Instances
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
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
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.
estimateTxSkelFee :: MonadBlockChainBalancing m => TxSkel -> Integer -> Maybe (Set TxOutRef, Wallet) -> m Integer Source #
This function was originally inspired by https://github.com/input-output-hk/plutus-apps/blob/d4255f05477fd8477ee9673e850ebb9ebb8c9657/plutus-ledger/src/Ledger/Fee.hs#L19
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 #
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
outputDatumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe OutputDatum) Source #
Extracts a potential OutputDatum
from a given TxOutRef
datumFromTxOutRef :: MonadBlockChainBalancing m => TxOutRef -> m (Maybe TxSkelOutDatum) Source #
Extracts a potential TxSkelOutDatum
from a given TxOutRef
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 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.
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 TxSkelOut
s 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.
runTweakFrom :: InitialDistribution -> Tweak InterpMockChain a -> TxSkel -> [MockChainReturn (a, TxSkel)] Source #
Runs a Tweak
from a given TxSkel
and InitialDistribution
within a
mockchain
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".
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 #
utxosOwnedBySearch :: (MonadBlockChainBalancing m, ToAddress addr) => addr -> UtxoSearch m TxSkelOut Source #
utxosFromCardanoTxSearch :: MonadBlockChainBalancing m => CardanoTx -> UtxoSearch m TxSkelOut Source #
txOutByRefSearch :: MonadBlockChainBalancing m => [TxOutRef] -> UtxoSearch m TxSkelOut Source #
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 TxSkelOut
s are only kept
when they contain only ADA
filterWithNotOnlyAda :: Monad m => UtxoSearch m TxSkelOut -> UtxoSearch m TxSkelOut Source #
A specific version of filterWithValuePred
when TxSkelOut
s 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 #
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
runMockChainTRaw :: Monad m => MockChainT m a -> m (MockChainReturn a) Source #
Runs a MockChainT
from a default MockChainState
runMockChainTFrom :: Monad m => InitialDistribution -> MockChainT m a -> m (MockChainReturn a) Source #
Runs a MockChainT
from an initial MockChainState
built from a given
InitialDistribution
.
runMockChainT :: Monad m => MockChainT m a -> m (MockChainReturn a) Source #
Executes a MockChainT
from the canonical initial state and environment.
runMockChainFrom :: InitialDistribution -> MockChain a -> MockChainReturn a Source #
runMockChain :: MockChain a -> MockChainReturn a Source #
See runMockChainT
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
.
testCookedQC :: Show a => String -> Test a Property -> TestTree Source #
Same as testCooked
, but for Property
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