Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed May 7, 2024
1 parent bd0c660 commit 25904f5
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -64,29 +61,29 @@ 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 =>
Spec
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
Expand Down

0 comments on commit 25904f5

Please sign in to comment.