From 4d850025a11c2ce4897303d15f0cbf99eae4203f Mon Sep 17 00:00:00 2001 From: teodanciu Date: Sat, 17 Sep 2022 23:59:14 +0100 Subject: [PATCH] Remove dependency on cardano-prelude (#2992) Update `plutus` and `cardano-base` dependencies. Remove usage of `cardano-prelude`: * Update nix shell to prebuild packages and make them available to ghc-pkg so that running cabal from within the shell doesn't have to (which sometimes fails). * Update plutus version and adjust to API changes * Update cardano-base to a version compatible with plutus and without cardano-prelude * Allow newer version of `hashable`, since plutus brings in version 1.4.1.0, but our dependency Unique is restricting it to 1.4. * Regenerate `PlutusScript` using `plutus-preprocessor` * Fix Plutus protocol version in test, which was wrong, but only started failing with the new plutus version * Replace `panic` function from `cardano-prelude` with `error` * Use HeapWords from cardano-base instead of cardano-prelude * Remove dependency on `cardano-prelude` from everywhere except byron Co-authored-by: Alexey Kuleshevich --- cabal.project | 12 +- eras/alonzo/impl/cardano-ledger-alonzo.cabal | 2 +- .../impl/src/Cardano/Ledger/Alonzo/Data.hs | 4 +- .../impl/src/Cardano/Ledger/Alonzo/Genesis.hs | 20 +-- .../impl/src/Cardano/Ledger/Alonzo/Scripts.hs | 74 ++++++--- .../impl/src/Cardano/Ledger/Alonzo/Tools.hs | 4 +- .../impl/src/Cardano/Ledger/Alonzo/TxInfo.hs | 17 +- .../cardano-ledger-alonzo-test.cabal | 7 +- .../Cardano/Ledger/Alonzo/AlonzoEraGen.hs | 23 ++- .../Cardano/Ledger/Alonzo/PlutusScripts.hs | 156 +++++++----------- .../src/Test/Cardano/Ledger/Alonzo/Scripts.hs | 2 +- .../Ledger/Alonzo/Serialisation/Generators.hs | 7 +- .../Test/Cardano/Ledger/Alonzo/Examples.hs | 10 +- .../test/Test/Cardano/Ledger/Alonzo/Golden.hs | 18 +- .../impl/src/Cardano/Ledger/Babbage/TxInfo.hs | 6 +- .../Test/Cardano/Ledger/Babbage/TxInfo.hs | 4 +- .../src/Cardano/Chain/Byron/API/Mempool.hs | 2 +- .../shelley/impl/cardano-ledger-shelley.cabal | 2 +- .../src/Cardano/Ledger/Shelley/PoolParams.hs | 5 +- .../impl/src/Cardano/Ledger/Shelley/TxOut.hs | 2 +- .../Cardano/Ledger/Shelley/Generator/Core.hs | 2 +- .../cardano-ledger-core.cabal | 2 +- .../src/Cardano/Ledger/Address.hs | 3 +- .../src/Cardano/Ledger/Coin.hs | 2 +- .../src/Cardano/Ledger/CompactAddress.hs | 7 +- .../src/Cardano/Ledger/Keys/Bootstrap.hs | 5 +- .../src/Cardano/Ledger/SafeHash.hs | 2 +- .../src/Cardano/Ledger/TxIn.hs | 7 +- .../src/Cardano/Ledger/Pretty/Alonzo.hs | 2 +- .../cardano-ledger-test.cabal | 2 +- .../src/Test/Cardano/Ledger/Alonzo/Tools.hs | 2 +- .../Test/Cardano/Ledger/Examples/AlonzoAPI.hs | 2 +- .../Cardano/Ledger/Examples/AlonzoBBODY.hs | 2 +- .../Ledger/Examples/AlonzoCollectInputs.hs | 2 +- .../Ledger/Examples/AlonzoInvalidTxUTXOW.hs | 4 +- .../Ledger/Examples/AlonzoValidTxUTXOW.hs | 2 +- .../Ledger/Examples/BabbageFeatures.hs | 2 +- .../Cardano/Ledger/Examples/STSTestUtils.hs | 4 +- .../Test/Cardano/Ledger/Generic/ApplyTx.hs | 2 +- .../Test/Cardano/Ledger/Generic/Consensus.hs | 2 +- .../plutus-preprocessor.cabal | 1 + libs/plutus-preprocessor/src/Main.hs | 44 +++-- libs/plutus-preprocessor/src/PlutusScripts.hs | 2 +- shell.nix | 4 - 44 files changed, 248 insertions(+), 238 deletions(-) diff --git a/cabal.project b/cabal.project index 65033dd3fe9..65bdbe9f016 100644 --- a/cabal.project +++ b/cabal.project @@ -47,14 +47,15 @@ test-show-details: streaming source-repository-package type: git location: https://github.com/input-output-hk/cardano-base - tag: 631cb6cf1fa01ab346233b610a38b3b4cba6e6ab - --sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp + tag: 7e3ddba98a61900181fe63cdd4c9ed9708d1a6a7 + --sha256: 1ci0aa8zkcld0d4i6xldvffhppf8bg0ys8y2jys912r7i5sxq5pa subdir: base-deriving-via binary binary/test cardano-crypto-class cardano-crypto-praos + heapwords measures slotting strict-containers @@ -83,8 +84,8 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/plutus - tag: 8ab4c3355c5fdf67dcf6acc1f5a14668d5e6f0a9 - --sha256: coD/Kpl7tutwXb6ukQCH5XojBjquYkW7ob0BWZtdpok= + tag: ecbfc46d3302f438a31c4f2f8f30cd1a87dab271 + --sha256: 1r16a9xk49bw3r9wihmf49p2f8pfqqymrpgf85lzccyjrxdvxd7r subdir: plutus-ledger-api plutus-tx @@ -110,6 +111,7 @@ source-repository-package allow-newer: monoidal-containers:aeson, size-based:template-haskell, + Unique:hashable constraints: -- bizarre issue: in earlier versions they define their own 'GEq', in newer @@ -118,7 +120,7 @@ constraints: , dependent-sum > 0.6.2.0 -- Plutus dependency - , algebraic-graphs < 0.7 + , algebraic-graphs >= 0.7 , protolude >= 0.3.2 diff --git a/eras/alonzo/impl/cardano-ledger-alonzo.cabal b/eras/alonzo/impl/cardano-ledger-alonzo.cabal index 6f3265c9d7a..aa9d4ba1ba0 100644 --- a/eras/alonzo/impl/cardano-ledger-alonzo.cabal +++ b/eras/alonzo/impl/cardano-ledger-alonzo.cabal @@ -70,11 +70,11 @@ library cardano-crypto-class, cardano-ledger-core, cardano-ledger-shelley-ma, - cardano-prelude, cardano-slotting, containers, data-default, deepseq, + heapwords, measures, mtl, microlens, diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs index 7e7ee874a68..8317df2b84b 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs @@ -55,6 +55,7 @@ import Cardano.Binary withSlice, ) import Cardano.Crypto.Hash.Class (HashAlgorithm) +import Cardano.HeapWords (HeapWords (..), heapWords0, heapWords1) import Cardano.Ledger.Alonzo.Era import Cardano.Ledger.Alonzo.Language (Language (..)) import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), validScript) @@ -72,7 +73,6 @@ import Cardano.Ledger.SafeHash ) import Cardano.Ledger.Serialization (mapFromCBOR) import Cardano.Ledger.Shelley.Metadata (Metadatum, validMetadatum) -import Cardano.Prelude (HeapWords (..), heapWords0, heapWords1) import qualified Codec.Serialise as Cborg (Serialise (..)) import Control.DeepSeq (NFData) import Data.ByteString.Lazy (fromStrict) @@ -87,7 +87,7 @@ import Data.Typeable (Typeable) import Data.Word (Word64) import GHC.Generics (Generic) import NoThunks.Class (InspectHeapNamed (..), NoThunks) -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus -- ===================================================================== -- Plutus.Data is the type that Plutus expects as data. diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs index a1489ad538c..606475205bd 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs @@ -27,6 +27,7 @@ import Cardano.Ledger.Alonzo.Scripts ExUnits (..), ExUnits', Prices (..), + costModelParamsNames, getCostModelParams, mkCostModel, ) @@ -42,15 +43,12 @@ import Data.Aeson.Types (FromJSONKey (..), ToJSONKey (..), toJSONKeyText) import Data.Coders import Data.Map (Map) import qualified Data.Map.Strict as Map -import Data.Maybe (mapMaybe) import Data.Scientific (fromRationalRepetendLimited) -import qualified Data.Set as Set import Data.Text (Text) import Data.Word (Word64) import GHC.Generics (Generic) import NoThunks.Class (NoThunks) import Numeric.Natural (Natural) -import Plutus.V1.Ledger.Api as PV1 (costModelParamNames) data AlonzoGenesis = AlonzoGenesis { coinsPerUTxOWord :: !Coin, @@ -213,8 +211,8 @@ instance ToJSONKey Language where instance FromJSONKey Language where fromJSONKey = Aeson.FromJSONKeyTextParser languageFromText -validateCostModel :: MonadFail m => (Language, Map Text Integer) -> m (Language, CostModel) -validateCostModel (lang, cmps) = case mkCostModel lang cmps of +validateCostModel :: MonadFail m => Language -> Map Text Integer -> m (Language, CostModel) +validateCostModel lang cmps = case mkCostModel lang cmps of Left err -> fail $ show err Right cm -> pure (lang, cm) @@ -223,19 +221,19 @@ validateCostModel (lang, cmps) = case mkCostModel lang cmps of -- Therefore we just replace (in order) the new keys for the old ones. translateLegacyV1paramNames :: Map Text Integer -> Map Text Integer translateLegacyV1paramNames cmps = - Map.fromList $ - zipWith (\(_, v) k2 -> (k2, v)) (Map.toList cmps) (Set.toList PV1.costModelParamNames) + Map.fromList $ zip (costModelParamsNames PlutusV1) (Map.elems cmps) instance FromJSON CostModels where parseJSON = Aeson.withObject "CostModels" $ \o -> do plutusV1 <- o .:? "PlutusV1" plutusV2 <- o .:? "PlutusV2" let plutusV1' = translateLegacyV1paramNames <$> plutusV1 - cms <- mapM validateCostModel $ mapMaybe f [(PlutusV1, plutusV1'), (PlutusV2, plutusV2)] + cms <- + sequence + [ validateCostModel lang cm + | (lang, Just cm) <- [(PlutusV1, plutusV1'), (PlutusV2, plutusV2)] + ] pure . CostModels . Map.fromList $ cms - where - f (_, Nothing) = Nothing - f (a, Just b) = Just (a, b) instance FromJSON AlonzoGenesis where parseJSON = Aeson.withObject "Alonzo Genesis" $ \o -> do diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs index 3c9dc78e8ea..a42c8f0ab07 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs @@ -30,6 +30,8 @@ module Cardano.Ledger.Alonzo.Scripts -- * Cost Model CostModel, mkCostModel, + costModelParamsNames, + costModelParamsNamesSet, getCostModelLanguage, getCostModelParams, getEvaluationContext, @@ -37,11 +39,11 @@ module Cardano.Ledger.Alonzo.Scripts ExUnits', Prices (..), hashCostModel, - assertWellFormedCostModelParams, + PV1.assertWellFormedCostModelParams, decodeCostModelMap, decodeCostModel, CostModels (..), - CostModelApplyError (..), + PV1.CostModelApplyError (..), contentsEq, ) where @@ -65,6 +67,7 @@ import Cardano.Ledger.ShelleyMA.Timelocks (Timelock) import qualified Cardano.Ledger.ShelleyMA.Timelocks as Timelocks import Control.DeepSeq (NFData (..), deepseq, rwhnf) import Control.Monad (when) +import Control.Monad.Trans.Writer (WriterT (runWriterT)) import Data.ByteString.Short (ShortByteString, fromShort) import Data.Coders ( Annotator, @@ -83,6 +86,7 @@ import Data.Coders (<*!), ) import Data.DerivingVia (InstantiatedAt (..)) +import Data.Either (isRight) import Data.Int (Int64) import Data.Map (Map) import qualified Data.Map.Strict as Map @@ -90,13 +94,26 @@ import Data.Measure (BoundedMeasure, Measure) import Data.Set (Set) import qualified Data.Set as Set import Data.Text (Text) +import qualified Data.Text as Text import Data.Typeable (Proxy (..), Typeable) import Data.Word (Word64, Word8) import GHC.Generics (Generic) import NoThunks.Class (InspectHeapNamed (..), NoThunks) import Numeric.Natural (Natural) -import Plutus.V1.Ledger.Api as PV1 hiding (Map, Script) -import Plutus.V2.Ledger.Api as PV2 (costModelParamNames, isScriptWellFormed, mkEvaluationContext) +import PlutusCore.Evaluation.Machine.CostModelInterface (CostModelApplyWarn) +import PlutusLedgerApi.Common (showParamName) +import qualified PlutusLedgerApi.V1 as PV1 + ( CostModelApplyError (..), + EvaluationContext, + ParamName, + ProtocolVersion (ProtocolVersion), + ScriptDecodeError, + assertScriptWellFormed, + assertWellFormedCostModelParams, + mkEvaluationContext, + ) +import qualified PlutusLedgerApi.V2 as PV2 (ParamName, assertScriptWellFormed, mkEvaluationContext) +import PlutusPrelude (enumerate) -- | Marker indicating the part of a transaction for which this script is acting -- as a validator. @@ -224,7 +241,7 @@ pointWiseExUnits oper (ExUnits m1 s1) (ExUnits m2 s2) = (m1 `oper` m2) && (s1 `o -- ===================================== -- | A language dependent cost model for the Plutus evaluator. --- Note that the `EvaluationContext` is entirely dependent on the +-- Note that the `PV1.EvaluationContext` is entirely dependent on the -- cost model parameters (ie the `Map` `Text` `Integer`) and that -- this type uses the smart constructor `mkCostModel` -- to hide the evaluation context. @@ -270,15 +287,18 @@ instance NFData CostModel where -- | Convert cost model parameters to a cost model, making use of the -- conversion function mkEvaluationContext from the Plutus API. -mkCostModel :: Language -> Map Text Integer -> Either CostModelApplyError CostModel -mkCostModel PlutusV1 cm = - case PV1.mkEvaluationContext cm of - Right evalCtx -> Right (CostModel PlutusV1 cm evalCtx) - Left e -> Left e -mkCostModel PlutusV2 cm = - case PV2.mkEvaluationContext cm of - Right evalCtx -> Right (CostModel PlutusV2 cm evalCtx) +mkCostModel :: Language -> Map Text Integer -> Either PV1.CostModelApplyError CostModel +mkCostModel lang cm = + case eCostModel of + Right (evalCtx, _) -> Right (CostModel lang cm evalCtx) Left e -> Left e + where + mkEvaluationContext = + case lang of + PlutusV1 -> PV1.mkEvaluationContext + PlutusV2 -> PV2.mkEvaluationContext + eCostModel :: Either PV1.CostModelApplyError (PV1.EvaluationContext, [CostModelApplyWarn]) + eCostModel = runWriterT (mkEvaluationContext (Map.elems cm)) getCostModelLanguage :: CostModel -> Language getCostModelLanguage (CostModel lang _ _) = lang @@ -291,14 +311,19 @@ decodeCostModelMap = decodeMapByKey fromCBOR decodeCostModel decodeCostModel :: Language -> Decoder s CostModel decodeCostModel lang = do + let keys = costModelParamsNamesSet lang checked <- mkCostModel lang <$> decodeArrayAsMap keys fromCBOR case checked of Left e -> fail $ show e Right cm -> pure cm - where - keys = case lang of - PlutusV1 -> PV1.costModelParamNames - PlutusV2 -> PV2.costModelParamNames + +costModelParamsNames :: Language -> [Text] +costModelParamsNames = \case + PlutusV1 -> Text.pack . showParamName <$> enumerate @PV1.ParamName + PlutusV2 -> Text.pack . showParamName <$> enumerate @PV2.ParamName + +costModelParamsNamesSet :: Language -> Set.Set Text +costModelParamsNamesSet = Set.fromList . costModelParamsNames decodeArrayAsMap :: Ord a => Set a -> Decoder s b -> Decoder s (Map a b) decodeArrayAsMap keys decodeValue = do @@ -426,10 +451,17 @@ instance Era era => FromCBOR (Annotator (Script era)) where -- Run deepseq to see that there are no infinite computations and that -- every Plutus Script unflattens into a real PV1.Script validScript :: ProtVer -> Script era -> Bool -validScript pv scrip = case scrip of - TimelockScript sc -> deepseq sc True - PlutusScript PlutusV1 bytes -> PV1.isScriptWellFormed (transProtocolVersion pv) bytes - PlutusScript PlutusV2 bytes -> PV2.isScriptWellFormed (transProtocolVersion pv) bytes +validScript pv script = + case script of + TimelockScript sc -> deepseq sc True + PlutusScript lang bytes -> + let assertScriptWellFormed = + case lang of + PlutusV1 -> PV1.assertScriptWellFormed + PlutusV2 -> PV2.assertScriptWellFormed + eWellFormed :: Either PV1.ScriptDecodeError () + eWellFormed = assertScriptWellFormed (transProtocolVersion pv) bytes + in isRight eWellFormed transProtocolVersion :: ProtVer -> PV1.ProtocolVersion transProtocolVersion (ProtVer major minor) = diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tools.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tools.hs index cece9ae72a8..4eb890567be 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tools.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tools.hs @@ -53,8 +53,8 @@ import qualified Data.Set as Set import Data.Text (Text) import GHC.Records (HasField (..)) import Lens.Micro -import qualified Plutus.V1.Ledger.Api as PV1 -import qualified Plutus.V2.Ledger.Api as PV2 +import qualified PlutusLedgerApi.V1 as PV1 +import qualified PlutusLedgerApi.V2 as PV2 -- | Script failures that can be returned by 'evaluateTransactionExecutionUnits'. data TransactionScriptFailure c diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs index c2dd3dd02d8..5e55fb69b7d 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxInfo.hs @@ -17,7 +17,6 @@ module Cardano.Ledger.Alonzo.TxInfo transDataHash, transDataHash', transKeyHash, - transScriptHash, transSafeHash, transHash, txInfoId, @@ -147,9 +146,9 @@ import GHC.Records (HasField (..)) import Lens.Micro import NoThunks.Class (NoThunks) import Numeric.Natural (Natural) -import qualified Plutus.V1.Ledger.Api as PV1 -import Plutus.V1.Ledger.Contexts () -import qualified Plutus.V2.Ledger.Api as PV2 +import qualified PlutusLedgerApi.V1 as PV1 +import PlutusLedgerApi.V1.Contexts () +import qualified PlutusLedgerApi.V2 as PV2 import Prettyprinter (Pretty (..)) -- ========================================================= @@ -227,9 +226,6 @@ transDataHash' safe = PV1.DatumHash (transSafeHash safe) transKeyHash :: KeyHash d c -> PV1.PubKeyHash transKeyHash (KeyHash h) = PV1.PubKeyHash (PV1.toBuiltin (hashToBytes h)) -transScriptHash :: ScriptHash c -> PV1.ValidatorHash -transScriptHash (ScriptHash h) = PV1.ValidatorHash (PV1.toBuiltin (hashToBytes h)) - transSafeHash :: SafeHash c i -> PV1.BuiltinByteString transSafeHash = PV1.toBuiltin . hashToBytes . extractHash @@ -240,8 +236,8 @@ txInfoId :: TxId c -> PV1.TxId txInfoId (TxId safe) = PV1.TxId (transSafeHash safe) transStakeCred :: Credential kr c -> PV1.Credential -transStakeCred (ScriptHashObj (ScriptHash kh)) = - PV1.ScriptCredential (PV1.ValidatorHash (PV1.toBuiltin (hashToBytes kh))) +transStakeCred (ScriptHashObj (ScriptHash sh)) = + PV1.ScriptCredential (PV1.ScriptHash (PV1.toBuiltin (hashToBytes sh))) transStakeCred (KeyHashObj (KeyHash kh)) = PV1.PubKeyCredential (PV1.PubKeyHash (PV1.toBuiltin (hashToBytes kh))) @@ -256,8 +252,7 @@ transStakeReference StakeRefNull = Nothing transCred :: Credential kr c -> PV1.Credential transCred (KeyHashObj (KeyHash kh)) = PV1.PubKeyCredential (PV1.PubKeyHash (PV1.toBuiltin (hashToBytes kh))) -transCred (ScriptHashObj (ScriptHash kh)) = - PV1.ScriptCredential (PV1.ValidatorHash (PV1.toBuiltin (hashToBytes kh))) +transCred (ScriptHashObj (ScriptHash sh)) = PV1.ScriptCredential (PV1.ScriptHash (PV1.toBuiltin (hashToBytes sh))) transAddr :: Addr c -> Maybe PV1.Address transAddr (Addr _net object stake) = Just (PV1.Address (transCred object) (transStakeReference stake)) diff --git a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal index 37aeae1cee5..39e3b073639 100644 --- a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal +++ b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal @@ -63,9 +63,10 @@ library cborg, containers, data-default-class, - hashable, + hashable >= 1.4.1.0, + plutus-core, plutus-tx, - plutus-ledger-api, + plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>=1.0, QuickCheck, cardano-ledger-shelley-test, cardano-ledger-shelley, @@ -111,7 +112,7 @@ test-suite cardano-ledger-alonzo-test containers, data-default-class, plutus-core, - plutus-ledger-api, + plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>=1.0, QuickCheck, small-steps, small-steps-test, diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs index d098d67eeb8..fac4fc4f3f1 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/AlonzoEraGen.hs @@ -25,16 +25,27 @@ import Cardano.Ledger.Alonzo.PParams ) import Cardano.Ledger.Alonzo.PlutusScriptApi as Alonzo (language) import Cardano.Ledger.Alonzo.Rules (vKeyLocked) -import Cardano.Ledger.Alonzo.Scripts (isPlutusScript, pointWiseExUnits, txscriptfee) import Cardano.Ledger.Alonzo.Scripts as Alonzo ( AlonzoScript (..), CostModel, CostModels (..), ExUnits (..), Prices (..), + costModelParamsNamesSet, + isPlutusScript, mkCostModel, + pointWiseExUnits, + txscriptfee, + ) +import Cardano.Ledger.Alonzo.Tx + ( AlonzoEraTx (..), + AlonzoTx (..), + IsValid (..), + ScriptPurpose (..), + hashScriptIntegrity, + rdptr, + totExUnits, ) -import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx (..), AlonzoTx (..), IsValid (..), ScriptPurpose (..), hashScriptIntegrity, rdptr, totExUnits) import Cardano.Ledger.Alonzo.TxBody ( AlonzoEraTxBody (..), AlonzoTxBody (..), @@ -95,7 +106,6 @@ import Data.Set as Set import GHC.Records (HasField (..)) import Lens.Micro import Numeric.Natural (Natural) -import Plutus.V1.Ledger.Api (costModelParamNames) import qualified PlutusTx as P (Data (..)) import qualified PlutusTx as Plutus import Test.Cardano.Ledger.AllegraEraGen (genValidityInterval) @@ -197,13 +207,14 @@ genAlonzoMint startvalue = do -- | A cost model that sets everything as being free freeCostModel :: CostModel freeCostModel = - fromRight (error "freeCostModel is not well-formed") $ - Alonzo.mkCostModel PlutusV1 $ Map.fromSet (const 0) costModelParamNames + let lang = PlutusV1 + in fromRight (error "freeCostModel is not well-formed") $ + Alonzo.mkCostModel lang $ Map.fromSet (const 0) $ costModelParamsNamesSet lang -- ================================================================ genPair :: Gen a -> Gen b -> Gen (a, b) -genPair x y = do a <- x; b <- y; pure (a, b) +genPair x y = (,) <$> x <*> y genPlutusData :: Gen Plutus.Data genPlutusData = resize 5 (sized gendata) diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs index 72093495e10..0a28eadfe72 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs @@ -2,20 +2,20 @@ module Test.Cardano.Ledger.Alonzo.PlutusScripts where import Cardano.Ledger.Alonzo.Language (Language (..)) -import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), CostModel, mkCostModel) +import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (PlutusScript), CostModel, mkCostModel) import Data.ByteString.Short (pack) import Data.Either (fromRight) -import qualified Plutus.V1.Ledger.EvaluationContext as PV1 +import PlutusLedgerApi.Test.EvaluationContext (costModelParamsForTesting) testingCostModelV1 :: CostModel testingCostModelV1 = fromRight (error "testingCostModelV1 is not well-formed") $ - mkCostModel PlutusV1 PV1.costModelParamsForTesting + mkCostModel PlutusV1 (0 <$ costModelParamsForTesting) testingCostModelV2 :: CostModel testingCostModelV2 = fromRight (error "testingCostModelV2 is not well-formed") $ - mkCostModel PlutusV2 PV1.costModelParamsForTesting -- TODO use PV2 when it exists + mkCostModel PlutusV2 (0 <$ costModelParamsForTesting) {- Preproceesed Plutus Script guessTheNumber'2_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -27,13 +27,10 @@ guessTheNumber'2_0 d1_1 d2_2 = if d1_1 PlutusTx.Eq.== d2_2 guessTheNumber2 :: AlonzoScript era guessTheNumber2 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 48, 1, 0, 0, 51, 50, 34, 51, 34, 34, 83, 53, 48, 5], - [51, 53, 115, 70, 110, 188, 0, 128, 4, 1, 192, 24, 64, 16, 76], - [152, 212, 192, 12, 1, 18, 97, 32, 1, 32, 1, 18, 32, 2, 18], - [32, 1, 32, 1, 1] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 25, 1, 0, 0, 34, 83, 53, 51, 53, 115, 70, 110, 188, 0], + [128, 4, 72, 128, 8, 72, 128, 4, 68, 128, 4, 89] + ] {- Preproceesed Plutus Script guessTheNumber'3_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -46,13 +43,10 @@ guessTheNumber'3_0 d1_1 d2_2 _d3_3 = if d1_1 PlutusTx.Eq.== d2_2 guessTheNumber3 :: AlonzoScript era guessTheNumber3 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 48, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 51, 87, 52, 102, 235, 192, 12, 0, 128, 32, 1, 196, 1, 68], - [201, 141, 76, 1, 0, 21, 38, 18, 0, 18, 0, 17, 34, 0, 33], - [34, 0, 18, 0, 17] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 26, 1, 0, 0, 34, 37, 51, 83, 51, 87, 52, 102, 235, 192], + [12, 0, 132, 136, 0, 132, 136, 0, 68, 72, 0, 69, 129] + ] {- Preproceesed Plutus Script evendata'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -66,14 +60,11 @@ evendata'_0 d1_1 _d2_2 _d3_3 = let n_4 = PlutusTx.Builtins.unsafeDataAsI d1_1 evendata3 :: AlonzoScript era evendata3 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 50, 35, 51, 87, 52, 102, 225, 192, 8, 0, 64, 40, 2, 76], - [200, 140, 220, 48, 1, 0, 9, 186, 208, 3, 72, 1, 18, 0, 1], - [0, 81, 50, 99, 83, 0, 64, 5, 73, 132, 128, 4, 128, 4, 72], - [128, 8, 72, 128, 4, 128, 5] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 37, 51, 83, 35, 51, 87, 52, 102, 225], + [192, 5, 32, 0, 18, 32, 2, 18, 32, 1, 50, 51, 112, 192, 2], + [144, 2, 27, 173, 0, 49, 18, 0, 17, 97] + ] {- Preproceesed Plutus Script odddata'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -87,14 +78,11 @@ odddata'_0 d1_1 _d2_2 _d3_3 = let n_4 = PlutusTx.Builtins.unsafeDataAsI d1_1 odddata3 :: AlonzoScript era odddata3 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 50, 35, 51, 87, 52, 102, 225, 192, 8, 0, 64, 40, 2, 76], - [200, 140, 220, 48, 1, 0, 9, 186, 208, 3, 72, 1, 18, 0, 33], - [0, 81, 50, 99, 83, 0, 64, 5, 73, 132, 128, 4, 128, 4, 72], - [128, 8, 72, 128, 4, 128, 5] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 37, 51, 83, 35, 51, 87, 52, 102, 225], + [192, 5, 32, 2, 18, 32, 2, 18, 32, 1, 50, 51, 112, 192, 2], + [144, 2, 27, 173, 0, 49, 18, 0, 17, 97] + ] {- Preproceesed Plutus Script evenRedeemer'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -108,14 +96,11 @@ evenRedeemer'_0 _d1_1 d2_2 _d3_3 = let n_4 = PlutusTx.Builtins.unsafeDataAsI d2_ evenRedeemer3 :: AlonzoScript era evenRedeemer3 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 50, 35, 51, 87, 52, 102, 225, 192, 8, 0, 64, 40, 2, 76], - [200, 140, 220, 48, 1, 0, 9, 186, 208, 2, 72, 1, 18, 0, 1], - [0, 81, 50, 99, 83, 0, 64, 5, 73, 132, 128, 4, 128, 4, 72], - [128, 8, 72, 128, 4, 128, 5] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 37, 51, 83, 35, 51, 87, 52, 102, 225], + [192, 5, 32, 0, 18, 32, 2, 18, 32, 1, 50, 51, 112, 192, 2], + [144, 2, 27, 173, 0, 33, 18, 0, 17, 97] + ] {- Preproceesed Plutus Script oddRedeemer'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -129,14 +114,11 @@ oddRedeemer'_0 _d1_1 d2_2 _d3_3 = let n_4 = PlutusTx.Builtins.unsafeDataAsI d2_2 oddRedeemer3 :: AlonzoScript era oddRedeemer3 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 50, 35, 51, 87, 52, 102, 225, 192, 8, 0, 64, 40, 2, 76], - [200, 140, 220, 48, 1, 0, 9, 186, 208, 2, 72, 1, 18, 0, 33], - [0, 81, 50, 99, 83, 0, 64, 5, 73, 132, 128, 4, 128, 4, 72], - [128, 8, 72, 128, 4, 128, 5] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 37, 51, 83, 35, 51, 87, 52, 102, 225], + [192, 5, 32, 2, 18, 32, 2, 18, 32, 1, 50, 51, 112, 192, 2], + [144, 2, 27, 173, 0, 33, 18, 0, 17, 97] + ] {- Preproceesed Plutus Script sumsTo10'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -151,14 +133,12 @@ sumsTo10'_0 d1_1 d2_2 _d3_3 = let {n_4 = PlutusTx.Builtins.unsafeDataAsI d1_1; sumsTo103 :: AlonzoScript era sumsTo103 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 72, 1, 0, 0, 51, 50, 34, 50, 51, 34, 34, 37, 51, 83], - [0, 115, 50, 35, 51, 87, 52, 102, 225, 192, 8, 0, 64, 44, 2], - [140, 200, 140, 220, 0, 1, 0, 9, 128, 48, 1, 24, 3, 0, 26], - [64, 40, 32, 10, 38, 76, 106, 96, 8, 0, 169, 48, 144, 0, 144], - [0, 145, 186, 208, 1, 18, 32, 2, 18, 32, 1, 32, 1, 1] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 47, 1, 0, 0, 50, 34, 37, 51, 83, 35, 51, 87, 52, 102], + [225, 192, 5, 32, 20, 18, 32, 2, 18, 32, 1, 50, 50, 51, 112], + [0, 4, 0, 38, 0, 160, 8, 96, 8, 0, 66, 36, 0, 34, 196], + [110, 180, 0, 65] + ] {- Preproceesed Plutus Script oddRedeemer2'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -171,14 +151,11 @@ oddRedeemer2'_0 d1_1 _d3_2 = let n_3 = PlutusTx.Builtins.unsafeDataAsI d1_1 oddRedeemer2 :: AlonzoScript era oddRedeemer2 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 83, 53, 48, 5], - [51, 34, 51, 53, 115, 70, 110, 28, 0, 128, 4, 2, 64, 32, 204], - [136, 205, 195, 0, 16, 0, 155, 173, 0, 36, 128, 17, 32, 2, 16], - [4, 19, 38, 53, 48, 3, 0, 68, 152, 72, 0, 72, 0, 68, 136], - [0, 132, 136, 0, 72, 0, 65] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 83, 53, 50, 51, 53, 115, 70, 110, 28], + [0, 82, 0, 33, 34, 0, 33, 34, 0, 19, 35, 55, 12, 0, 41], + [0, 33, 186, 208, 2, 17, 32, 1, 22, 1] + ] {- Preproceesed Plutus Script evenRedeemer2'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -191,14 +168,11 @@ evenRedeemer2'_0 d1_1 _d3_2 = let n_3 = PlutusTx.Builtins.unsafeDataAsI d1_1 evenRedeemer2 :: AlonzoScript era evenRedeemer2 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 65, 1, 0, 0, 51, 50, 34, 51, 34, 34, 83, 53, 48, 5], - [51, 34, 51, 53, 115, 70, 110, 28, 0, 128, 4, 2, 64, 32, 204], - [136, 205, 195, 0, 16, 0, 155, 173, 0, 36, 128, 17, 32, 0, 16], - [4, 19, 38, 53, 48, 3, 0, 68, 152, 72, 0, 72, 0, 68, 136], - [0, 132, 136, 0, 72, 0, 65] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 38, 1, 0, 0, 34, 83, 53, 50, 51, 53, 115, 70, 110, 28], + [0, 82, 0, 1, 34, 0, 33, 34, 0, 19, 35, 55, 12, 0, 41], + [0, 33, 186, 208, 2, 17, 32, 1, 22, 1] + ] {- Preproceesed Plutus Script redeemerIs102'_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -211,13 +185,11 @@ redeemerIs102'_0 d1_1 _d3_2 = let n_3 = PlutusTx.Builtins.unsafeDataAsI d1_1 redeemerIs102 :: AlonzoScript era redeemerIs102 = - PlutusScript PlutusV1 . pack $ - concat - [ [88, 55, 1, 0, 0, 51, 50, 34, 51, 34, 34, 83, 53, 48, 5], - [51, 34, 51, 53, 115, 70, 110, 28, 0, 128, 4, 2, 64, 32, 221], - [104, 1, 36, 2, 130, 0, 130, 100, 198, 166, 0, 96, 8, 147, 9], - [0, 9, 0, 8, 145, 0, 16, 145, 0, 9, 0, 9] - ] + (PlutusScript PlutusV1 . pack . concat) + [ [88, 30, 1, 0, 0, 34, 83, 53, 50, 51, 53, 115, 70, 110, 28], + [0, 82, 1, 65, 34, 0, 33, 34, 0, 19, 117, 160, 4, 34, 64], + [2, 45] + ] {- Preproceesed Plutus Script guessTheNumber'2_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -229,13 +201,10 @@ guessTheNumber'2_0 d1_1 d2_2 = if d1_1 PlutusTx.Eq.== d2_2 guessTheNumber2V2 :: AlonzoScript era guessTheNumber2V2 = - PlutusScript PlutusV2 . pack $ - concat - [ [88, 48, 1, 0, 0, 51, 50, 34, 51, 34, 34, 83, 53, 48, 5], - [51, 53, 115, 70, 110, 188, 0, 128, 4, 1, 192, 24, 64, 16, 76], - [152, 212, 192, 12, 1, 18, 97, 32, 1, 32, 1, 18, 32, 2, 18], - [32, 1, 32, 1, 1] - ] + (PlutusScript PlutusV2 . pack . concat) + [ [88, 25, 1, 0, 0, 34, 83, 53, 51, 53, 115, 70, 110, 188, 0], + [128, 4, 72, 128, 8, 72, 128, 4, 68, 128, 4, 89] + ] {- Preproceesed Plutus Script guessTheNumber'3_0 :: PlutusTx.Builtins.Internal.BuiltinData -> @@ -248,10 +217,7 @@ guessTheNumber'3_0 d1_1 d2_2 _d3_3 = if d1_1 PlutusTx.Eq.== d2_2 guessTheNumber3V2 :: AlonzoScript era guessTheNumber3V2 = - PlutusScript PlutusV2 . pack $ - concat - [ [88, 48, 1, 0, 0, 51, 50, 34, 51, 34, 34, 37, 51, 83, 0], - [99, 51, 87, 52, 102, 235, 192, 12, 0, 128, 32, 1, 196, 1, 68], - [201, 141, 76, 1, 0, 21, 38, 18, 0, 18, 0, 17, 34, 0, 33], - [34, 0, 18, 0, 17] - ] + (PlutusScript PlutusV2 . pack . concat) + [ [88, 26, 1, 0, 0, 34, 37, 51, 83, 51, 87, 52, 102, 235, 192], + [12, 0, 132, 136, 0, 132, 136, 0, 68, 72, 0, 69, 129] + ] diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Scripts.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Scripts.hs index 58caae2c69c..2c737b94b96 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Scripts.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Scripts.hs @@ -9,7 +9,7 @@ import Cardano.Ledger.Alonzo.Language (Language (..)) import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..)) import Data.ByteString.Short (ShortByteString) import Numeric.Natural (Natural) -import qualified Plutus.V1.Ledger.Examples as Plutus +import qualified PlutusLedgerApi.Test.Examples as Plutus ( alwaysFailingNAryFunction, alwaysSucceedingNAryFunction, saltFunction, diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Serialisation/Generators.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Serialisation/Generators.hs index 60b3876d11c..47f53e4c2fa 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Serialisation/Generators.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Serialisation/Generators.hs @@ -43,6 +43,7 @@ import Cardano.Ledger.Alonzo.Scripts ExUnits (..), Prices (..), Tag (..), + costModelParamsNamesSet, mkCostModel, ) import Cardano.Ledger.Alonzo.Tx @@ -83,8 +84,7 @@ import Data.Typeable (Typeable) import Data.Void (Void) import GHC.Records (HasField) import Numeric.Natural (Natural) -import qualified Plutus.V1.Ledger.Api as PV1 -import qualified Plutus.V2.Ledger.Api as PV2 +import qualified PlutusLedgerApi.V1 as PV1 import Test.Cardano.Ledger.Alonzo.Scripts (alwaysFails, alwaysSucceeds) import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (Mock) import Test.Cardano.Ledger.Shelley.Serialisation.EraIndepGenerators () @@ -242,8 +242,7 @@ genCM lang costModelParamNames = do either (error "Corrupt cost model") pure $ mkCostModel lang newCMPs genCostModel :: Language -> Gen (Language, CostModel) -genCostModel PlutusV1 = (PlutusV1,) <$> genCM PlutusV1 PV1.costModelParamNames -genCostModel PlutusV2 = (PlutusV2,) <$> genCM PlutusV2 PV2.costModelParamNames +genCostModel lang = (,) lang <$> genCM lang (costModelParamsNamesSet lang) instance Arbitrary CostModel where arbitrary = snd <$> (elements nonNativeLanguages >>= genCostModel) diff --git a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Examples.hs b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Examples.hs index 5c4423972d0..c7c24d883a5 100644 --- a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Examples.hs +++ b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Examples.hs @@ -21,12 +21,12 @@ import Cardano.Ledger.Alonzo.TxInfo import Cardano.Ledger.BaseTypes (ProtVer (..)) import Data.ByteString.Short (ShortByteString) import Data.Proxy (Proxy (..)) -import qualified Plutus.V1.Ledger.Api as P -import qualified Plutus.V1.Ledger.EvaluationContext as P -import Plutus.V1.Ledger.Examples +import PlutusLedgerApi.Test.EvaluationContext +import PlutusLedgerApi.Test.Examples ( alwaysFailingNAryFunction, alwaysSucceedingNAryFunction, ) +import qualified PlutusLedgerApi.V1 as P import Test.Cardano.Ledger.Alonzo.PlutusScripts (testingCostModelV1) import qualified Test.Cardano.Ledger.Alonzo.PlutusScripts as Generated ( evenRedeemer2, @@ -75,8 +75,8 @@ directPlutusTest expectation script ds = pv = P.ProtocolVersion 6 0 evalWithTightBudget :: ShortByteString -> [P.Data] -> Either P.EvaluationError P.ExBudget evalWithTightBudget scr datums = do - budget <- snd $ P.evaluateScriptCounting pv P.Quiet P.evalCtxForTesting scr datums - snd $ P.evaluateScriptRestricting pv P.Verbose P.evalCtxForTesting budget scr datums + budget <- snd $ P.evaluateScriptCounting pv P.Quiet evalCtxForTesting scr datums + snd $ P.evaluateScriptRestricting pv P.Verbose evalCtxForTesting budget scr datums getRawPlutusScript :: String -> AlonzoScript () -> ShortByteString getRawPlutusScript name = diff --git a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs index 7a89bab423b..35e081d02f7 100644 --- a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs +++ b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs @@ -23,7 +23,13 @@ import Cardano.Ledger.Alonzo.PParams emptyPParams, getLanguageView, ) -import Cardano.Ledger.Alonzo.Scripts (CostModel, CostModels (..), Prices (..), mkCostModel) +import Cardano.Ledger.Alonzo.Scripts + ( CostModel, + CostModels (..), + Prices (..), + costModelParamsNamesSet, + mkCostModel, + ) import Cardano.Ledger.Alonzo.TxBody (AlonzoTxOut (..), utxoEntrySize) import Cardano.Ledger.BaseTypes (StrictMaybe (..), boundRational) import Cardano.Ledger.Block (Block (..)) @@ -39,9 +45,7 @@ import Data.Foldable (toList) import qualified Data.Map.Strict as Map import Data.Maybe (fromJust) import GHC.Stack (HasCallStack) -import Plutus.V1.Ledger.Api (Data (..)) -import qualified Plutus.V1.Ledger.Api as PV1 (costModelParamNames) -import qualified Plutus.V2.Ledger.Api as PV2 (costModelParamNames) +import PlutusLedgerApi.V1 (Data (..)) import Test.Cardano.Ledger.Alonzo.Examples.Consensus (ledgerExamplesAlonzo) import Test.Cardano.Ledger.Alonzo.Serialisation.CDDL (readDataFile) import Test.Cardano.Ledger.EraBuffet (StandardCrypto) @@ -229,11 +233,9 @@ fromRightError errorMsg = -- | A cost model that sets everything as being free freeCostModel :: HasCallStack => Language -> CostModel freeCostModel lang = - fromRightError "freeCostModel is not well-formed" $ mkCostModel lang (cmps lang) + fromRightError "freeCostModel is not well-formed" $ mkCostModel lang cmps where - names PlutusV1 = PV1.costModelParamNames - names PlutusV2 = PV2.costModelParamNames - cmps = Map.fromSet (const 0) . names + cmps = Map.fromSet (const 0) $ costModelParamsNamesSet lang exPP :: AlonzoPParams Alonzo exPP = diff --git a/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs b/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs index fef0646874b..33a8cbd02db 100644 --- a/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs +++ b/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs @@ -43,9 +43,9 @@ import qualified Data.Set as Set import Data.Text (Text) import GHC.Records (HasField (..)) import Lens.Micro -import qualified Plutus.V1.Ledger.Api as PV1 -import Plutus.V1.Ledger.Contexts () -import qualified Plutus.V2.Ledger.Api as PV2 +import qualified PlutusLedgerApi.V1 as PV1 +import PlutusLedgerApi.V1.Contexts () +import qualified PlutusLedgerApi.V2 as PV2 transScriptHash :: ScriptHash c -> PV2.ScriptHash transScriptHash (ScriptHash h) = PV2.ScriptHash (PV2.toBuiltin (hashToBytes h)) diff --git a/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/TxInfo.hs b/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/TxInfo.hs index d5e4bab52ff..00323a42c4a 100644 --- a/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/TxInfo.hs +++ b/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/TxInfo.hs @@ -33,8 +33,8 @@ import qualified Data.Sequence.Strict as StrictSeq import qualified Data.Set as Set import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import GHC.Stack -import qualified Plutus.V1.Ledger.Api as Plutus -import qualified Plutus.V2.Ledger.Api as PV2 +import qualified PlutusLedgerApi.V1 as Plutus +import qualified PlutusLedgerApi.V2 as PV2 import Test.Cardano.Ledger.Alonzo.Scripts (alwaysSucceeds) import Test.Cardano.Ledger.EraBuffet (StandardCrypto) import Test.Cardano.Ledger.Shelley.Address.Bootstrap (aliceByronAddr) diff --git a/eras/byron/ledger/impl/src/Cardano/Chain/Byron/API/Mempool.hs b/eras/byron/ledger/impl/src/Cardano/Chain/Byron/API/Mempool.hs index c6afccf6106..e585d501b9c 100644 --- a/eras/byron/ledger/impl/src/Cardano/Chain/Byron/API/Mempool.hs +++ b/eras/byron/ledger/impl/src/Cardano/Chain/Byron/API/Mempool.hs @@ -26,7 +26,7 @@ import qualified Cardano.Chain.Update as Update import qualified Cardano.Chain.Update.Validation.Interface as U.Iface import qualified Cardano.Chain.ValidationMode as CC import Cardano.Crypto.ProtocolMagic -import Cardano.Prelude +import Cardano.Prelude hiding (cborError) import qualified Codec.CBOR.Decoding as CBOR import qualified Codec.CBOR.Encoding as CBOR import qualified Codec.CBOR.Write as CBOR diff --git a/eras/shelley/impl/cardano-ledger-shelley.cabal b/eras/shelley/impl/cardano-ledger-shelley.cabal index 7d996191da1..891491a4504 100644 --- a/eras/shelley/impl/cardano-ledger-shelley.cabal +++ b/eras/shelley/impl/cardano-ledger-shelley.cabal @@ -104,7 +104,6 @@ library cardano-data, cardano-ledger-byron, cardano-ledger-core, - cardano-prelude, cardano-slotting, cborg, vector-map, @@ -112,6 +111,7 @@ library data-default-class, deepseq, groups, + heapwords, iproute, mtl, microlens, diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs index 0dfb7149cf0..c496e988a5d 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs @@ -61,7 +61,6 @@ import Cardano.Ledger.Serialization ipv6ToCBOR, ) import Cardano.Ledger.Shelley.Orphans () -import Cardano.Prelude (panic) import Control.DeepSeq (NFData ()) import Data.Aeson (FromJSON (..), ToJSON (..), Value, (.!=), (.:), (.:?), (.=)) import qualified Data.Aeson as Aeson @@ -271,14 +270,14 @@ instance FromCBOR PoolMetadata where data SizeOfPoolOwners = SizeOfPoolOwners instance ToCBOR SizeOfPoolOwners where - toCBOR = panic "The `SizeOfPoolOwners` type cannot be encoded!" + toCBOR = error "The `SizeOfPoolOwners` type cannot be encoded!" -- | The size of the '_poolRelays' 'Set'. Only used to compute size of encoded -- 'PoolParams'. data SizeOfPoolRelays = SizeOfPoolRelays instance ToCBOR SizeOfPoolRelays where - toCBOR = panic "The `SizeOfPoolRelays` type cannot be encoded!" + toCBOR = error "The `SizeOfPoolRelays` type cannot be encoded!" instance CC.Crypto c => diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxOut.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxOut.hs index e29eaffba65..30febcba3e2 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxOut.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/TxOut.hs @@ -26,6 +26,7 @@ where import Cardano.Binary (FromCBOR (..), ToCBOR (..), encodeListLen) import qualified Cardano.Crypto.Hash as HS +import Cardano.HeapWords (HeapWords (..)) import Cardano.Ledger.Address (Addr (..)) import Cardano.Ledger.CompactAddress (CompactAddr, compactAddr, decompactAddr) import Cardano.Ledger.Compactible (Compactible (CompactForm, fromCompact, toCompact)) @@ -38,7 +39,6 @@ import Cardano.Ledger.Serialization (decodeRecordNamed) import Cardano.Ledger.Shelley.Era (ShelleyEra) import Cardano.Ledger.Shelley.PParams (_minUTxOValue) import Cardano.Ledger.Val (DecodeNonNegative (..)) -import Cardano.Prelude (HeapWords (..)) import Control.DeepSeq (NFData (rnf)) import Data.ByteString.Short (ShortByteString, pack) import Data.Maybe (fromMaybe) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Core.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Core.hs index ac3d1953350..1fd36abde24 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Core.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Core.hs @@ -148,7 +148,7 @@ import Data.Ratio (denominator, numerator, (%)) import qualified Data.Sequence.Strict as StrictSeq import Data.Word (Word64) import Numeric.Natural (Natural) -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Crypto.VRF.Fake (WithResult (..)) import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (ExMock, Mock) import Test.Cardano.Ledger.Shelley.Generator.Constants (Constants (..)) diff --git a/libs/cardano-ledger-core/cardano-ledger-core.cabal b/libs/cardano-ledger-core/cardano-ledger-core.cabal index c0cc815ad70..9745ff0320e 100644 --- a/libs/cardano-ledger-core/cardano-ledger-core.cabal +++ b/libs/cardano-ledger-core/cardano-ledger-core.cabal @@ -80,13 +80,13 @@ library cardano-crypto-wrapper, cardano-data, cardano-ledger-byron, - cardano-prelude, cardano-slotting, cborg, containers, data-default-class, deepseq, groups, + heapwords, iproute, mtl, microlens, diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs index a2c25c105b1..4f218202a1c 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs @@ -87,7 +87,6 @@ import Cardano.Ledger.Keys hashKey, ) import Cardano.Ledger.Slot (SlotNo (..)) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Data.Aeson (FromJSON (..), FromJSONKey (..), ToJSON (..), ToJSONKey (..), (.:), (.=)) import qualified Data.Aeson as Aeson @@ -495,6 +494,6 @@ bootstrapKeyHash (BootstrapAddress byronAddress) = let root = Byron.addrRoot byronAddress bytes = Byron.abstractHashToBytes root !hash = - fromMaybe (panic "bootstrapKeyHash: incorrect hash length") $ + fromMaybe (error "bootstrapKeyHash: incorrect hash length") $ Hash.hashFromBytes bytes in KeyHash hash diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs index e384ca993ec..d4e670762da 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs @@ -22,8 +22,8 @@ module Cardano.Ledger.Coin where import Cardano.Binary (FromCBOR (..), ToCBOR (..)) +import Cardano.HeapWords (HeapWords) import Cardano.Ledger.Compactible -import Cardano.Prelude (HeapWords) import Control.DeepSeq (NFData) import Data.Aeson (FromJSON, ToJSON) import Data.Group (Abelian, Group (..)) diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs index 8765fb8b7b5..32e84cfb2fb 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs @@ -66,7 +66,6 @@ import qualified Cardano.Ledger.Crypto as CC (Crypto) import Cardano.Ledger.Hashes (ScriptHash (..)) import Cardano.Ledger.Keys (KeyHash (..)) import Cardano.Ledger.Slot (SlotNo (..)) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Control.Monad (ap, guard, unless, when) import qualified Control.Monad.Fail @@ -83,7 +82,7 @@ import Data.Maybe (fromMaybe) import qualified Data.Primitive.ByteArray as BA import Data.Proxy (Proxy (..)) import Data.String (fromString) -import Data.Text (Text) +import Data.Text (Text, unpack) import Data.Word (Word16, Word32, Word64, Word8) import GHC.Show (intToDigit) import Numeric (showIntAtBase) @@ -112,7 +111,7 @@ decompactAddrOld short = snd . unwrap "CompactAddr" $ runGetShort getShortAddr 0 -- is using a CompactAddr, which can only be constructed using compactAddr. -- compactAddr serializes an Addr, so this is guaranteed to work. unwrap :: forall a. Text -> Maybe a -> a - unwrap name = fromMaybe (panic $ "Impossible failure when decoding " <> name) + unwrap name = fromMaybe (error $ unpack $ "Impossible failure when decoding " <> name) {-# NOINLINE decompactAddrOld #-} ------------------------------------------------------------------------------------------ @@ -594,7 +593,7 @@ decompactAddrLazy (UnsafeCompactAddr bytes) = -- is using a CompactAddr, which can only be constructed using compactAddr. -- compactAddr serializes an Addr, so this is guaranteed to work. unwrap :: forall a. Text -> Maybe a -> a - unwrap name = fromMaybe (panic $ "Impossible failure when decoding " <> name) + unwrap name = fromMaybe (error $ unpack $ "Impossible failure when decoding " <> name) header = run "address header" 0 bytes getWord addrNetId = unwrap "address network id" $ diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs index 9fa505f5d3f..f251bfa0fc2 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs @@ -56,7 +56,6 @@ import Cardano.Ledger.Keys ) import qualified Cardano.Ledger.Keys as Keys import Cardano.Ledger.Serialization (decodeRecordNamed) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LBS @@ -185,7 +184,7 @@ unpackByronVKey -- This maybe is produced by a check that the length of the public key -- is the correct one. (32 bytes). If the XPub was constructed correctly, -- we already know that it has this length. - Nothing -> panic "unpackByronVKey: impossible!" + Nothing -> error "unpackByronVKey: impossible!" Just vk -> (VKey vk, ChainCode chainCodeBytes) verifyBootstrapWit :: @@ -204,7 +203,7 @@ verifyBootstrapWit txbodyHash witness = coerceSignature :: WC.XSignature -> DSIGN.SigDSIGN DSIGN.Ed25519DSIGN coerceSignature sig = - fromMaybe (panic "coerceSignature: impossible! signature size mismatch") $ + fromMaybe (error "coerceSignature: impossible! signature size mismatch") $ DSIGN.rawDeserialiseSigDSIGN (WC.unXSignature sig) makeBootstrapWitness :: diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/SafeHash.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/SafeHash.hs index 9f8988c1805..9de329fd478 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/SafeHash.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/SafeHash.hs @@ -60,8 +60,8 @@ where import Cardano.Binary (FromCBOR (..), ToCBOR (..)) import qualified Cardano.Crypto.Hash as Hash +import Cardano.HeapWords (HeapWords (..)) import qualified Cardano.Ledger.Crypto as CC -import Cardano.Prelude (HeapWords (..)) import Control.DeepSeq (NFData) import Data.ByteString (ByteString) import Data.ByteString.Short (ShortByteString, fromShort) diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs index f6746c23da8..f973388eb71 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/TxIn.hs @@ -24,15 +24,16 @@ module Cardano.Ledger.TxIn where import Cardano.Binary (FromCBOR (fromCBOR), ToCBOR (..), encodeListLen) +import Cardano.HeapWords (HeapWords (..)) +import qualified Cardano.HeapWords as HW import Cardano.Ledger.BaseTypes (TxIx (..), mkTxIxPartial) import qualified Cardano.Ledger.Crypto as CC import Cardano.Ledger.Hashes (EraIndependentTxBody) import Cardano.Ledger.SafeHash (SafeHash) import Cardano.Ledger.Serialization (decodeRecordNamed) -import Cardano.Prelude (HeapWords (..)) -import qualified Cardano.Prelude as HW import Control.DeepSeq (NFData) import GHC.Generics (Generic) +import GHC.Stack (HasCallStack) import NoThunks.Class (NoThunks (..)) -- =================================================================================== @@ -66,7 +67,7 @@ data TxIn c = TxIn !(TxId c) {-# UNPACK #-} !TxIx -- | Construct `TxIn` while throwing an error for an out of range `TxIx`. Make -- sure to use it only for testing. -mkTxInPartial :: HW.HasCallStack => TxId c -> Integer -> TxIn c +mkTxInPartial :: HasCallStack => TxId c -> Integer -> TxIn c mkTxInPartial txId = TxIn txId . mkTxIxPartial deriving instance Eq (TxIn c) diff --git a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs index 16b4e4c24a2..c902d06368c 100644 --- a/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs +++ b/libs/cardano-ledger-pretty/src/Cardano/Ledger/Pretty/Alonzo.hs @@ -42,7 +42,7 @@ import Cardano.Ledger.Core import Cardano.Ledger.Pretty hiding (ppPParams, ppPParamsUpdate, ppTx, ppTxBody, ppTxOut) import Cardano.Ledger.Pretty.Mary (ppMultiAsset, ppTimelock, ppValidityInterval) import Cardano.Ledger.SafeHash (SafeToHash) -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import qualified Prettyprinter as PP ppTxSeq :: diff --git a/libs/cardano-ledger-test/cardano-ledger-test.cabal b/libs/cardano-ledger-test/cardano-ledger-test.cabal index f62b73750ce..affeb4ac545 100644 --- a/libs/cardano-ledger-test/cardano-ledger-test.cabal +++ b/libs/cardano-ledger-test/cardano-ledger-test.cabal @@ -96,7 +96,7 @@ library microlens, mtl, nothunks, - plutus-ledger-api, + plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>=1.0, plutus-core, prettyprinter, QuickCheck, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Alonzo/Tools.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Alonzo/Tools.hs index 0f9a2c7f7f4..a6094b8af8d 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Alonzo/Tools.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Alonzo/Tools.hs @@ -42,7 +42,7 @@ import Data.Text (Text) import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import GHC.Records (HasField) import Lens.Micro -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Alonzo.PlutusScripts (testingCostModelV1) import Test.Cardano.Ledger.Alonzo.Serialisation.Generators () import Test.Cardano.Ledger.Babbage.Serialisation.Generators () diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoAPI.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoAPI.hs index 4103b66aa18..a3c29ee0406 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoAPI.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoAPI.hs @@ -32,7 +32,7 @@ import Cardano.Ledger.Shelley.API import Cardano.Ledger.Shelley.UTxO (makeWitnessVKey) import Cardano.Ledger.Val (Val (inject)) import qualified Data.Map.Strict as Map -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( freeCostModelV1, mkGenesisTxIn, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs index c47a81a9523..b45707ef7bd 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs @@ -93,7 +93,7 @@ import Data.Maybe (fromJust) import qualified Data.Sequence.Strict as StrictSeq import Data.UMap (View (Rewards)) import qualified Data.UMap as UM -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( alwaysFailsHash, alwaysSucceedsHash, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoCollectInputs.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoCollectInputs.hs index 922917d60cd..1c3e05a285d 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoCollectInputs.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoCollectInputs.hs @@ -48,7 +48,7 @@ import Data.Either (fromRight) import qualified Data.Map.Strict as Map import Data.Text (Text) import Data.Time.Clock.POSIX (posixSecondsToUTCTime) -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( freeCostModelV1, initUTxO, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoInvalidTxUTXOW.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoInvalidTxUTXOW.hs index fbd2afed2ef..bcdcf48b77c 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoInvalidTxUTXOW.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoInvalidTxUTXOW.hs @@ -77,7 +77,7 @@ import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.Map.Strict as Map import qualified Data.Set as Set import GHC.Stack -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( AlonzoBased (..), alwaysSucceedsHash, @@ -964,7 +964,7 @@ defaultPPs = MaxValSize 1000000000, MaxTxExUnits $ ExUnits 1000000 1000000, MaxBlockExUnits $ ExUnits 1000000 1000000, - ProtocolVersion $ ProtVer 5 0, + ProtocolVersion $ ProtVer 7 0, CollateralPercentage 100 ] diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoValidTxUTXOW.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoValidTxUTXOW.hs index 1b7d3e2c5c2..83b7206c192 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoValidTxUTXOW.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoValidTxUTXOW.hs @@ -60,7 +60,7 @@ import Control.State.Transition.Extended hiding (Assertion) import Data.Default.Class (Default (..)) import qualified Data.Map.Strict as Map import GHC.Stack -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( alwaysFailsHash, alwaysSucceedsHash, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/BabbageFeatures.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/BabbageFeatures.hs index 3afdc01d6bf..cb14fa9dc05 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/BabbageFeatures.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/BabbageFeatures.hs @@ -73,7 +73,7 @@ import qualified Data.Sequence.Strict as StrictSeq import qualified Data.Set as Set import GHC.Stack import Lens.Micro -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils ( AlonzoBased (..), freeCostModelV1, diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/STSTestUtils.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/STSTestUtils.hs index 791fead9580..15a3d227146 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/STSTestUtils.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/STSTestUtils.hs @@ -104,8 +104,8 @@ import Data.Map (Map) import qualified Data.Map.Strict as Map import GHC.Natural (Natural) import GHC.Stack -import qualified Plutus.V1.Ledger.Api as Plutus -import Plutus.V1.Ledger.EvaluationContext (costModelParamsForTesting) +import PlutusLedgerApi.Test.EvaluationContext (costModelParamsForTesting) +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Generic.Fields ( TxOutField (..), ) diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/ApplyTx.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/ApplyTx.hs index 68ec4329e2c..113682f847f 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/ApplyTx.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/ApplyTx.hs @@ -46,7 +46,7 @@ import Data.Set (Set) import qualified Data.Set as Set import GHC.Stack (HasCallStack) import Lens.Micro -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import Test.Cardano.Ledger.Examples.STSTestUtils (freeCostModelV1, initUTxO, mkGenesisTxIn, mkTxDats, someAddr, someKeys) import Test.Cardano.Ledger.Generic.Fields ( PParamsField (..), diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Consensus.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Consensus.hs index cb3e27fbfde..84b87dc0f14 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Consensus.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/Consensus.hs @@ -90,7 +90,7 @@ import Data.Word (Word64, Word8) import GHC.Records (HasField) import GHC.Stack (HasCallStack) import Numeric.Natural (Natural) -import qualified Plutus.V1.Ledger.Api as Plutus +import qualified PlutusLedgerApi.V1 as Plutus import qualified Test.Cardano.Ledger.Allegra.Examples.Consensus as Old (ledgerExamplesAllegra) import Test.Cardano.Ledger.Alonzo.EraMapping () import qualified Test.Cardano.Ledger.Alonzo.Examples.Consensus as Old (ledgerExamplesAlonzo) diff --git a/libs/plutus-preprocessor/plutus-preprocessor.cabal b/libs/plutus-preprocessor/plutus-preprocessor.cabal index a6931ef148c..25bfcfddd47 100644 --- a/libs/plutus-preprocessor/plutus-preprocessor.cabal +++ b/libs/plutus-preprocessor/plutus-preprocessor.cabal @@ -34,6 +34,7 @@ executable plutus-preprocessor bytestring, cardano-ledger-alonzo, flat, + hashable >= 1.4.1.0, plutus-core, plutus-tx, plutus-tx-plugin, diff --git a/libs/plutus-preprocessor/src/Main.hs b/libs/plutus-preprocessor/src/Main.hs index 005977ca96c..475e985643a 100644 --- a/libs/plutus-preprocessor/src/Main.hs +++ b/libs/plutus-preprocessor/src/Main.hs @@ -2,14 +2,14 @@ {-# LANGUAGE TemplateHaskell #-} -- | The 'main' function in this file writes a file --- 'cardano-ledger/alonzo/test/lib/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs' +-- 'cardano-ledger/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs' -- When this file is compiled it exports a bunch of Alonzo era scripts that are plutus scripts. -- Compiling that file does not have any dependency on the plutus-plugin. --- Instead this package 'plutus-preproccssor' has that dependency, but one does not have +-- Instead this package 'plutus-preprocessor' has that dependency, but one does not have -- to compile this package to build the system. -- If the plutus package changes, we will have to regenerate the PlutusScripts.hs file. -- To regenerate PlutusScripts.hs, on a machine that can depend upon plutus=plugin, then --- cd into the plutus-preprocessor directory and type 'cabal run' +-- cd into the plutus-preprocessor directory and type 'cabal run plutus-preprocessor' module Main where import Cardano.Ledger.Alonzo.Language (Language (..)) @@ -19,7 +19,7 @@ import Data.ByteString.Short (ShortByteString, pack, toShort, unpack) import Flat (flat) import Language.Haskell.TH import Language.Haskell.TH.Ppr -import qualified Plutus.V1.Ledger.Api as P +import qualified PlutusLedgerApi.V1 as P import PlutusScripts ( evenRedeemerDecl, evenRedeemerDecl2Args, @@ -48,7 +48,7 @@ display h lang bytes code name = do concat [ "\n", name, - " :: Script era\n", + " :: AlonzoScript era\n", name, " = (PlutusScript ", show lang, @@ -144,18 +144,28 @@ redeemerIs10Bytes2Args = main :: IO () main = do - outh <- openFile "../alonzo/test/lib/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs" WriteMode - mapM_ - (hPutStrLn outh) - [ "-- | This file is generated by plutus-preprocessor/src/Main.hs", - "module Test.Cardano.Ledger.Alonzo.PlutusScripts where\n", - "import Cardano.Ledger.Alonzo.Language (Language (..))", - "import Cardano.Ledger.Alonzo.Scripts (CostModel (..), Script (..))", - "import Data.ByteString.Short (pack)", - "import Plutus.V1.Ledger.EvaluationContext (costModelParamsForTesting, mkEvaluationContext)\n", - "defaultCostModel :: CostModel", - "defaultCostModel = CostModel costModelParamsForTesting <$> (mkEvaluationContext costModelParamsForTesting)" - ] + outh <- openFile "../../eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/PlutusScripts.hs" WriteMode + hPutStrLn outh $ + unlines + [ "-- | This file is generated by plutus-preprocessor/src/Main.hs", + "module Test.Cardano.Ledger.Alonzo.PlutusScripts where\n", + "import Cardano.Ledger.Alonzo.Language (Language (..))", + "import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (PlutusScript), CostModel, mkCostModel)", + "import Data.ByteString.Short (pack)", + "import Data.Either (fromRight)", + "import PlutusLedgerApi.Test.EvaluationContext (costModelParamsForTesting)", + "", + "testingCostModelV1 :: CostModel", + "testingCostModelV1 =", + " fromRight (error \"testingCostModelV1 is not well-formed\") $", + " mkCostModel PlutusV1 (0 <$ costModelParamsForTesting)", + "", + "testingCostModelV2 :: CostModel", + "testingCostModelV2 =", + " fromRight (error \"testingCostModelV2 is not well-formed\") $", + " mkCostModel PlutusV2 (0 <$ costModelParamsForTesting)", + "" + ] display outh PlutusV1 guess2args guessDecl2args "guessTheNumber2" display outh PlutusV1 guessTheNumberBytes guessDecl "guessTheNumber3" display outh PlutusV1 evendataBytes evendataDecl "evendata3" diff --git a/libs/plutus-preprocessor/src/PlutusScripts.hs b/libs/plutus-preprocessor/src/PlutusScripts.hs index 327f1fd1102..ebef2657fa4 100644 --- a/libs/plutus-preprocessor/src/PlutusScripts.hs +++ b/libs/plutus-preprocessor/src/PlutusScripts.hs @@ -19,7 +19,7 @@ where import Data.String (fromString) import Language.Haskell.TH -import qualified Plutus.V1.Ledger.Api as P +import qualified PlutusLedgerApi.V1 as P import qualified PlutusTx as P (Data (..), compile) import qualified PlutusTx.Builtins as P import qualified PlutusTx.Prelude as P diff --git a/shell.nix b/shell.nix index ce21c655fde..852614f30ad 100644 --- a/shell.nix +++ b/shell.nix @@ -23,10 +23,6 @@ let shell = cardanoLedgerSpecsHaskellPackages.shellFor { name = "cabal-dev-shell"; - # If shellFor local packages selection is wrong, - # then list all local packages then include source-repository-package that cabal complains about: - packages = ps: lib.attrValues (haskell-nix.haskellLib.selectProjectPackages ps); - # These programs will be available inside the nix-shell. buildInputs = with haskellPackages; [ nix-prefetch-git