|
| 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 | + ] |
0 commit comments