Skip to content

Commit 624c116

Browse files
committed
export API from Cardano.Testnet
1 parent 8aee278 commit 624c116

28 files changed

+370
-341
lines changed

cardano-node-chairman/test/Spec/Chairman/Cardano.hs

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ import Data.Maybe
1111
import Spec.Chairman.Chairman (chairmanOver)
1212
import System.FilePath ((</>))
1313

14-
import Testnet ( TestnetOptions( CardanoOnlyTestnetOptions), testnet)
15-
1614
import qualified Hedgehog as H
1715
import qualified Hedgehog.Extras.Test.Base as H
1816
import qualified Hedgehog.Extras.Test.Process as H
1917
import qualified System.Directory as IO
20-
import qualified Testnet.Cardano as H
21-
import qualified Testnet.Conf as H
22-
import qualified Util.Base as H
23-
import qualified Util.Runtime as H
18+
19+
import qualified Cardano.Testnet as H
2420

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

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

3733
chairmanOver 120 50 conf allNodes

cardano-node-chairman/test/Spec/Chairman/Chairman.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import qualified Hedgehog.Extras.Test.Process as H
3131
import qualified System.Environment as IO
3232
import qualified System.IO as IO
3333
import qualified System.Process as IO
34-
import qualified Testnet.Conf as H
35-
import qualified Util.Process as H
34+
35+
import qualified Cardano.Testnet as H
3636

3737
{- HLINT ignore "Reduce duplication" -}
3838
{- HLINT ignore "Redundant <&>" -}

cardano-testnet/app/cardano-testnet.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Data.Function
55
import Data.Semigroup
66
import Options.Applicative
77
import System.IO (IO)
8-
import Parsers
8+
import Testnet.Parsers (commands)
99

1010
main :: IO ()
1111
main = join $ customExecParser

cardano-testnet/cardano-testnet.cabal

+11-10
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,28 @@ library
6262
, unordered-containers
6363

6464
hs-source-dirs: src
65-
exposed-modules: Parsers
66-
Parsers.Babbage
65+
exposed-modules: Cardano.Testnet
66+
Testnet.Byron
67+
Testnet.Util.Assert
68+
Testnet.Util.Base
69+
Testnet.Util.Ignore
70+
Testnet.Util.Process
71+
Testnet.Util.Runtime
72+
Testnet.Parsers
73+
74+
other-modules: Parsers.Babbage
6775
Parsers.Byron
6876
Parsers.Cardano
6977
Parsers.Shelley
7078
Parsers.Version
71-
Util.Assert
72-
Util.Base
73-
Util.Ignore
74-
Util.Process
75-
Util.Runtime
7679
Testnet
7780
Testnet.Babbage
78-
Testnet.Byron
7981
Testnet.Cardano
8082
Testnet.Conf
8183
Testnet.Run
8284
Testnet.Shelley
8385
Testnet.Utils
84-
85-
other-modules: Paths_cardano_testnet
86+
Paths_cardano_testnet
8687

8788
autogen-modules: Paths_cardano_testnet
8889

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- | This module provides a library interface for initiating a local testnet
2+
--
3+
module Cardano.Testnet (
4+
-- * Testnets
5+
6+
-- ** Start a testnet
7+
testnet,
8+
9+
-- ** Testnet options
10+
TestnetOptions(..),
11+
CardanoTestnetOptions(..),
12+
BabbageTestnetOptions(..),
13+
ShelleyTestnetOptions(..),
14+
TestnetNodeOptions(..),
15+
cardanoDefaultTestnetOptions,
16+
babbageDefaultTestnetOptions,
17+
shelleyDefaultTestnetOptions,
18+
cardanoDefaultTestnetNodeOptions,
19+
20+
-- * Configuration
21+
Conf(..),
22+
ProjectBase(..),
23+
YamlFilePath(..),
24+
mkConf,
25+
26+
-- * Processes
27+
procChairman,
28+
29+
-- * Utils
30+
integration,
31+
waitUntilEpoch,
32+
33+
-- * Runtime
34+
NodeRuntime(..),
35+
allNodes,
36+
37+
) where
38+
39+
import Testnet
40+
import Testnet.Babbage
41+
import Testnet.Cardano
42+
import Testnet.Conf hiding (base)
43+
import Testnet.Shelley as Shelley
44+
import Testnet.Utils (waitUntilEpoch)
45+
46+
import Testnet.Util.Base (integration)
47+
import Testnet.Util.Process (procChairman)
48+
import Testnet.Util.Runtime

