Skip to content

Commit

Permalink
export API from Cardano.Testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcFontaine committed Nov 16, 2022
1 parent 8177c2f commit 015f509
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 314 deletions.
8 changes: 4 additions & 4 deletions cardano-node-chairman/test/Spec/Chairman/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ 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.Byron as H
import qualified Testnet.Conf as H
import qualified Util.Base as H

import qualified Testnet.Byron as B
import qualified Cardano.Testnet as H

{- HLINT ignore "Reduce duplication" -}
{- HLINT ignore "Redundant <&>" -}
Expand All @@ -27,6 +27,6 @@ hprop_chairman = H.integration . H.runFinallies . H.workspace "chairman" $ \temp
base <- H.note =<< H.noteIO . IO.canonicalizePath =<< H.getProjectBase
configurationTemplate <- H.noteShow $ base </> "configuration/defaults/byron-mainnet/configuration.yaml"
conf <- H.mkConf (H.ProjectBase base) (H.YamlFilePath configurationTemplate) tempAbsPath' Nothing
allNodes <- H.testnet H.defaultTestnetOptions conf
allNodes <- B.testnet B.defaultTestnetOptions conf

chairmanOver 120 52 conf allNodes
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
8 changes: 3 additions & 5 deletions cardano-node-chairman/test/Spec/Chairman/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ 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.Conf as H
import qualified Testnet.Shelley as H
import qualified Util.Base as H
import qualified Util.Runtime as H

import qualified Cardano.Testnet as H

hprop_chairman :: H.Property
hprop_chairman = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsPath' -> do
base <- H.note =<< H.noteIO . IO.canonicalizePath =<< H.getProjectBase
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 <$> H.shelleyTestnet H.defaultTestnetOptions conf
allNodes <- fmap H.nodeName . H.allNodes <$> H.testnet (H.ShelleyOnlyTestnetOptions H.shelleyDefaultTestnetOptions) conf

chairmanOver 120 21 conf allNodes
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 Cardano.Testnet (commands)

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

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

other-modules: Parsers
Parsers.Babbage
Parsers.Byron
Parsers.Cardano
Parsers.Shelley
Parsers.Version
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 Util.Base (integration)
import Util.Process (procChairman)
import Util.Runtime
10 changes: 5 additions & 5 deletions cardano-testnet/src/Parsers/Babbage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 015f509

Please sign in to comment.