Skip to content

Commit

Permalink
Remove roundtrip_CDDL_Tx and any tests using it
Browse files Browse the repository at this point in the history
Implement allTxBodyEnvelopeRoundtrips which roundtrip tests the TxBody
TextEnvelope format in all eras
Update shelley era properties to check for
the correct TextEnvelopeType
  • Loading branch information
Jimbo4350 committed Feb 8, 2023
1 parent 6b3e8b9 commit 4d68cc1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 83 deletions.
9 changes: 0 additions & 9 deletions cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs
Expand Up @@ -2,7 +2,6 @@

module Test.Hedgehog.Roundtrip.CBOR
( roundtrip_CBOR
, roundtrip_CDDL_Tx
) where

import Cardano.Api
Expand All @@ -19,11 +18,3 @@ roundtrip_CBOR typeProxy gen =
H.property $ do
val <- H.forAll gen
H.tripping val serialiseToCBOR (deserialiseFromCBOR typeProxy)


roundtrip_CDDL_Tx
:: IsCardanoEra era => CardanoEra era -> Gen (Tx era) -> Property
roundtrip_CDDL_Tx era gen =
H.property $ do
val <- H.forAll gen
H.tripping val serialiseTxLedgerCddl (deserialiseTxLedgerCddl era)
72 changes: 9 additions & 63 deletions cardano-api/test/Test/Cardano/Api/Typed/CBOR.hs
Expand Up @@ -10,7 +10,9 @@ import Cardano.Api

import Data.Proxy (Proxy (..))
import Data.String (IsString (..))
import Hedgehog (Property, forAll, property, success, tripping)
import Gen.Cardano.Api.Typed
import Gen.Hedgehog.Roundtrip.CBOR (roundtrip_CBOR)
import Hedgehog (Property)
import Test.Cardano.Api.Typed.Orphans ()
import Test.Gen.Cardano.Api.Typed
import Test.Hedgehog.Roundtrip.CBOR (roundtrip_CBOR, roundtrip_CDDL_Tx)
Expand All @@ -22,13 +24,6 @@ import Test.Tasty.Hedgehog (testPropertyNamed)
-- TODO: Need to add PaymentExtendedKey roundtrip tests however
-- we can't derive an Eq instance for Crypto.HD.XPrv

test_roundtrip_txbody_CBOR :: [TestTree]
test_roundtrip_txbody_CBOR =
[ testPropertyNamed (show era) (fromString (show era)) $
roundtrip_CDDL_Tx era (makeSignedTransaction [] <$> genTxBody era)
| AnyCardanoEra era <- [minBound..(AnyCardanoEra BabbageEra)]
]

test_roundtrip_tx_CBOR :: [TestTree]
test_roundtrip_tx_CBOR =
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_CBOR (proxyToAsType Proxy) (genTx era)
Expand All @@ -39,21 +34,11 @@ prop_roundtrip_witness_byron_CBOR :: Property
prop_roundtrip_witness_byron_CBOR =
roundtrip_CBOR (AsKeyWitness AsByronEra) genByronKeyWitness

prop_roundtrip_witness_shelley_CBOR :: Property
prop_roundtrip_witness_shelley_CBOR =
roundtrip_CBOR (AsKeyWitness AsShelleyEra) (genShelleyWitness ShelleyEra)

prop_roundtrip_witness_allegra_CBOR :: Property
prop_roundtrip_witness_allegra_CBOR =
roundtrip_CBOR (AsKeyWitness AsAllegraEra) (genShelleyWitness AllegraEra)

prop_roundtrip_witness_mary_CBOR :: Property
prop_roundtrip_witness_mary_CBOR =
roundtrip_CBOR (AsKeyWitness AsMaryEra) (genShelleyWitness MaryEra)

prop_roundtrip_witness_alonzo_CBOR :: Property
prop_roundtrip_witness_alonzo_CBOR =
roundtrip_CBOR (AsKeyWitness AsAlonzoEra) (genShelleyWitness AlonzoEra)
-- KeyWitness serialization does not change with from the Shelley era onways
-- so we just default to the latest era.
prop_roundtrip_witness_CBOR :: Property
prop_roundtrip_witness_CBOR =
roundtrip_CBOR (AsKeyWitness AsBabbage) (genShelleyWitness BabbageEra)

prop_roundtrip_operational_certificate_CBOR :: Property
prop_roundtrip_operational_certificate_CBOR =
Expand Down Expand Up @@ -151,48 +136,12 @@ prop_roundtrip_UpdateProposal_CBOR :: Property
prop_roundtrip_UpdateProposal_CBOR =
roundtrip_CBOR AsUpdateProposal genUpdateProposal


test_roundtrip_Tx_Cddl :: [TestTree]
test_roundtrip_Tx_Cddl =
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_Tx_Cddl anyEra
| anyEra@(AnyCardanoEra era) <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
]

