Skip to content

Commit

Permalink
testnet: better API for using custom genesis files
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc authored and mgmeier committed May 8, 2024
1 parent 36f5564 commit 08df052
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cardano-testnet/src/Cardano/Testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Cardano.Testnet (
TestnetNodeOptions(..),
cardanoDefaultTestnetOptions,
cardanoDefaultTestnetNodeOptions,
getDefaultAlonzoGenesis,
getDefaultShelleyGenesis,

-- * Configuration
Conf(..),
Expand Down
28 changes: 23 additions & 5 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Testnet.Start.Cardano

, cardanoTestnet
, cardanoTestnetDefault
, getDefaultAlonzoGenesis
, getDefaultShelleyGenesis
, requestAvailablePortNumbers
) where

Expand Down Expand Up @@ -99,11 +101,27 @@ cardanoTestnetDefault :: ()
-> H.Integration TestnetRuntime
cardanoTestnetDefault opts conf = do
alonzoGenesis <- H.evalEither $ first prettyError Defaults.defaultAlonzoGenesis
(startTime, shelleyGenesis) <- getDefaultShelleyGenesis opts
cardanoTestnet opts conf startTime shelleyGenesis alonzoGenesis Defaults.defaultConwayGenesis

-- | An 'AlonzoGenesis' value that is fit to pass to 'cardanoTestnet'
getDefaultAlonzoGenesis :: ()
=> HasCallStack
=> MonadTest m
=> m AlonzoGenesis
getDefaultAlonzoGenesis = H.evalEither $ first prettyError Defaults.defaultAlonzoGenesis

-- | A start time and 'ShelleyGenesis' value that are fit to pass to 'cardanoTestnet'
getDefaultShelleyGenesis :: ()
=> HasCallStack
=> MonadIO m
=> MonadTest m
=> CardanoTestnetOptions
-> m (UTCTime, ShelleyGenesis StandardCrypto)
getDefaultShelleyGenesis opts = do
currentTime <- H.noteShowIO DTC.getCurrentTime
startTime <- H.noteShow $ DTC.addUTCTime startTimeOffsetSeconds currentTime
cardanoTestnet
opts conf startTime
(Defaults.defaultShelleyGenesis startTime opts) alonzoGenesis Defaults.defaultConwayGenesis
return (startTime, Defaults.defaultShelleyGenesis startTime opts)

-- | Hardcoded testnet IP address
testnetIpv4Address :: Text
Expand Down Expand Up @@ -193,9 +211,9 @@ cardanoTestnet :: ()
=> CardanoTestnetOptions -- ^ The options to use. Must be consistent with the genesis files.
-> Conf
-> UTCTime -- ^ The starting time. Must be the same as the one in the shelley genesis.
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'Defaults.defaultShelleyGenesis'.
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'getDefaultShelleyGenesis' from this module.
-- Some fields are overridden by the accompanying 'CardanoTestnetOptions'.
-> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'Defaults.defaultAlonzoGenesis'.
-> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'getDefaultAlonzoGenesis' from this module.
-> ConwayGenesis StandardCrypto -- ^ The conway genesis to use, for example 'Defaults.defaultConwayGenesis'.
-> H.Integration TestnetRuntime
cardanoTestnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ module Cardano.Testnet.Test.Node.Shutdown
import Cardano.Api

import Cardano.Testnet
import qualified Cardano.Testnet as Testnet

import Prelude

import Control.Monad
import Data.Aeson
import Data.Aeson.Types
import Data.Bifunctor
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Either (isRight)
import qualified Data.List as L
Expand Down Expand Up @@ -96,7 +96,7 @@ hprop_shutdown = H.integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' ->

-- 2. Create Alonzo genesis
alonzoBabbageTestGenesisJsonTargetFile <- H.noteShow $ tempAbsPath' </> shelleyDir </> "genesis.alonzo.spec.json"
gen <- H.evalEither $ first (docToString . prettyError) defaultAlonzoGenesis
gen <- Testnet.getDefaultAlonzoGenesis
H.evalIO $ LBS.writeFile alonzoBabbageTestGenesisJsonTargetFile $ encode gen

-- 2. Create Conway genesis
Expand Down

0 comments on commit 08df052

Please sign in to comment.