Skip to content

Commit

Permalink
Add test to check ConwayGenesis deserialization from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Aug 25, 2023
1 parent 6e731f6 commit fde8ac6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ description:
category: Network
build-type: Simple
extra-source-files: CHANGELOG.md
data-files:
data/*.json

source-repository head
type: git
Expand Down Expand Up @@ -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:
Expand All @@ -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
2 changes: 2 additions & 0 deletions eras/conway/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -10,3 +11,4 @@ main =
describe "Conway" $ do
BinarySpec.spec
RatifySpec.spec
GenesisSpec.spec
30 changes: 30 additions & 0 deletions eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.hs
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions eras/conway/impl/test/data/conway-genesis.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit fde8ac6

Please sign in to comment.