Skip to content

Commit 78331cd

Browse files
committed
Add property tests for Babbage Plutus TxInfo translation
Extend `Test.Cardano.Ledger.Babbage.TxInfoSpec` with a property test for Babbage TxInfo translation across PlutusV1/V2/V3/V4: * correctly translate tx with babbage-era features
1 parent 5072dfa commit 78331cd

4 files changed

Lines changed: 283 additions & 129 deletions

File tree

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

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

10-
module Test.Cardano.Ledger.Alonzo.TxInfoSpec (spec) where
10+
module Test.Cardano.Ledger.Alonzo.TxInfoSpec (spec, txInfoSpecV1) where
1111

1212
import Cardano.Ledger.Alonzo.Plutus.Context (
1313
ContextError,
@@ -62,8 +62,24 @@ spec ::
6262
) =>
6363
Spec
6464
spec = do
65+
describe "txInfo translation" (txInfoSpecV1 @era)
66+
67+
txInfoSpecV1 ::
68+
forall era.
69+
( EraTx era
70+
, AlonzoEraTxBody era
71+
, AlonzoEraTxWits era
72+
, AtMostEra "Babbage" era
73+
, Value era ~ MaryValue
74+
, EraPlutusTxInfo 'PlutusV1 era
75+
, TxCert era ~ ShelleyTxCert era
76+
, ShelleyEraTxCert era
77+
, Inject (AlonzoContextError era) (ContextError era)
78+
) =>
79+
Spec
80+
txInfoSpecV1 = do
6581
let lang = SPlutusV1
66-
describe "txInfo translation" $ do
82+
describe "Plutus V1" $ do
6783
prop "correctly translate tx with alonzo-era features" $ do
6884
inputs <- listOf1 genUtxoEntry
6985
outputs <- listOf1 genTxOut
@@ -246,9 +262,14 @@ genUtxoEntry = do
246262

247263
genTxOut :: forall era. (AlonzoEraTxOut era, Arbitrary (Value era)) => Gen (TxOut era)
248264
genTxOut = do
265+
let genAddr =
266+
-- Byron addresses are not permitted in later eras
267+
if eraName @era == "Alonzo"
268+
then arbitrary
269+
else Addr <$> arbitrary <*> arbitrary <*> arbitrary
249270
dataHash <- arbitrary
250271
txOut <-
251272
mkBasicTxOut
252-
<$> arbitrary
273+
<$> genAddr
253274
<*> scale (`div` 15) arbitrary
254275
pure $ txOut & dataHashTxOutL .~ dataHash

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ library testlib
209209
microlens,
210210
microlens-ghc,
211211
plutus-ledger-api,
212+
plutus-tx,
212213
small-steps >=1.1,
213214
time,
214215
tree-diff,

0 commit comments

Comments
 (0)