Skip to content

Commit 577e4b2

Browse files
committed
Add EraSpecificSpec class
1 parent c86ec02 commit 577e4b2

File tree

12 files changed

+83
-92
lines changed

12 files changed

+83
-92
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
{-# LANGUAGE TypeApplications #-}
66
{-# LANGUAGE TypeFamilies #-}
7+
{-# OPTIONS_GHC -Wno-orphans #-}
78

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

11+
import Cardano.Ledger.Allegra (AllegraEra)
1012
import Cardano.Ledger.Core
1113
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
1214
import qualified Test.Cardano.Ledger.Allegra.Imp.UtxowSpec as UtxowSpec
15+
import Test.Cardano.Ledger.Allegra.ImpTest
1316
import Test.Cardano.Ledger.Imp.Common
1417
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
15-
import Test.Cardano.Ledger.Shelley.ImpTest
1618

1719
spec ::
1820
forall era.
1921
( ShelleyEraImp era
22+
, EraSpecificSpec era
2023
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
2124
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
2225
) =>
@@ -25,3 +28,5 @@ spec = do
2528
ShelleyImp.spec @era
2629
describe "AllegraImpSpec" . withImpInit @(LedgerSpec era) $ do
2730
UtxowSpec.spec
31+
32+
instance EraSpecificSpec AllegraEra

eras/alonzo/impl/test/Main.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ main =
3131
Golden.spec
3232
describe "Imp" $ do
3333
Imp.spec @AlonzoEra
34-
Imp.shelleyCertsSpec @AlonzoEra
3534
describe "CostModels" $ do
3635
CostModelsSpec.spec @AlonzoEra
3736
describe "TxWits" $ do

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp.hs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@
44
{-# LANGUAGE RankNTypes #-}
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE TypeApplications #-}
7+
{-# OPTIONS_GHC -Wno-orphans #-}
78

89
module Test.Cardano.Ledger.Alonzo.Imp where
910

11+
import Cardano.Ledger.Alonzo (AlonzoEra)
1012
import Cardano.Ledger.Alonzo.Core
1113
import Cardano.Ledger.Alonzo.Rules (
1214
AlonzoUtxoPredFailure,
1315
AlonzoUtxosPredFailure,
1416
AlonzoUtxowPredFailure,
1517
)
1618
import Cardano.Ledger.Shelley.Rules (
17-
ShelleyDelegPredFailure,
1819
ShelleyUtxoPredFailure,
1920
ShelleyUtxowPredFailure,
2021
)
2122
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec as Utxo
2223
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec as Utxos
2324
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
24-
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, LedgerSpec)
25+
import Test.Cardano.Ledger.Alonzo.ImpTest
2526
import Test.Cardano.Ledger.Imp.Common
2627
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp
2728

2829
spec ::
2930
forall era.
3031
( AlonzoEraImp era
32+
, EraSpecificSpec era
3133
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
3234
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
3335
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
@@ -42,16 +44,5 @@ spec = do
4244
Utxos.spec
4345
Utxow.spec
4446

45-
shelleyCertsSpec ::
46-
forall era.
47-
( AlonzoEraImp era
48-
, ShelleyEraTxCert era
49-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
50-
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
51-
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
52-
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
53-
) =>
54-
Spec
55-
shelleyCertsSpec = do
56-
describe "AlonzoImp - certificates without deposit" . withImpInit @(LedgerSpec era) $ do
57-
Utxow.shelleyCertsSpec
47+
instance EraSpecificSpec AlonzoEra where
48+
eraSpecific = Utxow.shelleyCertsSpec

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxowSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ shelleyCertsSpec ::
4444
) =>
4545
SpecWith (ImpInit (LedgerSpec era))
4646
shelleyCertsSpec = do
47-
describe "UTXOW" $ do
47+
describe "UTXOW - certificates without deposits" $ do
4848
Valid.shelleyCertsSpec
4949
Invalid.shelleyCertsSpec

eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/Imp.hs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
{-# LANGUAGE TypeApplications #-}
66
{-# LANGUAGE TypeFamilies #-}
7+
{-# OPTIONS_GHC -Wno-orphans #-}
78

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

@@ -13,17 +14,18 @@ import Cardano.Ledger.Alonzo.Rules (
1314
AlonzoUtxosPredFailure,
1415
AlonzoUtxowPredFailure,
1516
)
17+
import Cardano.Ledger.Babbage (BabbageEra)
1618
import Cardano.Ledger.Babbage.Core (BabbageEraTxBody, InjectRuleFailure)
1719
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure, BabbageUtxowPredFailure)
1820
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
1921
import Cardano.Ledger.BaseTypes (Inject)
2022
import Cardano.Ledger.Shelley.Rules (
21-
-- ShelleyDelegPredFailure,
2223
ShelleyUtxoPredFailure,
2324
ShelleyUtxowPredFailure,
2425
)
2526
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
26-
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, LedgerSpec)
27+
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as AlonzoUtxow
28+
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, EraSpecificSpec (..), LedgerSpec)
2729
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxoSpec as Utxo
2830
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxosSpec as Utxos
2931
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxowSpec as Utxow
@@ -32,9 +34,9 @@ import Test.Cardano.Ledger.Imp.Common
3234
spec ::
3335
forall era.
3436
( AlonzoEraImp era
37+
, EraSpecificSpec era
3538
, BabbageEraTxBody era
36-
, -- , InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
37-
InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
39+
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
3840
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
3941
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
4042
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
@@ -46,8 +48,10 @@ spec ::
4648
Spec
4749
spec = do
4850
AlonzoImp.spec @era
49-
withImpInit @(LedgerSpec era) $
50-
describe "BabbageImpSpec" $ do
51-
Utxo.spec
52-
Utxow.spec
53-
Utxos.spec @era
51+
describe "BabbageImpSpec - era generic tests" . withImpInit @(LedgerSpec era) $ do
52+
Utxo.spec
53+
Utxow.spec
54+
Utxos.spec @era
55+
56+
instance EraSpecificSpec BabbageEra where
57+
eraSpecific = AlonzoUtxow.shelleyCertsSpec

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
{-# LANGUAGE TypeApplications #-}
66
{-# LANGUAGE TypeFamilies #-}
77
{-# LANGUAGE TypeOperators #-}
8-
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
8+
{-# OPTIONS_GHC -Wno-orphans #-}
99

10-
module Test.Cardano.Ledger.Conway.Imp (spec, conwaySpec, shelleyCertsSpec) where
10+
module Test.Cardano.Ledger.Conway.Imp (spec) where
1111

1212
import Cardano.Ledger.Alonzo.Plutus.Context (
1313
EraPlutusContext (ContextError),
@@ -21,6 +21,7 @@ import Cardano.Ledger.Alonzo.Rules (
2121
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure, BabbageUtxowPredFailure)
2222
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
2323
import Cardano.Ledger.BaseTypes (Inject)
24+
import Cardano.Ledger.Conway (ConwayEra)
2425
import Cardano.Ledger.Conway.Core
2526
import Cardano.Ledger.Conway.Rules (
2627
ConwayBbodyPredFailure,
@@ -39,13 +40,12 @@ import Cardano.Ledger.Conway.TxInfo (ConwayContextError)
3940
import Cardano.Ledger.Plutus (Language (..))
4041
import Cardano.Ledger.Shelley.API.Mempool (ApplyTx (..))
4142
import Cardano.Ledger.Shelley.Rules (
42-
ShelleyDelegPredFailure,
4343
ShelleyUtxoPredFailure,
4444
ShelleyUtxowPredFailure,
4545
)
4646
import Control.State.Transition.Extended
4747
import Data.Typeable (Typeable)
48-
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
48+
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as AlonzoUtxow
4949
import qualified Test.Cardano.Ledger.Babbage.Imp as BabbageImp
5050
import qualified Test.Cardano.Ledger.Conway.Imp.BbodySpec as Bbody
5151
import qualified Test.Cardano.Ledger.Conway.Imp.CertsSpec as Certs
@@ -65,11 +65,12 @@ import Test.Cardano.Ledger.Conway.ImpTest (
6565
modifyImpInitProtVer,
6666
)
6767
import Test.Cardano.Ledger.Imp.Common
68-
import Test.Cardano.Ledger.Shelley.ImpTest (ImpInit)
68+
import Test.Cardano.Ledger.Shelley.ImpTest (EraSpecificSpec (..), ImpInit)
6969

7070
spec ::
7171
forall era.
7272
( ConwayEraImp era
73+
, EraSpecificSpec era
7374
, Inject (BabbageContextError era) (ContextError era)
7475
, Inject (ConwayContextError era) (ContextError era)
7576
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
@@ -79,7 +80,6 @@ spec ::
7980
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
8081
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
8182
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
82-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
8383
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
8484
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
8585
, InjectRuleFailure "LEDGER" ConwayDelegPredFailure era
@@ -106,10 +106,10 @@ spec = do
106106
withImpInit @(LedgerSpec era) $
107107
forM_ (eraProtVersions @era) $ \protVer ->
108108
describe ("ConwayImpSpec - " <> show protVer) $
109-
modifyImpInitProtVer protVer $
110-
conwaySpec @era
109+
modifyImpInitProtVer protVer $ do
110+
conwayEraGenericSpec @era
111111

112-
conwaySpec ::
112+
conwayEraGenericSpec ::
113113
forall era.
114114
( ConwayEraImp era
115115
, Inject (BabbageContextError era) (ContextError era)
@@ -139,7 +139,7 @@ conwaySpec ::
139139
, EraPlutusTxInfo PlutusV2 era
140140
) =>
141141
SpecWith (ImpInit (LedgerSpec era))
142-
conwaySpec = do
142+
conwayEraGenericSpec = do
143143
describe "BBODY" Bbody.spec
144144
describe "CERTS" Certs.spec
145145
describe "DELEG" Deleg.spec
@@ -154,40 +154,23 @@ conwaySpec = do
154154

155155
-- describe "UTXOW" Utxow.spec
156156

157-
shelleyCertsSpec ::
158-
forall era.
157+
conwayEraSpecificSpec ::
159158
( ConwayEraImp era
160159
, ShelleyEraTxCert era
161-
, Inject (BabbageContextError era) (ContextError era)
162160
, Inject (ConwayContextError era) (ContextError era)
163-
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
164-
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
165-
, InjectRuleFailure "LEDGER" BabbageUtxoPredFailure era
166-
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
167-
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
168-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
169-
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
170161
, InjectRuleFailure "LEDGER" ConwayDelegPredFailure era
171-
, InjectRuleFailure "LEDGER" ConwayGovCertPredFailure era
172162
, InjectRuleFailure "LEDGER" ConwayLedgerPredFailure era
173-
, InjectRuleFailure "LEDGER" ConwayUtxoPredFailure era
174-
, InjectRuleFailure "BBODY" ConwayBbodyPredFailure era
175-
, InjectRuleEvent "TICK" ConwayEpochEvent era
176-
, Event (EraRule "EPOCH" era) ~ ConwayEpochEvent era
177-
, Event (EraRule "NEWEPOCH" era) ~ ConwayNewEpochEvent era
178-
, Event (EraRule "HARDFORK" era) ~ ConwayHardForkEvent era
179-
, ApplyTx era
180-
, NFData (Event (EraRule "ENACT" era))
181-
, ToExpr (Event (EraRule "ENACT" era))
182-
, Eq (Event (EraRule "ENACT" era))
183-
, Typeable (Event (EraRule "ENACT" era))
163+
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
184164
) =>
185-
Spec
186-
shelleyCertsSpec = do
187-
AlonzoImp.shelleyCertsSpec @era
188-
withImpInit @(LedgerSpec era) $
189-
forM_ (eraProtVersions @era) $ \protVer ->
190-
describe ("Certificates without deposits - " <> show protVer) $
191-
modifyImpInitProtVer protVer $ do
192-
describe "DELEG" Deleg.shelleyCertsSpec
193-
describe "UTXO" Utxo.shelleyCertsSpec
165+
SpecWith (ImpInit (LedgerSpec era))
166+
conwayEraSpecificSpec = do
167+
describe "DELEG - certificates without deposits" Deleg.shelleyCertsSpec
168+
describe "LEDGER - certificates without deposits" Ledger.shelleyCertsSpec
169+
describe "RATIFY - certificates without deposits" Ratify.shelleyCertsSpec
170+
describe "UTXO - certificates without deposits" Utxo.shelleyCertsSpec
171+
describe "UTXOS - certificates without deposits" Utxos.shelleyCertsSpec
172+
173+
instance EraSpecificSpec ConwayEra where
174+
eraSpecific =
175+
AlonzoUtxow.shelleyCertsSpec
176+
>> conwayEraSpecificSpec

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Spec.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import Cardano.Ledger.Plutus.Language (SLanguage (..))
3939
import Cardano.Ledger.Shelley.API (ApplyTx)
4040
import Cardano.Ledger.Shelley.LedgerState (StashedAVVMAddresses)
4141
import Cardano.Ledger.Shelley.Rules (
42-
ShelleyDelegPredFailure,
4342
ShelleyUtxoPredFailure,
4443
ShelleyUtxowPredFailure,
4544
)
@@ -54,7 +53,7 @@ import qualified Test.Cardano.Ledger.Conway.BinarySpec as Binary
5453
import qualified Test.Cardano.Ledger.Conway.CommitteeRatifySpec as CommitteeRatify
5554
import qualified Test.Cardano.Ledger.Conway.DRepRatifySpec as DRepRatify
5655
import qualified Test.Cardano.Ledger.Conway.Imp as Imp
57-
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp)
56+
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp, EraSpecificSpec)
5857
import qualified Test.Cardano.Ledger.Conway.Proposals as Proposals
5958
import qualified Test.Cardano.Ledger.Conway.SPORatifySpec as SPORatifySpec
6059
import qualified Test.Cardano.Ledger.Conway.TxInfoSpec as TxInfo
@@ -68,6 +67,7 @@ spec ::
6867
, EraPlutusTxInfo PlutusV3 era
6968
, RuleListEra era
7069
, ConwayEraImp era
70+
, EraSpecificSpec era
7171
, ApplyTx era
7272
, DecCBOR (TxWits era)
7373
, DecCBOR (TxBody era)
@@ -88,7 +88,6 @@ spec ::
8888
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
8989
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
9090
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
91-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
9291
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
9392
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
9493
, InjectRuleFailure "LEDGER" ConwayDelegPredFailure era
@@ -116,7 +115,6 @@ spec =
116115
roundTripJsonEraSpec @era
117116
describe "Imp" $ do
118117
Imp.spec @era
119-
Imp.shelleyCertsSpec @era
120118
describe "CostModels" $ do
121119
CostModelsSpec.spec @era
122120
describe "TxWits" $ do

eras/dijkstra/test/Main.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ import Test.Cardano.Ledger.Shelley.JSON (roundTripJsonShelleyEraSpec)
1515

1616
main :: IO ()
1717
main =
18-
ledgerTestMain $ do
19-
describe "Dijkstra era-generic" $ do
20-
TxInfo.spec -- @DijkstraEra
18+
ledgerTestMain $
19+
describe "Dijkstra" $ do
20+
GoldenSpec.spec
21+
roundTripJsonShelleyEraSpec @DijkstraEra
22+
TxInfo.spec
2123
describe "Imp" $ do
2224
Imp.spec @DijkstraEra
23-
describe "Dijkstra era-specific" $ do
24-
-- TODO
25-
pure ()
26-
roundTripJsonShelleyEraSpec @DijkstraEra
27-
GoldenSpec.spec

0 commit comments

Comments
 (0)