cardano-testnet/src/Parsers/Babbage.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import qualified Options.Applicative as OA
1111
import Testnet
1212
import Testnet.Babbage
1313
import Testnet.Run (runTestnet)
14-
import Util.Runtime (readNodeLoggingFormat)
14+
import Testnet.Util.Runtime (readNodeLoggingFormat)
1515

1616
data BabbageOptions = BabbageOptions
1717
{ maybeTestnetMagic :: Maybe Int
@@ -25,35 +25,35 @@ optsTestnet = BabbageTestnetOptions
2525
<> OA.help "Number of SPO nodes"
2626
<> OA.metavar "COUNT"
2727
<> OA.showDefault
28-
<> OA.value (numSpoNodes defaultTestnetOptions)
28+
<> OA.value (babbageNumSpoNodes defaultTestnetOptions)
2929
)
3030
<*> OA.option auto
3131
( OA.long "slot-duration"
3232
<> OA.help "Slot duration"
3333
<> OA.metavar "MILLISECONDS"
3434
<> OA.showDefault
35-
<> OA.value (slotDuration defaultTestnetOptions)
35+
<> OA.value (babbageSlotDuration defaultTestnetOptions)
3636
)
3737
<*> OA.option auto
3838
( OA.long "security-param"
3939
<> OA.help "Security parameter"
4040
<> OA.metavar "INT"
4141
<> OA.showDefault
42-
<> OA.value (securityParam defaultTestnetOptions)
42+
<> OA.value (babbageSecurityParam defaultTestnetOptions)
4343
)
4444
<*> OA.option auto
4545
( OA.long "total-balance"
4646
<> OA.help "Total balance"
4747
<> OA.metavar "INT"
4848
<> OA.showDefault
49-
<> OA.value (totalBalance defaultTestnetOptions)
49+
<> OA.value (babbageTotalBalance defaultTestnetOptions)
5050
)
5151
<*> OA.option (OA.eitherReader readNodeLoggingFormat)
5252
( OA.long "nodeLoggingFormat"
5353
<> OA.help "Node logging format (json|text)"
5454
<> OA.metavar "LOGGING_FORMAT"
5555
<> OA.showDefault
56-
<> OA.value (nodeLoggingFormat defaultTestnetOptions)
56+
<> OA.value (babbageNodeLoggingFormat defaultTestnetOptions)
5757
)
5858

5959
optsBabbage :: Parser BabbageOptions

cardano-testnet/src/Parsers/Cardano.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Options.Applicative
1212
import qualified Options.Applicative as OA
1313
import Text.Read
1414

