Skip to content

Commit 8f6be2b

Browse files
committed
Add Test.Cardano.Ledger.Core.Binary.Golden.goldenExampleEraTxCborSpec in cardano-ledger-core:testlib and generate the golden example transactions for each era.
`goldenExampleEraTxCborSpec` allows us to generate a `Spec` for generating a `golden/tx.cbor` golden file out of some `Tx` provided as a parameter. Then, for each era's test-suite, we call this function to generate the golden file using the example transaction we have defined for each era. We also extended `EraTest` so that we don't need to manually call `getDataFileName` in order to get the fullpath for each era's cabal project. We also create new `Binary.Golden` modules for Mary and Babbage (previously they reused Allegra's and Alonzo's respectively, which used the wrong era's example transactions). Additionally, fix `exampleDijkstraBasedTopTx` to not add PlutusV4 scripts to `scriptTxWitsL`: PlutusV4 is not included in Dijkstra's `transaction_witness_set` CDDL, so those scripts were silently dropped during serialization, causing a roundtrip failure.
1 parent 64dfb8c commit 8f6be2b

56 files changed

Lines changed: 267 additions & 156 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eras/allegra/impl/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Make `Test.Cardano.Ledger.Allegra.Imp.spec` accept `Proxy era`
1818
* In `Test.Cardano.Ledger.Allegra.Examples`:
1919
- Remove `mkAllegraBasedExampleTx`, `exampleAllegraBasedTxBody`, `exampleAllegraBasedShelleyTxBody`
20-
- Add `exampleAllegraBasedTx`
20+
- Add `exampleAllegraBasedTx`, `exampleAllegraTx`
2121

2222
## 1.9.0.0
2323

eras/allegra/impl/cardano-ledger-allegra.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ description:
1111

