Skip to content

Commit

Permalink
Generate protocolParamUTxOCostPerByte only if it is supported in era.
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Apr 7, 2023
1 parent bbf25f6 commit 1bba825
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ genTxBodyContent era = do
txMetadata <- genTxMetadataInEra era
txAuxScripts <- genTxAuxScripts era
let txExtraKeyWits = TxExtraKeyWitnessesNone --TODO: Alonzo era: Generate witness key hashes
txProtocolParams <- BuildTxWith <$> Gen.maybe genProtocolParameters
txProtocolParams <- BuildTxWith <$> Gen.maybe (genProtocolParameters era)
txWithdrawals <- genTxWithdrawals era
txCertificates <- genTxCertificates era
txUpdateProposal <- genTxUpdateProposal era
Expand Down Expand Up @@ -809,8 +809,8 @@ genPraosNonce = makePraosNonce <$> Gen.bytes (Range.linear 0 32)
genMaybePraosNonce :: Gen (Maybe PraosNonce)
genMaybePraosNonce = Gen.maybe genPraosNonce

genProtocolParameters :: Gen ProtocolParameters
genProtocolParameters = do
genProtocolParameters :: CardanoEra era -> Gen ProtocolParameters
genProtocolParameters era = do
protocolParamProtocolVersion <- (,) <$> genNat <*> genNat
protocolParamDecentralization <- Gen.maybe genRational
protocolParamExtraPraosEntropy <- genMaybePraosNonce
Expand Down Expand Up @@ -838,7 +838,7 @@ genProtocolParameters = do
protocolParamMaxValueSize <- Gen.maybe genNat
protocolParamCollateralPercent <- Gen.maybe genNat
protocolParamMaxCollateralInputs <- Gen.maybe genNat
protocolParamUTxOCostPerByte <- Gen.maybe genLovelace
protocolParamUTxOCostPerByte <- sequence $ protocolUTxOCostPerByteSupportedInEra era $> genLovelace

pure ProtocolParameters {..}

Expand Down
5 changes: 4 additions & 1 deletion cardano-api/test/Test/Cardano/Api/Typed/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Test.Cardano.Api.Typed.JSON
( tests
) where

import Cardano.Api

import Data.Aeson (eitherDecode, encode)

import Hedgehog (Property, forAll, tripping)
Expand All @@ -28,7 +30,8 @@ prop_roundtrip_praos_nonce_JSON = H.property $ do

prop_roundtrip_protocol_parameters_JSON :: Property
prop_roundtrip_protocol_parameters_JSON = H.property $ do
pp <- forAll genProtocolParameters
AnyCardanoEra era <- forAll $ Gen.element [minBound .. maxBound]
pp <- forAll (genProtocolParameters era)
tripping pp encode eitherDecode

-- -----------------------------------------------------------------------------
Expand Down

0 comments on commit 1bba825

Please sign in to comment.