Skip to content

Commit

Permalink
Restructure babbage Imp hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Apr 23, 2024
1 parent 058977e commit f28b6ed
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 51 deletions.
1 change: 1 addition & 0 deletions eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ library testlib
exposed-modules:
Test.Cardano.Ledger.Allegra.Arbitrary
Test.Cardano.Ledger.Allegra.Binary.Cddl
Test.Cardano.Ledger.Allegra.Imp
Test.Cardano.Ledger.Allegra.ImpTest
Test.Cardano.Ledger.Allegra.TreeDiff

Expand Down
4 changes: 2 additions & 2 deletions eras/allegra/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import qualified Test.Cardano.Ledger.Allegra.Binary.CddlSpec as CddlSpec
import qualified Test.Cardano.Ledger.Allegra.BinarySpec as BinarySpec
import Test.Cardano.Ledger.Allegra.ImpTest ()
import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
import qualified Test.Cardano.Ledger.Allegra.Imp as Imp

main :: IO ()
main =
Expand All @@ -16,4 +16,4 @@ main =
BinarySpec.spec
CddlSpec.spec
describe "Imp" $ do
ShelleyImp.spec @Allegra
Imp.spec @Allegra
23 changes: 23 additions & 0 deletions eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Imp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.Allegra.Imp (spec) where

import Cardano.Ledger.Core
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Shelley.ImpTest (ShelleyEraImp)
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp

spec ::
forall era.
( ShelleyEraImp era
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
) =>
Spec
spec = do
ShelleyImp.spec @era
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Allegra.ImpTest (impAllegraSatisfyNativeScript) where
module Test.Cardano.Ledger.Allegra.ImpTest (
impAllegraSatisfyNativeScript,
module Test.Cardano.Ledger.Shelley.ImpTest,
) where

import Cardano.Crypto.DSIGN (DSIGNAlgorithm (..), Ed25519DSIGN)
import Cardano.Crypto.Hash.Class (Hash)
Expand Down
1 change: 0 additions & 1 deletion eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ library testlib
containers,
cardano-crypto-class,
cardano-data,
cardano-ledger-allegra:testlib,
cardano-ledger-alonzo,
cardano-ledger-binary,
cardano-ledger-mary:testlib,
Expand Down
6 changes: 2 additions & 4 deletions eras/alonzo/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import qualified Test.Cardano.Ledger.Alonzo.Binary.CddlSpec as CddlSpec
import qualified Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec as CostModelsSpec
import qualified Test.Cardano.Ledger.Alonzo.Binary.TxWitsSpec as TxWitsSpec
import qualified Test.Cardano.Ledger.Alonzo.BinarySpec as BinarySpec
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
import qualified Test.Cardano.Ledger.Alonzo.Imp as Imp
import Test.Cardano.Ledger.Alonzo.ImpTest ()
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.JSON (roundTripJsonEraSpec)
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp

main :: IO ()
main =
Expand All @@ -21,8 +20,7 @@ main =
CddlSpec.spec
roundTripJsonEraSpec @Alonzo
describe "Imp" $ do
ShelleyImp.spec @Alonzo
AlonzoImp.spec @Alonzo
Imp.spec @Alonzo
describe "CostModels" $ do
CostModelsSpec.spec @Alonzo
describe "TxWits" $ do
Expand Down
15 changes: 10 additions & 5 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

module Test.Cardano.Ledger.Alonzo.Imp where

import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx)
import Cardano.Ledger.Alonzo.Core
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec as Utxos
import Test.Cardano.Ledger.Alonzo.ImpTest (ShelleyEraImp, withImpState)
import Test.Cardano.Ledger.Alonzo.ImpTest (MaryEraImp, withImpState)
import Test.Cardano.Ledger.Common (Spec, describe)
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp

