8
8
{-# OPTIONS_GHC -Wno-unused-local-binds -Wno-unused-matches #-}
9
9
10
10
module Testnet.Babbage
11
- ( TestnetOptions (.. )
11
+ ( BabbageTestnetOptions (.. )
12
12
, defaultTestnetOptions
13
13
, TestnetNodeOptions (.. )
14
14
, defaultTestnetNodeOptions
@@ -17,64 +17,57 @@ module Testnet.Babbage
17
17
, TestnetNode (.. )
18
18
, PaymentKeyPair (.. )
19
19
20
- , testnet
20
+ , babbageTestnet
21
21
) where
22
22
23
23
import Control.Applicative (Applicative (.. ))
24
- import Control.Monad ( Monad ( .. ), fmap , forM , forM_ , return , void , when , (=<<) )
24
+ import Control.Monad
25
25
import Data.Aeson (encode , object , toJSON , (.=) )
26
26
import Data.Bool (Bool (.. ))
27
27
import Data.Eq (Eq )
28
28
import Data.Function (flip , ($) , (.) )
29
- import Data.Functor ( (<$>) , (<&>) )
29
+ import Data.Functor
30
30
import Data.Int (Int )
31
- import Data.Maybe (Maybe (.. ))
32
- import Data.Ord (Ord ((<=) ))
33
31
import Data.Semigroup (Semigroup ((<>) ))
34
32
import Data.String (String )
35
33
import GHC.Float (Double )
36
- import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (.. ))
37
34
import Hedgehog.Extras.Stock.Time (showUTCTimeSeconds )
38
35
import System.FilePath.Posix ((</>) )
36
+
39
37
import Test.Runtime (Delegator (.. ), NodeLoggingFormat (.. ), PaymentKeyPair (.. ),
40
38
PoolNode (PoolNode ), PoolNodeKeys (.. ), StakingKeyPair (.. ), TestnetNode (.. ),
41
39
TestnetRuntime (.. ))
40
+ import Testnet.Utils
42
41
import Text.Show (Show (show ))
43
42
44
43
import qualified Data.HashMap.Lazy as HM
45
44
import qualified Data.List as L
46
45
import qualified Data.Time.Clock as DTC
47
- import qualified Hedgehog as H
48
46
import qualified Hedgehog.Extras.Stock.Aeson as J
49
- import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
50
47
import qualified Hedgehog.Extras.Stock.OS as OS
51
- import qualified Hedgehog.Extras.Stock.String as S
52
48
import qualified Hedgehog.Extras.Test.Base as H
53
49
import qualified Hedgehog.Extras.Test.File as H
54
- import qualified Hedgehog.Extras.Test.Process as H
55
50
import qualified System.Info as OS
56
- import qualified System.IO as IO
57
- import qualified System.Process as IO
58
51
import qualified Test.Assert as H
59
- import qualified Test.Process as H
60
52
import qualified Testnet.Conf as H
61
53
54
+ import Test.Process (execCli_ )
62
55
{- HLINT ignore "Reduce duplication" -}
63
56
{- HLINT ignore "Redundant <&>" -}
64
57
{- HLINT ignore "Redundant flip" -}
65
58
{- HLINT ignore "Redundant id" -}
66
59
{- HLINT ignore "Use let" -}
67
60
68
- data TestnetOptions = TestnetOptions
61
+ data BabbageTestnetOptions = BabbageTestnetOptions
69
62
{ numSpoNodes :: Int
70
63
, slotDuration :: Int
71
64
, securityParam :: Int
72
65
, totalBalance :: Int
73
66
, nodeLoggingFormat :: NodeLoggingFormat
74
67
} deriving (Eq , Show )
75
68
76
- defaultTestnetOptions :: TestnetOptions
77
- defaultTestnetOptions = TestnetOptions
69
+ defaultTestnetOptions :: BabbageTestnetOptions
70
+ defaultTestnetOptions = BabbageTestnetOptions
78
71
{ numSpoNodes = 3
79
72
, slotDuration = 1000
80
73
, securityParam = 10
@@ -92,8 +85,8 @@ defaultTestnetNodeOptions = TestnetNodeOptions
92
85
startTimeOffsetSeconds :: DTC. NominalDiffTime
93
86
startTimeOffsetSeconds = if OS. isWin32 then 90 else 15
94
87
95
- testnet :: TestnetOptions -> H. Conf -> H. Integration TestnetRuntime
96
- testnet testnetOptions H. Conf {.. } = do
88
+ babbageTestnet :: BabbageTestnetOptions -> H. Conf -> H. Integration TestnetRuntime
89
+ babbageTestnet testnetOptions H. Conf {.. } = do
97
90
H. createDirectoryIfMissing (tempAbsPath </> " logs" )
98
91
99
92
H. lbsWriteFile (tempAbsPath </> " byron.genesis.spec.json" ) . encode $ object
@@ -124,7 +117,7 @@ testnet testnetOptions H.Conf {..} = do
124
117
currentTime <- H. noteShowIO DTC. getCurrentTime
125
118
startTime <- H. noteShow $ DTC. addUTCTime startTimeOffsetSeconds currentTime
126
119
127
- void . H. execCli $
120
+ execCli_
128
121
[ " byron" , " genesis" , " genesis"
129
122
, " --protocol-magic" , show @ Int testnetMagic
130
123
, " --start-time" , showUTCTimeSeconds startTime
@@ -180,7 +173,7 @@ testnet testnetOptions H.Conf {..} = do
180
173
181
174
let numPoolNodes = 3 :: Int
182
175
183
- void . H. execCli $
176
+ execCli_
184
177
[ " genesis" , " create-staked"
185
178
, " --genesis-dir" , tempAbsPath
186
179
, " --testnet-magic" , show @ Int testnetMagic
@@ -340,49 +333,19 @@ testnet testnetOptions H.Conf {..} = do
340
333
]
341
334
]
342
335
343
- (poolSprockets, poolStdins, poolStdouts, poolStderrs, poolProcessHandles) <- fmap L. unzip5 . forM spoNodes $ \ node -> do
344
- dbDir <- H. noteShow $ tempAbsPath </> " db/" <> node
345
- nodeStdoutFile <- H. noteTempFile logDir $ node <> " .stdout.log"
346
- nodeStderrFile <- H. noteTempFile logDir $ node <> " .stderr.log"
347
- sprocket <- H. noteShow $ Sprocket tempBaseAbsPath (socketDir </> node)
348
-
349
- H. createDirectoryIfMissing dbDir
350
- H. createDirectoryIfMissing $ tempBaseAbsPath </> socketDir
351
-
352
- hNodeStdout <- H. openFile nodeStdoutFile IO. WriteMode
353
- hNodeStderr <- H. openFile nodeStderrFile IO. WriteMode
354
-
355
- H. diff (L. length (IO. sprocketArgumentName sprocket)) (<=) IO. maxSprocketArgumentNameLength
356
-
357
- portString <- fmap S. strip . H. readFile $ tempAbsPath </> node </> " port"
358
-
359
- (Just stdIn, _, _, hProcess, _) <- H. createProcess =<<
360
- ( H. procNode
336
+ poolNodes <- forM (L. zip spoNodes poolKeys) $ \ (node,key) -> do
337
+ runtime <- startNode socketDir tempBaseAbsPath tempAbsPath logDir node
361
338
[ " run"
362
339
, " --config" , tempAbsPath </> " configuration.yaml"
363
340
, " --topology" , tempAbsPath </> node </> " topology.json"
364
341
, " --database-path" , tempAbsPath </> node </> " db"
365
- , " --socket-path" , IO. sprocketArgumentName sprocket
366
342
, " --shelley-kes-key" , tempAbsPath </> node </> " kes.skey"
367
343
, " --shelley-vrf-key" , tempAbsPath </> node </> " vrf.skey"
368
344
, " --byron-delegation-certificate" , tempAbsPath </> node </> " byron-delegation.cert"
369
345
, " --byron-signing-key" , tempAbsPath </> node </> " byron-delegate.key"
370
346
, " --shelley-operational-certificate" , tempAbsPath </> node </> " opcert.cert"
371
- , " --port" , portString
372
- ] <&>
373
- ( \ cp -> cp
374
- { IO. std_in = IO. CreatePipe
375
- , IO. std_out = IO. UseHandle hNodeStdout
376
- , IO. std_err = IO. UseHandle hNodeStderr
377
- , IO. cwd = Just tempBaseAbsPath
378
- }
379
- )
380
- )
381
-
382
- when (OS. os `L.elem` [" darwin" , " linux" ]) $ do
383
- H. onFailure . H. noteIO_ $ IO. readProcess " lsof" [" -iTCP:" <> portString, " -sTCP:LISTEN" , " -n" , " -P" ] " "
384
-
385
- return (sprocket, stdIn, nodeStdoutFile, nodeStderrFile, hProcess)
347
+ ]
348
+ return $ PoolNode runtime key
386
349
387
350
now <- H. noteShowIO DTC. getCurrentTime
388
351
deadline <- H. noteShow $ DTC. addUTCTime 90 now
@@ -401,14 +364,7 @@ testnet testnetOptions H.Conf {..} = do
401
364
{ configurationFile
402
365
, shelleyGenesisFile = tempAbsPath </> " genesis/shelley/genesis.json"
403
366
, testnetMagic
404
- , poolNodes = L. zipWith7 PoolNode
405
- spoNodes
406
- poolSprockets
407
- poolStdins
408
- poolStdouts
409
- poolStderrs
410
- poolProcessHandles
411
- poolKeys
367
+ , poolNodes
412
368
, wallets = wallets
413
369
, bftNodes = []
414
370
, delegators = delegators
0 commit comments