Skip to content

Remove Pretty from cardano-ledger-test #4966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions eras/alonzo/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.14.0.0

* Added `Generic` instance for `AlonzoScriptsNeeded`
* Move to `testlib` `DecCBOR` instances for: `AlonzoTxSeq`, `AlonzoTx`, `TxBody AlonzoEra`, `AlonzoTxAuxDataRaw`, `AlonzoTxAuxData`, `AlonzoScript`, `AlonzoTxWitsRaw`, `AlonzoTxWits`, `RedeemersRaw`, `Redeemers`, `TxDatsRaw`, `TxDats`
* Added to `PParams`: `ppCollateralPercentage`,`ppCostModels`,`ppMaxBlockExUnits`,`ppMaxCollateralInputs`,`ppMaxTxExUnits`,`ppMaxValSize`,`ppPrices`
* Removed `alonzoCommonPParamsHKDPairs` from `PParams`
Expand All @@ -21,6 +22,11 @@

### `testlib`

* Added `ToExpr` instances for:
* `AsIxItem`
* `AlonzoScriptsNeeded`
* `AlonzoPlutusPurpose AsIxItem`
* `AlonzoBbodyPredFailure`
* Deprecated `mkPlutusScript'`
* Change type signature of `genPlutusScript`, `genNativeScript`, `genAlonzoScript`, `alwaysSucceedsLang` and `alwaysFailsLang`.
* Remove `TxInfoLanguage` and `mkTxInfoLanguage`
Expand Down
4 changes: 3 additions & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/UTxO.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Expand Down Expand Up @@ -63,13 +64,14 @@ import qualified Data.Map.Strict as Map
import Data.Maybe (catMaybes, fromMaybe, isJust)
import qualified Data.Set as Set
import Data.Word (Word32)
import GHC.Generics
import Lens.Micro ((^.))
import Lens.Micro.Extras (view)

-- | Alonzo era style `ScriptsNeeded` require also a `PlutusPurpose`, not only the `ScriptHash`
newtype AlonzoScriptsNeeded era
= AlonzoScriptsNeeded [(PlutusPurpose AsIxItem era, ScriptHash)]
deriving (Monoid, Semigroup)
deriving (Monoid, Semigroup, Generic)

deriving instance AlonzoEraScript era => Eq (AlonzoScriptsNeeded era)

Expand Down
2 changes: 2 additions & 0 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Era.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class
, AlonzoEraTxAuxData era
, AlonzoEraUTxO era
, ToExpr (PlutusScript era)
, ToExpr (PlutusPurpose AsIx era)
, ToExpr (PlutusPurpose AsIxItem era)
, Script era ~ AlonzoScript era
) =>
AlonzoEraTest era
Expand Down
11 changes: 11 additions & 0 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/TreeDiff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Ledger.Alonzo.Tx
import Cardano.Ledger.Alonzo.TxAuxData
import Cardano.Ledger.Alonzo.TxBody
import Cardano.Ledger.Alonzo.TxWits
import Cardano.Ledger.Alonzo.UTxO
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Compactible
import Cardano.Ledger.Plutus.Evaluate (PlutusWithContext (..))
Expand All @@ -45,6 +46,12 @@ deriving newtype instance ToExpr ix => ToExpr (AsIx ix it)

deriving newtype instance ToExpr it => ToExpr (AsItem ix it)

instance (ToExpr ix, ToExpr it) => ToExpr (AsIxItem ix it)

instance ToExpr (PlutusPurpose AsIxItem era) => ToExpr (AlonzoScriptsNeeded era)

instance ToExpr (TxCert era) => ToExpr (AlonzoPlutusPurpose AsIxItem era)

-- Core
deriving newtype instance ToExpr CoinPerWord

Expand Down Expand Up @@ -168,3 +175,7 @@ instance
, ("pwcExUnits", toExpr pwcExUnits)
, ("pwcCostModel", toExpr pwcCostModel)
]

instance
ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
ToExpr (AlonzoBbodyPredFailure era)
4 changes: 4 additions & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