test_roundtrip_TxWitness_Cddl :: [TestTree]
test_roundtrip_TxWitness_Cddl =
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_TxWitness_Cddl era
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
, AnyCardanoEra era /= AnyCardanoEra ByronEra
]

roundtrip_TxWitness_Cddl :: CardanoEra era -> Property
roundtrip_TxWitness_Cddl era =
property $
case cardanoEraStyle era of
LegacyByronEra -> success
ShelleyBasedEra sbe -> do
keyWit <- forAll $ genShelleyKeyWitness era
tripping keyWit
(serialiseWitnessLedgerCddl sbe)
(deserialiseWitnessLedgerCddl sbe)

roundtrip_Tx_Cddl :: AnyCardanoEra -> Property
roundtrip_Tx_Cddl (AnyCardanoEra era) =
property $ do
tx <- forAll $ genTx era
tripping tx
serialiseTxLedgerCddl
(deserialiseTxLedgerCddl era)

-- -----------------------------------------------------------------------------

tests :: TestTree
tests = testGroup "Test.Cardano.Api.Typed.CBOR"
[ testPropertyNamed "roundtrip witness byron CBOR" "roundtrip witness byron CBOR" prop_roundtrip_witness_byron_CBOR
, testPropertyNamed "roundtrip witness shelley CBOR" "roundtrip witness shelley CBOR" prop_roundtrip_witness_shelley_CBOR
, testPropertyNamed "roundtrip witness allegra CBOR" "roundtrip witness allegra CBOR" prop_roundtrip_witness_allegra_CBOR
, testPropertyNamed "roundtrip witness mary CBOR" "roundtrip witness mary CBOR" prop_roundtrip_witness_mary_CBOR
, testPropertyNamed "roundtrip witness alonzo CBOR" "roundtrip witness alonzo CBOR" prop_roundtrip_witness_alonzo_CBOR
, testPropertyNamed "roundtrip witness CBOR" "roundtrip witness CBOR" prop_roundtrip_witness_CBOR
, testPropertyNamed "roundtrip operational certificate CBOR" "roundtrip operational certificate CBOR" prop_roundtrip_operational_certificate_CBOR
, testPropertyNamed "roundtrip operational certificate issue counter CBOR" "roundtrip operational certificate issue counter CBOR" prop_roundtrip_operational_certificate_issue_counter_CBOR
, testPropertyNamed "roundtrip verification key byron CBOR" "roundtrip verification key byron CBOR" prop_roundtrip_verification_key_byron_CBOR
Expand All @@ -216,8 +165,5 @@ tests = testGroup "Test.Cardano.Api.Typed.CBOR"
, testPropertyNamed "roundtrip script PlutusScriptV1 CBOR" "roundtrip script PlutusScriptV1 CBOR" prop_roundtrip_script_PlutusScriptV1_CBOR
, testPropertyNamed "roundtrip script PlutusScriptV2 CBOR" "roundtrip script PlutusScriptV2 CBOR" prop_roundtrip_script_PlutusScriptV2_CBOR
, testPropertyNamed "roundtrip UpdateProposal CBOR" "roundtrip UpdateProposal CBOR" prop_roundtrip_UpdateProposal_CBOR
, testGroup "roundtrip txbody CBOR" test_roundtrip_txbody_CBOR
, testGroup "roundtrip tx CBOR" test_roundtrip_tx_CBOR
, testGroup "roundtrip Tx Cddl" test_roundtrip_Tx_Cddl
, testGroup "roundtrip TxWitness Cddl" test_roundtrip_TxWitness_Cddl
]
26 changes: 24 additions & 2 deletions cardano-api/test/Test/Cardano/Api/Typed/Envelope.hs
Expand Up @@ -6,6 +6,9 @@ module Test.Cardano.Api.Typed.Envelope

import Cardano.Api

import Data.String (fromString)
import qualified Data.Text as Text
import Gen.Cardano.Api.Typed
import Hedgehog (Property)
import Test.Cardano.Api.Typed.Orphans ()
import Test.Gen.Cardano.Api.Typed
Expand Down Expand Up @@ -86,6 +89,23 @@ prop_roundtrip_VrfSigningKey_envelope :: Property
prop_roundtrip_VrfSigningKey_envelope =
roundtrip_SigningKey_envelope AsVrfKey

roundtrip_TxBody_envelope :: IsCardanoEra era => CardanoEra era -> Property
roundtrip_TxBody_envelope era = H.property $ do
txBody <- H.forAll $ genTxBody era
H.tripping txBody (serialiseToTextEnvelope Nothing)
(deserialiseFromTextEnvelope
(AsTxBody $ proxyToAsType (Proxy :: Proxy era))
)

