Skip to content

Commit 38dcfaa

Browse files
committed
test(api): refactor TxOut JSON roundtrip tests to use era-agnostic property testing
Consolidates individual era-specific test properties into unified era-agnostic implementations that test all Shelley-based eras dynamically. This reduces code duplication and ensures new eras are automatically tested when added to the framework. Replaces 12 individual era test properties with 2 unified implementations
1 parent 79ddfb9 commit 38dcfaa

File tree

1 file changed

+16
-86
lines changed

1 file changed

+16
-86
lines changed

cardano-api/test/cardano-api-test/Test/Cardano/Api/TxOut/JsonRoundtrip.hs

Lines changed: 16 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE ScopedTypeVariables #-}
34

45
-- | Comprehensive roundtrip tests for TxOut JSON instances across all eras
@@ -11,6 +12,7 @@ import Cardano.Api
1112

1213
import Data.Aeson (eitherDecode, encode)
1314

15+
import Test.Gen.Cardano.Api.Era
1416
import Test.Gen.Cardano.Api.TxOut
1517
import Test.Gen.Cardano.Api.Typed
1618

@@ -32,27 +34,13 @@ tests =
3234
-- | Roundtrip tests for TxOut CtxTx across all eras
3335
testsCtxTx :: [TestTree]
3436
testsCtxTx =
35-
[ testProperty "shelley" prop_json_roundtrip_txout_ctx_tx_shelley
36-
, testProperty "allegra" prop_json_roundtrip_txout_ctx_tx_allegra
37-
, testProperty "mary" prop_json_roundtrip_txout_ctx_tx_mary
38-
, testProperty "alonzo" prop_json_roundtrip_txout_ctx_tx_alonzo
39-
, testProperty "babbage" prop_json_roundtrip_txout_ctx_tx_babbage
40-
, testProperty "conway" prop_json_roundtrip_txout_ctx_tx_conway
41-
-- Dijkstra era not yet supported in shelleyBasedEraConstraints
42-
-- , testProperty "dijkstra" prop_json_roundtrip_txout_ctx_tx_dijkstra
37+
[ testProperty "all eras" prop_json_roundtrip_txout_ctx_tx
4338
]
4439

4540
-- | Roundtrip tests for TxOut CtxUTxO across all eras
4641
testsCtxUTxO :: [TestTree]
4742
testsCtxUTxO =
48-
[ testProperty "shelley" prop_json_roundtrip_txout_ctx_utxo_shelley
49-
, testProperty "allegra" prop_json_roundtrip_txout_ctx_utxo_allegra
50-
, testProperty "mary" prop_json_roundtrip_txout_ctx_utxo_mary
51-
, testProperty "alonzo" prop_json_roundtrip_txout_ctx_utxo_alonzo
52-
, testProperty "babbage" prop_json_roundtrip_txout_ctx_utxo_babbage
53-
, testProperty "conway" prop_json_roundtrip_txout_ctx_utxo_conway
54-
-- Dijkstra era not yet supported in shelleyBasedEraConstraints
55-
-- , testProperty "dijkstra" prop_json_roundtrip_txout_ctx_utxo_dijkstra
43+
[ testProperty "all eras" prop_json_roundtrip_txout_ctx_utxo
5644
]
5745

5846
-- | Datum-specific roundtrip tests
@@ -68,81 +56,23 @@ testsDatumSpecific =
6856
-- CtxTx Roundtrip Properties
6957
-- -----------------------------------------------------------------------------
7058

71-
prop_json_roundtrip_txout_ctx_tx_shelley :: Property
72-
prop_json_roundtrip_txout_ctx_tx_shelley = H.property $ do
73-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraShelley
74-
tripping txOut encode eitherDecode
75-
76-
prop_json_roundtrip_txout_ctx_tx_allegra :: Property
77-
prop_json_roundtrip_txout_ctx_tx_allegra = H.property $ do
78-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraAllegra
79-
tripping txOut encode eitherDecode
80-
81-
prop_json_roundtrip_txout_ctx_tx_mary :: Property
82-
prop_json_roundtrip_txout_ctx_tx_mary = H.property $ do
83-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraMary
84-
tripping txOut encode eitherDecode
85-
86-
prop_json_roundtrip_txout_ctx_tx_alonzo :: Property
87-
prop_json_roundtrip_txout_ctx_tx_alonzo = H.property $ do
88-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraAlonzo
89-
tripping txOut encode eitherDecode
90-
91-
prop_json_roundtrip_txout_ctx_tx_babbage :: Property
92-
prop_json_roundtrip_txout_ctx_tx_babbage = H.property $ do
93-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraBabbage
94-
tripping txOut encode eitherDecode
95-
96-
prop_json_roundtrip_txout_ctx_tx_conway :: Property
97-
prop_json_roundtrip_txout_ctx_tx_conway = H.property $ do
98-
txOut <- forAll $ genTxOutTxContext ShelleyBasedEraConway
99-
tripping txOut encode eitherDecode
100-
101-
-- Dijkstra era not yet supported in shelleyBasedEraConstraints
102-
-- prop_json_roundtrip_txout_ctx_tx_dijkstra :: Property
103-
-- prop_json_roundtrip_txout_ctx_tx_dijkstra = H.property $ do
104-
-- txOut <- forAll $ genTxOutTxContext ShelleyBasedEraDijkstra
105-
-- tripping txOut encode eitherDecode
59+
prop_json_roundtrip_txout_ctx_tx :: Property
60+
prop_json_roundtrip_txout_ctx_tx = H.property $ do
61+
AnyShelleyBasedEra sbe <- forAll genAnyShelleyBasedEra
62+
shelleyBasedEraConstraints sbe $ do
63+
txOut <- forAll $ genTxOutTxContext sbe
64+
tripping txOut encode eitherDecode
10665

10766
-- -----------------------------------------------------------------------------
10867
-- CtxUTxO Roundtrip Properties
10968
-- -----------------------------------------------------------------------------
11069

111-
prop_json_roundtrip_txout_ctx_utxo_shelley :: Property
112-
prop_json_roundtrip_txout_ctx_utxo_shelley = H.property $ do
113-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraShelley
114-
tripping txOut encode eitherDecode
115-
116-
prop_json_roundtrip_txout_ctx_utxo_allegra :: Property
117-
prop_json_roundtrip_txout_ctx_utxo_allegra = H.property $ do
118-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraAllegra
119-
tripping txOut encode eitherDecode
120-
121-
prop_json_roundtrip_txout_ctx_utxo_mary :: Property
122-
prop_json_roundtrip_txout_ctx_utxo_mary = H.property $ do
123-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraMary
124-
tripping txOut encode eitherDecode
125-
126-
prop_json_roundtrip_txout_ctx_utxo_alonzo :: Property
127-
prop_json_roundtrip_txout_ctx_utxo_alonzo = H.property $ do
128-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraAlonzo
129-
tripping txOut encode eitherDecode
130-
131-
prop_json_roundtrip_txout_ctx_utxo_babbage :: Property
132-
prop_json_roundtrip_txout_ctx_utxo_babbage = H.property $ do
133-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraBabbage
134-
tripping txOut encode eitherDecode
135-
136-
prop_json_roundtrip_txout_ctx_utxo_conway :: Property
137-
prop_json_roundtrip_txout_ctx_utxo_conway = H.property $ do
138-
txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraConway
139-
tripping txOut encode eitherDecode
140-
141-
-- Dijkstra era not yet supported in shelleyBasedEraConstraints
142-
-- prop_json_roundtrip_txout_ctx_utxo_dijkstra :: Property
143-
-- prop_json_roundtrip_txout_ctx_utxo_dijkstra = H.property $ do
144-
-- txOut <- forAll $ genTxOutUTxOContext ShelleyBasedEraDijkstra
145-
-- tripping txOut encode eitherDecode
70+
prop_json_roundtrip_txout_ctx_utxo :: Property
71+
prop_json_roundtrip_txout_ctx_utxo = H.property $ do
72+
AnyShelleyBasedEra sbe <- forAll genAnyShelleyBasedEra
73+
shelleyBasedEraConstraints sbe $ do
74+
txOut <- forAll $ genTxOutUTxOContext sbe
75+
tripping txOut encode eitherDecode
14676

14777
-- -----------------------------------------------------------------------------
14878
-- Datum-Specific Roundtrip Properties

0 commit comments

Comments
 (0)