### `testlib`

* Added `ToExpr` instances for:
* `ConwayPlutusPurpose AsIxItem`
* `DRepPulser`
* `ConwayBbodyPredFailure`
* Added `Era` module with `ConwayEraTest` class

## 1.19.0.0
Expand Down
21 changes: 21 additions & 0 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/TreeDiff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ instance
) =>
ToExpr (ConwayPlutusPurpose AsItem era)

instance
( ToExpr (TxCert era)
, ToExpr (PParamsHKD StrictMaybe era)
) =>
ToExpr (ConwayPlutusPurpose AsIxItem era)

-- PlutusContext
instance
( Era era
Expand Down Expand Up @@ -127,6 +133,17 @@ instance
where
(a, b) = finishDRepPulser x

instance
( EraStake era
, EraPParams era
, ToExpr (DRepPulsingState era)
, ToExpr (RatifyState era)
, ToExpr (PParamsHKD StrictMaybe era)
) =>
ToExpr (DRepPulser era Identity (RatifyState era))
where
toExpr = toExpr . finishDRepPulser . DRPulsing

instance ToExpr (InstantStake era) => ToExpr (RatifyEnv era) where
toExpr (RatifyEnv stake pool drep dstate ep cs delegatees poolps) =
App
Expand Down Expand Up @@ -291,3 +308,7 @@ instance
instance ToExpr (VState era)

instance ConwayEraCertState era => ToExpr (ConwayCertState era)

instance
ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
ToExpr (ConwayBbodyPredFailure era)
14 changes: 14 additions & 0 deletions eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.17.0.0

* Added `Generic` instances for:
* `ShelleyBbodyState`
* `ShelleyScriptsNeeded`
* Remove Bool argument from `auxDataSeqDecoder`
* Move to `testlib` `DecCBOR` instances for: `ShelleyTxSeq`, `ShelleyTxRaw`, `ShelleyTx`, `TxBody ShelleyEra`, `ShelleyTxAuxData`, `ShelleyTxWitsRaw`, `ShelleyTxWits`, `MultiSigRaw`, `MultiSig`
* Remove `segWitTx`
Expand Down Expand Up @@ -37,6 +40,17 @@

### `testlib`

* Added `ToExpr` instances for:
* `ShelleyScriptsNeeded`
* `ShelleyBbodyState`
* `ShelleyTickPredFailure`
* `ShelleyNewEpochPredFailure`
* `ShelleyEpochPredFailure`
* `ShelleyUpecPredFailure`
* `ShelleyPoolPredFailure`
* `ShelleySnapPredFailure`
* `ShelleyMirPredFailure`
* `ShelleyRupdPredFailure`
* Added `Era` module with `ShelleyEraTest` class

## 1.16.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import NoThunks.Class (NoThunks (..))

data ShelleyBbodyState era
= BbodyState !(State (EraRule "LEDGERS" era)) !BlocksMade
deriving (Generic)

deriving stock instance Show (State (EraRule "LEDGERS" era)) => Show (ShelleyBbodyState era)

Expand Down
4 changes: 3 additions & 1 deletion eras/shelley/impl/src/Cardano/Ledger/Shelley/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -79,6 +80,7 @@ import Data.Foldable (Foldable (fold), foldr', toList)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro ((^.))

-- | Compute the subset of inputs of the set 'txIns' for which each input is
Expand Down Expand Up @@ -172,7 +174,7 @@ getConsumedCoin pp lookupRefund utxo txBody =
withdrawals = fold . unWithdrawals $ txBody ^. withdrawalsTxBodyL

newtype ShelleyScriptsNeeded era = ShelleyScriptsNeeded (Set ScriptHash)
deriving (Eq, Show)
deriving (Eq, Show, Generic)

instance EraUTxO ShelleyEra where
type ScriptsNeeded ShelleyEra = ShelleyScriptsNeeded ShelleyEra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Test.Cardano.Ledger.Shelley.Era (
import Cardano.Ledger.Shelley
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.Scripts
import Cardano.Ledger.State
import Data.Default
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Era
Expand All @@ -25,6 +26,7 @@ class
, NFData (StashedAVVMAddresses era)
, Default (StashedAVVMAddresses era)
, Arbitrary (StashedAVVMAddresses era)
, ToExpr (ScriptsNeeded era)
) =>
ShelleyEraTest era

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Cardano.Ledger.Shelley.TxBody
import Cardano.Ledger.Shelley.TxCert
import Cardano.Ledger.Shelley.TxOut
import Cardano.Ledger.Shelley.TxWits
import Cardano.Ledger.Shelley.UTxO
import Test.Cardano.Ledger.TreeDiff

-- PParams
Expand Down Expand Up @@ -159,6 +160,8 @@ instance

instance ToExpr (ShelleyInstantStake era)

instance ToExpr (ShelleyScriptsNeeded era)

-- Rules/Utxo
instance
( ToExpr (EraRuleFailure "PPUP" era)
Expand Down Expand Up @@ -279,3 +282,40 @@ instance
ToExpr (ShelleyLedgersPredFailure era)

instance EraCertState era => ToExpr (ShelleyCertState era)

instance
ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
ToExpr (ShelleyBbodyPredFailure era)

instance
ToExpr (State (EraRule "LEDGERS" era)) =>
ToExpr (ShelleyBbodyState era)

instance
( ToExpr (PredicateFailure (EraRule "NEWEPOCH" era))
, ToExpr (PredicateFailure (EraRule "RUPD" era))
) =>
ToExpr (ShelleyTickPredFailure era)

instance
( ToExpr (PredicateFailure (EraRule "EPOCH" era))
, ToExpr (PredicateFailure (EraRule "MIR" era))
) =>
ToExpr (ShelleyNewEpochPredFailure era)

instance
( ToExpr (UpecPredFailure era)
, ToExpr (PredicateFailure (EraRule "POOLREAP" era))
, ToExpr (PredicateFailure (EraRule "SNAP" era))
) =>
ToExpr (ShelleyEpochPredFailure era)

instance ToExpr (ShelleyUpecPredFailure era)

instance ToExpr (ShelleyPoolreapPredFailure era)

instance ToExpr (ShelleySnapPredFailure era)

instance ToExpr (ShelleyMirPredFailure era)

instance ToExpr (ShelleyRupdPredFailure era)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import Test.Cardano.Ledger.Generic.GenState (
runGenRS,
)
import qualified Test.Cardano.Ledger.Generic.GenState as GenSize
import qualified Test.Cardano.Ledger.Generic.PrettyCore as PP
import qualified Test.Cardano.Ledger.Generic.Proof as Proof
import Test.Cardano.Ledger.Generic.TxGen (genAlonzoTx)

Expand Down Expand Up @@ -97,14 +96,14 @@ instance ExecSpecRule "UTXO" ConwayEra where
extraInfo _ ctx env@UtxoEnv {..} st@UTxOState {..} sig st' =
PP.vcat
[ "Impl:"
, PP.ppString (showConwayTxBalance uePParams ueCertState utxosUtxo sig)
, "initial TotalAda:" <+> PP.ppString (showExpr $ totalAda st)
, PP.pretty (showConwayTxBalance uePParams ueCertState utxosUtxo sig)
, "initial TotalAda:" <+> PP.pretty (showExpr $ totalAda st)
, "final TotalAda: " <+> case st' of
Right (x, _) -> PP.ppString (showExpr $ totalAda x)
Right (x, _) -> PP.pretty (showExpr $ totalAda x)
Left _ -> "N/A"
, mempty
, "Spec:"
, PP.ppString
, PP.pretty
( either show T.unpack . runSpecTransM ctx $
Agda.utxoDebug externalFunctions
<$> toSpecRep env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import qualified Data.Text as T
import Lens.Micro ((^.))
import qualified MAlonzo.Code.Ledger.Foreign.API as Agda
import qualified Prettyprinter as PP
import Test.Cardano.Ledger.Common (showExpr)
import Test.Cardano.Ledger.Conformance (
ExecSpecRule (..),
SpecTranslate,
Expand All @@ -42,9 +43,7 @@ import Test.Cardano.Ledger.Constrained.Conway (
utxoStateSpec,
utxoTxSpec,
)
import qualified Test.Cardano.Ledger.Generic.PrettyCore as PP
import Test.Cardano.Ledger.Shelley.Utils (runSTS)
import Test.Cardano.Ledger.TreeDiff (showExpr)

instance
SpecTranslate ConwayTxBodyTransContext (ConwayTxCert ConwayEra) =>
Expand Down Expand Up @@ -73,11 +72,11 @@ instance
[ "UTXOW"
, "Impl:"
, "witsVKeyNeeded"
, PP.ppString . showExpr $
, PP.pretty . showExpr $
getConwayWitsVKeyNeeded @ConwayEra (utxosUtxo st) (sig ^. bodyTxL)
, "witsVKeyHashes"
, "Spec:"
, PP.ppString result
, PP.pretty result
, mempty
, "UTXO"
, utxoInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway (
namePoolCert,
nameTxCert,
)
import Test.Cardano.Ledger.Generic.PrettyCore (PrettyA (..))
import Test.Cardano.Ledger.Generic.Proof (Proof (..), WitRule (..), goSTS)
import qualified Test.Cardano.Ledger.Generic.Proof as Proof

Expand All @@ -50,8 +49,8 @@ minitraceEither ::
forall s e.
( ExecSpecRule s e
, ExecState s e ~ State (EraRule s e)
, PrettyA (Signal (EraRule s e))
, PrettyA (State (EraRule s e))
, ToExpr (Signal (EraRule s e))
, ToExpr (State (EraRule s e))
) =>
WitRule s e ->
Int ->
Expand All @@ -77,8 +76,8 @@ minitraceEither witrule n0 = do
Left ps ->
pure
( Left
( [ "\nSIGNAL = " ++ show (prettyA signal2)
, "\nSTATE = " ++ show (prettyA state)
( [ "\nSIGNAL = " ++ show (toExpr signal2)
, "\nSTATE = " ++ show (toExpr state)
, "\nPredicateFailures"
]
++ map show (NE.toList ps)
Expand All @@ -96,8 +95,8 @@ minitrace ::
forall s e.
( ExecSpecRule s e
, ExecState s e ~ State (EraRule s e)
, PrettyA (Signal (EraRule s e))
, PrettyA (State (EraRule s e))
, ToExpr (Signal (EraRule s e))
, ToExpr (State (EraRule s e))
) =>
WitRule s e ->
Int ->
Expand All @@ -112,8 +111,8 @@ minitraceProp ::
forall s e.
( ExecSpecRule s e
, ExecState s e ~ State (EraRule s e)
, PrettyA (Signal (EraRule s e))
, PrettyA (State (EraRule s e))
, ToExpr (Signal (EraRule s e))
, ToExpr (State (EraRule s e))
) =>
WitRule s e ->
Int ->
Expand Down
4 changes: 0 additions & 4 deletions libs/cardano-ledger-test/cardano-ledger-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ library
Test.Cardano.Ledger.Generic.Indexed
Test.Cardano.Ledger.Generic.MockChain
Test.Cardano.Ledger.Generic.ModelState
Test.Cardano.Ledger.Generic.PrettyCore
Test.Cardano.Ledger.Generic.PrettyTest
Test.Cardano.Ledger.Generic.Proof
Test.Cardano.Ledger.Generic.Properties
Test.Cardano.Ledger.Generic.Same
Test.Cardano.Ledger.Generic.Scriptic
Test.Cardano.Ledger.Generic.Trace
Test.Cardano.Ledger.Generic.TxGen
Expand All @@ -123,7 +120,6 @@ library
QuickCheck,
array,
base >=4.18 && <5,
bech32,
bytestring,
cardano-crypto,
cardano-crypto-class,
Expand Down
Loading