Skip to content

Commit c3d4f5d

Browse files
authored
Merge pull request #5137 from IntersectMBO/ldan/dijkstra-certs
* Remove Shelley style certs in Dijkstra era * Add `EraSpecificSpec` class * Adjust and organise tests that use certificates Resolves #4963
2 parents 403eb94 + c0a7ab3 commit c3d4f5d

File tree

52 files changed

+1306
-422
lines changed

Some content is hidden

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

52 files changed

+1306
-422
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
### `testlib`
1919

20+
* Added `EraSpecificSpec AllegraEra` instance
2021
* Added `Examples` module with: `ledgerExamples`, `exampleAllegraTxBody`, `exampleAllegraTxAuxData`
2122
* Added `Arbitrary` instance for `TransitionConfig AllegraEra`
2223
* Added `Era` module with `AllegraEraTest` class

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
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 (
1214
ShelleyPoolPredFailure,
1315
ShelleyUtxoPredFailure,
1416
ShelleyUtxowPredFailure,
1517
)
1618
import qualified Test.Cardano.Ledger.Allegra.Imp.UtxowSpec as UtxowSpec
19+
import Test.Cardano.Ledger.Allegra.ImpTest
1720
import Test.Cardano.Ledger.Imp.Common
1821
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
19-
import Test.Cardano.Ledger.Shelley.ImpTest
2022

