Skip to content

Commit 2f0f333

Browse files
committed
export API from Cardano.Testnet
1 parent 8177c2f commit 2f0f333

20 files changed

+343
-314
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
61-
Parsers.Babbage
62-
Parsers.Byron
63-
Parsers.Cardano
64-
Parsers.Shelley
65-
Parsers.Version
60+
exposed-modules: Cardano.Testnet
61+
Testnet.Byron
6662
Util.Assert
6763
Util.Base
6864
Util.Ignore
6965
Util.Process
7066
Util.Runtime
67+
Parsers
68+
69+
other-modules: Parsers.Babbage
70+
Parsers.Byron
71+
Parsers.Cardano
72+
Parsers.Shelley
73+
Parsers.Version
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 Util.Base (integration)
47+
import Util.Process (procChairman)
48+
import Util.Runtime

cardano-testnet/src/Parsers/Babbage.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -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

+9-9
Original file line numberDiff line numberDiff line change
@@ -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)