From e706b816aa5ae2ce3dc583b848323c5bdefe4e40 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 6 Jan 2024 15:05:46 +1100 Subject: [PATCH 1/2] Use lenses for config --- cardano-testnet/cardano-testnet.cabal | 4 ++- .../src/Testnet/Components/Configuration.hs | 30 ++++++------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index f6d591abae9..3450bbc4025 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -55,7 +55,9 @@ library , exceptions , filepath , hedgehog - , hedgehog-extras ^>= 0.5.0.0 + , hedgehog-extras ^>= 0.5.1.0 + , microlens + , lens-aeson , mtl , network , network-mux diff --git a/cardano-testnet/src/Testnet/Components/Configuration.hs b/cardano-testnet/src/Testnet/Components/Configuration.hs index 9d50713c468..812e26c319d 100644 --- a/cardano-testnet/src/Testnet/Components/Configuration.hs +++ b/cardano-testnet/src/Testnet/Components/Configuration.hs @@ -23,7 +23,6 @@ import Control.Monad.Catch (MonadCatch) import Control.Monad.IO.Class (MonadIO) import Data.Aeson import qualified Data.Aeson as Aeson -import qualified Data.Aeson.KeyMap as KM import qualified Data.ByteString.Lazy as LBS import qualified Data.List as List import Data.String @@ -34,11 +33,13 @@ import System.FilePath.Posix (()) import Hedgehog import qualified Hedgehog as H -import qualified Hedgehog.Extras.Stock.Aeson as J import qualified Hedgehog.Extras.Stock.Time as DTC import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H +import qualified Data.Aeson.Lens as L +import Lens.Micro + import Testnet.Defaults import Testnet.Filepath import Testnet.Process.Run (execCli_) @@ -75,13 +76,6 @@ createConfigYaml (TmpAbsolutePath tempAbsPath') anyCardanoEra' = GHC.withFrozenC numSeededUTxOKeys :: Int numSeededUTxOKeys = 3 --- | Adjust a value at a specific key. When the key is not a member of the map, the original map is returned -adjustKM :: (v -> v) -> KM.Key -> KM.KeyMap v -> KM.KeyMap v -adjustKM f k m = - case KM.lookup k m of - Nothing -> m - Just v -> KM.insert k (f v) m - createSPOGenesisAndFiles :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) => CardanoTestnetOptions @@ -111,18 +105,12 @@ createSPOGenesisAndFiles testnetOptions startTime (TmpAbsolutePath tempAbsPath') -- TODO: Remove this rewrite. -- 50 second epochs -- Epoch length should be "10 * k / f" where "k = securityParam, f = activeSlotsCoeff" - H.rewriteJsonFile createStakedInitialGenesisFile $ J.rewriteObject - ( KM.insert "securityParam" (toJSON @Int 5) -- TODO: USE config p arameter - . adjustKM - (J.rewriteObject - $ adjustKM - (J.rewriteObject (KM.insert "major" (toJSON @Int 8))) - "protocolVersion" - ) "protocolParams" - . KM.insert "rho" (toJSON @Double 0.1) - . KM.insert "tau" (toJSON @Double 0.1) - . KM.insert "updateQuorum" (toJSON @Int 2) - ) + H.rewriteJsonFile createStakedInitialGenesisFile $ \o -> o + & L.key "securityParam" . L._Integer .~ 5 + & L.key "rho" . L._Double .~ 0.1 + & L.key "tau" . L._Double .~ 0.1 + & L.key "updateQuorum" . L._Integer .~ 2 + & L.key "protocolParams" . L.key "protocolVersion" . L.key "major" . L._Integer .~ 8 execCli_ [ "genesis", "create-staked" From 0db4af8eeb05da3964ce8fb9b9807c9847918f99 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 13 Jan 2024 00:45:51 +1100 Subject: [PATCH 2/2] Upgrade to hedgehog-extras-0.5.1.0 --- bench/locli/locli.cabal | 2 +- cardano-node-chairman/cardano-node-chairman.cabal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/locli/locli.cabal b/bench/locli/locli.cabal index 13482f90dcd..fe039c8d294 100644 --- a/bench/locli/locli.cabal +++ b/bench/locli/locli.cabal @@ -175,7 +175,7 @@ test-suite test-locli build-depends: cardano-prelude , containers , hedgehog - , hedgehog-extras ^>= 0.5.0.0 + , hedgehog-extras ^>= 0.5.1.0 , locli , text diff --git a/cardano-node-chairman/cardano-node-chairman.cabal b/cardano-node-chairman/cardano-node-chairman.cabal index 3c7ea69ff92..0a4f0040a4d 100644 --- a/cardano-node-chairman/cardano-node-chairman.cabal +++ b/cardano-node-chairman/cardano-node-chairman.cabal @@ -73,7 +73,7 @@ test-suite chairman-tests , cardano-crypto-class ^>= 2.1.2 , filepath , hedgehog - , hedgehog-extras ^>= 0.5.0.0 + , hedgehog-extras ^>= 0.5.1.0 , network , process , random