Skip to content

Commit 761a00b

Browse files
committed
Create Testnet.Options module
Implement createByronGenesis
1 parent 5842c62 commit 761a00b

File tree

7 files changed

+97
-57
lines changed

7 files changed

+97
-57
lines changed

cardano-testnet/cardano-testnet.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ library
8282
Testnet.Conf
8383
Testnet.Commands.Genesis
8484
Testnet.Commands.Governance
85+
Testnet.Options
8586
Testnet.Run
8687
Testnet.Shelley
8788
Testnet.Utils

cardano-testnet/src/Cardano/Testnet.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ module Cardano.Testnet (
3737
) where
3838

3939
import Testnet
40-
import Testnet.Babbage
4140
import Testnet.Cardano
4241
import Testnet.Conf hiding (base)
42+
import Testnet.Options
4343
import Testnet.Shelley as Shelley
4444
import Testnet.Utils (waitUntilEpoch)
4545

cardano-testnet/src/Parsers/Babbage.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ module Parsers.Babbage
44
, runBabbageOptions
55
) where
66

7-
import Prelude
87
import Options.Applicative
98
import qualified Options.Applicative as OA
9+
import Prelude
1010

1111
import Testnet
12-
import Testnet.Babbage
12+
import Testnet.Options
1313
import Testnet.Run (runTestnet)
1414
import Testnet.Util.Runtime (readNodeLoggingFormat)
1515

cardano-testnet/src/Testnet.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Hedgehog.Extras.Test.Base (Integration, noteShow_)
1616
import Testnet.Babbage as Babbage
1717
import Testnet.Cardano as Cardano
1818
import Testnet.Conf
19+
import qualified Testnet.Options as Options
20+
import Testnet.Options
1921
import Testnet.Shelley as Shelley (ShelleyTestnetOptions, defaultTestnetOptions,
2022
shelleyTestnet)
2123

@@ -48,7 +50,7 @@ testnet options conf = case options of
4850
cardanoTestnet o conf
4951

5052
babbageDefaultTestnetOptions :: BabbageTestnetOptions
51-
babbageDefaultTestnetOptions = Babbage.defaultTestnetOptions
53+
babbageDefaultTestnetOptions = Options.defaultTestnetOptions
5254

5355
cardanoDefaultTestnetOptions :: CardanoTestnetOptions
5456
cardanoDefaultTestnetOptions = Cardano.defaultTestnetOptions

cardano-testnet/src/Testnet/Babbage.hs

