Skip to content

Export cardano-testnet API from Cardano.Testnet #4636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cardano-node-chairman/test/Spec/Chairman/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import Data.Maybe
import Spec.Chairman.Chairman (chairmanOver)
import System.FilePath ((</>))

import Testnet ( TestnetOptions( CardanoOnlyTestnetOptions), testnet)

import qualified Hedgehog as H
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.Process as H
import qualified System.Directory as IO
import qualified Testnet.Cardano as H
import qualified Testnet.Conf as H
import qualified Util.Base as H
import qualified Util.Runtime as H

import qualified Cardano.Testnet as H

{- HLINT ignore "Reduce duplication" -}
{- HLINT ignore "Redundant <&>" -}
Expand All @@ -32,6 +28,6 @@ hprop_chairman = H.integration . H.runFinallies . H.workspace "chairman" $ \temp
configurationTemplate <- H.noteShow $ base </> "configuration/defaults/byron-mainnet/configuration.yaml"
conf <- H.mkConf (H.ProjectBase base) (H.YamlFilePath configurationTemplate) tempAbsPath' Nothing

allNodes <- fmap H.nodeName . H.allNodes <$> testnet (CardanoOnlyTestnetOptions H.defaultTestnetOptions) conf
allNodes <- fmap H.nodeName . H.allNodes <$> H.testnet (H.CardanoOnlyTestnetOptions H.cardanoDefaultTestnetOptions) conf

chairmanOver 120 50 conf allNodes
4 changes: 2 additions & 2 deletions cardano-node-chairman/test/Spec/Chairman/Chairman.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import qualified Hedgehog.Extras.Test.Process as H
import qualified System.Environment as IO
import qualified System.IO as IO
import qualified System.Process as IO
import qualified Testnet.Conf as H
import qualified Util.Process as H

import qualified Cardano.Testnet as H

{- HLINT ignore "Reduce duplication" -}
{- HLINT ignore "Redundant <&>" -}
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/app/cardano-testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Data.Function
import Data.Semigroup
import Options.Applicative
import System.IO (IO)
import Parsers
import Testnet.Parsers (commands)

main :: IO ()
main = join $ customExecParser
Expand Down
21 changes: 11 additions & 10 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,28 @@ library
, unordered-containers

hs-source-dirs: src
exposed-modules: Parsers
Parsers.Babbage
exposed-modules: Cardano.Testnet
Testnet.Byron
Testnet.Util.Assert
Testnet.Util.Base
Testnet.Util.Ignore
Testnet.Util.Process
Testnet.Util.Runtime
Testnet.Parsers

other-modules: Parsers.Babbage
Parsers.Byron
Parsers.Cardano
Parsers.Shelley
Parsers.Version
Util.Assert
Util.Base
Util.Ignore
Util.Process
Util.Runtime
Testnet
Testnet.Babbage
Testnet.Byron
Testnet.Cardano
Testnet.Conf
Testnet.Run
Testnet.Shelley
Testnet.Utils

other-modules: Paths_cardano_testnet
Paths_cardano_testnet

autogen-modules: Paths_cardano_testnet

Expand Down
48 changes: 48 additions & 0 deletions cardano-testnet/src/Cardano/Testnet.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- | This module provides a library interface for initiating a local testnet
--
module Cardano.Testnet (
-- * Testnets

-- ** Start a testnet
testnet,

-- ** Testnet options
TestnetOptions(..),
CardanoTestnetOptions(..),
BabbageTestnetOptions(..),
ShelleyTestnetOptions(..),
TestnetNodeOptions(..),
cardanoDefaultTestnetOptions,
babbageDefaultTestnetOptions,
shelleyDefaultTestnetOptions,
cardanoDefaultTestnetNodeOptions,

-- * Configuration
Conf(..),
ProjectBase(..),
YamlFilePath(..),
mkConf,

-- * Processes
procChairman,

-- * Utils
integration,
waitUntilEpoch,

-- * Runtime
NodeRuntime(..),
allNodes,

) where

import Testnet
import Testnet.Babbage
import Testnet.Cardano
import Testnet.Conf hiding (base)
import Testnet.Shelley as Shelley
import Testnet.Utils (waitUntilEpoch)

