Skip to content

Commit 521a696

Browse files
committed
Added duplicate deleg certs golden test
1 parent f297532 commit 521a696

File tree

17 files changed

+255
-183
lines changed

17 files changed

+255
-183
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ library testlib
8989
Test.Cardano.Ledger.Allegra.Arbitrary
9090
Test.Cardano.Ledger.Allegra.Binary.Annotator
9191
Test.Cardano.Ledger.Allegra.Binary.Cddl
92+
Test.Cardano.Ledger.Allegra.Binary.Golden
9293
Test.Cardano.Ledger.Allegra.CDDL
9394
Test.Cardano.Ledger.Allegra.Era
9495
Test.Cardano.Ledger.Allegra.Examples

eras/allegra/impl/test/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Main where
44

55
import Cardano.Ledger.Allegra (AllegraEra)
66
import qualified Test.Cardano.Ledger.Allegra.Binary.CddlSpec as CddlSpec
7+
import qualified Test.Cardano.Ledger.Allegra.Binary.Golden as Golden
78
import qualified Test.Cardano.Ledger.Allegra.BinarySpec as BinarySpec
89
import qualified Test.Cardano.Ledger.Allegra.Imp as Imp
910
import Test.Cardano.Ledger.Allegra.ImpTest ()
@@ -21,3 +22,4 @@ main =
2122
Imp.spec @AllegraEra
2223
roundTripJsonEraSpec @AllegraEra
2324
roundTripJsonShelleyEraSpec @AllegraEra
25+
Golden.spec
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{-# LANGUAGE AllowAmbiguousTypes #-}
2+
{-# LANGUAGE PatternSynonyms #-}
3+
{-# LANGUAGE RankNTypes #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
{-# LANGUAGE TypeApplications #-}
6+
7+
module Test.Cardano.Ledger.Allegra.Binary.Golden (
8+
spec,
9+
allegraDecodeDuplicateDelegCertSucceeds,
10+
module Test.Cardano.Ledger.Shelley.Binary.Golden,
11+
) where
12+
13+
import Cardano.Ledger.Allegra.Core (
14+
AllegraEraTxBody (..),
15+
ShelleyEraTxCert,
16+
ValidityInterval (..),
17+
pattern DelegStakeTxCert,
18+
)
19+
import Cardano.Ledger.Binary (Version)
20+
import Cardano.Ledger.Credential (Credential (..))
21+
import Cardano.Ledger.MemoBytes (EqRaw (..))
22+
import Cardano.Ledger.Shelley.Core (EraTxBody (..), TxLevel (..))
23+
import Data.Maybe.Strict (StrictMaybe (..))
24+
import qualified Data.Sequence.Strict as SSeq
25+
import Lens.Micro ((&), (.~))
26+
import Test.Cardano.Ledger.Allegra.Era (AllegraEraTest)
27+
import Test.Cardano.Ledger.Common (Spec, describe, it, prop)
28+
import Test.Cardano.Ledger.Core.KeyPair (mkKeyHash)
29+
import Test.Cardano.Ledger.Imp.Common (forEachEraVersion)
30+
import Test.Cardano.Ledger.Shelley.Binary.Golden hiding (spec)
31+
32+
allegraDecodeDuplicateDelegCertSucceeds ::
33+
forall era. (AllegraEraTest era, ShelleyEraTxCert era) => Version -> Spec
34+
allegraDecodeDuplicateDelegCertSucceeds version =
35+
it "Decodes duplicate delegation certificates successfully" $ do
36+
let testCert = DelegStakeTxCert @era (KeyHashObj $ mkKeyHash 0) (mkKeyHash 1)
37+
expectDecoderSuccessAnnWith eqRaw version (duplicateDelegCertsTxBody @era version) $
38+
mkBasicTxBody @era @TopTx
39+
& certsTxBodyL .~ SSeq.fromList [testCert, testCert]
40+
& vldtTxBodyL .~ ValidityInterval SNothing (SJust 300)
41+
42+
spec ::
43+
forall era.
44+
( AllegraEraTest era
45+
, ShelleyEraTxCert era
46+
) =>
47+
Spec
48+
spec =
49+
describe "Golden" $ do
50+
prop "NewEpochState" $ goldenNewEpochStateExpectation @era
51+
describe "TxCerts" $ do
52+
forEachEraVersion @era $ allegraDecodeDuplicateDelegCertSucceeds @era

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ library testlib
147147
base,
148148
bytestring,
149149
cardano-data:{cardano-data, testlib},
150-
cardano-ledger-allegra,
150+
cardano-ledger-allegra:{cardano-ledger-allegra, testlib},
151151
cardano-ledger-alonzo,
152152
cardano-ledger-binary:{cardano-ledger-binary, testlib},
153153
cardano-ledger-core:{cardano-ledger-core, testlib},

eras/alonzo/impl/test/Test/Cardano/Ledger/Alonzo/BinarySpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ spec = do
4343
decoderEquivalenceEraSpec @AlonzoEra @(TxDats AlonzoEra)
4444
decoderEquivalenceEraSpec @AlonzoEra @(Redeemers AlonzoEra)
4545
Binary.txSizeSpec @AlonzoEra
46-
Golden.spec @AlonzoEra (eraProtVerLow @AlonzoEra)
46+
Golden.spec @AlonzoEra

eras/alonzo/impl/test/Test/Cardano/Ledger/Alonzo/GoldenSpec.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Test.Cardano.Ledger.Alonzo.GoldenSpec (spec) where
55

66
import Cardano.Ledger.Alonzo
7-
import Cardano.Ledger.Core (eraProtVersions)
87
import Paths_cardano_ledger_alonzo (getDataFileName)
98
import qualified Test.Cardano.Ledger.Alonzo.Binary.Golden as Golden
109
import Test.Cardano.Ledger.Alonzo.Era ()
@@ -14,9 +13,9 @@ import Test.Cardano.Ledger.Core.JSON (goldenJsonPParamsSpec, goldenJsonPParamsUp
1413
spec :: Spec
1514
spec =
1615
describe "Golden" $ do
17-
beforeAll (getDataFileName "golden/pparams.json") $
18-
goldenJsonPParamsSpec @AlonzoEra
19-
beforeAll (getDataFileName "golden/pparams-update.json") $
20-
goldenJsonPParamsUpdateSpec @AlonzoEra
21-
forM_ (eraProtVersions @AlonzoEra) $ \version ->
22-
describe (show version) $ Golden.spec @AlonzoEra version
16+
describe "JSON files" $ do
17+
beforeAll (getDataFileName "golden/pparams.json") $
18+
goldenJsonPParamsSpec @AlonzoEra
19+
beforeAll (getDataFileName "golden/pparams-update.json") $
20+
goldenJsonPParamsUpdateSpec @AlonzoEra
21+
describe "CBOR" $ Golden.spec @AlonzoEra

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/Golden.hs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
module Test.Cardano.Ledger.Alonzo.Binary.Golden (
1010
spec,
1111
witsEmptyField,
12-
module Test.Cardano.Ledger.Shelley.Binary.Golden,
12+
module Test.Cardano.Ledger.Allegra.Binary.Golden,
1313
) where
1414

15-
import Cardano.Ledger.Alonzo.Core (EraTxWits (..))
15+
import Cardano.Ledger.Alonzo.Core (EraTxWits (..), ShelleyEraTxCert)
1616
import Cardano.Ledger.Binary (
1717
Annotator,
1818
DecoderError (..),
1919
DeserialiseFailure (..),
2020
Tokens (..),
21-
Version,
2221
)
2322
import qualified Cardano.Ledger.Binary as Binary
2423
import Cardano.Ledger.MemoBytes (EqRaw (..))
2524
import Data.Data (Proxy (..))
2625
import Data.Void (Void)
26+
import Test.Cardano.Ledger.Allegra.Binary.Golden hiding (spec)
2727
import Test.Cardano.Ledger.Alonzo.Era (AlonzoEraTest)
2828
import Test.Cardano.Ledger.Binary.Plain.Golden (Enc (..))
2929
import Test.Cardano.Ledger.Common (
3030
Spec,
3131
describe,
3232
it,
3333
)
34-
import Test.Cardano.Ledger.Shelley.Binary.Golden hiding (spec)
34+
import Test.Cardano.Ledger.Imp.Common (forEachEraVersion)
3535

3636
witsEmptyField :: Int -> Enc
3737
witsEmptyField k =
@@ -43,28 +43,31 @@ witsEmptyField k =
4343

4444
spec ::
4545
forall era.
46-
AlonzoEraTest era =>
47-
Version -> Spec
48-
spec version =
46+
(AlonzoEraTest era, ShelleyEraTxCert era) =>
47+
Spec
48+
spec = do
4949
describe "TxWits" $ do
50-
describe "Empty fields allowed" $ do
51-
let
52-
expectSuccessOnEmptyFieldRaw k =
53-
expectDecoderSuccessAnnWith eqRaw version (witsEmptyField k) (mkBasicTxWits @era)
54-
expectFailureOnEmptyField k =
55-
expectDecoderFailureAnn @(TxWits era) version (witsEmptyField k)
56-
it "addrTxWits" $ expectSuccessOnEmptyFieldRaw 0
57-
it "nativeScripts" $ expectSuccessOnEmptyFieldRaw 1
58-
it "bootstrapWitness" $ expectSuccessOnEmptyFieldRaw 2
59-
it "plutusV1Script" $ expectSuccessOnEmptyFieldRaw 3
60-
it "plutusData" $ expectSuccessOnEmptyFieldRaw 4
61-
it "redeemers" $ expectSuccessOnEmptyFieldRaw 5
62-
-- Fields 6 and 7 should not deserialize, but they do due to a bug in the Alonzo decoder
63-
-- This should not be a problem starting with PV9, because we won't allow empty lists
64-
-- from there onwards
65-
it "plutusV2Script" $ expectSuccessOnEmptyFieldRaw 6
66-
it "plutusV3Script" $ expectSuccessOnEmptyFieldRaw 7
67-
it "8th field" . expectFailureOnEmptyField 8 $
68-
DecoderErrorDeserialiseFailure
69-
(Binary.label $ Proxy @(Annotator (TxWits era)))
70-
(DeserialiseFailure 2 "An error occured while decoding (Int,Void) not a valid key:.\nError: 8")
50+
forEachEraVersion @era $ \version ->
51+
describe "Empty fields allowed" $ do
52+
let
53+
expectSuccessOnEmptyFieldRaw k =
54+
expectDecoderSuccessAnnWith eqRaw version (witsEmptyField k) (mkBasicTxWits @era)
55+
expectFailureOnEmptyField k =
56+
expectDecoderFailureAnn @(TxWits era) version (witsEmptyField k)
57+
it "addrTxWits" $ expectSuccessOnEmptyFieldRaw 0
58+
it "nativeScripts" $ expectSuccessOnEmptyFieldRaw 1
59+
it "bootstrapWitness" $ expectSuccessOnEmptyFieldRaw 2
60+
it "plutusV1Script" $ expectSuccessOnEmptyFieldRaw 3
61+
it "plutusData" $ expectSuccessOnEmptyFieldRaw 4
62+
it "redeemers" $ expectSuccessOnEmptyFieldRaw 5
63+
-- Fields 6 and 7 should not deserialize, but they do due to a bug in the Alonzo decoder
64+
-- This should not be a problem starting with PV9, because we won't allow empty lists
65+
-- from there onwards
66+
it "plutusV2Script" $ expectSuccessOnEmptyFieldRaw 6
67+
it "plutusV3Script" $ expectSuccessOnEmptyFieldRaw 7
68+
it "8th field" . expectFailureOnEmptyField 8 $
69+
DecoderErrorDeserialiseFailure
70+
(Binary.label $ Proxy @(Annotator (TxWits era)))
71+
(DeserialiseFailure 2 "An error occured while decoding (Int,Void) not a valid key:.\nError: 8")
72+
describe "TxCerts" $ do
73+
forEachEraVersion @era $ allegraDecodeDuplicateDelegCertSucceeds @era

eras/babbage/impl/test/Test/Cardano/Ledger/Babbage/GoldenSpec.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Test.Cardano.Ledger.Babbage.GoldenSpec (spec) where
55

66
import Cardano.Ledger.Babbage
7-
import Cardano.Ledger.Babbage.Core (eraProtVersions)
87
import Paths_cardano_ledger_babbage (getDataFileName)
98
import qualified Test.Cardano.Ledger.Alonzo.Binary.Golden as Golden
109
import Test.Cardano.Ledger.Babbage.Era ()
@@ -14,9 +13,9 @@ import Test.Cardano.Ledger.Core.JSON (goldenJsonPParamsSpec, goldenJsonPParamsUp
1413
spec :: Spec
1514
spec =
1615
describe "Golden" $ do
17-
beforeAll (getDataFileName "golden/pparams.json") $
18-
goldenJsonPParamsSpec @BabbageEra
19-
beforeAll (getDataFileName "golden/pparams-update.json") $
20-
goldenJsonPParamsUpdateSpec @BabbageEra
21-
forM_ (eraProtVersions @BabbageEra) $ \version ->
22-
describe (show version) . describe "Alonzo era golden tests" $ Golden.spec @BabbageEra version
16+
describe "JSON files" $ do
17+
beforeAll (getDataFileName "golden/pparams.json") $
18+
goldenJsonPParamsSpec @BabbageEra
19+
beforeAll (getDataFileName "golden/pparams-update.json") $
20+
goldenJsonPParamsUpdateSpec @BabbageEra
21+
describe "CBOR" $ Golden.spec @BabbageEra

eras/conway/impl/test/Test/Cardano/Ledger/Conway/GoldenSpec.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
module Test.Cardano.Ledger.Conway.GoldenSpec (spec) where
66

77
import Cardano.Ledger.Conway (ConwayEra)
8-
import Cardano.Ledger.Conway.Core (eraProtVersions)
98
import Paths_cardano_ledger_conway (getDataFileName)
109
import Test.Cardano.Ledger.Common
1110
import qualified Test.Cardano.Ledger.Conway.Binary.Golden as Golden
@@ -19,5 +18,4 @@ spec =
1918
goldenJsonPParamsSpec @ConwayEra
2019
beforeAll (getDataFileName "golden/pparams-update.json") $
2120
goldenJsonPParamsUpdateSpec @ConwayEra
22-
forM_ (eraProtVersions @ConwayEra) $ \version ->
23-
describe (show version) . describe "Conway era golden tests" $ Golden.spec @ConwayEra version
21+
describe "Conway era golden tests" $ Golden.spec @ConwayEra

0 commit comments

Comments
 (0)