Skip to content

Commit fb5de89

Browse files
committed
Add tests for text envelope roundtrip
1 parent 8a70e1c commit fb5de89

File tree

1 file changed

+28
-1
lines changed
  • cardano-api/test/cardano-api-test/Test/Cardano/Api

1 file changed

+28
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ where
1313
import Cardano.Api
1414
import Cardano.Api.Internal.Script
1515
import Cardano.Api.Internal.SerialiseLedgerCddl (cddlTypeToEra)
16+
import Cardano.Api.Internal.SerialiseTextEnvelope (TextEnvelopeDescr (TextEnvelopeDescr))
1617
import Cardano.Api.Shelley (AsType (..))
1718

1819
import qualified Data.ByteString.Base16 as Base16
@@ -40,6 +41,30 @@ import Test.Tasty.Hedgehog (testProperty)
4041
-- TODO: Need to add PaymentExtendedKey roundtrip tests however
4142
-- we can't derive an Eq instance for Crypto.HD.XPrv
4243

44+
prop_text_envelope_roundtrip_txbody_CBOR :: Property
45+
prop_text_envelope_roundtrip_txbody_CBOR = H.property $ do
46+
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
47+
x <- H.forAll $ makeSignedTransaction [] . fst <$> genValidTxBody era
48+
shelleyBasedEraConstraints
49+
era
50+
( H.tripping
51+
x
52+
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")))
53+
(deserialiseFromTextEnvelope (shelleyBasedEraConstraints era $ proxyToAsType Proxy))
54+
)
55+
56+
prop_text_envelope_roundtrip_tx_CBOR :: Property
57+
prop_text_envelope_roundtrip_tx_CBOR = H.property $ do
58+
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
59+
x <- H.forAll $ genTx era
60+
shelleyBasedEraConstraints
61+
era
62+
( H.tripping
63+
x
64+
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")))
65+
(deserialiseFromTextEnvelope (shelleyBasedEraConstraints era $ proxyToAsType Proxy))
66+
)
67+
4368
prop_roundtrip_tx_CBOR :: Property
4469
prop_roundtrip_tx_CBOR = H.property $ do
4570
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
@@ -286,7 +311,9 @@ tests :: TestTree
286311
tests =
287312
testGroup
288313
"Test.Cardano.Api.Typed.CBOR"
289-
[ testProperty "roundtrip witness CBOR" prop_roundtrip_witness_CBOR
314+
[ testProperty "rountrip txbody text envelope" prop_text_envelope_roundtrip_txbody_CBOR
315+
, testProperty "rountrip tx text envelope" prop_text_envelope_roundtrip_tx_CBOR
316+
, testProperty "roundtrip witness CBOR" prop_roundtrip_witness_CBOR
290317
, testProperty
291318
"roundtrip operational certificate CBOR"
292319
prop_roundtrip_operational_certificate_CBOR

0 commit comments

Comments
 (0)