55{-# LANGUAGE NamedFieldPuns #-}
66{-# LANGUAGE OverloadedStrings #-}
77{-# LANGUAGE RankNTypes #-}
8- {-# LANGUAGE RecordWildCards #-}
98{-# LANGUAGE ScopedTypeVariables #-}
109{-# LANGUAGE TupleSections #-}
1110{-# LANGUAGE TypeApplications #-}
@@ -28,6 +27,8 @@ module Test.Gen.Cardano.Api.Typed
2827 , genCostModel
2928 , genCostModels
3029 , genMaybePraosNonce
30+ , genTxUpdateProposal
31+ , genUpdateProposal
3132 , genPraosNonce
3233 , genValidProtocolParameters
3334 , genValueNestedRep
@@ -107,15 +108,12 @@ module Test.Gen.Cardano.Api.Typed
107108 , genValueDefault
108109 , genVerificationKey
109110 , genVerificationKeyHash
110- , genUpdateProposal
111- , genProtocolParametersUpdate
112111 , genTxOutDatumHashTxContext
113112 , genTxOutDatumHashUTxOContext
114113 , genTxOutValue
115114 , genTxReturnCollateral
116115 , genTxScriptValidity
117116 , genTxTotalCollateral
118- , genTxUpdateProposal
119117 , genTxValidityLowerBound
120118 , genTxValidityUpperBound
121119 , genTxWithdrawals
@@ -165,12 +163,10 @@ import Cardano.Api.Parser.Text qualified as P
165163import Cardano.Api.Tx qualified as A
166164
167165import Cardano.Binary qualified as CBOR
168- import Cardano.Crypto.DSIGN.Class qualified as Crypto
169166import Cardano.Crypto.Hash qualified as Crypto
170167import Cardano.Crypto.Hash.Class qualified as CRYPTO
171168import Cardano.Crypto.Seed qualified as Crypto
172169import Cardano.Ledger.Alonzo.Scripts qualified as Alonzo
173- import Cardano.Ledger.BaseTypes qualified as Ledger
174170import Cardano.Ledger.Core qualified as Ledger
175171import Cardano.Ledger.Hashes (unsafeMakeSafeHash )
176172import Cardano.Ledger.Plutus.Language qualified as L
@@ -187,17 +183,19 @@ import Data.Maybe
187183import Data.Ratio (Ratio , (%) )
188184import Data.String
189185import Data.Typeable
190- import Data.Word (Word16 , Word32 , Word64 )
186+ import Data.Word (Word32 , Word64 )
191187import GHC.Exts (IsList (.. ))
192188import GHC.Stack
193189import Numeric.Natural (Natural )
194190
195191import Test.Gen.Cardano.Api.Era (conwayEraOnwardsTestConstraints , shelleyBasedEraTestConstraints )
196192import Test.Gen.Cardano.Api.Hardcoded
197193import Test.Gen.Cardano.Api.Metadata (genTxMetadata )
194+ import Test.Gen.Cardano.Api.ProtocolParameters (genEraBasedProtocolParametersUpdate )
198195
199196import Test.Cardano.Chain.UTxO.Gen (genVKWitness )
200197import Test.Cardano.Crypto.Gen (genProtocolMagicId )
198+ import Test.Cardano.Ledger.Alonzo.Arbitrary ()
201199import Test.Cardano.Ledger.Conway.Arbitrary ()
202200import Test.Cardano.Ledger.Core.Arbitrary ()
203201
@@ -655,15 +653,6 @@ genPaymentCredential = do
655653 vKey <- genVerificationKey AsPaymentKey
656654 return . PaymentCredentialByKey $ verificationKeyHash vKey
657655
658- genSigningKey :: Key keyrole => AsType keyrole -> Gen (SigningKey keyrole )
659- genSigningKey roletoken = do
660- seed <- genSeed (fromIntegral seedSize)
661- let sk = deterministicSigningKey roletoken seed
662- return sk
663- where
664- seedSize :: Word
665- seedSize = deterministicSigningKeySeedSize roletoken
666-
667656genStakeAddress :: Gen StakeAddress
668657genStakeAddress = makeStakeAddress <$> genNetworkId <*> genStakeCredential
669658
@@ -955,15 +944,6 @@ genMirCertificateRequirements w =
955944 shelleyToBabbageEraConstraints w $
956945 MirCertificateRequirements w <$> Q. arbitrary <*> Q. arbitrary
957946
958- genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era )
959- genTxUpdateProposal sbe =
960- Gen. choice $
961- catMaybes
962- [ Just $ pure TxUpdateProposalNone
963- , forEraInEon sbe Nothing $ \ w ->
964- Just $ TxUpdateProposal w <$> genUpdateProposal (toCardanoEra w)
965- ]
966-
967947genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era )
968948genTxMintValue =
969949 inEonForEra
@@ -1183,23 +1163,6 @@ genWitnesses sbe = do
11831163 keyWits <- Gen. list (Range. constant 0 10 ) (genShelleyKeyWitness sbe)
11841164 return $ bsWits ++ keyWits
11851165
1186- genVerificationKey
1187- :: ()
1188- => HasTypeProxy keyrole
1189- => Key keyrole
1190- => AsType keyrole
1191- -> Gen (VerificationKey keyrole )
1192- genVerificationKey roletoken = getVerificationKey <$> genSigningKey roletoken
1193-
1194- genVerificationKeyHash
1195- :: ()
1196- => HasTypeProxy keyrole
1197- => Key keyrole
1198- => AsType keyrole
1199- -> Gen (Hash keyrole )
1200- genVerificationKeyHash roletoken =
1201- verificationKeyHash <$> genVerificationKey roletoken
1202-
12031166genByronKeyWitness :: Gen (KeyWitness ByronEra )
12041167genByronKeyWitness = do
12051168 pmId <- genProtocolMagicId
@@ -1260,18 +1223,9 @@ genCardanoKeyWitness
12601223 -> Gen (KeyWitness era )
12611224genCardanoKeyWitness = genShelleyWitness
12621225
1263- genSeed :: Int -> Gen Crypto. Seed
1264- genSeed n = Crypto. mkSeedFromBytes <$> Gen. bytes (Range. singleton n)
1265-
12661226genNat :: Gen Natural
12671227genNat = Gen. integral (Range. linear 0 10 )
12681228
1269- genWord16 :: Gen Word16
1270- genWord16 = Gen. integral (Range. linear 0 10 )
1271-
1272- genWord32 :: Gen Word32
1273- genWord32 = Gen. integral (Range. linear 0 10 )
1274-
12751229genRational :: Gen Rational
12761230genRational =
12771231 (\ d -> ratioToRational (1 % d)) <$> genDenominator
@@ -1294,12 +1248,6 @@ genRationalInt64 =
12941248 ratioToRational :: Ratio Int64 -> Rational
12951249 ratioToRational = toRational
12961250
1297- genEpochNo :: Gen EpochNo
1298- genEpochNo = EpochNo <$> Gen. word64 (Range. linear 0 10 )
1299-
1300- genEpochInterval :: Gen Ledger. EpochInterval
1301- genEpochInterval = Ledger. EpochInterval <$> Gen. word32 (Range. linear 0 10 )
1302-
13031251genPraosNonce :: Gen PraosNonce
13041252genPraosNonce = makePraosNonce <$> Gen. bytes (Range. linear 0 32 )
13051253
@@ -1313,56 +1261,9 @@ genValidProtocolParameters sbe =
13131261 shelleyBasedEraTestConstraints sbe $
13141262 LedgerProtocolParameters <$> Q. arbitrary
13151263
1316- genProtocolParametersUpdate :: CardanoEra era -> Gen ProtocolParametersUpdate
1317- genProtocolParametersUpdate era = do
1318- protocolUpdateProtocolVersion <- Gen. maybe ((,) <$> genNat <*> genNat)
1319- protocolUpdateDecentralization <- Gen. maybe genRational
1320- protocolUpdateExtraPraosEntropy <- Gen. maybe genMaybePraosNonce
1321- protocolUpdateMaxBlockHeaderSize <- Gen. maybe genWord16
1322- protocolUpdateMaxBlockBodySize <- Gen. maybe genWord32
1323- protocolUpdateMaxTxSize <- Gen. maybe genWord32
1324- protocolUpdateTxFeeFixed <- Gen. maybe genLovelace
1325- protocolUpdateTxFeePerByte <- Gen. maybe genLovelace
1326- protocolUpdateMinUTxOValue <- Gen. maybe genLovelace
1327- protocolUpdateStakeAddressDeposit <- Gen. maybe genLovelace
1328- protocolUpdateStakePoolDeposit <- Gen. maybe genLovelace
1329- protocolUpdateMinPoolCost <- Gen. maybe genLovelace
1330- protocolUpdatePoolRetireMaxEpoch <- Gen. maybe genEpochInterval
1331- protocolUpdateStakePoolTargetNum <- Gen. maybe genWord16
1332- protocolUpdatePoolPledgeInfluence <- Gen. maybe genRationalInt64
1333- protocolUpdateMonetaryExpansion <- Gen. maybe genRational
1334- protocolUpdateTreasuryCut <- Gen. maybe genRational
1335- let protocolUpdateCostModels = mempty -- genCostModels
1336- -- TODO: Babbage figure out how to deal with
1337- -- asymmetric cost model JSON instances
1338- protocolUpdatePrices <- Gen. maybe genExecutionUnitPrices
1339- protocolUpdateMaxTxExUnits <- Gen. maybe genExecutionUnits
1340- protocolUpdateMaxBlockExUnits <- Gen. maybe genExecutionUnits
1341- protocolUpdateMaxValueSize <- Gen. maybe genWord32
1342- protocolUpdateCollateralPercent <- Gen. maybe genWord16
1343- protocolUpdateMaxCollateralInputs <- Gen. maybe genWord16
1344- protocolUpdateUTxOCostPerByte <-
1345- inEonForEra @ BabbageEraOnwards (pure Nothing ) (const (Just <$> genLovelace)) era
1346-
1347- pure ProtocolParametersUpdate {.. }
1348-
1349- genUpdateProposal :: CardanoEra era -> Gen UpdateProposal
1350- genUpdateProposal era =
1351- UpdateProposal
1352- <$> Gen. map
1353- (Range. constant 1 3 )
1354- ( (,)
1355- <$> genVerificationKeyHash AsGenesisKey
1356- <*> genProtocolParametersUpdate era
1357- )
1358- <*> genEpochNo
1359-
13601264genCostModel :: MonadGen m => m Alonzo. CostModel
13611265genCostModel = Q. arbitrary
13621266
1363- genCostModels :: MonadGen m => m Alonzo. CostModels
1364- genCostModels = Q. arbitrary
1365-
13661267genExecutionUnits :: Gen ExecutionUnits
13671268genExecutionUnits =
13681269 ExecutionUnits
@@ -1733,3 +1634,58 @@ genChainPoint =
17331634genChainPointAt :: SlotNo -> Gen ChainPoint
17341635genChainPointAt s =
17351636 ChainPoint s <$> genBlockHeaderHash
1637+
1638+ genEpochNo :: Gen EpochNo
1639+ genEpochNo = EpochNo <$> Gen. word64 (Range. linear 0 10 )
1640+
1641+ genCostModels :: MonadGen m => m Alonzo. CostModels
1642+ genCostModels = Q. arbitrary
1643+
1644+ genVerificationKeyHash
1645+ :: ()
1646+ => HasTypeProxy keyrole
1647+ => Key keyrole
1648+ => AsType keyrole
1649+ -> Gen (Hash keyrole )
1650+ genVerificationKeyHash roletoken =
1651+ verificationKeyHash <$> genVerificationKey roletoken
1652+
1653+ genVerificationKey
1654+ :: ()
1655+ => HasTypeProxy keyrole
1656+ => Key keyrole
1657+ => AsType keyrole
1658+ -> Gen (VerificationKey keyrole )
1659+ genVerificationKey roletoken = getVerificationKey <$> genSigningKey roletoken
1660+
1661+ genSigningKey :: Key keyrole => AsType keyrole -> Gen (SigningKey keyrole )
1662+ genSigningKey roletoken = do
1663+ seed <- genSeed (fromIntegral seedSize)
1664+ let sk = deterministicSigningKey roletoken seed
1665+ return sk
1666+ where
1667+ seedSize :: Word
1668+ seedSize = deterministicSigningKeySeedSize roletoken
1669+
1670+ genSeed :: Int -> Gen Crypto. Seed
1671+ genSeed n = Crypto. mkSeedFromBytes <$> Gen. bytes (Range. singleton n)
1672+
1673+ genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era )
1674+ genTxUpdateProposal sbe =
1675+ Gen. choice $
1676+ catMaybes
1677+ [ Just $ pure TxUpdateProposalNone
1678+ , forEraInEon sbe Nothing $ \ w ->
1679+ Just $ TxUpdateProposal w <$> genUpdateProposal (toCardanoEra w)
1680+ ]
1681+
1682+ genUpdateProposal :: CardanoEra era -> Gen (UpdateProposal era )
1683+ genUpdateProposal era =
1684+ UpdateProposal
1685+ <$> Gen. map
1686+ (Range. constant 1 3 )
1687+ ( (,)
1688+ <$> genVerificationKeyHash AsGenesisKey
1689+ <*> genEraBasedProtocolParametersUpdate era
1690+ )
1691+ <*> genEpochNo
0 commit comments