15-
import Util.Runtime (readNodeLoggingFormat)
15+
import Testnet.Util.Runtime (readNodeLoggingFormat)
1616
import Testnet
1717
import Testnet.Cardano
1818
import Testnet.Run (runTestnet)
@@ -26,61 +26,61 @@ data CardanoOptions = CardanoOptions
2626
optsTestnet :: Parser CardanoTestnetOptions
2727
optsTestnet = CardanoTestnetOptions
2828
<$> OA.option
29-
((`L.replicate` defaultTestnetNodeOptions) <$> auto)
29+
((`L.replicate` cardanoDefaultTestnetNodeOptions) <$> auto)
3030
( OA.long "num-bft-nodes"
3131
<> OA.help "Number of BFT nodes"
3232
<> OA.metavar "COUNT"
3333
<> OA.showDefault
34-
<> OA.value (bftNodeOptions defaultTestnetOptions)
34+
<> OA.value (cardanoBftNodeOptions defaultTestnetOptions)
3535
)
3636
<*> OA.option auto
3737
( OA.long "num-pool-nodes"
3838
<> OA.help "Number of pool nodes"
3939
<> OA.metavar "COUNT"
4040
<> OA.showDefault
41-
<> OA.value (numPoolNodes defaultTestnetOptions)
41+
<> OA.value (cardanoNumPoolNodes defaultTestnetOptions)
4242
)
4343
<*> OA.option (OA.eitherReader readEither)
4444
( OA.long "era"
4545
<> OA.help ("Era to upgrade to. " <> show @[Era] [minBound .. maxBound])
4646
<> OA.metavar "ERA"
4747
<> OA.showDefault
48-
<> OA.value (era defaultTestnetOptions)
48+
<> OA.value (cardanoEra defaultTestnetOptions)
4949
)
5050
<*> OA.option auto
5151
( OA.long "epoch-length"
5252
<> OA.help "Epoch length"
5353
<> OA.metavar "MILLISECONDS"
5454
<> OA.showDefault
55-
<> OA.value (epochLength defaultTestnetOptions)
55+
<> OA.value (cardanoEpochLength defaultTestnetOptions)
5656
)
5757
<*> OA.option auto
5858
( OA.long "slot-length"
5959
<> OA.help "Slot length"
6060
<> OA.metavar "SECONDS"
6161
<> OA.showDefault
62-
<> OA.value (slotLength defaultTestnetOptions)
62+
<> OA.value (cardanoSlotLength defaultTestnetOptions)
6363
)
6464
<*> OA.option auto
6565
( OA.long "active-slots-coeff"
6666
<> OA.help "Active slots co-efficient"
6767
<> OA.metavar "DOUBLE"
6868
<> OA.showDefault
69-
<> OA.value (activeSlotsCoeff defaultTestnetOptions)
69+
<> OA.value (cardanoActiveSlotsCoeff defaultTestnetOptions)
7070
)
7171
<*> OA.option auto
7272
( OA.long "enable-p2p"
7373
<> OA.help "Enable P2P"
7474
<> OA.metavar "BOOL"
7575
<> OA.showDefault
76-
<> OA.value (enableP2P defaultTestnetOptions)
76+
<> OA.value (cardanoEnableP2P defaultTestnetOptions)
7777
)
7878
<*> OA.option (OA.eitherReader readNodeLoggingFormat)
7979
( OA.long "nodeLoggingFormat"
8080
<> OA.help "Node logging format (json|text)"
8181
<> OA.metavar "LOGGING_FORMAT"
8282
<> OA.showDefault
83-
<> OA.value (nodeLoggingFormat defaultTestnetOptions)
83+
<> OA.value (cardanoNodeLoggingFormat defaultTestnetOptions)
8484
)
8585

8686
optsCardano :: Parser CardanoOptions

