Skip to content

Commit

Permalink
Restrict scope of mock protocol parameters for txConstraints.
Browse files Browse the repository at this point in the history
These mock protocol parameters are specific to the property tests for
`txConstraints`, and not used elsewhere.
  • Loading branch information
jonathanknowles committed Oct 17, 2023
1 parent d4c14e6 commit 6e5965a
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions lib/wallet/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,64 +1362,63 @@ emptyTxSkeleton =
mockTxConstraints :: TxConstraints
mockTxConstraints =
txConstraints
(_mockPParamsForTxConstraints @Cardano.BabbageEra)
(mockPParamsForTxConstraints @Cardano.BabbageEra)
TxWitnessShelleyUTxO
where
mockPParamsForTxConstraints
:: forall era . Write.IsRecentEra era => Write.ProtocolParameters era
mockPParamsForTxConstraints =
Write.ProtocolParameters . either (error . show) id $
Cardano.toLedgerPParams
(Write.shelleyBasedEra @era)
mockCardanoApiPParamsForTxConstraints

mockCardanoApiPParamsForTxConstraints :: Cardano.ProtocolParameters
mockCardanoApiPParamsForTxConstraints = Cardano.ProtocolParameters
{ Cardano.protocolParamTxFeeFixed = 155_381
, Cardano.protocolParamTxFeePerByte = 44
, Cardano.protocolParamMaxTxSize = 16_384
, Cardano.protocolParamMinUTxOValue = Nothing
, Cardano.protocolParamMaxTxExUnits =
Just $ Cardano.ExecutionUnits 10_000_000_000 14_000_000
, Cardano.protocolParamMaxValueSize = Just 4_000
, Cardano.protocolParamProtocolVersion = (6, 0)
, Cardano.protocolParamDecentralization = Just 0
, Cardano.protocolParamExtraPraosEntropy = Nothing
, Cardano.protocolParamMaxBlockHeaderSize = 100_000 -- Dummy value
, Cardano.protocolParamMaxBlockBodySize = 100_000
, Cardano.protocolParamStakeAddressDeposit = Cardano.Lovelace 2_000_000
, Cardano.protocolParamStakePoolDeposit = Cardano.Lovelace 500_000_000
, Cardano.protocolParamMinPoolCost = Cardano.Lovelace 32_000_000
, Cardano.protocolParamPoolRetireMaxEpoch = Cardano.EpochNo 2
, Cardano.protocolParamStakePoolTargetNum = 100
, Cardano.protocolParamPoolPledgeInfluence = 0
, Cardano.protocolParamMonetaryExpansion = 0
, Cardano.protocolParamTreasuryCut = 0
, Cardano.protocolParamUTxOCostPerWord =
Just $ Cardano.fromShelleyLovelace $
Alonzo.unCoinPerWord testParameter_coinsPerUTxOWord_Alonzo
, Cardano.protocolParamUTxOCostPerByte =
Just $ Cardano.fromShelleyLovelace $
Babbage.unCoinPerByte testParameter_coinsPerUTxOByte_Babbage
-- Note: since 'txConstraints' does not make use of cost models, here
-- we use the simplest possible value, which is 'mempty'.
, Cardano.protocolParamCostModels = mempty
, Cardano.protocolParamPrices =
Just $ Cardano.ExecutionUnitPrices (721 % 10_000_000) (577 % 10_000)
, Cardano.protocolParamMaxBlockExUnits =
Just $ Cardano.ExecutionUnits 10_000_000_000 14_000_000
, Cardano.protocolParamCollateralPercent = Just 150
, Cardano.protocolParamMaxCollateralInputs = Just 3
}

_mockPParamsForTxConstraints
:: forall era . Write.IsRecentEra era => Write.ProtocolParameters era
_mockPParamsForTxConstraints =
Write.ProtocolParameters . either (error . show) id $
Cardano.toLedgerPParams
(Write.shelleyBasedEra @era)
_mockCardanoApiPParamsForTxConstraints

-- | A set of protocol parameters for testing 'txConstraints'.
_mockCardanoApiPParamsForTxConstraints :: Cardano.ProtocolParameters
_mockCardanoApiPParamsForTxConstraints = Cardano.ProtocolParameters
{ Cardano.protocolParamTxFeeFixed = 155_381
, Cardano.protocolParamTxFeePerByte = 44
, Cardano.protocolParamMaxTxSize = 16_384
, Cardano.protocolParamMinUTxOValue = Nothing
, Cardano.protocolParamMaxTxExUnits =
Just $ Cardano.ExecutionUnits 10_000_000_000 14_000_000
, Cardano.protocolParamMaxValueSize = Just 4_000
, Cardano.protocolParamProtocolVersion = (6, 0)
, Cardano.protocolParamDecentralization = Just 0
, Cardano.protocolParamExtraPraosEntropy = Nothing
, Cardano.protocolParamMaxBlockHeaderSize = 100_000 -- Dummy value
, Cardano.protocolParamMaxBlockBodySize = 100_000
, Cardano.protocolParamStakeAddressDeposit = Cardano.Lovelace 2_000_000
, Cardano.protocolParamStakePoolDeposit = Cardano.Lovelace 500_000_000
, Cardano.protocolParamMinPoolCost = Cardano.Lovelace 32_000_000
, Cardano.protocolParamPoolRetireMaxEpoch = Cardano.EpochNo 2
, Cardano.protocolParamStakePoolTargetNum = 100
, Cardano.protocolParamPoolPledgeInfluence = 0
, Cardano.protocolParamMonetaryExpansion = 0
, Cardano.protocolParamTreasuryCut = 0
, Cardano.protocolParamUTxOCostPerWord =
Just $ Cardano.fromShelleyLovelace $
Alonzo.unCoinPerWord testParameter_coinsPerUTxOWord_Alonzo
, Cardano.protocolParamUTxOCostPerByte =
Just $ Cardano.fromShelleyLovelace $
Babbage.unCoinPerByte testParameter_coinsPerUTxOByte_Babbage
-- Note: since 'txConstraints' does not make use of cost models, here
-- we use the simplest possible value, which is 'mempty'.
, Cardano.protocolParamCostModels = mempty
, Cardano.protocolParamPrices =
Just $ Cardano.ExecutionUnitPrices (721 % 10_000_000) (577 % 10_000)
, Cardano.protocolParamMaxBlockExUnits =
Just $ Cardano.ExecutionUnits 10_000_000_000 14_000_000
, Cardano.protocolParamCollateralPercent = Just 150
, Cardano.protocolParamMaxCollateralInputs = Just 3
}

testParameter_coinsPerUTxOWord_Alonzo :: Ledger.CoinPerWord
testParameter_coinsPerUTxOWord_Alonzo
= Ledger.CoinPerWord $ Ledger.Coin 34_482
testParameter_coinsPerUTxOWord_Alonzo :: Ledger.CoinPerWord
testParameter_coinsPerUTxOWord_Alonzo
= Ledger.CoinPerWord $ Ledger.Coin 34_482

testParameter_coinsPerUTxOByte_Babbage :: Ledger.CoinPerByte
testParameter_coinsPerUTxOByte_Babbage
= Ledger.CoinPerByte $ Ledger.Coin 4_310
testParameter_coinsPerUTxOByte_Babbage :: Ledger.CoinPerByte
testParameter_coinsPerUTxOByte_Babbage
= Ledger.CoinPerByte $ Ledger.Coin 4_310

data MockSelection = MockSelection
{ txInputCount :: Int
Expand Down

0 comments on commit 6e5965a

Please sign in to comment.