From 25904f55ddd2c5960b932786caf3ae7183bf7fdb Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Mon, 6 May 2024 19:39:44 -0600 Subject: [PATCH] Fix more tests --- .../Ledger/Alonzo/Binary/CostModelsSpec.hs | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/CostModelsSpec.hs b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/CostModelsSpec.hs index 3687465bbda..d5fc9564a69 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/CostModelsSpec.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/CostModelsSpec.hs @@ -28,22 +28,19 @@ spec = do underspecifiedCostModelProp @era unknownCostModelProp @era prop "applyPPUpdates" $ \valid validUpdate unknown unknownUpdate -> do - let - validExpected = mkCostModels (costModelsValid validUpdate <> costModelsValid valid) - unknownExpected = unknownUpdate <> unknown original <- mkCostModelsLenient (flattenCostModels valid <> unknown) - update <- mkCostModelsLenient (flattenCostModels validUpdate <> unknownUpdate) - expected <- mkCostModelsLenient (flattenCostModels validExpected <> unknownExpected) + originalUpdate <- mkCostModelsLenient (flattenCostModels validUpdate <> unknownUpdate) let pp = emptyPParams & ppCostModelsL .~ original - ppUpdate = - emptyPParamsUpdate & ppuCostModelsL .~ SJust update + ppUpdate = emptyPParamsUpdate & ppuCostModelsL .~ SJust originalUpdate + updated = applyPPUpdates @era pp ppUpdate -- Starting with Conway we update CostModel on per-language basis, while before -- that CostModels where overwritten completely - applyPPUpdates @era pp ppUpdate - `shouldBe` if eraProtVerLow @era >= natVersion @9 - then pp & ppCostModelsL .~ expected - else pp & ppCostModelsL .~ update + if eraProtVerLow @era >= natVersion @9 + then do + expected <- mkCostModelsLenient (flattenCostModels originalUpdate <> flattenCostModels original) + updated `shouldBe` (pp & ppCostModelsL .~ expected) + else updated `shouldBe` (pp & ppCostModelsL .~ originalUpdate) validCostModelProp :: forall era. @@ -64,6 +61,7 @@ validCostModelProp = do validCm cms = not (null (costModelsValid cms)) && null (costModelsUnknown cms) +-- | Underspecified is a CostModel that has less than the normal number of parameters underspecifiedCostModelProp :: forall era. AlonzoEraPParams era => @@ -71,22 +69,21 @@ underspecifiedCostModelProp :: underspecifiedCostModelProp = do prop "CostModels with less than expected parameters within PParamsUpdate" $ \(lang :: Language) -> do - forAllShow (genInvalidCostModelEnc lang) (showEnc @era) $ + forAllShow (genUnderspecifiedCostModelEnc lang) (showEnc @era) $ \shortCmEnc -> do encodeAndCheckDecoded @era shortCmEnc $ \cmDecoded ppuDecoded -> do - -- pre-Conway we are failing when deserializing invalid costmodels + -- pre-Conway we are failing when deserializing underspecified costmodels if eraProtVerHigh @era < natVersion @9 - then expectDeserialiseFailure cmDecoded (Just "CostModels") + then do + expectDeserialiseFailure cmDecoded (Just "CostModels") + expectDeserialiseFailure ppuDecoded Nothing else do -- post-Conway, we are collecting CostModels deserialization errors cmRes <- expectRight cmDecoded cmRes `shouldSatisfy` not . null . costModelsValid - - -- in no era are we deserializing invalid costmodels within PParamsUpdate - expectDeserialiseFailure ppuDecoded Nothing where - genInvalidCostModelEnc lang = do + genUnderspecifiedCostModelEnc lang = do let validCount = costModelParamsCount lang count <- choose (0, validCount - 1) genCostModelEncForLanguage lang count