Skip to content

Commit 8e5c3bf

Browse files
committed
Inline test_roundtrip_Tx_Cddl and test_roundtrip_TxWitness_Cddl and convert tests into property tests
1 parent ea38355 commit 8e5c3bf

File tree

2 files changed

+15
-40
lines changed

2 files changed

+15
-40
lines changed

cardano-api/src/Cardano/Api/Eras.hs

+2-7
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,7 @@ deriving instance Ord (ShelleyBasedEra era)
342342
deriving instance Show (ShelleyBasedEra era)
343343

344344
instance ToJSON (ShelleyBasedEra era) where
345-
toJSON ShelleyBasedEraShelley = "Shelley"
346-
toJSON ShelleyBasedEraAllegra = "Allegra"
347-
toJSON ShelleyBasedEraMary = "Mary"
348-
toJSON ShelleyBasedEraAlonzo = "Alonzo"
349-
toJSON ShelleyBasedEraBabbage = "Babbage"
350-
toJSON ShelleyBasedEraConway = "Conway"
345+
toJSON = toJSON . shelleyBasedToCardanoEra
351346

352347
instance TestEquality ShelleyBasedEra where
353348
testEquality ShelleyBasedEraShelley ShelleyBasedEraShelley = Just Refl
@@ -436,7 +431,7 @@ instance FromJSON AnyShelleyBasedEra where
436431
"Alonzo" -> pure $ AnyShelleyBasedEra ShelleyBasedEraAlonzo
437432
"Babbage" -> pure $ AnyShelleyBasedEra ShelleyBasedEraBabbage
438433
"Conway" -> pure $ AnyShelleyBasedEra ShelleyBasedEraConway
439-
wrong -> fail $ "Failed to parse unknown era: " <> Text.unpack wrong
434+
wrong -> fail $ "Failed to parse unknown shelley-based era: " <> Text.unpack wrong
440435

441436

442437
-- | This pairs up some era-dependent type with a 'ShelleyBasedEra' value that

cardano-api/test/Test/Cardano/Api/Typed/CBOR.hs

+13-33
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Cardano.Api
1010

1111
import Data.Proxy (Proxy (..))
1212
import Data.String (IsString (..))
13-
import Hedgehog (Property, forAll, property, success, tripping)
13+
import Hedgehog (Property, forAll, tripping)
1414
import qualified Hedgehog as H
1515
import qualified Hedgehog.Gen as Gen
1616
import Test.Cardano.Api.Typed.Orphans ()
@@ -156,38 +156,18 @@ prop_roundtrip_UpdateProposal_CBOR :: Property
156156
prop_roundtrip_UpdateProposal_CBOR =
157157
roundtrip_CBOR AsUpdateProposal genUpdateProposal
158158

159+
prop_roundtrip_Tx_Cddl :: Property
160+
prop_roundtrip_Tx_Cddl = H.property $ do
161+
AnyCardanoEra era <- H.forAll $ Gen.element [minBound..maxBound]
162+
x <- forAll $ genTx era
163+
H.tripping x serialiseTxLedgerCddl (deserialiseTxLedgerCddl era)
159164

160-
test_roundtrip_Tx_Cddl :: [TestTree]
161-
test_roundtrip_Tx_Cddl =
162-
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_Tx_Cddl anyEra
163-
| anyEra@(AnyCardanoEra era) <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
164-
]
165-
166-
test_roundtrip_TxWitness_Cddl :: [TestTree]
167-
test_roundtrip_TxWitness_Cddl =
168-
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_TxWitness_Cddl era
169-
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
170-
, AnyCardanoEra era /= AnyCardanoEra ByronEra
171-
]
165+
prop_roundtrip_TxWitness_Cddl :: Property
166+
prop_roundtrip_TxWitness_Cddl = H.property $ do
167+
AnyShelleyBasedEra sbe <- H.forAll $ Gen.element [minBound..maxBound]
168+
x <- forAll $ genShelleyKeyWitness $ shelleyBasedToCardanoEra sbe
169+
tripping x (serialiseWitnessLedgerCddl sbe) (deserialiseWitnessLedgerCddl sbe)
172170

173-
roundtrip_TxWitness_Cddl :: CardanoEra era -> Property
174-
roundtrip_TxWitness_Cddl era =
175-
property $
176-
case cardanoEraStyle era of
177-
LegacyByronEra -> success
178-
ShelleyBasedEra sbe -> do
179-
keyWit <- forAll $ genShelleyKeyWitness era
180-
tripping keyWit
181-
(serialiseWitnessLedgerCddl sbe)
182-
(deserialiseWitnessLedgerCddl sbe)
183-
184-
roundtrip_Tx_Cddl :: AnyCardanoEra -> Property
185-
roundtrip_Tx_Cddl (AnyCardanoEra era) =
186-
property $ do
187-
tx <- forAll $ genTx era
188-
tripping tx
189-
serialiseTxLedgerCddl
190-
(deserialiseTxLedgerCddl era)
191171

192172
-- -----------------------------------------------------------------------------
193173

@@ -223,7 +203,7 @@ tests = testGroup "Test.Cardano.Api.Typed.CBOR"
223203
, testPropertyNamed "roundtrip UpdateProposal CBOR" "roundtrip UpdateProposal CBOR" prop_roundtrip_UpdateProposal_CBOR
224204
, testPropertyNamed "roundtrip ScriptData CBOR" "roundtrip ScriptData CBOR" prop_roundtrip_ScriptData_CBOR
225205
, testPropertyNamed "roundtrip txbody CBOR" "roundtrip txbody CBOR" prop_roundtrip_txbody_CBOR
206+
, testPropertyNamed "roundtrip Tx Cddl" "roundtrip Tx Cddl" prop_roundtrip_Tx_Cddl
207+
, testPropertyNamed "roundtrip TxWitness Cddl" "roundtrip TxWitness Cddl" prop_roundtrip_TxWitness_Cddl
226208
, testGroup "roundtrip tx CBOR" test_roundtrip_tx_CBOR
227-
, testGroup "roundtrip Tx Cddl" test_roundtrip_Tx_Cddl
228-
, testGroup "roundtrip TxWitness Cddl" test_roundtrip_TxWitness_Cddl
229209
]

0 commit comments

Comments
 (0)