Skip to content

Commit f18144e

Browse files
committed
Add golden test function checking JSON deserialization ofPParamsUpdate
1 parent 32cb074 commit f18144e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
### `testlib`
5050

51+
* Added `goldenJsonPParamsUpdateSpec`
5152
* Added `Era` module with `EraTest` class
5253

5354
## 1.17.0.0

libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/JSON.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Test.Cardano.Ledger.Core.JSON (
88
roundTripJsonEraSpec,
99
roundTripJsonProperty,
1010
goldenJsonPParamsSpec,
11+
goldenJsonPParamsUpdateSpec,
1112
) where
1213

1314
import Cardano.Ledger.Core
@@ -20,6 +21,8 @@ import qualified Data.Text.Encoding as T
2021
import Data.Typeable (Proxy (..), Typeable, typeRep)
2122
import GHC.Stack
2223
import Test.Cardano.Ledger.Common
24+
import Test.Cardano.Ledger.Core.Arbitrary ()
25+
import Test.Cardano.Ledger.Era (EraTest)
2326

2427
-- | QuickCheck property spec that uses `roundTripJsonProperty`
2528
roundTripJsonSpec ::
@@ -51,8 +54,7 @@ roundTripJsonProperty original = do
5154
roundTripJsonEraSpec ::
5255
forall era.
5356
( HasCallStack
54-
, EraPParams era
55-
, Arbitrary (PParams era)
57+
, EraTest era
5658
) =>
5759
Spec
5860
roundTripJsonEraSpec =
@@ -68,3 +70,14 @@ goldenJsonPParamsSpec =
6870
it "Golden JSON specs for PParams " $ \file -> do
6971
decoded <- eitherDecodeFileStrict @(PParams era) file
7072
void $ expectRightExpr decoded
73+
74+
goldenJsonPParamsUpdateSpec ::
75+
forall era.
76+
EraTest era =>
77+
SpecWith FilePath
78+
goldenJsonPParamsUpdateSpec =
79+
it "Golden JSON specs for PParamsUpdate" $ \file -> do
80+
let ppu = runGen 100 100 (arbitrary @(PParamsUpdate era))
81+
let encoded = T.decodeUtf8 $ BSL.toStrict $ encodePretty ppu
82+
fileContent <- T.decodeUtf8 . BSL.toStrict <$> BSL.readFile file
83+
encoded `shouldBe` fileContent

0 commit comments

Comments
 (0)