Skip to content

Commit

Permalink
Fix test generation of Rational protocol parameter values
Browse files Browse the repository at this point in the history
They have to fit into a UnitInterval.

We also need validation.
  • Loading branch information
dcoutts committed Jun 8, 2021
1 parent 3915b99 commit 3cba3b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Expand Up @@ -823,6 +823,8 @@ makeShelleyUpdateProposal :: ProtocolParametersUpdate
-> UpdateProposal
makeShelleyUpdateProposal params genesisKeyHashes =
--TODO decide how to handle parameter validation
-- for example we need to validate the Rational values can convert
-- into the UnitInterval type ok.
UpdateProposal (Map.fromList [ (kh, params) | kh <- genesisKeyHashes ])


Expand Down
3 changes: 2 additions & 1 deletion cardano-api/src/Cardano/Api/TxBody.hs
Expand Up @@ -2097,7 +2097,8 @@ makeShelleyTransactionBody era@ShelleyBasedEraAlonzo
case txProtocolParams of
BuildTxWith Nothing | not (Set.null languages)
-> Left TxBodyMissingProtocolParams
_ -> return ()
_ -> return () --TODO alonzo: validate protocol params for the Alonzo era.
-- All the necessary params must be provided.

return $
ShelleyTxBody era
Expand Down
9 changes: 7 additions & 2 deletions cardano-api/test/Test/Cardano/Api/Typed/Gen.hs
Expand Up @@ -55,7 +55,7 @@ import qualified Cardano.Binary as CBOR
import qualified Cardano.Crypto.Hash as Crypto
import qualified Cardano.Crypto.Seed as Crypto
import qualified Shelley.Spec.Ledger.TxBody as Ledger (EraIndependentTxBody)

import qualified Cardano.Ledger.BaseTypes as Ledger

import Hedgehog (Gen, Range)
import qualified Hedgehog.Gen as Gen
Expand Down Expand Up @@ -683,7 +683,12 @@ genNat :: Gen Natural
genNat = Gen.integral (Range.linear 0 10)

genRational :: Gen Rational
genRational = Gen.realFrac_ (Range.linearFrac 0 1)
genRational = Ledger.unitIntervalToRational <$> genUnitInterval

genUnitInterval :: Gen Ledger.UnitInterval
genUnitInterval =
Gen.just $
Ledger.mkUnitInterval <$> Gen.realFrac_ (Range.linearFrac 0 1)

genEpochNo :: Gen EpochNo
genEpochNo = EpochNo <$> Gen.word64 (Range.linear 0 10)
Expand Down

0 comments on commit 3cba3b2

Please sign in to comment.