spec ::
forall era.
( ShelleyEraImp era
( MaryEraImp era
, AlonzoEraTx era
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
) =>
Spec
spec =
describe "AlonzoImpTest" . withImpState @era $ do
spec = do
MaryImp.spec @era
describe "AlonzoImpSpec" . withImpState @era $ do
Utxos.spec @era
20 changes: 13 additions & 7 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Alonzo.ImpTest (
module ImpTest,
module Test.Cardano.Ledger.Mary.ImpTest,
AlonzoEraImp (..),
initAlonzoImpNES,
impLookupPlutusScriptMaybe,
Expand Down Expand Up @@ -77,22 +77,19 @@ import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro
import qualified PlutusLedgerApi.Common as P
import Test.Cardano.Ledger.Allegra.ImpTest (
impAllegraSatisfyNativeScript,
)
import Test.Cardano.Ledger.Alonzo.TreeDiff ()
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.Cardano.Ledger.Imp.Common
import Test.Cardano.Ledger.Mary.ImpTest
import Test.Cardano.Ledger.Plutus (
PlutusArgs (..),
ScriptTestContext (..),
testingCostModels,
)
import Test.Cardano.Ledger.Plutus.Examples
import Test.Cardano.Ledger.Shelley.ImpTest as ImpTest

class
( ShelleyEraImp era
( MaryEraImp era
, AlonzoEraScript era
, AlonzoEraTxWits era
, AlonzoEraTx era
Expand Down Expand Up @@ -391,7 +388,16 @@ instance
impSatisfyNativeScript = impAllegraSatisfyNativeScript
fixupTx = alonzoFixupTx

instance ShelleyEraImp (AlonzoEra c) => AlonzoEraImp (AlonzoEra c) where
instance
( Crypto c
, NFData (SigDSIGN (DSIGN c))
, NFData (VerKeyDSIGN (DSIGN c))
, DSIGN c ~ Ed25519DSIGN
, Signable (DSIGN c) (Hash (HASH c) EraIndependentTxBody)
) =>
MaryEraImp (AlonzoEra c)

instance MaryEraImp (AlonzoEra c) => AlonzoEraImp (AlonzoEra c) where
scriptTestContexts = plutusTestScripts SPlutusV1

impGetScriptContextMaybe ::
Expand Down
5 changes: 2 additions & 3 deletions eras/babbage/impl/cardano-ledger-babbage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ library testlib
exposed-modules:
Test.Cardano.Ledger.Babbage.Arbitrary
Test.Cardano.Ledger.Babbage.Binary.Cddl
Test.Cardano.Ledger.Babbage.Imp
Test.Cardano.Ledger.Babbage.ImpTest
Test.Cardano.Ledger.Babbage.TreeDiff

Expand All @@ -109,9 +110,8 @@ library testlib
build-depends:
base,
bytestring,
cardano-ledger-allegra:testlib,
cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib},
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
cardano-ledger-shelley,
cardano-crypto-class,
cardano-ledger-babbage,
cardano-ledger-binary,
Expand Down Expand Up @@ -141,7 +141,6 @@ test-suite tests
cardano-ledger-babbage,
cardano-ledger-core,
cardano-ledger-binary:testlib,
cardano-ledger-shelley:testlib,
cardano-ledger-core:testlib,
cardano-ledger-alonzo:testlib,
data-default-class,
Expand Down
6 changes: 2 additions & 4 deletions eras/babbage/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ module Main where
import Cardano.Ledger.Babbage (Babbage)
import qualified Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec as CostModelsSpec
import qualified Test.Cardano.Ledger.Alonzo.Binary.TxWitsSpec as TxWitsSpec
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
import qualified Test.Cardano.Ledger.Babbage.Binary.CddlSpec as CddlSpec
import qualified Test.Cardano.Ledger.Babbage.BinarySpec as BinarySpec
import qualified Test.Cardano.Ledger.Babbage.Imp as Imp
import Test.Cardano.Ledger.Babbage.ImpTest ()
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.JSON (roundTripJsonEraSpec)
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp

main :: IO ()
main =
Expand All @@ -21,8 +20,7 @@ main =
CddlSpec.spec
roundTripJsonEraSpec @Babbage
describe "Imp" $ do
AlonzoImp.spec @Babbage
ShelleyImp.spec @Babbage
Imp.spec @Babbage
describe "CostModels" $ do
CostModelsSpec.spec @Babbage
describe "TxWits" $ do
Expand Down
24 changes: 24 additions & 0 deletions eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/Imp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Cardano.Ledger.Babbage.Imp (spec) where

import Cardano.Ledger.Babbage.Core
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp)
import Test.Cardano.Ledger.Common

spec ::
forall era.
( AlonzoEraImp era
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
) =>
Spec
spec = do
AlonzoImp.spec @era
15 changes: 6 additions & 9 deletions eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Ledger.Babbage.ImpTest () where
module Test.Cardano.Ledger.Babbage.ImpTest (
module Test.Cardano.Ledger.Alonzo.ImpTest,
) where

import Cardano.Crypto.DSIGN (DSIGNAlgorithm (..), Ed25519DSIGN)
import Cardano.Crypto.Hash (Hash)
import Cardano.Ledger.Babbage (BabbageEra)
import Cardano.Ledger.Core
import Cardano.Ledger.Crypto (Crypto (..))
import Cardano.Ledger.Plutus.Language (SLanguage (..))
import Test.Cardano.Ledger.Allegra.ImpTest (impAllegraSatisfyNativeScript)
import Test.Cardano.Ledger.Alonzo.ImpTest (
AlonzoEraImp (..),
alonzoFixupTx,
initAlonzoImpNES,
plutusTestScripts,
)
import Test.Cardano.Ledger.Alonzo.ImpTest
import Test.Cardano.Ledger.Babbage.TreeDiff ()
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Shelley.ImpTest (ShelleyEraImp (..))

instance
( Crypto c
Expand All @@ -39,5 +34,7 @@ instance
impSatisfyNativeScript = impAllegraSatisfyNativeScript
fixupTx = alonzoFixupTx

instance ShelleyEraImp (BabbageEra c) => MaryEraImp (BabbageEra c)

instance ShelleyEraImp (BabbageEra c) => AlonzoEraImp (BabbageEra c) where
scriptTestContexts = plutusTestScripts SPlutusV1 <> plutusTestScripts SPlutusV2
7 changes: 5 additions & 2 deletions eras/mary/impl/cardano-ledger-mary.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ library testlib
exposed-modules:
Test.Cardano.Ledger.Mary.Arbitrary
Test.Cardano.Ledger.Mary.Binary.Cddl
Test.Cardano.Ledger.Mary.Imp
Test.Cardano.Ledger.Mary.ImpTest
Test.Cardano.Ledger.Mary.Imp.UtxoSpec
Test.Cardano.Ledger.Mary.TreeDiff

visibility: public
Expand All @@ -115,9 +117,10 @@ library testlib
cardano-ledger-binary:testlib,
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-mary,
cardano-ledger-allegra:testlib,
cardano-ledger-allegra:{cardano-ledger-allegra, testlib},
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
cardano-strict-containers
cardano-strict-containers,
microlens

test-suite tests
type: exitcode-stdio-1.0
Expand Down
4 changes: 2 additions & 2 deletions eras/mary/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import qualified Test.Cardano.Ledger.Mary.Binary.CddlSpec as CddlSpec
import qualified Test.Cardano.Ledger.Mary.BinarySpec as BinarySpec
import Test.Cardano.Ledger.Mary.ImpTest ()
import qualified Test.Cardano.Ledger.Mary.ValueSpec as ValueSpec
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
import qualified Test.Cardano.Ledger.Mary.Imp as Imp

main :: IO ()
main =
Expand All @@ -18,4 +18,4 @@ main =
BinarySpec.spec
CddlSpec.spec
describe "Imp" $ do
ShelleyImp.spec @Mary
Imp.spec @Mary
28 changes: 28 additions & 0 deletions eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/Imp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Cardano.Ledger.Mary.Imp (spec) where

import Cardano.Ledger.Mary.Core
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Allegra.Imp as AllegraImp
import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Ledger.Mary.Imp.UtxoSpec as Utxo
import Test.Cardano.Ledger.Mary.ImpTest (MaryEraImp)
import Test.Cardano.Ledger.Shelley.ImpTest (withImpState)

spec ::
forall era.
( MaryEraImp era
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
) =>
Spec
spec = do
AllegraImp.spec @era
describe "MaryImpSpec" $ withImpState @era $ do
Utxo.spec @era
40 changes: 40 additions & 0 deletions eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/Imp/UtxoSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Cardano.Ledger.Mary.Imp.UtxoSpec (spec) where

import Cardano.Ledger.Allegra.Scripts
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Mary.Core
import Cardano.Ledger.Mary.Value
--import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure (..))
import qualified Data.Map.Strict as Map
import Lens.Micro
import Test.Cardano.Ledger.Imp.Common
import Test.Cardano.Ledger.Shelley.ImpTest

spec ::
( ShelleyEraImp era
, MaryEraTxBody era
--, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
, NativeScript era ~ Timelock era
, Value era ~ MaryValue (EraCrypto era)
) =>
SpecWith (ImpTestState era)
spec = describe "UTXO" $ do
it "Mint a Token" $ do
(_, addr) <- freshKeyAddr
(keyHash, _) <- freshKeyPair
scriptHash <- impAddNativeScript $ RequireSignature keyHash
let txCoin = Coin 1000000
txAsset = MultiAsset $ Map.singleton (PolicyID scriptHash) $ Map.singleton (AssetName "testAsset") 100
txValue = MaryValue txCoin txAsset
txBody =
mkBasicTxBody
& outputsTxBodyL .~ [mkBasicTxOut addr txValue]
& mintTxBodyL .~ txAsset
submitTx_ $ mkBasicTx txBody

0 comments on commit f28b6ed

Please sign in to comment.