1212
category: Network
1313
build-type: Simple
14-
data-files: cddl/data/allegra.cddl
14+
data-files:
15+
cddl/data/allegra.cddl
16+
golden/*.cbor
17+
1518
extra-source-files: CHANGELOG.md
1619

1720
source-repository head

eras/allegra/impl/golden/tx.cbor

1.7 KB
Binary file not shown.

eras/allegra/impl/test/Main.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE TypeApplications #-}
2+
{-# OPTIONS_GHC -Wno-orphans #-}
23

34
module Main where
45

@@ -8,7 +9,6 @@ import qualified Test.Cardano.Ledger.Allegra.Binary.Golden as Golden
89
import qualified Test.Cardano.Ledger.Allegra.BinarySpec as BinarySpec
910
import qualified Test.Cardano.Ledger.Allegra.Imp as Imp
1011
import Test.Cardano.Ledger.Allegra.ImpTest ()
11-
import Test.Cardano.Ledger.Common
1212
import Test.Cardano.Ledger.Core.JSON (roundTripJsonEraSpec)
1313
import Test.Cardano.Ledger.Era
1414
import qualified Test.Cardano.Ledger.Shelley.Imp as Imp (shelleyEraSpecificSpec)
@@ -21,12 +21,9 @@ instance EraSpec AllegraEra where
2121

2222
main :: IO ()
2323
main =
24-
ledgerTestMain $
25-
describe "Allegra" $ do
26-
BinarySpec.spec
27-
CddlSpec.spec
28-
describe "Imp" $ do
29-
Imp.spec @AllegraEra
30-
roundTripJsonEraSpec @AllegraEra
31-
roundTripJsonShelleyEraSpec @AllegraEra
32-
Golden.spec @AllegraEra
24+
ledgerEraTestMain @AllegraEra $ do
25+
BinarySpec.spec
26+
CddlSpec.spec
27+
roundTripJsonEraSpec @AllegraEra
28+
roundTripJsonShelleyEraSpec @AllegraEra
29+
Golden.spec @AllegraEra

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Era.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import Cardano.Ledger.Allegra.Core
1212
import Cardano.Ledger.Allegra.Scripts
1313
import Cardano.Ledger.MemoBytes (EqRaw)
1414
import Cardano.Ledger.Plutus (emptyCostModels)
15+
import Paths_cardano_ledger_allegra (getDataFileName)
1516
import Test.Cardano.Ledger.Allegra.Arbitrary ()
1617
import Test.Cardano.Ledger.Allegra.Binary.Annotator ()
18+
import Test.Cardano.Ledger.Allegra.Examples (exampleAllegraTx)
1719
import Test.Cardano.Ledger.Allegra.TreeDiff ()
1820
import Test.Cardano.Ledger.Common
1921
import Test.Cardano.Ledger.Shelley.Era
@@ -37,6 +39,10 @@ instance EraTest AllegraEra where
3739

3840
accountsFromAccountsMap = shelleyAccountsFromAccountsMap
3941

42+
mkEraFullPath = getDataFileName
43+
44+
exampleTx = exampleAllegraTx
45+
4046
instance ShelleyEraTest AllegraEra
4147

4248
instance AllegraEraTest AllegraEra

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Examples.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-- don't care, we are only interested in serialisation, not validation.
99
module Test.Cardano.Ledger.Allegra.Examples (
1010
ledgerExamples,
11+
exampleAllegraTx,
1112
exampleAllegraBasedTx,
1213
) where
1314

@@ -49,14 +50,14 @@ ledgerExamples =
4950
exampleCoin
5051
exampleAllegraTx
5152
NoGenesis
52-
where
53-
exampleAllegraTx :: Tx TopTx AllegraEra
54-
exampleAllegraTx =
55-
exampleAllegraBasedTx
56-
& addShelleyBasedTopTxExampleFee
57-
& addShelleyToBabbageExampleProposedPUpdates
58-
& addShelleyToBabbageTxCerts
59-
& addShelleyToConwayTxCerts
53+
54+
exampleAllegraTx :: Tx TopTx AllegraEra
55+
exampleAllegraTx =
56+
exampleAllegraBasedTx
57+
& addShelleyBasedTopTxExampleFee
58+
& addShelleyToBabbageExampleProposedPUpdates
59+
& addShelleyToBabbageTxCerts
60+
& addShelleyToConwayTxCerts
6061

6162
-- Complete transaction which is compatible with any era starting with Allegra.
6263
-- This transaction forms the basis on which future era transactions will be

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Imp.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import Test.Cardano.Ledger.Imp.Common
1616
import qualified Test.Cardano.Ledger.Shelley.Imp as Shelley
1717

1818
spec ::
19-
forall era.
19+
forall proxy era.
2020
( ShelleyEraImp era
2121
, Event (EraRule "RUPD" era) ~ RupdEvent
2222
) =>
23+
proxy era ->
2324
Spec
2425
spec era = do
2526
Shelley.spec era

eras/alonzo/impl/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* `TranslationInstance` has a new field `tiPlutusPurpose`
5050
* In `Test.Cardano.Ledger.Alonzo.Examples`:
5151
- Remove `mkAlonzoBasedExampleTx`, `exampleAlonzoBasedShelleyTxBody`, `exampleAlonzoBasedTxBody`, `exampleRedeemer`
52-
- Add `exampleAlonzoBasedTopTx`, `exampleAlonzoBasedTopTx`, `addAlonzoToConwayExampleReqSigners`
52+
- Add `exampleAlonzoTx`, `exampleAlonzoBasedTopTx`, `exampleAlonzoBasedTopTx`, `addAlonzoToConwayExampleReqSigners`
5353

5454
## 1.15.0.0
5555

eras/alonzo/impl/golden/tx.cbor

2.22 KB
Binary file not shown.

eras/alonzo/impl/test/Main.hs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE TypeApplications #-}
2+
{-# OPTIONS_GHC -Wno-orphans #-}
23

34
module Main where
45

@@ -8,7 +9,7 @@ import qualified Test.Cardano.Ledger.Alonzo.Binary.CddlSpec as CddlSpec
89
import qualified Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec as CostModelsSpec
910
import qualified Test.Cardano.Ledger.Alonzo.Binary.TxWitsSpec as TxWitsSpec
1011
import qualified Test.Cardano.Ledger.Alonzo.BinarySpec as BinarySpec
11-
import qualified Test.Cardano.Ledger.Alonzo.GoldenSpec as Golden
12+
import qualified Test.Cardano.Ledger.Alonzo.GoldenSpec as GoldenSpec
1213
import qualified Test.Cardano.Ledger.Alonzo.GoldenTranslation as GoldenTranslation
1314
import qualified Test.Cardano.Ledger.Alonzo.Imp as Imp
1415
import qualified Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec as TxInfoImp
@@ -27,19 +28,16 @@ instance EraSpec AlonzoEra where
2728

2829
main :: IO ()
2930
main =
30-
ledgerTestMain $
31-
describe "Alonzo" $ do
32-
BinarySpec.spec
33-
Canonical.spec
34-
CddlSpec.spec
35-
roundTripJsonEraSpec @AlonzoEra
36-
roundTripJsonShelleyEraSpec @AlonzoEra
37-
GoldenTranslation.tests
38-
Golden.spec
39-
describe "Imp" $ do
40-
Imp.spec @AlonzoEra
41-
describe "CostModels" $ do
42-
CostModelsSpec.spec @AlonzoEra
43-
describe "TxWits" $ do
44-
TxWitsSpec.spec @AlonzoEra
45-
TxInfoImp.spec
31+
ledgerEraTestMain @AlonzoEra $ do
32+
BinarySpec.spec
33+
Canonical.spec
34+
CddlSpec.spec
35+
roundTripJsonEraSpec @AlonzoEra
36+
roundTripJsonShelleyEraSpec @AlonzoEra
37+
GoldenTranslation.tests
38+
GoldenSpec.spec
39+
describe "CostModels" $ do
40+
CostModelsSpec.spec @AlonzoEra
41+
describe "TxWits" $ do
42+
TxWitsSpec.spec @AlonzoEra
43+
TxInfoImp.spec

0 commit comments

Comments
 (0)