Skip to content

Commit 7aaba5b

Browse files
authored
Merge pull request #1321 from IntersectMBO/parse-dijkstra-hard-fork-trigger
Honour TestDijkstraHardForkAtEpoch when parsing the node configuration
2 parents a866166 + 7693458 commit 7aaba5b

5 files changed

Lines changed: 87 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: |
2+
`foldBlocks` and the rest of the ledger-state machinery now honour `TestDijkstraHardForkAtEpoch` in the node configuration file, so they can follow a chain into the Dijkstra era.
3+
kind:
4+
- bugfix
5+
pr: 1321
6+
project: cardano-api

cardano-api/cardano-api.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ test-suite cardano-api-test
398398
hedgehog-quickcheck,
399399
microlens,
400400
mtl,
401-
ouroboros-consensus:{ouroboros-consensus, protocol},
401+
ouroboros-consensus:{cardano, ouroboros-consensus, protocol},
402402
raw-strings-qq,
403403
tasty,
404404
tasty-hedgehog,
@@ -427,6 +427,7 @@ test-suite cardano-api-test
427427
Test.Cardano.Api.Ledger
428428
Test.Cardano.Api.Leios
429429
Test.Cardano.Api.Metadata
430+
Test.Cardano.Api.NodeConfig
430431
Test.Cardano.Api.Ord
431432
Test.Cardano.Api.Orphans
432433
Test.Cardano.Api.RawBytes

cardano-api/src/Cardano/Api/LedgerState.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ instance FromJSON NodeConfig where
11731173
<*> parseAlonzoHardForkEpoch o
11741174
<*> parseBabbageHardForkEpoch o
11751175
<*> parseConwayHardForkEpoch o
1176-
<*> pure Consensus.CardanoTriggerHardForkAtDefaultVersion -- TODO Dijkstra
1176+
<*> parseDijkstraHardForkEpoch o
11771177
parseShelleyHardForkEpoch :: Object -> Parser (Consensus.CardanoHardForkTrigger blk)
11781178
parseShelleyHardForkEpoch o =
11791179
asum
@@ -1215,6 +1215,13 @@ instance FromJSON NodeConfig where
12151215
, pure Consensus.CardanoTriggerHardForkAtDefaultVersion
12161216
]
12171217

1218+
parseDijkstraHardForkEpoch :: Object -> Parser (Consensus.CardanoHardForkTrigger blk)
1219+
parseDijkstraHardForkEpoch o =
1220+
asum
1221+
[ Consensus.CardanoTriggerHardForkAtEpoch <$> o .: "TestDijkstraHardForkAtEpoch"
1222+
, pure Consensus.CardanoTriggerHardForkAtDefaultVersion
1223+
]
1224+
12181225
----------------------------------------------------------------------
12191226
-- WARNING When adding new entries above, be aware that if there is an
12201227
-- intra-era fork, then the numbering is not consecutive.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module Test.Cardano.Api.NodeConfig
4+
( tests
5+
)
6+
where
7+
8+
import Cardano.Api (EpochNo (..))
9+
import Cardano.Api.LedgerState (NodeConfig (..))
10+
11+
import Ouroboros.Consensus.Cardano.Node qualified as Consensus
12+
13+
import Data.Aeson qualified as Aeson
14+
import GHC.Stack
15+
16+
import Hedgehog as H
17+
import Hedgehog.Extras (propertyOnce)
18+
import Test.Tasty (TestTree, testGroup)
19+
import Test.Tasty.Hedgehog (testProperty)
20+
21+
-- | A minimal node configuration with the given extra keys.
22+
nodeConfigWith :: [(Aeson.Key, Aeson.Value)] -> Aeson.Value
23+
nodeConfigWith extras =
24+
Aeson.object $
25+
[ "ByronGenesisFile" Aeson..= ("byron-genesis.json" :: String)
26+
, "ShelleyGenesisFile" Aeson..= ("shelley-genesis.json" :: String)
27+
, "AlonzoGenesisFile" Aeson..= ("alonzo-genesis.json" :: String)
28+
, "ConwayGenesisFile" Aeson..= ("conway-genesis.json" :: String)
29+
, "RequiresNetworkMagic" Aeson..= ("RequiresNoMagic" :: String)
30+
, "LastKnownBlockVersion-Major" Aeson..= (3 :: Int)
31+
, "LastKnownBlockVersion-Minor" Aeson..= (0 :: Int)
32+
, "LastKnownBlockVersion-Alt" Aeson..= (0 :: Int)
33+
]
34+
<> map (uncurry (Aeson..=)) extras
35+
36+
parseTriggers
37+
:: (HasCallStack, MonadTest m)
38+
=> [(Aeson.Key, Aeson.Value)]
39+
-> m Consensus.CardanoHardForkTriggers
40+
parseTriggers extras =
41+
case Aeson.fromJSON $ nodeConfigWith extras of
42+
Aeson.Error e -> withFrozenCallStack $ H.annotate e >> H.failure
43+
Aeson.Success nc -> pure $ ncHardForkTriggers nc
44+
45+
prop_parse_dijkstra_hard_fork_at_epoch :: Property
46+
prop_parse_dijkstra_hard_fork_at_epoch = propertyOnce $ do
47+
triggers <- parseTriggers [("TestDijkstraHardForkAtEpoch", Aeson.toJSON (5 :: Int))]
48+
case triggers of
49+
Consensus.CardanoHardForkTriggers'{Consensus.triggerHardForkDijkstra = trigger} ->
50+
case trigger of
51+
Consensus.CardanoTriggerHardForkAtEpoch (EpochNo 5) -> H.success
52+
other -> H.annotateShow other >> H.failure
53+
54+
prop_parse_dijkstra_hard_fork_default :: Property
55+
prop_parse_dijkstra_hard_fork_default = propertyOnce $ do
56+
triggers <- parseTriggers []
57+
case triggers of
58+
Consensus.CardanoHardForkTriggers'{Consensus.triggerHardForkDijkstra = trigger} ->
59+
case trigger of
60+
Consensus.CardanoTriggerHardForkAtDefaultVersion -> H.success
61+
other -> H.annotateShow other >> H.failure
62+
63+
tests :: TestTree
64+
tests =
65+
testGroup
66+
"Test.Cardano.Api.NodeConfig"
67+
[ testProperty "parse TestDijkstraHardForkAtEpoch" prop_parse_dijkstra_hard_fork_at_epoch
68+
, testProperty "parse Dijkstra hard fork default" prop_parse_dijkstra_hard_fork_default
69+
]

cardano-api/test/cardano-api-test/cardano-api-test.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Test.Cardano.Api.KeysByron qualified
2525
import Test.Cardano.Api.Ledger qualified
2626
import Test.Cardano.Api.Leios qualified
2727
import Test.Cardano.Api.Metadata qualified
28+
import Test.Cardano.Api.NodeConfig qualified
2829
import Test.Cardano.Api.Ord qualified
2930
import Test.Cardano.Api.RawBytes qualified
3031
import Test.Cardano.Api.Transaction.Autobalance qualified
@@ -67,6 +68,7 @@ tests =
6768
, Test.Cardano.Api.Ledger.tests
6869
, Test.Cardano.Api.Leios.tests
6970
, Test.Cardano.Api.Metadata.tests
71+
, Test.Cardano.Api.NodeConfig.tests
7072
, Test.Cardano.Api.Ord.tests
7173
, Test.Cardano.Api.RawBytes.tests
7274
, Test.Cardano.Api.Transaction.Body.Plutus.Scripts.tests

0 commit comments

Comments
 (0)