cardano-testnet/src/Parsers/Shelley.hs

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,56 +31,56 @@ optsTestnet = ShelleyTestnetOptions
3131
<> OA.help "Number of PRAOS nodes"
3232
<> OA.metavar "COUNT"
3333
<> OA.showDefault
34-
<> OA.value (numPraosNodes defaultTestnetOptions)
34+
<> OA.value (shelleyNumPraosNodes defaultTestnetOptions)
3535
)
3636
<*> OA.option auto
3737
( OA.long "num-pool-nodes"
3838
<> OA.help "Number of pool nodes"
3939
<> OA.metavar "COUNT"
4040
<> OA.showDefault
41-
<> OA.value (numPoolNodes defaultTestnetOptions)
41+
<> OA.value (shelleyNumPoolNodes defaultTestnetOptions)
4242
)
4343
<*> OA.option auto
4444
( OA.long "active-slots-coeff"
4545
<> OA.help "Active slots co-efficient"
4646
<> OA.metavar "DOUBLE"
4747
<> OA.showDefault
48-
<> OA.value (activeSlotsCoeff defaultTestnetOptions)
48+
<> OA.value (shelleyActiveSlotsCoeff defaultTestnetOptions)
4949
)
5050
<*> OA.option auto
5151
( OA.long "security-param"
5252
<> OA.help "Security param"
5353
<> OA.metavar "INT"
5454
<> OA.showDefault
55-
<> OA.value (securityParam defaultTestnetOptions)
55+
<> OA.value (shelleySecurityParam defaultTestnetOptions)
5656
)
5757
<*> OA.option auto
5858
( OA.long "epoch-length"
5959
<> OA.help "Epoch length"
6060
<> OA.metavar "MILLISECONDS"
6161
<> OA.showDefault
62-
<> OA.value (epochLength defaultTestnetOptions)
62+
<> OA.value (shelleyEpochLength defaultTestnetOptions)
6363
)
6464
<*> OA.option auto
6565
( OA.long "slot-length"
6666
<> OA.help "Slot length"
6767
<> OA.metavar "MILLISECONDS"
6868
<> OA.showDefault
69-
<> OA.value (slotLength defaultTestnetOptions)
69+
<> OA.value (shelleySlotLength defaultTestnetOptions)
7070
)
7171
<*> OA.option auto
7272
( OA.long "max-lovelace-supply"
7373
<> OA.help "Max lovelace supply"
7474
<> OA.metavar "INTEGER"
7575
<> OA.showDefault
76-
<> OA.value (maxLovelaceSupply defaultTestnetOptions)
76+
<> OA.value (shelleyMaxLovelaceSupply defaultTestnetOptions)
7777
)
7878
<*> OA.option auto
7979
( OA.long "enable-p2p"
8080
<> OA.help "Enable P2P"
8181
<> OA.metavar "BOOL"
8282
<> OA.showDefault
83-
<> OA.value (enableP2P defaultTestnetOptions)
83+
<> OA.value (shelleyEnableP2P defaultTestnetOptions)
8484
)
8585

8686
optsShelley :: Parser ShelleyOptions

cardano-testnet/src/Testnet.hs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Testnet
22
( TestnetOptions(..)
3+
, babbageDefaultTestnetOptions
4+
, cardanoDefaultTestnetOptions
5+
, shelleyDefaultTestnetOptions
36
, Testnet.testnet
47
) where
58

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

912
import qualified Hedgehog.Extras.Test.Base as H
1013

11-
import Testnet.Babbage
12-
import Testnet.Cardano
14+
import Testnet.Babbage as Babbage
15+
import Testnet.Cardano as Cardano
1316
import Testnet.Conf
14-
import Testnet.Shelley
17+
import Testnet.Shelley as Shelley
1518

1619
data TestnetOptions
1720
= ShelleyOnlyTestnetOptions ShelleyTestnetOptions
@@ -25,3 +28,11 @@ testnet options = case options of
2528
BabbageOnlyTestnetOptions o -> babbageTestnet o
2629
CardanoOnlyTestnetOptions o -> cardanoTestnet o
2730

31+
babbageDefaultTestnetOptions :: BabbageTestnetOptions
32+
babbageDefaultTestnetOptions = Babbage.defaultTestnetOptions
33+
34+
cardanoDefaultTestnetOptions :: CardanoTestnetOptions
35+
cardanoDefaultTestnetOptions = Cardano.defaultTestnetOptions
36+
37+
shelleyDefaultTestnetOptions :: ShelleyTestnetOptions
38+
shelleyDefaultTestnetOptions = Shelley.defaultTestnetOptions

0 commit comments

Comments
 (0)