Skip to content

Commit

Permalink
Merge #1999
Browse files Browse the repository at this point in the history
1999: Additional roundtrip tests for cardano-api r=intricate a=Jimbo4350



Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 committed Oct 22, 2020
2 parents 7d3ebd6 + 23a6cd0 commit bf9e008
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
5 changes: 4 additions & 1 deletion cardano-api/test/Test/Cardano/Api/Typed/CBOR.hs
Expand Up @@ -36,7 +36,6 @@ prop_roundtrip_tx_shelley_CBOR :: Property
prop_roundtrip_tx_shelley_CBOR =
roundtrip_CBOR AsShelleyTx genTxShelley


prop_roundtrip_witness_shelley_CBOR :: Property
prop_roundtrip_witness_shelley_CBOR =
roundtrip_CBOR AsShelleyWitness genShelleyWitness
Expand Down Expand Up @@ -117,6 +116,10 @@ prop_roundtrip_signing_key_kes_CBOR :: Property
prop_roundtrip_signing_key_kes_CBOR =
roundtrip_CBOR (AsSigningKey AsKesKey) (genSigningKey AsKesKey)

prop_roundtrip_script_CBOR :: Property
prop_roundtrip_script_CBOR =
roundtrip_CBOR AsScript genScript

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

roundtrip_CBOR
Expand Down
8 changes: 8 additions & 0 deletions cardano-api/test/Test/Cardano/Api/Typed/Gen.hs
Expand Up @@ -5,8 +5,10 @@ module Test.Cardano.Api.Typed.Gen
, genRequiredSig
, genMofNRequiredSig
, genMultiSigScript
, genScriptHash
, genOperationalCertificate
, genOperationalCertificateIssueCounter
, genScript
, genShelleyWitness
, genSigningKey
, genStakeAddress
Expand Down Expand Up @@ -80,6 +82,12 @@ genMultiSigScript :: Gen MultiSigScript
genMultiSigScript =
Gen.choice [genAllRequiredSig, genAnyRequiredSig, genMofNRequiredSig]

genScript :: Gen Script
genScript = makeMultiSigScript <$> genMultiSigScript

genScriptHash :: Gen (Hash Script)
genScriptHash = scriptHash <$> genScript

genNetworkId :: Gen NetworkId
genNetworkId =
Gen.choice
Expand Down
34 changes: 19 additions & 15 deletions cardano-api/test/Test/Cardano/Api/Typed/RawBytes.hs
Expand Up @@ -20,26 +20,21 @@ import qualified Hedgehog as H
-- Address CBOR round trips

prop_roundtrip_shelley_address_raw :: Property
prop_roundtrip_shelley_address_raw = H.property $ do
addr <- H.forAll genAddressShelley
H.tripping addr serialiseToRawBytes (deserialiseFromRawBytes AsShelleyAddress)
prop_roundtrip_shelley_address_raw =
roundtrip_raw_bytes AsShelleyAddress genAddressShelley

prop_roundtrip_byron_address_raw :: Property
prop_roundtrip_byron_address_raw = H.property $ do
addr <- H.forAll genAddressByron
H.tripping addr serialiseToRawBytes (deserialiseFromRawBytes AsByronAddress)

{-
--TODO: Follow up
This property will fail due to:
Shelley.deserialiseRewardAcnt not being available
prop_roundtrip_byron_address_raw :: Property
prop_roundtrip_byron_address_raw =
roundtrip_raw_bytes AsByronAddress genAddressByron

prop_roundtrip_stake_address_raw :: Property
prop_roundtrip_stake_address_raw = H.property $ do
addr <- H.forAll genStakeAddress
H.tripping addr serialiseToRawBytes (deserialiseFromRawBytes AsStakeAddress)
-}
prop_roundtrip_stake_address_raw =
roundtrip_raw_bytes AsStakeAddress genStakeAddress

prop_roundtrip_script_hash_raw :: Property
prop_roundtrip_script_hash_raw =
roundtrip_raw_bytes (AsHash AsScript) genScriptHash

prop_roundtrip_verification_ByronKey_hash_raw :: Property
prop_roundtrip_verification_ByronKey_hash_raw =
Expand Down Expand Up @@ -79,6 +74,15 @@ prop_roundtrip_verification_GenesisUTxOKey_hash_raw =

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

roundtrip_raw_bytes
:: ( SerialiseAsRawBytes a
, Eq a
, Show a) => AsType a -> H.Gen a -> Property
roundtrip_raw_bytes asType g =
H.property $ do
v <- H.forAll g
H.tripping v serialiseToRawBytes (deserialiseFromRawBytes asType)

roundtrip_verification_key_hash_raw
:: (Key keyrole, Eq (Hash keyrole), Show (Hash keyrole))
=> AsType keyrole -> Property
Expand Down

0 comments on commit bf9e008

Please sign in to comment.