Skip to content

Commit

Permalink
Use lenses for config
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jan 6, 2024
1 parent 1147cab commit 21dd804
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ library
, filepath
, hedgehog
, hedgehog-extras ^>= 0.4.7.0
, microlens
, lens-aeson
, mtl
, network
, network-mux
Expand All @@ -76,7 +78,6 @@ library
, time
, transformers
, transformers-except
, unordered-containers
, vector

hs-source-dirs: src
Expand Down
23 changes: 9 additions & 14 deletions cardano-testnet/src/Testnet/Components/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Control.Monad.IO.Class (MonadIO)
import Data.Aeson
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as List
import Data.String
import Data.Time
Expand All @@ -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_)
Expand Down Expand Up @@ -104,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
( HM.insert "securityParam" (toJSON @Int 5) -- TODO: USE config p arameter
. HM.adjust
(J.rewriteObject
$ HM.adjust
(J.rewriteObject (HM.insert "major" (toJSON @Int 8)))
"protocolVersion"
) "protocolParams"
. HM.insert "rho" (toJSON @Double 0.1)
. HM.insert "tau" (toJSON @Double 0.1)
. HM.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"
Expand Down

0 comments on commit 21dd804

Please sign in to comment.