Skip to content

Commit cd56d4b

Browse files
authored
Merge pull request #4991 from IntersectMBO/td/fix-pparam-json-serialization
Fix `PParams` JSON deserialization
2 parents 98d9021 + f28432e commit cd56d4b

File tree

20 files changed

+249
-15
lines changed

20 files changed

+249
-15
lines changed

eras/alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ build-type: Simple
1515
data-files:
1616
cddl-files/alonzo.cddl
1717
golden/*.cbor
18+
golden/*.json
1819

1920
extra-source-files: CHANGELOG.md
2021

@@ -214,6 +215,7 @@ test-suite tests
214215
Paths_cardano_ledger_alonzo
215216
Test.Cardano.Ledger.Alonzo.Binary.CddlSpec
216217
Test.Cardano.Ledger.Alonzo.BinarySpec
218+
Test.Cardano.Ledger.Alonzo.GoldenSpec
217219
Test.Cardano.Ledger.Alonzo.GoldenTranslation
218220

219221
default-language: Haskell2010
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"txFeePerByte":44,
3+
"txFeeFixed":155381,
4+
"maxBlockBodySize":65536,
5+
"maxTxSize":16384,
6+
"maxBlockHeaderSize":1100,
7+
"stakeAddressDeposit":2000000,
8+
"stakePoolDeposit":500000000,
9+
"poolRetireMaxEpoch":18,
10+
"stakePoolTargetNum":500,
11+
"poolPledgeInfluence":0.3,
12+
"monetaryExpansion":0.003,
13+
"treasuryCut":0.2,
14+
"decentralization":0.0,
15+
"extraPraosEntropy":null,
16+
"protocolVersion":{
17+
"major":6,
18+
"minor":0
19+
},
20+
"minPoolCost":340000000,
21+
"utxoCostPerByte":4310,
22+
"costModels":{
23+
"PlutusV1":[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
24+
},
25+
"executionUnitPrices":{
26+
"priceSteps":0.0000721,
27+
"prMem":0.0577
28+
},
29+
"maxTxExecutionUnits":{
30+
"steps":10000000000,
31+
"memory":14000000
32+
},
33+
"maxBlockExecutionUnits":{
34+
"steps":40000000000,
35+
"memory":62000000
36+
},
37+
"maxValueSize":5000,
38+
"collateralPercentage":150,
39+
"maxCollateralInputs":3
40+
}

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ import Data.Aeson as Aeson (
134134
object,
135135
pairs,
136136
withObject,
137-
(.!=),
138137
(.:),
139138
)
140139
import qualified Data.Aeson.Types as Aeson
@@ -484,7 +483,7 @@ instance FromJSON (AlonzoPParams Identity era) where
484483
<*> obj .: "decentralization"
485484
<*> obj .: "extraPraosEntropy"
486485
<*> obj .: "protocolVersion"
487-
<*> obj .: "minPoolCost" .!= mempty
486+
<*> obj .: "minPoolCost"
488487
<*> obj .: "utxoCostPerByte"
489488
<*> obj .: "costModels"
490489
<*> obj .: "executionUnitPrices"

eras/alonzo/impl/test/Main.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import qualified Test.Cardano.Ledger.Alonzo.Binary.CddlSpec as CddlSpec
77
import qualified Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec as CostModelsSpec
88
import qualified Test.Cardano.Ledger.Alonzo.Binary.TxWitsSpec as TxWitsSpec
99
import qualified Test.Cardano.Ledger.Alonzo.BinarySpec as BinarySpec
10-
import qualified Test.Cardano.Ledger.Alonzo.GoldenTranslation as Golden
10+
import qualified Test.Cardano.Ledger.Alonzo.GoldenSpec as Golden
11+
import qualified Test.Cardano.Ledger.Alonzo.GoldenTranslation as GoldenTranslation
1112
import qualified Test.Cardano.Ledger.Alonzo.Imp as Imp
1213
import Test.Cardano.Ledger.Alonzo.ImpTest ()
1314
import Test.Cardano.Ledger.Common
@@ -20,7 +21,8 @@ main =
2021
BinarySpec.spec
2122
CddlSpec.spec
2223
roundTripJsonEraSpec @AlonzoEra
23-
Golden.tests
24+
GoldenTranslation.tests
25+
Golden.spec
2426
describe "Imp" $ do
2527
Imp.spec @AlonzoEra
2628
describe "CostModels" $ do
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE TypeApplications #-}
3+
4+
module Test.Cardano.Ledger.Alonzo.GoldenSpec (spec) where
5+
6+
import Cardano.Ledger.Alonzo
7+
import Paths_cardano_ledger_alonzo (getDataFileName)
8+
import Test.Cardano.Ledger.Common
9+
import Test.Cardano.Ledger.Core.JSON (goldenJsonPParamsSpec)
10+
11+
spec :: Spec
12+
spec =
13+
describe "Golden" $ do
14+
beforeAll (getDataFileName "golden/pparams.json") $
15+
goldenJsonPParamsSpec @AlonzoEra

eras/babbage/impl/cardano-ledger-babbage.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ build-type: Simple
1717
data-files:
1818
cddl-files/babbage.cddl
1919
golden/*.cbor
20+
golden/*.json
2021

2122
extra-source-files: CHANGELOG.md
2223

@@ -188,6 +189,7 @@ test-suite tests
188189
Paths_cardano_ledger_babbage
189190
Test.Cardano.Ledger.Babbage.Binary.CddlSpec
190191
Test.Cardano.Ledger.Babbage.BinarySpec
192+
Test.Cardano.Ledger.Babbage.GoldenSpec
191193
Test.Cardano.Ledger.Babbage.GoldenTranslation
192194

193195
default-language: Haskell2010
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"txFeePerByte":125936,
3+
"txFeeFixed":708372,
4+
"maxBlockBodySize":1,
5+
"maxTxSize":1,
6+
"maxBlockHeaderSize":1,
7+
"stakeAddressDeposit":568321,
8+
"stakePoolDeposit":525721,
9+
"poolRetireMaxEpoch":0,
10+
"stakePoolTargetNum":1,
11+
"poolPledgeInfluence":4.00525056366491892,
12+
"monetaryExpansion":0.956320129784306867,
13+
"treasuryCut":0.1704528968981345,
14+
"minPoolCost":805247,
15+
"costModels":{
16+
"PlutusV1":[ 0, -1, 0, 1, 1, -1, 0, -1, 0, -1, 1, 1, 0, 1, 0, 0, -1, 0, -1, 0, 0, -1, 1, 0, 1, -1, 0, 1, 1, 0, 1, 1, -1, 1, 0, 1, 1, -1, -1, -1, 1, 1, -1, 0, 0, 1, 1, 0, -1, 1, -1, -1, -1, 0, -1, 1, -1, -1, 1, -1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, -1, -1, 0, -1, -1, 0, -1, 1, 1, -1, 0, 0, 1, 0, 1, 1, -1, -1, 0, -1, -1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, -1, 1, -1, -1, -1, -1, 1, 0, 1, -1, 1, 1, 1, 0, -1, 1, 1, 0, 0, 1, -1, 1, 1, 0, -1, -1, 0, -1, 1, 0, 1, 1, 1, 1, 1, -1, 0, 1, 1, 0, 0, -1, 0, 0, -1, -1, -1, -1, 0, -1, 0, -1, -1, 0, 0, 1, 0, 1 ],
17+
"PlutusV2":[ -1, 1, -1, -1, -1, 0, 1, 1, 0, -1, -1, 0, -1, 0, 1, 1, 0, 0, -1, 1, -1, 0, -1, 0, 0, -1, 1, -1, 0, 1, 1, 0, -1, -1, -1, -1, 1, 0, -1, -1, 0, -1, 0, -1, 0, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, 1, -1, -1, -1, 0, -1, -1, 1, 0, -1, -1, -1, -1, 0, 0, -1, 0, 0, 0, 1, 1, -1, -1, 0, 0, 1, 0, 0, -1, 1, 0, 1, 1, -1, 1, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0, -1, -1, 0, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 0, 1, -1, 0, -1, 0, -1, 0, 0, 1, 1, 0, -1, 0, 0, -1, 1, 0, 1, 1, 1, -1, 0, -1, -1, -1, 0, 0, -1, 0, 1, 1, 0, 1, 1, 1, 1, 1, -1, 0, 1, -1, 1, 1, 0, -1, 1, 0, 1, 0, 1, -1, -1, 0, -1, -1, 1, 0, 1, -1, -1, -1 ]
18+
},
19+
"executionUnitPrices":{ "priceMemory":1708.666753535008936, "priceSteps":9548718419223053632 },
20+
"maxTxExecutionUnits":{
21+
"memory":5032611896682840784,
22+
"steps":4247616078198573105
23+
},
24+
"maxBlockExecutionUnits":{
25+
"memory":7479707704554150331,
26+
"steps":1214717225589080517
27+
},
28+
"maxValueSize":1,
29+
"collateralPercentage":0,
30+
"maxCollateralInputs":0,
31+
"utxoCostPerByte":441050,
32+
"protocolVersion":{
33+
"major":7,
34+
"minor":1
35+
}
36+
}

eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ import Data.Aeson as Aeson (
106106
object,
107107
pairs,
108108
withObject,
109-
(.!=),
110109
(.:),
111110
)
112111
import Data.Functor.Identity (Identity (..))
@@ -364,7 +363,7 @@ instance FromJSON (BabbagePParams Identity era) where
364363
<*> obj .: "monetaryExpansion"
365364
<*> obj .: "treasuryCut"
366365
<*> obj .: "protocolVersion"
367-
<*> obj .: "minPoolCost" .!= mempty
366+
<*> obj .: "minPoolCost"
368367
<*> obj .: "utxoCostPerByte"
369368
<*> obj .: "costModels"
370369
<*> obj .: "executionUnitPrices"

eras/babbage/impl/test/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import qualified Test.Cardano.Ledger.Alonzo.Binary.CostModelsSpec as CostModelsS
77
import qualified Test.Cardano.Ledger.Alonzo.Binary.TxWitsSpec as TxWitsSpec
88
import qualified Test.Cardano.Ledger.Babbage.Binary.CddlSpec as CddlSpec
99
import qualified Test.Cardano.Ledger.Babbage.BinarySpec as BinarySpec
10-
import qualified Test.Cardano.Ledger.Babbage.GoldenTranslation as Golden
10+
import qualified Test.Cardano.Ledger.Babbage.GoldenSpec as Golden
11+
import qualified Test.Cardano.Ledger.Babbage.GoldenTranslation as GoldenTranslation
1112
import qualified Test.Cardano.Ledger.Babbage.Imp as Imp
1213
import Test.Cardano.Ledger.Babbage.ImpTest ()
1314
import Test.Cardano.Ledger.Common
@@ -17,6 +18,7 @@ main :: IO ()
1718
main =
1819
ledgerTestMain $
1920
describe "Babbage" $ do
21+
GoldenTranslation.spec
2022
Golden.spec
2123
BinarySpec.spec
2224
CddlSpec.spec
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
{-# LANGUAGE TypeApplications #-}
3+
4+
module Test.Cardano.Ledger.Babbage.GoldenSpec (spec) where
5+
6+
import Cardano.Ledger.Babbage
7+
import Paths_cardano_ledger_babbage (getDataFileName)
8+
import Test.Cardano.Ledger.Common
9+
import Test.Cardano.Ledger.Core.JSON (goldenJsonPParamsSpec)
10+
11+
spec :: Spec
12+
spec =
13+
describe "Golden" $ do
14+
beforeAll (getDataFileName "golden/pparams.json") $
15+
goldenJsonPParamsSpec @BabbageEra

0 commit comments

Comments
 (0)