allTxBodyEnvelopeRoundtrips :: [TestTree]
allTxBodyEnvelopeRoundtrips =
[ testPropertyNamed
("roundtrip " <> (fromString . Text.unpack $ renderEra aEra) <> " TxBody envelope")
("roundtrip " <> (fromString . Text.unpack $ renderEra aEra) <> " TxBody envelope")
(roundtrip_TxBody_envelope era)
| aEra@(AnyCardanoEra era) <- [minBound..(AnyCardanoEra BabbageEra)]
]

-- -----------------------------------------------------------------------------

roundtrip_VerificationKey_envelope :: Key keyrole
Expand All @@ -109,7 +129,7 @@ roundtrip_SigningKey_envelope roletoken =
-- -----------------------------------------------------------------------------

tests :: TestTree
tests = testGroup "Test.Cardano.Api.Typed.Envelope"
tests = testGroup "Test.Cardano.Api.Typed.Envelope" $
[ testPropertyNamed "roundtrip ByronVerificationKey envelope" "roundtrip ByronVerificationKey envelope" prop_roundtrip_ByronVerificationKey_envelope
, testPropertyNamed "roundtrip ByronSigningKey envelope" "roundtrip ByronSigningKey envelope" prop_roundtrip_ByronSigningKey_envelope
, testPropertyNamed "roundtrip PaymentVerificationKey envelope" "roundtrip PaymentVerificationKey envelope" prop_roundtrip_PaymentVerificationKey_envelope
Expand All @@ -126,4 +146,6 @@ tests = testGroup "Test.Cardano.Api.Typed.Envelope"
, testPropertyNamed "roundtrip KesSigningKey envelope" "roundtrip KesSigningKey envelope" prop_roundtrip_KesSigningKey_envelope
, testPropertyNamed "roundtrip VrfVerificationKey envelope" "roundtrip VrfVerificationKey envelope" prop_roundtrip_VrfVerificationKey_envelope
, testPropertyNamed "roundtrip VrfSigningKey envelope" "roundtrip VrfSigningKey envelope" prop_roundtrip_VrfSigningKey_envelope
]
] ++
allTxBodyEnvelopeRoundtrips

4 changes: 3 additions & 1 deletion cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Tx/Tx.hs
Expand Up @@ -4,6 +4,7 @@ module Test.Golden.Shelley.TextEnvelope.Tx.Tx
( golden_shelleyTx
) where

import Cardano.Api
import Cardano.Prelude

import Hedgehog (Property)
Expand Down Expand Up @@ -49,4 +50,5 @@ golden_shelleyTx = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do

-- Check the newly created files have not deviated from the
-- golden files
checkTxCddlFormat referenceTx transactionFile
let txBodyTextEnvType = textEnvelopeType $ AsTx AsAlonzoEra
checkTextEnvelopeFormat txBodyTextEnvType referenceTx transactionFile
Expand Up @@ -4,6 +4,7 @@ module Test.Golden.Shelley.TextEnvelope.Tx.TxBody
( golden_shelleyTxBody
) where

import Cardano.Api
import Cardano.Prelude

import Hedgehog (Property)
Expand Down Expand Up @@ -37,4 +38,5 @@ golden_shelleyTxBody = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do

-- Check the newly created files have not deviated from the
-- golden files
checkTxCddlFormat referenceTxBody transactionBodyFile
let txBodyTextEnvType = textEnvelopeType $ AsTxBody AsMaryEra
checkTextEnvelopeFormat txBodyTextEnvType referenceTxBody transactionBodyFile
10 changes: 5 additions & 5 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/Build.hs
Expand Up @@ -41,7 +41,7 @@ golden_shelleyTransactionBuild =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile

Expand All @@ -64,7 +64,7 @@ golden_shelleyTransactionBuild_CertificateScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile

Expand Down Expand Up @@ -96,7 +96,7 @@ golden_shelleyTransactionBuild_Minting =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile

Expand All @@ -120,7 +120,7 @@ golden_shelleyTransactionBuild_WithdrawalScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile

Expand All @@ -140,6 +140,6 @@ golden_shelleyTransactionBuild_TxInScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
@@ -1,5 +1,5 @@
{
"type": "TxWitness MaryEra",
"description": "",
"cborHex": "82008258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea42342758409f69aa4bf41acf78deaffb002c4f36157f3bad7c434a19b1ffe7e7df5f98f629e58503a762e83c1f60e54c9eb7eef9885b16c2b42ce1336914f2df9aa63b1407"
"description": "Key Witness ShelleyEra",
"cborHex": "8258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea42342758409f69aa4bf41acf78deaffb002c4f36157f3bad7c434a19b1ffe7e7df5f98f629e58503a762e83c1f60e54c9eb7eef9885b16c2b42ce1336914f2df9aa63b1407"
}

0 comments on commit 4d68cc1

Please sign in to comment.