From fde8ac65959796ba977b32d31f95fa35638f58a8 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Sat, 26 Aug 2023 00:20:01 +0100 Subject: [PATCH] Add test to check ConwayGenesis deserialization from a file --- eras/conway/impl/CHANGELOG.md | 1 + eras/conway/impl/cardano-ledger-conway.cabal | 6 ++++ eras/conway/impl/test/Main.hs | 2 ++ .../Test/Cardano/Ledger/Conway/GenesisSpec.hs | 30 ++++++++++++++++ .../conway/impl/test/data/conway-genesis.json | 34 +++++++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.hs create mode 100644 eras/conway/impl/test/data/conway-genesis.json diff --git a/eras/conway/impl/CHANGELOG.md b/eras/conway/impl/CHANGELOG.md index ea3bb82152c..384b1ca4b1a 100644 --- a/eras/conway/impl/CHANGELOG.md +++ b/eras/conway/impl/CHANGELOG.md @@ -20,6 +20,7 @@ * Change type of `rsRemoved` in `RatifyState` to use `GovActionState` instead of a tuple * Change `RatifySignal` to use `GovActionsState` instead of a tuple * Add `FromJSON` instance for `Committee` +* Add `constitution` and `committee` fields to `ConwayGenesis` ## 1.7.0.0 diff --git a/eras/conway/impl/cardano-ledger-conway.cabal b/eras/conway/impl/cardano-ledger-conway.cabal index 5c2255ac000..3a44034802b 100644 --- a/eras/conway/impl/cardano-ledger-conway.cabal +++ b/eras/conway/impl/cardano-ledger-conway.cabal @@ -12,6 +12,8 @@ description: category: Network build-type: Simple extra-source-files: CHANGELOG.md +data-files: + data/*.json source-repository head type: git @@ -115,6 +117,8 @@ test-suite tests other-modules: Test.Cardano.Ledger.Conway.BinarySpec Test.Cardano.Ledger.Conway.RatifySpec + Test.Cardano.Ledger.Conway.GenesisSpec + Paths_cardano_ledger_conway default-language: Haskell2010 ghc-options: @@ -123,9 +127,11 @@ test-suite tests -Wunused-packages -threaded -rtsopts -with-rtsopts=-N build-depends: + aeson, base, cardano-ledger-core:testlib, cardano-ledger-conway, cardano-ledger-core, containers, + data-default-class, testlib diff --git a/eras/conway/impl/test/Main.hs b/eras/conway/impl/test/Main.hs index 1e97c97966a..c1ecba7da90 100644 --- a/eras/conway/impl/test/Main.hs +++ b/eras/conway/impl/test/Main.hs @@ -2,6 +2,7 @@ module Main where import Test.Cardano.Ledger.Common import qualified Test.Cardano.Ledger.Conway.BinarySpec as BinarySpec +import qualified Test.Cardano.Ledger.Conway.GenesisSpec as GenesisSpec import qualified Test.Cardano.Ledger.Conway.RatifySpec as RatifySpec main :: IO () @@ -10,3 +11,4 @@ main = describe "Conway" $ do BinarySpec.spec RatifySpec.spec + GenesisSpec.spec diff --git a/eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.hs b/eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.hs new file mode 100644 index 00000000000..043c3ed9c5d --- /dev/null +++ b/eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Test.Cardano.Ledger.Conway.GenesisSpec (spec) where + +import Test.Cardano.Ledger.Common +import Cardano.Ledger.Conway +import Cardano.Ledger.Conway.Genesis (ConwayGenesis(..)) +import Paths_cardano_ledger_conway (getDataFileName) +import Data.Aeson hiding (Encoding) +import Data.Default.Class (Default (def)) + +spec :: Spec +spec = do + describe "Genesis Golden Spec" $ do + goldenJSON "test/data/conway-genesis.json" + +goldenJSON :: FilePath -> Spec +goldenJSON fileName = do + it "should deserialize to the default value" $ do + file <- getDataFileName fileName + dec <- eitherDecodeFileStrict' file + cg <- case dec of + Left err -> fail ("Failed to deserialize JSON: " ++ err) + Right x -> pure x + cg `shouldBe` (def :: ConwayGenesis Conway) + print cg diff --git a/eras/conway/impl/test/data/conway-genesis.json b/eras/conway/impl/test/data/conway-genesis.json new file mode 100644 index 00000000000..3387cb5a708 --- /dev/null +++ b/eras/conway/impl/test/data/conway-genesis.json @@ -0,0 +1,34 @@ +{ + "upgradeProtocolParams":{ + "poolVotingThresholds":{ + "pvtCommitteeNormal":0, + "pvtCommitteeNoConfidence":0, + "pvtHardForkInitiation":0, + "pvtMotionNoConfidence":0 + }, + "dRepVotingThresholds":{ + "dvtMotionNoConfidence":0, + "dvtCommitteeNormal":0, + "dvtCommitteeNoConfidence":0, + "dvtUpdateToConstitution":0, + "dvtHardForkInitiation":0, + "dvtPPNetworkGroup":0, + "dvtPPEconomicGroup":0, + "dvtPPTechnicalGroup":0, + "dvtPPGovGroup":0, + "dvtTreasuryWithdrawal":0 + }, + "minCommitteeSize":0, + "committeeTermLimit":0, + "govActionExpiration":0, + "govActionDeposit":0, + "dRepDeposit":0, + "dRepActivity":0 + }, + "constitution": { + "anchor": { + "url": "", + "dataHash": "0000000000000000000000000000000000000000000000000000000000000000" + } + } +}