+12-38
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@
88
{-# OPTIONS_GHC -Wno-unused-local-binds -Wno-unused-matches #-}
99

1010
module Testnet.Babbage
11-
( BabbageTestnetOptions(..)
12-
, defaultTestnetOptions
13-
, TestnetRuntime (..)
11+
( TestnetRuntime (..)
1412
, PaymentKeyPair(..)
1513

1614
, babbageTestnet
1715
) where
1816

19-
import Control.Monad
20-
import Data.Aeson (encode, object, toJSON, (.=))
21-
import Hedgehog.Extras.Stock.Time (showUTCTimeSeconds)
2217
import Prelude
23-
import System.FilePath.Posix ((</>))
2418

19+
import Control.Monad
20+
import Data.Aeson (encode, object, toJSON, (.=))
2521
import qualified Data.HashMap.Lazy as HM
2622
import qualified Data.List as L
2723
import qualified Data.Time.Clock as DTC
2824
import qualified Hedgehog.Extras.Stock.Aeson as J
2925
import qualified Hedgehog.Extras.Stock.OS as OS
3026
import qualified Hedgehog.Extras.Test.Base as H
3127
import qualified Hedgehog.Extras.Test.File as H
28+
import System.FilePath.Posix ((</>))
3229
import qualified System.Info as OS
3330

3431
import Testnet.Commands.Genesis
3532
import qualified Testnet.Conf as H
33+
import Testnet.Options
3634
import qualified Testnet.Util.Assert as H
3735
import Testnet.Util.Process (execCli_)
3836
import Testnet.Util.Runtime (Delegator (..), NodeLoggingFormat (..), PaymentKeyPair (..),
@@ -42,23 +40,6 @@ import Testnet.Util.Runtime (Delegator (..), NodeLoggingFormat (..), P
4240

4341
{- HLINT ignore "Redundant flip" -}
4442

45-
data BabbageTestnetOptions = BabbageTestnetOptions
46-
{ babbageNumSpoNodes :: Int
47-
, babbageSlotDuration :: Int
48-
, babbageSecurityParam :: Int
49-
, babbageTotalBalance :: Int
50-
, babbageNodeLoggingFormat :: NodeLoggingFormat
51-
} deriving (Eq, Show)
52-
53-
defaultTestnetOptions :: BabbageTestnetOptions
54-
defaultTestnetOptions = BabbageTestnetOptions
55-
{ babbageNumSpoNodes = 3
56-
, babbageSlotDuration = 200
57-
, babbageSecurityParam = 10
58-
, babbageTotalBalance = 10020000000
59-
, babbageNodeLoggingFormat = NodeLoggingFormatAsJson
60-
}
61-
6243
-- | For an unknown reason, CLI commands are a lot slower on Windows than on Linux and
6344
-- MacOS. We need to allow a lot more time to set up a testnet.
6445
startTimeOffsetSeconds :: DTC.NominalDiffTime
@@ -75,20 +56,13 @@ babbageTestnet testnetOptions H.Conf {..} = do
7556
currentTime <- H.noteShowIO DTC.getCurrentTime
7657
startTime <- H.noteShow $ DTC.addUTCTime startTimeOffsetSeconds currentTime
7758

78-
execCli_
79-
[ "byron", "genesis", "genesis"
80-
, "--protocol-magic", show @Int testnetMagic
81-
, "--start-time", showUTCTimeSeconds startTime
82-
, "--k", show @Int (babbageSecurityParam testnetOptions)
83-
, "--n-poor-addresses", "0"
84-
, "--n-delegate-addresses", show @Int (babbageNumSpoNodes testnetOptions)
85-
, "--total-balance", show @Int (babbageTotalBalance testnetOptions)
86-
, "--delegate-share", "1"
87-
, "--avvm-entry-count", "0"
88-
, "--avvm-entry-balance", "0"
89-
, "--protocol-parameters-file", tempAbsPath </> "byron.genesis.spec.json"
90-
, "--genesis-output-dir", tempAbsPath </> "byron-gen-command"
91-
]
59+
createByronGenesis
60+
testnetMagic
61+
startTime
62+
testnetOptions
63+
(tempAbsPath </> "byron.genesis.spec.json")
64+
(tempAbsPath </> "byron-gen-command")
65+
9266

9367
-- Because in Babbage the overlay schedule and decentralization parameter
9468
-- are deprecated, we must use the "create-staked" cli command to create

cardano-testnet/src/Testnet/Commands/Genesis.hs

+45-15
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,63 @@
33

44
-- | All Byron and Shelley Genesis related functionality
55
module Testnet.Commands.Genesis
6-
( defaultByronGenesisJsonValue
7-
, createShelleyGenesisInitialTxIn
6+
( createShelleyGenesisInitialTxIn
7+
, createByronGenesis
8+
, defaultByronGenesisJsonValue
89
) where
910

1011
import Prelude
1112

1213
import Control.Monad.Catch
1314
import Control.Monad.IO.Class
1415
import Data.Aeson
16+
import Data.Time.Clock (UTCTime)
1517

18+
import Hedgehog.Extras.Stock.Time (showUTCTimeSeconds)
1619
import Hedgehog.Internal.Property
1720

21+
import Testnet.Options
1822
import Testnet.Util.Process
1923

24+
-- | Creates a default Byron genesis. This is required for any testnet, predominantly because
25+
-- we inject our ADA supply into our testnet via the Byron genesis.
26+
createByronGenesis
27+
:: (MonadTest m, MonadCatch m, MonadIO m)
28+
=> Int
29+
-> UTCTime
30+
-> BabbageTestnetOptions
31+
-> String
32+
-> String
33+
-> m ()
34+
createByronGenesis testnetMagic startTime testnetOptions pParamFp genOutputDir =
35+
execCli_
36+
[ "byron", "genesis", "genesis"
37+
, "--protocol-magic", show testnetMagic
38+
, "--start-time", showUTCTimeSeconds startTime
39+
, "--k", show (babbageSecurityParam testnetOptions)
40+
, "--n-poor-addresses", "0"
41+
, "--n-delegate-addresses", show @Int (babbageNumSpoNodes testnetOptions)
42+
, "--total-balance", show @Int (babbageTotalBalance testnetOptions)
43+
, "--delegate-share", "1"
44+
, "--avvm-entry-count", "0"
45+
, "--avvm-entry-balance", "0"
46+
, "--protocol-parameters-file", pParamFp
47+
, "--genesis-output-dir", genOutputDir
48+
]
49+
50+
-- | The Shelley initial UTxO is constructed from the 'sgInitialFunds' field which
51+
-- is not a full UTxO but just a map from addresses to coin values. Therefore this
52+
-- command creates a transaction input that defaults to the 0th index and therefore
53+
-- we can spend spend this tx input in a transaction.
54+
createShelleyGenesisInitialTxIn
55+
:: (MonadTest m, MonadCatch m, MonadIO m)
56+
=> Int -> FilePath -> m String
57+
createShelleyGenesisInitialTxIn testnetMagic vKeyFp =
58+
execCli
59+
[ "genesis", "initial-txin"
60+
, "--testnet-magic", show @Int testnetMagic
61+
, "--verification-key-file", vKeyFp
62+
]
2063

2164
-- | We need a Byron genesis in order to be able to hardfork to the later Shelley based eras.
2265
-- The values here don't matter as the testnet conditions are ultimately determined
@@ -47,16 +90,3 @@ defaultByronGenesisJsonValue =
4790
, "updateVoteThd" .= toJSON @String "1000000000000"
4891
]
4992

50-
-- | The Shelley initial UTxO is constructed from the 'sgInitialFunds' field which
51-
-- is not a full UTxO but just a map from addresses to coin values. Therefore this
52-
-- command creates a transaction input that defaults to the 0th index and therefore
53-
-- we can spend spend this tx input in a transaction.
54-
createShelleyGenesisInitialTxIn
55-
:: (MonadTest m, MonadCatch m, MonadIO m)
56-
=> Int -> FilePath -> m String
57-
createShelleyGenesisInitialTxIn testnetMagic vKeyFp =
58-
execCli
59-
[ "genesis", "initial-txin"
60-
, "--testnet-magic", show @Int testnetMagic
61-
, "--verification-key-file", vKeyFp
62-
]
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
4+
5+
{-# OPTIONS_GHC -Wno-unused-local-binds -Wno-unused-matches #-}
6+
7+
module Testnet.Options
8+
( BabbageTestnetOptions(..)
9+
, defaultTestnetOptions
10+
) where
11+
12+
import Prelude
13+
14+
import Testnet.Util.Runtime (NodeLoggingFormat (..))
15+
16+
{- HLINT ignore "Redundant flip" -}
17+
18+
data BabbageTestnetOptions = BabbageTestnetOptions
19+
{ babbageNumSpoNodes :: Int
20+
, babbageSlotDuration :: Int
21+
, babbageSecurityParam :: Int
22+
, babbageTotalBalance :: Int
23+
, babbageNodeLoggingFormat :: NodeLoggingFormat
24+
} deriving (Eq, Show)
25+
26+
defaultTestnetOptions :: BabbageTestnetOptions
27+
defaultTestnetOptions = BabbageTestnetOptions
28+
{ babbageNumSpoNodes = 3
29+
, babbageSlotDuration = 200
30+
, babbageSecurityParam = 10
31+
, babbageTotalBalance = 10020000000
32+
, babbageNodeLoggingFormat = NodeLoggingFormatAsJson
33+
}

0 commit comments

Comments
 (0)