From 83a065228ff571023b8ce911270c3342d3c4b45d Mon Sep 17 00:00:00 2001 From: teodanciu Date: Wed, 18 Oct 2023 11:54:34 +0100 Subject: [PATCH] Improve costModel generation and thus fix failing test --- cardano-api/cardano-api.cabal | 3 +-- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index f616c48e49..8c34461be4 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -261,8 +261,7 @@ library gen , cardano-binary >= 1.6 && < 1.8 , cardano-crypto-class ^>= 2.1.2 , cardano-crypto-test ^>= 1.5 - , cardano-ledger-alonzo >= 1.5.0 - , cardano-ledger-alonzo-test + , cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >= 1.5.0 , cardano-ledger-byron-test >= 1.5 , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8.0 , cardano-ledger-shelley >= 1.7.0 diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index d45fc17668..ccd5d2999d 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -161,7 +161,7 @@ import Test.Gen.Cardano.Api.Metadata (genTxMetadata) import Test.Cardano.Chain.UTxO.Gen (genVKWitness) import Test.Cardano.Crypto.Gen (genProtocolMagicId) -import qualified Test.Cardano.Ledger.Alonzo.PlutusScripts as Plutus +import Test.Cardano.Ledger.Alonzo.Arbitrary (genValidCostModel) import Test.Cardano.Ledger.Conway.Arbitrary () import Test.Cardano.Ledger.Core.Arbitrary () @@ -969,15 +969,12 @@ genUpdateProposal era = genCostModel :: Gen Alonzo.CostModel genCostModel = do - let costModelParams = Alonzo.getCostModelParams Plutus.testingCostModelV1 - eCostModel <- Alonzo.mkCostModel <$> genPlutusLanguage - <*> mapM (const $ Gen.integral (Range.linear 0 5000)) costModelParams - case eCostModel of - Left err -> error $ "genCostModel: " <> show err - Right cModel -> return cModel + lang <- genPlutusLanguage + cm <- Q.quickcheck (genValidCostModel lang) + pure cm genPlutusLanguage :: Gen Language -genPlutusLanguage = Gen.element [PlutusV1, PlutusV2] +genPlutusLanguage = Gen.element [PlutusV1, PlutusV2, PlutusV3] _genCostModels :: Gen (Map AnyPlutusScriptVersion CostModel) _genCostModels =