Skip to content

Commit

Permalink
Add tests for text envelope roundtrip
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Feb 11, 2025
1 parent 8a70e1c commit fb5de89
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion cardano-api/test/cardano-api-test/Test/Cardano/Api/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ where
import Cardano.Api
import Cardano.Api.Internal.Script
import Cardano.Api.Internal.SerialiseLedgerCddl (cddlTypeToEra)
import Cardano.Api.Internal.SerialiseTextEnvelope (TextEnvelopeDescr (TextEnvelopeDescr))
import Cardano.Api.Shelley (AsType (..))

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

prop_text_envelope_roundtrip_txbody_CBOR :: Property
prop_text_envelope_roundtrip_txbody_CBOR = H.property $ do
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
x <- H.forAll $ makeSignedTransaction [] . fst <$> genValidTxBody era
shelleyBasedEraConstraints
era
( H.tripping
x
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")))
(deserialiseFromTextEnvelope (shelleyBasedEraConstraints era $ proxyToAsType Proxy))
)

prop_text_envelope_roundtrip_tx_CBOR :: Property
prop_text_envelope_roundtrip_tx_CBOR = H.property $ do
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
x <- H.forAll $ genTx era
shelleyBasedEraConstraints
era
( H.tripping
x
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")))
(deserialiseFromTextEnvelope (shelleyBasedEraConstraints era $ proxyToAsType Proxy))
)

prop_roundtrip_tx_CBOR :: Property
prop_roundtrip_tx_CBOR = H.property $ do
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
Expand Down Expand Up @@ -286,7 +311,9 @@ tests :: TestTree
tests =
testGroup
"Test.Cardano.Api.Typed.CBOR"
[ testProperty "roundtrip witness CBOR" prop_roundtrip_witness_CBOR
[ testProperty "rountrip txbody text envelope" prop_text_envelope_roundtrip_txbody_CBOR
, testProperty "rountrip tx text envelope" prop_text_envelope_roundtrip_tx_CBOR
, testProperty "roundtrip witness CBOR" prop_roundtrip_witness_CBOR
, testProperty
"roundtrip operational certificate CBOR"
prop_roundtrip_operational_certificate_CBOR
Expand Down

0 comments on commit fb5de89

Please sign in to comment.