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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -Wno-orphans #-}

Expand All @@ -19,6 +20,7 @@ class
, AllegraEraTxBody era
, AllegraEraTxAuxData era
, AllegraEraScript era
, NativeScript era ~ Timelock era
) =>
AllegraEraTest era

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)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -Wno-orphans #-}

Expand Down
22 changes: 22 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,18 @@ instance
where
(a, b) = finishDRepPulser x

-- TODO: consider this
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 +309,7 @@ instance
instance ToExpr (VState era)

instance ConwayEraCertState era => ToExpr (ConwayCertState era)

instance
ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
ToExpr (ConwayBbodyPredFailure era)
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ instance ToExpr AssetName where

deriving newtype instance ToExpr (CompactForm MaryValue)

instance ToExpr (TxBody MaryEra)
instance ToExpr (TxBody MaryEra) -- TODO: investigate
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 @@ -23,8 +23,7 @@ import qualified Data.Text as T
import Lens.Micro ((&), (.~), (^.))
import qualified MAlonzo.Code.Ledger.Foreign.API as Agda
import Prettyprinter ((<+>))
import qualified Prettyprinter as PP
import Test.Cardano.Ledger.Common (Arbitrary (..), Gen, showExpr)
import Test.Cardano.Ledger.Common (Arbitrary (..), Gen, ppString, showExpr, vcat)
import Test.Cardano.Ledger.Conformance (
ExecSpecRule (..),
SpecTranslate (..),
Expand All @@ -50,7 +49,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 @@ -95,16 +93,16 @@ instance ExecSpecRule "UTXO" ConwayEra where
Agda.utxoStep externalFunctions env st sig

extraInfo _ ctx env@UtxoEnv {..} st@UTxOState {..} sig st' =
PP.vcat
vcat
[ "Impl:"
, PP.ppString (showConwayTxBalance uePParams ueCertState utxosUtxo sig)
, "initial TotalAda:" <+> PP.ppString (showExpr $ totalAda st)
, ppString (showConwayTxBalance uePParams ueCertState utxosUtxo sig)
, "initial TotalAda:" <+> ppString (showExpr $ totalAda st)
, "final TotalAda: " <+> case st' of
Right (x, _) -> PP.ppString (showExpr $ totalAda x)
Right (x, _) -> ppString (showExpr $ totalAda x)
Left _ -> "N/A"
, mempty
, "Spec:"
, PP.ppString
, ppString
( 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 @@ -21,7 +21,7 @@ import Data.Bifunctor (Bifunctor (..))
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 (ppString, showExpr, vcat)
import Test.Cardano.Ledger.Conformance (
ExecSpecRule (..),
SpecTranslate,
Expand All @@ -42,9 +42,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 All @@ -69,15 +67,15 @@ instance
stFinal = first showOpaqueErrorString $ runSTS @"UTXO" @ConwayEra globals env st sig
utxoInfo = extraInfo @"UTXO" @ConwayEra globals ctx env st sig stFinal
in
PP.vcat
vcat
[ "UTXOW"
, "Impl:"
, "witsVKeyNeeded"
, PP.ppString . showExpr $
, ppString . showExpr $
getConwayWitsVKeyNeeded @ConwayEra (utxosUtxo st) (sig ^. bodyTxL)
, "witsVKeyHashes"
, "Spec:"
, PP.ppString result
, ppString 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ module Test.Cardano.Ledger.Common (

-- * Miscellanous helpers
tracedDiscard,

-- * Prettyprinter related
ppString,
vcat,
) where

import Control.DeepSeq (NFData)
import Control.Monad as X (forM_, replicateM, replicateM_, unless, void, when, (>=>))
import qualified Debug.Trace as Debug
import Prettyprinter (Doc, pretty, vcat)
import Test.Cardano.Ledger.Binary.TreeDiff (
ToExpr (..),
ansiExpr,
Expand Down Expand Up @@ -122,3 +127,6 @@ runGen ::
Gen a ->
a
runGen seed size gen = unGen gen (mkQCGen seed) size

ppString :: String -> Doc a
ppString = pretty
Loading
Loading