2123
spec ::
2224
forall era.
2325
( ShelleyEraImp era
26+
, EraSpecificSpec era
2427
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
2528
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
2629
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
@@ -30,3 +33,6 @@ spec = do
3033
ShelleyImp.spec @era
3134
describe "AllegraImpSpec" . withEachEraVersion @era $
3235
UtxowSpec.spec
36+
37+
instance EraSpecificSpec AllegraEra where
38+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec

eras/alonzo/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
### `testlib`
5656

57+
* Added `EraSpecificSpec AlonzoEra` instance
5758
* Added shrinking to `AlonzoTxAuxData`, `Redeemers`, `TxDats`
5859
* Added `Examples` module with: `ledgerExamples`, `mkLedgerExamples`, `exampleTx`, `exampleDatum`, `exampleAlonzoGenesis`
5960
* Added `Twiddle` instances for Alonzo core types

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
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,
@@ -25,11 +27,12 @@ import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
2527
import Test.Cardano.Ledger.Alonzo.ImpTest
2628
import Test.Cardano.Ledger.Imp.Common
2729
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp
30+
import qualified Test.Cardano.Ledger.Shelley.Imp.PoolSpec as ShelleyImp
2831

2932
spec ::
3033
forall era.
3134
( AlonzoEraImp era
32-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
35+
, EraSpecificSpec era
3336
, InjectRuleFailure "LEDGER" ShelleyPoolPredFailure era
3437
, InjectRuleFailure "LEDGER" ShelleyUtxoPredFailure era
3538
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
@@ -40,8 +43,25 @@ spec ::
4043
Spec
4144
spec = do
4245
MaryImp.spec @era
43-
withEachEraVersion @era $ do
44-
describe "AlonzoImpSpec" $ do
45-
Utxo.spec
46-
Utxos.spec
47-
Utxow.spec
46+
describe "AlonzoImpSpec" . withEachEraVersion @era $ do
47+
Utxo.spec
48+
Utxos.spec
49+
Utxow.spec
50+
51+
alonzoEraSpecificSpec ::
52+
forall era.
53+
( AlonzoEraImp era
54+
, ShelleyEraTxCert era
55+
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
56+
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
57+
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
58+
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
59+
) =>
60+
SpecWith (ImpInit (LedgerSpec era))
61+
alonzoEraSpecificSpec = do
62+
describe "Alonzo era specific Imp spec" $
63+
describe "Certificates without deposits" $
64+
Utxow.alonzoEraSpecificSpec
65+
66+
instance EraSpecificSpec AlonzoEra where
67+
eraSpecificSpec = ShelleyImp.shelleyEraSpecificSpec >> alonzoEraSpecificSpec

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
{-# LANGUAGE ScopedTypeVariables #-}
66
{-# LANGUAGE TypeFamilies #-}
77

8-
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec (spec) where
8+
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec (spec, alonzoEraSpecificSpec) where
99

10-
import Cardano.Ledger.Alonzo.Core (InjectRuleFailure)
10+
import Cardano.Ledger.Alonzo.Core
1111
import Cardano.Ledger.Alonzo.Rules (
1212
AlonzoUtxosPredFailure,
1313
AlonzoUtxowPredFailure,
@@ -21,7 +21,6 @@ import Test.Cardano.Ledger.Common
2121
spec ::
2222
forall era.
2323
( AlonzoEraImp era
24-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
2524
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
2625
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
2726
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
@@ -31,3 +30,18 @@ spec = do
3130
describe "UTXOW" $ do
3231
Valid.spec
3332
Invalid.spec
33+
34+
alonzoEraSpecificSpec ::
35+
forall era.
36+
( AlonzoEraImp era
37+
, ShelleyEraTxCert era
38+
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
39+
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
40+
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
41+
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
42+
) =>
43+
SpecWith (ImpInit (LedgerSpec era))
44+
alonzoEraSpecificSpec = do
45+
describe "UTXOW" $ do
46+
Valid.alonzoEraSpecificSpec
47+
Invalid.alonzoEraSpecificSpec

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

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{-# LANGUAGE ScopedTypeVariables #-}
88
{-# LANGUAGE TypeApplications #-}
99

10-
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Invalid (spec) where
10+
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Invalid (spec, alonzoEraSpecificSpec) where
1111

1212
import Cardano.Ledger.Allegra.Scripts (AllegraEraScript (..))
1313
import Cardano.Ledger.Alonzo (AlonzoEra)
@@ -73,7 +73,6 @@ spec = describe "Invalid transactions" $ do
7373
describe (show lang) $ do
7474
let redeemerSameAsDatumHash = hashPlutusScript $ redeemerSameAsDatum slang
7575
alwaysSucceedsWithDatumHash = hashPlutusScript $ alwaysSucceedsWithDatum slang
76-
alwaysSucceedsNoDatumHash = hashPlutusScript $ alwaysSucceedsNoDatum slang
7776

7877
it "MissingRedeemers" $ do
7978
let scriptHash = redeemerSameAsDatumHash
@@ -156,25 +155,6 @@ spec = describe "Invalid transactions" $ do
156155
then submitPhase2Invalid_ tx
157156
else submitFailingTx tx [injectFailure $ UnspendableUTxONoDatumHash [txIn]]
158157

159-
it "No ExtraRedeemers on same script certificates" $ do
160-
Positive n <- arbitrary
161-
replicateM_ n $ freshKeyHash >>= registerPool
162-
pools <- getsNES $ nesEsL . epochStateStakePoolsL
163-
poolId <- elements $ Map.keys pools
164-
let scriptHash = alwaysSucceedsNoDatumHash
165-
cred = ScriptHashObj scriptHash
166-
certs =
167-
[ mkRegTxCert cred
168-
, mkDelegStakeTxCert cred poolId
169-
, mkUnRegTxCert cred
170-
]
171-
tx <- submitTx $ mkBasicTx (mkBasicTxBody & certsTxBodyL .~ certs)
172-
let redeemers = tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL
173-
Map.keys redeemers
174-
`shouldBe` [ mkCertifyingPurpose $ AsIx 1
175-
, mkCertifyingPurpose $ AsIx 2
176-
]
177-
178158
it "Missing phase-2 script witness" $ do
179159
let scriptHash = alwaysSucceedsWithDatumHash
180160
txIn <- produceScript scriptHash
@@ -252,6 +232,43 @@ spec = describe "Invalid transactions" $ do
252232
it "Spending" $
253233
testPurpose (mkSpendingPurpose $ AsIx 99)
254234

235+
alonzoEraSpecificSpec ::
236+
forall era.
237+
( AlonzoEraImp era
238+
, ShelleyEraTxCert era
239+
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
240+
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
241+
) =>
242+
SpecWith (ImpInit (LedgerSpec era))
243+
alonzoEraSpecificSpec = describe "Invalid transactions" $ do
244+
forM_ (eraLanguages @era) $ \lang ->
245+
withSLanguage lang $ \slang ->
246+
describe (show lang) $ do
247+
let alwaysSucceedsWithDatumHash = hashPlutusScript $ alwaysSucceedsWithDatum slang
248+
alwaysSucceedsNoDatumHash = hashPlutusScript $ alwaysSucceedsNoDatum slang
249+
250+
it "No ExtraRedeemers on same script certificates" $ do
251+
Positive n <- arbitrary
252+
replicateM_ n $ freshKeyHash >>= registerPool
253+
pools <- getsNES $ nesEsL . epochStateStakePoolsL
254+
poolId <- elements $ Map.keys pools
255+
let scriptHash = alwaysSucceedsNoDatumHash
256+
cred = ScriptHashObj scriptHash
257+
certs =
258+
[ mkRegTxCert cred
259+
, mkDelegStakeTxCert cred poolId
260+
, mkUnRegTxCert cred
261+
]
262+
tx <- submitTx $ mkBasicTx (mkBasicTxBody & certsTxBodyL .~ certs)
263+
let redeemers = tx ^. witsTxL . rdmrsTxWitsL . unRedeemersL
264+
Map.keys redeemers
265+
`shouldBe` [ mkCertifyingPurpose $ AsIx 1
266+
, mkCertifyingPurpose $ AsIx 2
267+
]
268+
269+
-- Post-Alonzo eras produce additional post-Alonzo predicate failures that we can't include here
270+
unless (lang > eraMaxLanguage @AlonzoEra) $ do
271+
describe "Extra Redeemer" $ do
255272
it "Multiple equal plutus-locked certs" $ do
256273
let scriptHash = alwaysSucceedsWithDatumHash
257274
Positive n <- arbitrary

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

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{-# LANGUAGE TypeApplications #-}
99
{-# LANGUAGE TypeFamilies #-}
1010

11-
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Valid (spec) where
11+
module Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Valid (spec, alonzoEraSpecificSpec) where
1212

1313
import Cardano.Ledger.Allegra.Scripts (
1414
pattern RequireTimeExpire,
@@ -47,7 +47,6 @@ import Test.Cardano.Ledger.Plutus.Examples
4747
spec ::
4848
forall era.
4949
( AlonzoEraImp era
50-
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
5150
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
5251
) =>
5352
SpecWith (ImpInit (LedgerSpec era))
@@ -88,6 +87,51 @@ spec = describe "Valid transactions" $ do
8887
mkBasicTx $
8988
mkBasicTxBody & inputsTxBodyL .~ [txIn]
9089

90+
it "Validating MINT script" $ do
91+
submitTx_ =<< mkTokenMintingTx alwaysSucceedsNoDatumHash
92+
93+
it "Not validating MINT script" $ do
94+
submitPhase2Invalid_ =<< mkTokenMintingTx alwaysFailsNoDatumHash
95+
96+
it "Acceptable supplementary datum" $ do
97+
inputAddr <- freshKeyHash @'Payment
98+
amount <- Coin <$> choose (2_000_000, 8_000_000)
99+
txIn <- sendCoinTo (mkAddr inputAddr StakeRefNull) amount
100+
let
101+
datum = Data (P.I 123)
102+
datumHash = hashData datum
103+
txOut =
104+
mkBasicTxOut
105+
(mkAddr alwaysSucceedsWithDatumHash StakeRefNull)
106+
(MaryValue amount mempty)
107+
& dataHashTxOutL .~ SJust datumHash
108+
txBody =
109+
mkBasicTxBody
110+
& inputsTxBodyL .~ [txIn]
111+
& outputsTxBodyL .~ [txOut]
112+
tx =
113+
mkBasicTx txBody
114+
& witsTxL . datsTxWitsL . unTxDatsL %~ Map.insert datumHash datum
115+
submitTx_ tx
116+
117+
alonzoEraSpecificSpec ::
118+
forall era.
119+
( AlonzoEraImp era
120+
, ShelleyEraTxCert era
121+
, InjectRuleFailure "LEDGER" ShelleyDelegPredFailure era
122+
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
123+
) =>
124+
SpecWith (ImpInit (LedgerSpec era))
125+
alonzoEraSpecificSpec = do
126+
forM_ (eraLanguages @era) $ \lang ->
127+
withSLanguage lang $ \slang ->
128+
describe (show lang) $ do
129+
let
130+
alwaysSucceedsWithDatumHash = hashPlutusScript $ alwaysSucceedsWithDatum slang :: ScriptHash
131+
alwaysSucceedsNoDatumHash = hashPlutusScript $ alwaysSucceedsNoDatum slang :: ScriptHash
132+
alwaysFailsWithDatumHash = hashPlutusScript $ alwaysFailsWithDatum slang :: ScriptHash
133+
alwaysFailsNoDatumHash = hashPlutusScript $ alwaysFailsNoDatum slang :: ScriptHash
134+
91135
it "Validating CERT script" $ do
92136
txIn <- produceScript alwaysSucceedsWithDatumHash
93137
let txCert = RegTxCert $ ScriptHashObj alwaysSucceedsNoDatumHash
@@ -118,12 +162,6 @@ spec = describe "Valid transactions" $ do
118162
mkBasicTx $
119163
mkBasicTxBody & withdrawalsTxBodyL .~ Withdrawals [(account, mempty)]
120164

121-
it "Validating MINT script" $ do
122-
submitTx_ =<< mkTokenMintingTx alwaysSucceedsNoDatumHash
123-
124-
it "Not validating MINT script" $ do
125-
submitPhase2Invalid_ =<< mkTokenMintingTx alwaysFailsNoDatumHash
126-
127165
-- Process a transaction with a succeeding script in every place possible,
128166
-- and also with succeeding timelock scripts.
129167
it "Validating scripts everywhere" $ do
@@ -162,27 +200,6 @@ spec = describe "Valid transactions" $ do
162200
& outputsTxBodyL .~ [txOut]
163201
submitTx_ $ mkBasicTx txBody
164202

165-
it "Acceptable supplementary datum" $ do
166-
inputAddr <- freshKeyHash @'Payment
167-
amount <- Coin <$> choose (2_000_000, 8_000_000)
168-
txIn <- sendCoinTo (mkAddr inputAddr StakeRefNull) amount
169-
let
170-
datum = Data (P.I 123)
171-
datumHash = hashData datum
172-
txOut =
173-
mkBasicTxOut
174-
(mkAddr alwaysSucceedsWithDatumHash StakeRefNull)
175-
(MaryValue amount mempty)
176-
& dataHashTxOutL .~ SJust datumHash
177-
txBody =
178-
mkBasicTxBody
179-
& inputsTxBodyL .~ [txIn]
180-
& outputsTxBodyL .~ [txOut]
181-
tx =
182-
mkBasicTx txBody
183-
& witsTxL . datsTxWitsL . unTxDatsL %~ Map.insert datumHash datum
184-
submitTx_ tx
185-
186203
it "Multiple identical certificates" $ do
187204
let scriptHash = alwaysSucceedsNoDatumHash
188205
void . registerStakeCredential $ ScriptHashObj scriptHash

eras/babbage/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
### `testlib`
2020

21+
* Added `EraSpecificSpec BabbageEra` instance
2122
* Added `Examples` module with: `ledgerExamples`, `exampleBabbageNewEpochState`, `exampleCollateralOutput`
2223
* Added `Twiddle` instances for Babbage core types
2324
* Added `TxInfoSpec` (moved from `cardano-ledger-babbage-test`)

0 commit comments

Comments
 (0)