Skip to content

Commit 45e54b3

Browse files
Merge #4636
4636: Export cardano-testnet API from Cardano.Testnet r=MarcFontaine a=MarcFontaine Co-authored-by: MarcFontaine <[email protected]>
2 parents 7bd6944 + e702883 commit 45e54b3

28 files changed

+367
-339
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import qualified Hedgehog as H
1414
import qualified Hedgehog.Extras.Test.Base as H
1515
import qualified Hedgehog.Extras.Test.Process as H
1616
import qualified System.Directory as IO
17-
import qualified Testnet.Byron as H
18-
import qualified Testnet.Conf as H
19-
import qualified Util.Base as H
17+
18+
import qualified Testnet.Byron as B
19+
import qualified Cardano.Testnet as H
2020

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

3232
chairmanOver 120 52 conf allNodes

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-node-chairman/test/Spec/Chairman/Shelley.hs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ import qualified Hedgehog as H
1212
import qualified Hedgehog.Extras.Test.Base as H
1313
import qualified Hedgehog.Extras.Test.Process as H
1414
import qualified System.Directory as IO
15-
import qualified Testnet.Conf as H
16-
import qualified Testnet.Shelley as H
17-
import qualified Util.Base as H
18-
import qualified Util.Runtime as H
15+
16+
import qualified Cardano.Testnet as H
1917

2018
hprop_chairman :: H.Property
2119
hprop_chairman = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsPath' -> do
2220
base <- H.note =<< H.noteIO . IO.canonicalizePath =<< H.getProjectBase
2321
configurationTemplate <- H.noteShow $ base </> "configuration/defaults/byron-mainnet/configuration.yaml"
2422
conf <- H.mkConf (H.ProjectBase base) (H.YamlFilePath configurationTemplate) tempAbsPath' Nothing
2523

26-
allNodes <- fmap H.nodeName . H.allNodes <$> H.shelleyTestnet H.defaultTestnetOptions conf
24+
allNodes <- fmap H.nodeName . H.allNodes <$> H.testnet (H.ShelleyOnlyTestnetOptions H.shelleyDefaultTestnetOptions) conf
2725

2826
chairmanOver 120 21 conf allNodes

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 Parsers (commands)
99

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

cardano-testnet/cardano-testnet.cabal

+10-9
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,28 @@ library
5757
, unordered-containers
5858

5959
hs-source-dirs: src
60-
exposed-modules: Parsers
60+
exposed-modules: Cardano.Testnet
61+
Testnet.Byron
62+
Testnet.Util.Assert
63+
Testnet.Util.Base
64+
Testnet.Util.Ignore
65+
Testnet.Util.Process
66+
Testnet.Util.Runtime
67+
68+
other-modules: Parsers
6169
Parsers.Babbage
6270
Parsers.Byron
6371
Parsers.Cardano
6472
Parsers.Shelley
6573
Parsers.Version
66-
Util.Assert
67-
Util.Base
68-
Util.Ignore
69-
Util.Process
70-
Util.Runtime
7174
Testnet
7275
Testnet.Babbage
73-
Testnet.Byron
7476
Testnet.Cardano
7577
Testnet.Conf
7678
Testnet.Run
7779
Testnet.Shelley
7880
Testnet.Utils
79-
80-
other-modules: Paths_cardano_testnet
81+
Paths_cardano_testnet
8182

8283
autogen-modules: Paths_cardano_testnet
8384

+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

0 commit comments

Comments
 (0)