import Testnet.Util.Base (integration)
import Testnet.Util.Process (procChairman)
import Testnet.Util.Runtime
12 changes: 6 additions & 6 deletions cardano-testnet/src/Parsers/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import qualified Options.Applicative as OA
import Testnet
import Testnet.Babbage
import Testnet.Run (runTestnet)
import Util.Runtime (readNodeLoggingFormat)
import Testnet.Util.Runtime (readNodeLoggingFormat)

data BabbageOptions = BabbageOptions
{ maybeTestnetMagic :: Maybe Int
Expand All @@ -25,35 +25,35 @@ optsTestnet = BabbageTestnetOptions
<> OA.help "Number of SPO nodes"
<> OA.metavar "COUNT"
<> OA.showDefault
<> OA.value (numSpoNodes defaultTestnetOptions)
<> OA.value (babbageNumSpoNodes defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "slot-duration"
<> OA.help "Slot duration"
<> OA.metavar "MILLISECONDS"
<> OA.showDefault
<> OA.value (slotDuration defaultTestnetOptions)
<> OA.value (babbageSlotDuration defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "security-param"
<> OA.help "Security parameter"
<> OA.metavar "INT"
<> OA.showDefault
<> OA.value (securityParam defaultTestnetOptions)
<> OA.value (babbageSecurityParam defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "total-balance"
<> OA.help "Total balance"
<> OA.metavar "INT"
<> OA.showDefault
<> OA.value (totalBalance defaultTestnetOptions)
<> OA.value (babbageTotalBalance defaultTestnetOptions)
)
<*> OA.option (OA.eitherReader readNodeLoggingFormat)
( OA.long "nodeLoggingFormat"
<> OA.help "Node logging format (json|text)"
<> OA.metavar "LOGGING_FORMAT"
<> OA.showDefault
<> OA.value (nodeLoggingFormat defaultTestnetOptions)
<> OA.value (babbageNodeLoggingFormat defaultTestnetOptions)
)

optsBabbage :: Parser BabbageOptions
Expand Down
20 changes: 10 additions & 10 deletions cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Options.Applicative
import qualified Options.Applicative as OA
import Text.Read

import Util.Runtime (readNodeLoggingFormat)
import Testnet.Util.Runtime (readNodeLoggingFormat)
import Testnet
import Testnet.Cardano
import Testnet.Run (runTestnet)
Expand All @@ -26,61 +26,61 @@ data CardanoOptions = CardanoOptions
optsTestnet :: Parser CardanoTestnetOptions
optsTestnet = CardanoTestnetOptions
<$> OA.option
((`L.replicate` defaultTestnetNodeOptions) <$> auto)
((`L.replicate` cardanoDefaultTestnetNodeOptions) <$> auto)
( OA.long "num-bft-nodes"
<> OA.help "Number of BFT nodes"
<> OA.metavar "COUNT"
<> OA.showDefault
<> OA.value (bftNodeOptions defaultTestnetOptions)
<> OA.value (cardanoBftNodeOptions defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "num-pool-nodes"
<> OA.help "Number of pool nodes"
<> OA.metavar "COUNT"
<> OA.showDefault
<> OA.value (numPoolNodes defaultTestnetOptions)
<> OA.value (cardanoNumPoolNodes defaultTestnetOptions)
)
<*> OA.option (OA.eitherReader readEither)
( OA.long "era"
<> OA.help ("Era to upgrade to. " <> show @[Era] [minBound .. maxBound])
<> OA.metavar "ERA"
<> OA.showDefault
<> OA.value (era defaultTestnetOptions)
<> OA.value (cardanoEra defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "epoch-length"
<> OA.help "Epoch length"
<> OA.metavar "MILLISECONDS"
<> OA.showDefault
<> OA.value (epochLength defaultTestnetOptions)
<> OA.value (cardanoEpochLength defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "slot-length"
<> OA.help "Slot length"
<> OA.metavar "SECONDS"
<> OA.showDefault
<> OA.value (slotLength defaultTestnetOptions)
<> OA.value (cardanoSlotLength defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "active-slots-coeff"
<> OA.help "Active slots co-efficient"
<> OA.metavar "DOUBLE"
<> OA.showDefault
<> OA.value (activeSlotsCoeff defaultTestnetOptions)
<> OA.value (cardanoActiveSlotsCoeff defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "enable-p2p"
<> OA.help "Enable P2P"
<> OA.metavar "BOOL"
<> OA.showDefault
<> OA.value (enableP2P defaultTestnetOptions)
<> OA.value (cardanoEnableP2P defaultTestnetOptions)
)
<*> OA.option (OA.eitherReader readNodeLoggingFormat)
( OA.long "nodeLoggingFormat"
<> OA.help "Node logging format (json|text)"
<> OA.metavar "LOGGING_FORMAT"
<> OA.showDefault
<> OA.value (nodeLoggingFormat defaultTestnetOptions)
<> OA.value (cardanoNodeLoggingFormat defaultTestnetOptions)
)

optsCardano :: Parser CardanoOptions
Expand Down
16 changes: 8 additions & 8 deletions cardano-testnet/src/Parsers/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,56 @@ optsTestnet = ShelleyTestnetOptions
<> OA.help "Number of PRAOS nodes"
<> OA.metavar "COUNT"
<> OA.showDefault
<> OA.value (numPraosNodes defaultTestnetOptions)
<> OA.value (shelleyNumPraosNodes defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "num-pool-nodes"
<> OA.help "Number of pool nodes"
<> OA.metavar "COUNT"
<> OA.showDefault
<> OA.value (numPoolNodes defaultTestnetOptions)
<> OA.value (shelleyNumPoolNodes defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "active-slots-coeff"
<> OA.help "Active slots co-efficient"
<> OA.metavar "DOUBLE"
<> OA.showDefault
<> OA.value (activeSlotsCoeff defaultTestnetOptions)
<> OA.value (shelleyActiveSlotsCoeff defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "security-param"
<> OA.help "Security param"
<> OA.metavar "INT"
<> OA.showDefault
<> OA.value (securityParam defaultTestnetOptions)
<> OA.value (shelleySecurityParam defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "epoch-length"
<> OA.help "Epoch length"
<> OA.metavar "MILLISECONDS"
<> OA.showDefault
<> OA.value (epochLength defaultTestnetOptions)
<> OA.value (shelleyEpochLength defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "slot-length"
<> OA.help "Slot length"
<> OA.metavar "MILLISECONDS"
<> OA.showDefault
<> OA.value (slotLength defaultTestnetOptions)
<> OA.value (shelleySlotLength defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "max-lovelace-supply"
<> OA.help "Max lovelace supply"
<> OA.metavar "INTEGER"
<> OA.showDefault
<> OA.value (maxLovelaceSupply defaultTestnetOptions)
<> OA.value (shelleyMaxLovelaceSupply defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "enable-p2p"
<> OA.help "Enable P2P"
<> OA.metavar "BOOL"
<> OA.showDefault
<> OA.value (enableP2P defaultTestnetOptions)
<> OA.value (shelleyEnableP2P defaultTestnetOptions)
)

optsShelley :: Parser ShelleyOptions
Expand Down
17 changes: 14 additions & 3 deletions cardano-testnet/src/Testnet.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Testnet
( TestnetOptions(..)
, babbageDefaultTestnetOptions
, cardanoDefaultTestnetOptions
, shelleyDefaultTestnetOptions
, Testnet.testnet
) where

Expand All @@ -8,10 +11,10 @@ import Text.Show (Show)

import qualified Hedgehog.Extras.Test.Base as H

import Testnet.Babbage
import Testnet.Cardano
import Testnet.Babbage as Babbage
import Testnet.Cardano as Cardano
import Testnet.Conf
import Testnet.Shelley
import Testnet.Shelley as Shelley

data TestnetOptions
= ShelleyOnlyTestnetOptions ShelleyTestnetOptions
Expand All @@ -25,3 +28,11 @@ testnet options = case options of
BabbageOnlyTestnetOptions o -> babbageTestnet o
CardanoOnlyTestnetOptions o -> cardanoTestnet o

babbageDefaultTestnetOptions :: BabbageTestnetOptions
babbageDefaultTestnetOptions = Babbage.defaultTestnetOptions

cardanoDefaultTestnetOptions :: CardanoTestnetOptions
cardanoDefaultTestnetOptions = Cardano.defaultTestnetOptions

shelleyDefaultTestnetOptions :: ShelleyTestnetOptions
shelleyDefaultTestnetOptions = Shelley.defaultTestnetOptions
Loading