Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
7ee51bb
doc ltl
mmontin Dec 21, 2025
8fb4fd8
this works !
mmontin Dec 27, 2025
db7c5cf
better ltlsimpl
mmontin Dec 29, 2025
82bed7d
laying out things nicely + commenting
mmontin Dec 29, 2025
e6b5cd5
perfecting the new ltl
mmontin Jan 3, 2026
b864fd1
final adjustements before diving into effects
mmontin Jan 3, 2026
0b29b87
back to booleans
mmontin Jan 3, 2026
f2419a2
all builtins at the same location
mmontin Jan 4, 2026
cfd30f7
before attempting effects
mmontin Jan 6, 2026
fac0044
cleaning up, adding proper type classes
mmontin Jan 8, 2026
77d6137
Requirment
mmontin Jan 8, 2026
49c7c59
minor cleanup
mmontin Jan 8, 2026
93015ee
laying out things in relevant files
mmontin Jan 8, 2026
e9b4626
fix haddock warnings
mmontin Jan 8, 2026
00bda78
comment updated
mmontin Jan 9, 2026
84efc2e
haddock rendering
mmontin Jan 9, 2026
9f692d8
restructuring and renaming combinators
mmontin Jan 9, 2026
faf0806
hm
mmontin Jan 11, 2026
94f605d
finished sketch
mmontin Jan 18, 2026
3f09a58
a more flexible version of handling tweaks
mmontin Jan 18, 2026
1dc7f29
moving families
mmontin Jan 19, 2026
7233b61
comments
mmontin Jan 19, 2026
bf73eea
comments
mmontin Jan 19, 2026
cdc88f9
running tweaks
mmontin Jan 19, 2026
6bcce61
Ltl
mmontin Jan 20, 2026
dea340a
no more Staged
mmontin Jan 20, 2026
5959cfd
ltl doc and exports
mmontin Jan 20, 2026
235513e
tweaks
mmontin Jan 20, 2026
e8ba4f6
datum hijacking
mmontin Jan 21, 2026
0a7d243
all effects spread around properly
mmontin Jan 22, 2026
b3fbf0c
removing old files
mmontin Jan 22, 2026
98d87e0
begin of autofillingé
mmontin Jan 22, 2026
f038ea9
GenerateTx
mmontin Jan 22, 2026
cf08230
more files transformed
mmontin Jan 22, 2026
7acfc4a
Only Testing and UtxoSearch remain
mmontin Jan 22, 2026
7971f23
pretty
mmontin Jan 22, 2026
37adaf5
starting Testing.hs
mmontin Jan 22, 2026
07d8971
main sources fully transformed
mmontin Jan 23, 2026
b9bf548
UtxoSearch
mmontin Jan 23, 2026
0cd2a41
StagedMockChain is back
mmontin Jan 23, 2026
52fc668
all but Spec.Ltl
mmontin Jan 24, 2026
723b998
fixing running
mmontin Jan 24, 2026
26c5bf6
progressing, but a lot of work remains in tests
mmontin Jan 24, 2026
42706ba
it finally compiles ... but it doesn't work ... yet
mmontin Jan 25, 2026
d40c963
MockChainState -> State
mmontin Jan 25, 2026
2406854
fixing bug in UTxOSearch
mmontin Jan 25, 2026
55b256a
fixing DH spec change
mmontin Jan 25, 2026
0ed2290
all good
mmontin Jan 25, 2026
299143f
improving pretty-printing of runs + note primitive
mmontin Jan 25, 2026
edde6ba
here comes MockChainJournal
mmontin Jan 25, 2026
c4de79e
migrating temporarily to the haskell-update branch from nixpkgs to ge…
mmontin Jan 25, 2026
995c205
tweak file in mockchain
mmontin Jan 26, 2026
679d118
Byebye UtxoState.hs
mmontin Jan 26, 2026
231bc34
optics utxoState
mmontin Jan 26, 2026
d397a78
Runnable + docs
mmontin Jan 26, 2026
22e7ad3
documentation
mmontin Jan 26, 2026
402f108
updating CHANGELOG from main
mmontin Jan 27, 2026
5612866
txSkelLabel -> txSkelLabels
mmontin Jan 27, 2026
82784eb
improvements
mmontin Jan 28, 2026
92b63f9
Merge branch 'main' into mm/effectful
mmontin Jan 28, 2026
6850bdc
ormolu
mmontin Jan 28, 2026
55be72d
assert + beginning of StagedRun
mmontin Jan 28, 2026
e3ff2fa
bye bye double nondet
mmontin Jan 29, 2026
ce1664d
bye InitialDistribution.hs
mmontin Jan 29, 2026
c3a5b8a
Inject + pretty
mmontin Jan 31, 2026
447600a
improving Staged instance
mmontin Feb 2, 2026
1ff0fce
more generic testing framework
mmontin Feb 2, 2026
1f1a923
improving the testing framework
mmontin Feb 2, 2026
efc2fbb
manual export of instances
mmontin Feb 2, 2026
e53fd35
merge + extraEffs
mmontin Feb 10, 2026
202443c
refactoring of initial distributions
mmontin Feb 11, 2026
556fe7c
some improvements here and there
mmontin Feb 13, 2026
e409f51
continuing the presentation
mmontin Feb 13, 2026
1df10c8
very slight adjustments
mmontin Feb 13, 2026
f2770cc
defer validtation errors during balancing
mmontin Feb 14, 2026
b1a92db
balancing
mmontin Feb 15, 2026
785f97f
without the demo
mmontin Feb 16, 2026
c93753e
fixing doc comments
mmontin Feb 16, 2026
42f1efd
merged
mmontin Feb 16, 2026
c5185e4
balancing use min extra size
mmontin Feb 18, 2026
ce610b5
balancing give back the body
mmontin Feb 18, 2026
3cf7932
simplifying main balancing function
mmontin Feb 18, 2026
aa0ea3b
fixing optimization bug
mmontin Feb 19, 2026
76c1467
cherry-picking-v8-release
mmontin Jan 19, 2026
c5c0aba
cherry-picking-cne-chap-update
mmontin Feb 16, 2026
6027328
Create CODEOWNERS (#517)
mmontin Feb 16, 2026
76f454f
Merge branch 'main' into mm/effectful
mmontin Feb 19, 2026
164026e
Merge branch 'mm/effectful' into mm/balancing
mmontin Feb 19, 2026
1cd0b81
Merge branch 'main' into mm/effectful
mmontin Feb 19, 2026
e1f6edb
Merge branch 'mm/effectful' into mm/balancing
mmontin Feb 19, 2026
f7fbd4d
reverting changelog
mmontin Feb 19, 2026
d344414
Merge branch 'mm/effectful' into mm/balancing
mmontin Feb 19, 2026
52b65e1
attempting another config
mmontin Feb 19, 2026
2295bf0
cabal file
mmontin Feb 19, 2026
6d79060
Merge branch 'mm/effectful' into mm/balancing
mmontin Feb 19, 2026
643511f
beginning of changelog + cleanup packages
mmontin Feb 19, 2026
4161311
CHANGELOG
mmontin Feb 20, 2026
3173d32
Merge branch 'mm/effectful' into mm/balancing
mmontin Feb 20, 2026
0619465
Updating the README
mmontin Feb 20, 2026
85e97aa
Merge branch 'main' into mm/effectful
mmontin Mar 20, 2026
898e906
reworking cheatsheet
mmontin Mar 24, 2026
c5c2d32
Merge branch 'mm/effectful' of github.com:tweag/cooked-validators int…
mmontin Mar 24, 2026
ffe722a
more cheatsheet
mmontin Mar 24, 2026
e81c5ba
full table of contents
mmontin Mar 24, 2026
5fbecbf
finalizing cheatsheet
mmontin Mar 24, 2026
a2f7063
querried
mmontin Mar 24, 2026
601c8b8
Merge branch 'mm/effectful' into mm/balancing
mmontin Mar 24, 2026
64365f8
fixing haddock warnings
mmontin Mar 25, 2026
7035b28
Merge branch 'main' into mm/balancing
mmontin Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
592 changes: 339 additions & 253 deletions src/Cooked/MockChain/Balancing.hs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Cooked/MockChain/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Cooked.MockChain.Common
where

import Cooked.Skeleton.Output
import Cooked.Skeleton.User
import Data.Set (Set)
import PlutusLedgerApi.V3 qualified as Api

Expand All @@ -22,8 +21,9 @@ type Fee = Integer
-- | An alias for sets of utxos used as collateral inputs
type CollateralIns = Set Api.TxOutRef

-- | An alias for optional pairs of collateral inputs and return collateral peer
type Collaterals = Maybe (CollateralIns, Peer)
-- | An alias for optional pairs of collateral inputs and optional return
-- collateral output
type Collaterals = (CollateralIns, Maybe TxSkelOut)

-- | An alias for an output and its reference
type Utxo = (Api.TxOutRef, TxSkelOut)
Expand Down
28 changes: 22 additions & 6 deletions src/Cooked/MockChain/Error.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- | This module exposes the errors that can be raised during a mockchain run
module Cooked.MockChain.Error
( -- * Mockchain errors
BalancingError (..),
MockChainError (..),

-- * Interpretating effects into `Error MockChainError`
Expand All @@ -18,16 +19,31 @@ import Polysemy
import Polysemy.Error
import Polysemy.Fail

-- | Errors that can be produced during balancing
data BalancingError
= -- | The balancing user theoretically has enough funds to balancing the
-- trasaction, but this balancing results in a surplus payment which they
-- cannot afford ADA-wise.
NotEnoughFundForExtraMinAda Peer
| -- | The balancing does not have enough funds to sustain the fee required to
-- balance the transaction.
NotEnoughFundForProperFee Peer
| -- | The balancing wallet does not have enough funds to balance the
-- transaction
NotEnoughFund Peer Api.Value
| -- | The provided of collateral UTxOs does not have enough funds to cover
-- the potential collateral cost
NoSuitableCollateral Integer Integer Api.Value
| -- | The balancing user has not be provided, but the balancing requires it
MissingBalancingUser
deriving (Show, Eq)

-- | Errors that can be produced by the blockchain
data MockChainError
= -- | Validation errors, either in Phase 1 or Phase 2
MCEValidationError Ledger.ValidationPhase Ledger.ValidationError
| -- | The balancing user does not have enough funds
MCEUnbalanceable Peer Api.Value
| -- | The balancing user is required but missing
MCEMissingBalancingUser String
| -- | No suitable collateral could be associated with a skeleton
MCENoSuitableCollateral Integer Integer Api.Value
| -- | Balancing errors
MCEBalancingError BalancingError
| -- | Translating a skeleton element to its Cardano counterpart failed
MCEToCardanoError Ledger.ToCardanoError
| -- | The required reference script is missing from a witness utxo
Expand Down
23 changes: 14 additions & 9 deletions src/Cooked/MockChain/GenerateTx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ txSkelToTxBodyContent ::
(Members '[MockChainRead, Error MockChainError, Error Ledger.ToCardanoError, Fail] effs) =>
TxSkel ->
Fee ->
Collaterals ->
Maybe Collaterals ->
Sem effs (Cardano.TxBodyContent Cardano.BuildTx Cardano.ConwayEra)
txSkelToTxBodyContent skel@TxSkel {..} fee mCollaterals = do
txIns <- mapM toTxInAndWitness $ Map.toList txSkelIns
txInsReference <- toInsReference skel
(txInsCollateral, txTotalCollateral, txReturnCollateral) <- toCollateralTriplet fee mCollaterals
(txInsCollateral, txTotalCollateral, txReturnCollateral) <- toCollateralTriplet mCollaterals
txOuts <- mapM toCardanoTxOut txSkelOuts
(txValidityLowerBound, txValidityUpperBound) <- fromEither $ Ledger.toCardanoValidityRange txSkelValidityRange
txMintValue <- toMintValue txSkelMints
Expand Down Expand Up @@ -85,7 +85,7 @@ txBodyContentToTxBody txBodyContent = do
txSkelToIndex ::
(Members '[MockChainRead, Error Ledger.ToCardanoError] effs) =>
TxSkel ->
Collaterals ->
Maybe Collaterals ->
Sem effs (Cardano.UTxO Cardano.ConwayEra)
txSkelToIndex txSkel mCollaterals = do
-- We build the index of UTxOs which are known to this skeleton. This includes
Expand All @@ -106,7 +106,7 @@ txSkelToTxBody ::
(Members '[MockChainRead, Error MockChainError, Error Ledger.ToCardanoError, Fail] effs) =>
TxSkel ->
Fee ->
Collaterals ->
Maybe Collaterals ->
Sem effs (Cardano.TxBody Cardano.ConwayEra)
txSkelToTxBody txSkel fee mCollaterals = do
-- We create a first body content and body, without execution units
Expand All @@ -119,9 +119,14 @@ txSkelToTxBody txSkel fee mCollaterals = do
params <- getParams
-- We retrieve the execution units associated with the transaction
case Emulator.getTxExUnitsWithLogs params (Ledger.fromPlutusIndex index) tx' of
-- Computing the execution units can result in all kinds of validation
-- errors except for the ones related to the execution units themselves.
Left err -> throw $ uncurry MCEValidationError err
-- Computing the execution units can result in all kinds of phase 2
-- validation failures, except for the ones related to the execution units
-- themselves. Unless required in the options, we throw the validation
-- failure right away when applicable.
Left err | not $ txSkelOptDeferPhase2FailuresDuringBalancing $ txSkelOpts txSkel -> throw $ uncurry MCEValidationError err
-- The other option is to ignore those and return the unchanged body with
-- the existing execution units, postponing the handling of the failures.
Left _ -> return txBody'
-- When no error arises, we get an execution unit for each script usage. We
-- first have to transform this Ledger map to a cardano API map.
Right (Map.mapKeysMonotonic (Cardano.toScriptIndex Cardano.AlonzoEraOnwardsConway) . fmap (Cardano.fromAlonzoExUnits . snd) -> exUnits) ->
Expand All @@ -131,7 +136,7 @@ txSkelToTxBody txSkel fee mCollaterals = do
Left _ -> fail "Error while assigning execution units"
-- We now have a body content with proper execution units and can create
-- the final body from it
Right txBody -> txBodyContentToTxBody txBody
Right txBodyContent -> txBodyContentToTxBody txBodyContent

-- | Generates a Cardano transaction and signs it
txSignatoriesAndBodyToCardanoTx ::
Expand All @@ -145,7 +150,7 @@ txSkelToCardanoTx ::
(Members '[MockChainRead, Error MockChainError, Error Ledger.ToCardanoError, Fail] effs) =>
TxSkel ->
Fee ->
Collaterals ->
Maybe Collaterals ->
Sem effs (Cardano.Tx Cardano.ConwayEra)
txSkelToCardanoTx txSkel fee =
fmap (txSignatoriesAndBodyToCardanoTx (txSkelSignatories txSkel))
Expand Down
68 changes: 23 additions & 45 deletions src/Cooked/MockChain/GenerateTx/Collateral.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,54 @@
module Cooked.MockChain.GenerateTx.Collateral where

import Cardano.Api qualified as Cardano
import Cardano.Ledger.Conway.Core qualified as Conway
import Cardano.Node.Emulator.Internal.Node qualified as Emulator
import Control.Monad
import Cooked.MockChain.Common
import Cooked.MockChain.GenerateTx.Output
import Cooked.MockChain.Read
import Cooked.Skeleton.Output
import Cooked.Skeleton.Value
import Data.Map qualified as Map
import Data.Set qualified as Set
import Ledger.Tx.CardanoAPI qualified as Ledger
import Lens.Micro.Extras qualified as MicroLens
import Plutus.Script.Utils.Address qualified as Script
import Plutus.Script.Utils.Value qualified as Script
import PlutusTx.Numeric qualified as PlutusTx
import Optics.Core
import PlutusLedgerApi.V3 qualified as Api
import Polysemy
import Polysemy.Error

-- | Computes the collateral triplet from the fees and the collateral inputs in
-- the context. What we call a collateral triplet is composed of:
-- | Computes the collateral triplet from the potential collaterals. What we
-- call a collateral triplet is composed of:
--
-- * The set of collateral inputs
--
-- * The total collateral paid by the transaction in case of phase 2 failure
--
-- * An output returning excess collateral value when collaterals are used
--
-- These quantity should satisfy the equation (in terms of their values):
-- collateral inputs = total collateral + return collateral
toCollateralTriplet ::
(Members '[MockChainRead, Error Ledger.ToCardanoError] effs) =>
Fee ->
Collaterals ->
Maybe Collaterals ->
Sem
effs
( Cardano.TxInsCollateral Cardano.ConwayEra,
Cardano.TxTotalCollateral Cardano.ConwayEra,
Cardano.TxReturnCollateral Cardano.CtxTx Cardano.ConwayEra
)
toCollateralTriplet _ Nothing = return (Cardano.TxInsCollateralNone, Cardano.TxTotalCollateralNone, Cardano.TxReturnCollateralNone)
toCollateralTriplet fee (Just (Set.toList -> collateralInsList, returnCollateralUser)) = do
toCollateralTriplet Nothing = return (Cardano.TxInsCollateralNone, Cardano.TxTotalCollateralNone, Cardano.TxReturnCollateralNone)
toCollateralTriplet (Just (Set.toList -> collateralInsList, mReturnCollateral)) = do
-- We build the collateral inputs from this list
txInsCollateral <-
case collateralInsList of
[] -> return Cardano.TxInsCollateralNone
l -> fromEither $ Cardano.TxInsCollateral Cardano.AlonzoEraOnwardsConway <$> mapM Ledger.toCardanoTxIn l
-- Retrieving the total value in collateral inputs. This fails if one of the
-- collateral inputs has not been successfully resolved.
collateralInsValue <-
foldM (\val -> ((val <>) <$>) . viewByRef txSkelOutValueL) mempty collateralInsList
-- We retrieve the collateral percentage compared to fees. By default, we use
-- 150% which is the current value in the parameters, although the default
-- value should never be used here, as the call is supposed to always succeed.
collateralPercentage <- toInteger . MicroLens.view Conway.ppCollateralPercentageL . Emulator.pEmulatorPParams <$> getParams
-- The total collateral corresponds to the fees multiplied by the collateral
-- percentage. We add 1 because the ledger apparently rounds up this value.
let coinTotalCollateral = 1 + (fee * collateralPercentage) `div` 100
-- We create the total collateral based on the computed value
let txTotalCollateral = Cardano.TxTotalCollateral Cardano.BabbageEraOnwardsConway $ Cardano.Coin coinTotalCollateral
-- We compute a return collateral value by subtracting the total collateral to
-- the value in collateral inputs
let returnCollateralValue = collateralInsValue <> PlutusTx.negate (Script.lovelace coinTotalCollateral)
-- The return collateral is then computed
-- We collect the amount of lovelace in the collateral inputs
Api.Lovelace collateralInsLovelace <- foldOf (folded % txSkelOutValueL % valueLovelaceL) . Map.elems <$> lookupUtxos collateralInsList
-- We collect the amount of lovelace in the return collateral output
let Api.Lovelace returnCollateralLovelace = maybe 0 (view (txSkelOutValueL % valueLovelaceL)) mReturnCollateral
-- The total collateral is the difference between the two
let txTotalCollateral = Cardano.TxTotalCollateral Cardano.BabbageEraOnwardsConway $ Cardano.Coin $ collateralInsLovelace - returnCollateralLovelace
txReturnCollateral <-
-- If the total collateral equal what the inputs provide, we return
-- `TxReturnCollateralNone`, otherwise, we compute the new output
if returnCollateralValue == mempty
then return Cardano.TxReturnCollateralNone
else do
-- The value is a translation of the remaining value
txReturnCollateralValue <- Ledger.toCardanoTxOutValue <$> fromEither (Ledger.toCardanoValue returnCollateralValue)
-- The address is the one from the return collateral user, which is
-- required to exist here.
networkId <- Emulator.pNetworkId <$> getParams
address <- fromEither $ Ledger.toCardanoAddressInEra networkId (Script.toAddress returnCollateralUser)
-- The return collateral is built up from those elements
return $
Cardano.TxReturnCollateral Cardano.BabbageEraOnwardsConway $
Cardano.TxOut address txReturnCollateralValue Cardano.TxOutDatumNone Cardano.ReferenceScriptNone
case mReturnCollateral of
Nothing -> return Cardano.TxReturnCollateralNone
Just collateralOut -> Cardano.TxReturnCollateral Cardano.BabbageEraOnwardsConway <$> toCardanoTxOut collateralOut
return (txInsCollateral, txTotalCollateral, txReturnCollateral)
2 changes: 1 addition & 1 deletion src/Cooked/MockChain/Log.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data MockChainLogEntry
MCLogSubmittedTxSkel TxSkel
| -- | Logging a Skeleton as it has been adjusted by the balancing mechanism,
-- alongside fee, and possible collateral utxos and return collateral user.
MCLogAdjustedTxSkel TxSkel Fee Collaterals
MCLogAdjustedTxSkel TxSkel Fee (Maybe Collaterals)
| -- | Logging the successful validation of a new transaction, with its id and
-- number of produced outputs.
MCLogNewTx Api.TxId Integer
Expand Down
19 changes: 9 additions & 10 deletions src/Cooked/MockChain/Write.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ runMockChainWrite = interpret $ \case
autoFillWithdrawalAmounts
-- We balance the skeleton when requested in the skeleton option, and get
-- the associated fee, collateral inputs and return collateral user
(finalTxSkel, fee, mCollaterals) <- viewTweak simple >>= balanceTxSkel
ExtendedTxSkel finalTxSkel fee mCollaterals body <- viewTweak simple >>= balanceTxSkel
-- We log the adjusted skeleton
logEvent $ MCLogAdjustedTxSkel finalTxSkel fee mCollaterals
-- We generate the transaction asscoiated with the skeleton, and apply on it
-- the modifications from the skeleton options
cardanoTx <- Ledger.CardanoEmulatorEraTx . txSkelOptModTx <$> txSkelToCardanoTx finalTxSkel fee mCollaterals
signatories <- viewTweak txSkelSignatoriesL
let cardanoTx = Ledger.CardanoEmulatorEraTx $ txSkelOptModTx $ txSignatoriesAndBodyToCardanoTx signatories body
-- To run transaction validation we need a minimal ledger state
eLedgerState <- gets mcstLedgerState
-- We finally run the emulated validation. We update our internal state
Expand All @@ -193,18 +194,16 @@ runMockChainWrite = interpret $ \case
newOutputs <- case Emulator.validateCardanoTx newParams eLedgerState cardanoTx of
-- In case of a phase 1 error, we give back the same index
(_, Ledger.FailPhase1 _ err) -> throw $ MCEValidationError Ledger.Phase1 err
(newELedgerState, Ledger.FailPhase2 _ err _) | Just (colInputs, retColUser) <- mCollaterals -> do
(newELedgerState, Ledger.FailPhase2 _ err _) | Just (colInputs, mRetColOutput) <- mCollaterals -> do
-- We update the emulated ledger state
modify' (set mcstLedgerStateL newELedgerState)
-- We remove the collateral utxos from our own stored outputs
forM_ colInputs $ modify' . removeOutput
-- We add the returned collateral to our outputs (in practice this map
-- either contains no element, or a single one)
forM_ (Map.toList $ Ledger.getCardanoTxProducedReturnCollateral cardanoTx) $ \(txIn, txOut) ->
modify' $
addOutput
(Ledger.fromCardanoTxIn txIn)
(retColUser `receives` Value (Api.txOutValue . Ledger.fromCardanoTxOutToPV2TxInfoTxOut . Ledger.getTxOut $ txOut))
-- We add the returned collateral to our outputs when it exists
case (mRetColOutput, Map.toList $ Ledger.getCardanoTxProducedReturnCollateral cardanoTx) of
(Nothing, []) -> return ()
(Just retColOutput, [(txIn, _)]) -> modify' $ addOutput (Ledger.fromCardanoTxIn txIn) retColOutput
_ -> fail "Unreachable case when processing return collaterals, please report a bug at https://github.com/tweag/cooked-validators/issues"
-- We throw a mockchain error
throw $ MCEValidationError Ledger.Phase2 err
-- In case of success, we update the index with all inputs and outputs
Expand Down
35 changes: 18 additions & 17 deletions src/Cooked/Pretty/MockChain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,15 @@ instance (Show a) => PrettyCooked (MockChainReturn a) where
instance PrettyCooked Peer where
prettyCookedOpt opts = prettyHash opts . Script.toPubKeyHash

instance PrettyCooked MockChainError where
prettyCookedOpt opts (MCEValidationError plutusPhase plutusError) =
PP.vsep ["Validation error " <+> prettyCookedOpt opts plutusPhase, PP.indent 2 (prettyCookedOpt opts plutusError)]
prettyCookedOpt _ (MCEMissingBalancingUser msg) = "Missing balancing user:" <+> PP.pretty msg
prettyCookedOpt opts (MCEUnbalanceable balUser missingValue) =
prettyItemize
opts
"Unbalanceable:"
"-"
[ prettyCookedOpt opts balUser <+> "does not have enough funds",
if missingValue == mempty
then "Not enough funds to sustain the minimal ada of the return utxo"
else "Unable to find" <+> prettyCookedOpt opts missingValue
]
prettyCookedOpt opts (MCENoSuitableCollateral fee percentage colVal) =
instance PrettyCooked BalancingError where
prettyCookedOpt opts (NotEnoughFundForExtraMinAda peer) =
prettyCookedOpt opts peer <+> "does not have enough funds to account for the min ADA of the surplus payment"
prettyCookedOpt opts (NotEnoughFundForProperFee peer) =
prettyCookedOpt opts peer <+> "does not have enough funds to account for the minimum required fee"
prettyCookedOpt opts (NotEnoughFund peer missingValue) =
prettyCookedOpt opts peer <+> "does not have enough funds to account for this missing value:" <+> prettyCookedOpt opts missingValue
prettyCookedOpt _ MissingBalancingUser = "Missing balancing user"
prettyCookedOpt opts (NoSuitableCollateral fee percentage colVal) =
prettyItemize
opts
"No suitable collateral"
Expand All @@ -90,6 +84,11 @@ instance PrettyCooked MockChainError where
"Percentage in params was" <+> prettyCookedOpt opts percentage,
"Resulting minimal collateral value was" <+> prettyCookedOpt opts colVal
]

instance PrettyCooked MockChainError where
prettyCookedOpt opts (MCEValidationError plutusPhase plutusError) =
PP.vsep ["Validation error " <+> prettyCookedOpt opts plutusPhase, PP.indent 2 (prettyCookedOpt opts plutusError)]
prettyCookedOpt opts (MCEBalancingError err) = prettyCookedOpt opts err
prettyCookedOpt _ (MCEToCardanoError cardanoError) =
"Transaction generation error:" <+> PP.pretty cardanoError
prettyCookedOpt opts (MCEUnknownOutRef txOutRef) = "Unknown transaction output ref:" <+> prettyCookedOpt opts txOutRef
Expand Down Expand Up @@ -136,9 +135,11 @@ instance PrettyCooked (Contextualized MockChainLogEntry) where
++ ( ("Fee:" <+> prettyCookedOpt opts (Script.lovelace fee))
: maybe
["No collateral required"]
( \(collaterals, returnUser) ->
( \(collaterals, mRetColOutput) ->
[ prettyItemize opts "Collateral inputs:" "-" (Contextualized outputs . CollateralInput <$> Set.toList collaterals),
"Return collateral target:" <+> prettyCookedOpt opts returnUser
case mRetColOutput of
Nothing -> "No return collateral output"
Just retColOutput -> prettyItemize opts "Return collateral output:" "-" retColOutput
]
)
mCollaterals
Expand Down
9 changes: 6 additions & 3 deletions src/Cooked/Pretty/Skeleton.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE DeriveFunctor #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | This module implements 'PrettyCooked', 'PrettyCookedList' and
Expand All @@ -13,7 +12,7 @@ import Cooked.Wallet (Wallet)
import Data.Default
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Maybe (catMaybes)
import Data.Maybe (catMaybes, fromJust)
import Data.Set qualified as Set
import Ledger.Slot qualified as Ledger
import Optics.Core
Expand Down Expand Up @@ -293,13 +292,17 @@ instance PrettyCookedList TxSkelOpts where
txSkelOptBalancingUtxos
_
txSkelOptCollateralUtxos
txSkelOptDeferFailures
txSkelOptMaxNbOfBalancingUtxos
) =
[ prettyIfNot True prettyAutoSlotIncrease txSkelOptAutoSlotIncrease,
prettyIfNot def prettyBalanceOutputPolicy txSkelOptBalanceOutputPolicy,
prettyIfNot def prettyBalanceFeePolicy txSkelOptFeePolicy,
prettyIfNot def prettyBalancingPolicy txSkelOptBalancingPolicy,
prettyIfNot def prettyBalancingUtxos txSkelOptBalancingUtxos,
prettyIfNot def prettyCollateralUtxos txSkelOptCollateralUtxos
prettyIfNot def prettyCollateralUtxos txSkelOptCollateralUtxos,
prettyIfNot False (const "Defer Phase 2 failures during balancing") txSkelOptDeferFailures,
prettyIfNot Nothing (("Limit the number of balancing Utxos to " <>) . PP.pretty . fromJust) txSkelOptMaxNbOfBalancingUtxos
]
where
prettyIfNot :: (Eq a) => a -> (a -> DocCooked) -> a -> Maybe DocCooked
Expand Down
Loading