Skip to content

Commit

Permalink
Remove remaining uses of CardanoEraStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Oct 28, 2023
1 parent 93d71ad commit db42dc1
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,15 @@ genAddressShelley = makeShelleyAddress <$> genNetworkId
<*> genStakeAddressReference

genAddressInEra :: CardanoEra era -> Gen (AddressInEra era)
genAddressInEra era =
case cardanoEraStyle era of
LegacyByronEra ->
byronAddressInEra <$> genAddressByron

ShelleyBasedEra sbe ->
genAddressInEra =
inEonForEra
(byronAddressInEra <$> genAddressByron)
(\sbe ->
Gen.choice
[ byronAddressInEra <$> genAddressByron
, shelleyAddressInEra sbe <$> genAddressShelley
]
)

genKESPeriod :: Gen KESPeriod
genKESPeriod = KESPeriod <$> Gen.word Range.constantBounded
Expand Down Expand Up @@ -643,9 +642,7 @@ genTxBodyContent era = do
txMetadata <- genTxMetadataInEra era
txAuxScripts <- genTxAuxScripts era
let txExtraKeyWits = TxExtraKeyWitnessesNone --TODO: Alonzo era: Generate witness key hashes
txProtocolParams <- BuildTxWith <$> case cardanoEraStyle era of
LegacyByronEra -> return Nothing
ShelleyBasedEra sbe -> Gen.maybe $ genValidProtocolParameters sbe
txProtocolParams <- BuildTxWith <$> forEraInEon era (pure Nothing) (Gen.maybe . genValidProtocolParameters)
txWithdrawals <- genTxWithdrawals era
txCertificates <- genTxCertificates era
txUpdateProposal <- genTxUpdateProposal era
Expand Down Expand Up @@ -755,13 +752,14 @@ genTx era =
<*> genTxBody era

genWitnesses :: CardanoEra era -> Gen [KeyWitness era]
genWitnesses era =
case cardanoEraStyle era of
LegacyByronEra -> Gen.list (Range.constant 1 10) genByronKeyWitness
ShelleyBasedEra sbe -> do
genWitnesses =
caseByronOrShelleyBasedEra
(Gen.list (Range.constant 1 10) . genByronKeyWitness)
(\sbe -> do
bsWits <- Gen.list (Range.constant 0 10) (genShelleyBootstrapWitness sbe)
keyWits <- Gen.list (Range.constant 0 10) (genShelleyKeyWitness sbe)
return $ bsWits ++ keyWits
)

genVerificationKey :: ()
#if MIN_VERSION_base(4,17,0)
Expand All @@ -786,8 +784,8 @@ genVerificationKeyHash :: ()
genVerificationKeyHash roletoken =
verificationKeyHash <$> genVerificationKey roletoken

genByronKeyWitness :: Gen (KeyWitness ByronEra)
genByronKeyWitness = do
genByronKeyWitness :: ByronEraOnly era -> Gen (KeyWitness era)
genByronKeyWitness ByronEraOnlyByron = do
pmId <- genProtocolMagicId
txinWitness <- genVKWitness pmId
return $ ByronKeyWitness txinWitness
Expand Down Expand Up @@ -838,9 +836,7 @@ genShelleyWitnessSigningKey =
genCardanoKeyWitness :: ()
=> CardanoEra era
-> Gen (KeyWitness era)
genCardanoKeyWitness era = case cardanoEraStyle era of
LegacyByronEra -> genByronKeyWitness
ShelleyBasedEra sbe -> genShelleyWitness sbe
genCardanoKeyWitness = caseByronOrShelleyBasedEra genByronKeyWitness genShelleyWitness

genSeed :: Int -> Gen Crypto.Seed
genSeed n = Crypto.mkSeedFromBytes <$> Gen.bytes (Range.singleton n)
Expand Down

0 comments on commit db42dc1

Please sign in to comment.