@@ -12,18 +12,17 @@ module Testnet.Shelley
12
12
, hprop_testnet_pause
13
13
) where
14
14
15
- import Control.Monad ( Monad ( .. ), forever , forM_ , void , (=<<) , when )
15
+ import Control.Monad
16
16
import Control.Monad.IO.Class (MonadIO (liftIO ))
17
17
import Control.Monad.Trans.Resource (MonadResource (liftResourceT ), resourceForkIO )
18
18
import Data.Aeson (Value , ToJSON (toJSON ))
19
19
import Data.ByteString.Lazy (ByteString )
20
20
import Data.Eq (Eq )
21
21
import Data.Function (($) , (.) , flip )
22
- import Data.Functor ( Functor ( fmap ), (<$>) , (<&>) )
22
+ import Data.Functor
23
23
import Data.Int (Int )
24
24
import Data.List ((\\) )
25
- import Data.Maybe (Maybe (Nothing , Just ), fromJust )
26
- import Data.Ord (Ord ((<=) ))
25
+ import Data.Maybe
27
26
import Data.Semigroup (Semigroup ((<>) ))
28
27
import Data.String (String , fromString )
29
28
import Data.Time.Clock (UTCTime )
@@ -36,6 +35,9 @@ import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPo
36
35
import Prelude (Bool (.. ), Integer , (-) )
37
36
import System.FilePath.Posix ((</>) )
38
37
import Text.Show (Show (show ))
38
+ import Test.Process (execCli_ )
39
+ import Test.Runtime hiding (allNodes )
40
+ import Testnet.Utils
39
41
40
42
import qualified Cardano.Node.Configuration.Topology as NonP2P
41
43
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
@@ -58,13 +60,9 @@ import qualified Hedgehog.Extras.Test.Network as H
58
60
import qualified Hedgehog.Extras.Test.Process as H
59
61
import qualified System.Directory as IO
60
62
import qualified System.Info as OS
61
- import qualified System.IO as IO
62
- import qualified System.Process as IO
63
63
import qualified Test.Base as H
64
64
import qualified Test.Process as H
65
65
import qualified Testnet.Conf as H
66
- import Test.Runtime (TestnetRuntime (.. ))
67
-
68
66
69
67
{- HLINT ignore "Reduce duplication" -}
70
68
{- HLINT ignore "Redundant <&>" -}
@@ -189,7 +187,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
189
187
liftIO $ IO. copyFile sourceAlonzoGenesisSpecFile alonzoSpecFile
190
188
191
189
-- Set up our template
192
- void $ H. execCli
190
+ execCli_
193
191
[ " genesis" , " create"
194
192
, " --testnet-magic" , show @ Int testnetMagic
195
193
, " --genesis-dir" , tempAbsPath
@@ -207,7 +205,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
207
205
H. assertIsJsonFile $ tempAbsPath </> " genesis.spec.json"
208
206
209
207
-- Now generate for real
210
- void $ H. execCli
208
+ execCli_
211
209
[ " genesis" , " create"
212
210
, " --testnet-magic" , show @ Int testnetMagic
213
211
, " --genesis-dir" , tempAbsPath
@@ -221,14 +219,14 @@ shelleyTestnet testnetOptions H.Conf {..} = do
221
219
-- Make the pool operator cold keys
222
220
-- This was done already for the BFT nodes as part of the genesis creation
223
221
forM_ poolNodes $ \ n -> do
224
- void $ H. execCli
222
+ execCli_
225
223
[ " node" , " key-gen"
226
224
, " --cold-verification-key-file" , tempAbsPath </> n </> " operator.vkey"
227
225
, " --cold-signing-key-file" , tempAbsPath </> n </> " operator.skey"
228
226
, " --operational-certificate-issue-counter-file" , tempAbsPath </> n </> " operator.counter"
229
227
]
230
228
231
- void $ H. execCli
229
+ execCli_
232
230
[ " node" , " key-gen-VRF"
233
231
, " --verification-key-file" , tempAbsPath </> n </> " vrf.vkey"
234
232
, " --signing-key-file" , tempAbsPath </> n </> " vrf.skey"
@@ -243,13 +241,13 @@ shelleyTestnet testnetOptions H.Conf {..} = do
243
241
244
242
-- Make hot keys and for all nodes
245
243
forM_ allNodes $ \ node -> do
246
- void $ H. execCli
244
+ execCli_
247
245
[ " node" , " key-gen-KES"
248
246
, " --verification-key-file" , tempAbsPath </> node </> " kes.vkey"
249
247
, " --signing-key-file" , tempAbsPath </> node </> " kes.skey"
250
248
]
251
249
252
- void $ H. execCli
250
+ execCli_
253
251
[ " node" , " issue-op-cert"
254
252
, " --kes-period" , " 0"
255
253
, " --kes-verification-key-file" , tempAbsPath </> node </> " kes.vkey"
@@ -278,21 +276,21 @@ shelleyTestnet testnetOptions H.Conf {..} = do
278
276
279
277
forM_ addrs $ \ addr -> do
280
278
-- Payment address keys
281
- void $ H. execCli
279
+ execCli_
282
280
[ " address" , " key-gen"
283
281
, " --verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " .vkey"
284
282
, " --signing-key-file" , tempAbsPath </> " addresses/" <> addr <> " .skey"
285
283
]
286
284
287
285
-- Stake address keys
288
- void $ H. execCli
286
+ execCli_
289
287
[ " stake-address" , " key-gen"
290
288
, " --verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.vkey"
291
289
, " --signing-key-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.skey"
292
290
]
293
291
294
292
-- Payment addresses
295
- void $ H. execCli
293
+ execCli_
296
294
[ " address" , " build"
297
295
, " --payment-verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " .vkey"
298
296
, " --stake-verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.vkey"
@@ -301,23 +299,23 @@ shelleyTestnet testnetOptions H.Conf {..} = do
301
299
]
302
300
303
301
-- Stake addresses
304
- void $ H. execCli
302
+ execCli_
305
303
[ " stake-address" , " build"
306
304
, " --stake-verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.vkey"
307
305
, " --testnet-magic" , show @ Int testnetMagic
308
306
, " --out-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.addr"
309
307
]
310
308
311
309
-- Stake addresses registration certs
312
- void $ H. execCli
310
+ execCli_
313
311
[ " stake-address" , " registration-certificate"
314
312
, " --stake-verification-key-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.vkey"
315
313
, " --out-file" , tempAbsPath </> " addresses/" <> addr <> " -stake.reg.cert"
316
314
]
317
315
318
316
forM_ userPoolN $ \ n -> do
319
317
-- Stake address delegation certs
320
- void $ H. execCli
318
+ execCli_
321
319
[ " stake-address" , " delegation-certificate"
322
320
, " --stake-verification-key-file" , tempAbsPath </> " addresses/user" <> n <> " -stake.vkey"
323
321
, " --cold-verification-key-file" , tempAbsPath </> " node-pool" <> n </> " operator.vkey"
@@ -333,7 +331,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
333
331
334
332
-- Next is to make the stake pool registration cert
335
333
forM_ poolNodes $ \ node -> do
336
- void $ H. execCli
334
+ execCli_
337
335
[ " stake-pool" , " registration-certificate"
338
336
, " --testnet-magic" , show @ Int testnetMagic
339
337
, " --pool-pledge" , " 0"
@@ -367,7 +365,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
367
365
368
366
userNAddr <- H. readFile $ tempAbsPath </> " addresses/user" <> n <> " .addr"
369
367
370
- void $ H. execCli
368
+ execCli_
371
369
[ " transaction" , " build-raw"
372
370
, " --invalid-hereafter" , " 1000"
373
371
, " --fee" , " 0"
@@ -386,7 +384,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
386
384
-- 3. the pool n owner key, due to the pool registration cert
387
385
-- 3. the pool n operator key, due to the pool registration cert
388
386
389
- void $ H. execCli
387
+ execCli_
390
388
[ " transaction" , " sign"
391
389
, " --signing-key-file" , tempAbsPath </> " utxo-keys/utxo" <> n <> " .skey"
392
390
, " --signing-key-file" , tempAbsPath </> " addresses/user" <> n <> " -stake.skey"
@@ -409,24 +407,8 @@ shelleyTestnet testnetOptions H.Conf {..} = do
409
407
<&> L. unlines . fmap (rewriteConfiguration (enableP2P testnetOptions)) . L. lines
410
408
>>= H. writeFile (tempAbsPath </> " configuration.yaml" )
411
409
412
- forM_ allNodes $ \ node -> do
413
- dbDir <- H. noteShow $ tempAbsPath </> " db/" <> node
414
- nodeStdoutFile <- H. noteTempFile logDir $ node <> " .stdout.log"
415
- nodeStderrFile <- H. noteTempFile logDir $ node <> " .stderr.log"
416
- sprocket <- H. noteShow $ Sprocket tempBaseAbsPath (socketDir </> node)
417
-
418
- H. createDirectoryIfMissing dbDir
419
- H. createDirectoryIfMissing $ tempBaseAbsPath </> socketDir
420
-
421
- hNodeStdout <- H. openFile nodeStdoutFile IO. WriteMode
422
- hNodeStderr <- H. openFile nodeStderrFile IO. WriteMode
423
-
424
- H. diff (L. length (IO. sprocketArgumentName sprocket)) (<=) IO. maxSprocketArgumentNameLength
425
-
426
- portString <- H. readFile $ tempAbsPath </> node </> " port"
427
-
428
- void $ H. createProcess =<<
429
- ( H. procNode
410
+ allNodeRuntimes <- forM allNodes $ \ node -> do
411
+ runtime <- startNode socketDir tempBaseAbsPath tempAbsPath logDir node
430
412
[ " run"
431
413
, " --config" , tempAbsPath </> " configuration.yaml"
432
414
, " --topology" , tempAbsPath </> node </> " topology.json"
@@ -435,20 +417,8 @@ shelleyTestnet testnetOptions H.Conf {..} = do
435
417
, " --shelley-vrf-key" , tempAbsPath </> node </> " vrf.skey"
436
418
, " --shelley-operational-certificate" , tempAbsPath </> node </> " node.cert"
437
419
, " --host-addr" , ifaceAddress
438
- , " --port" , portString
439
- , " --socket-path" , IO. sprocketArgumentName sprocket
440
- ] <&>
441
- ( \ cp -> cp
442
- { IO. std_in = IO. CreatePipe
443
- , IO. std_out = IO. UseHandle hNodeStdout
444
- , IO. std_err = IO. UseHandle hNodeStderr
445
- , IO. cwd = Just tempBaseAbsPath
446
- }
447
- )
448
- )
449
-
450
- when (OS. os `L.elem` [" darwin" , " linux" ]) $ do
451
- H. onFailure . H. noteIO_ $ IO. readProcess " lsof" [" -iTCP:" <> portString, " -sTCP:LISTEN" , " -n" , " -P" ] " "
420
+ ]
421
+ return $ TestnetNode runtime
452
422
453
423
now <- H. noteShowIO DTC. getCurrentTime
454
424
deadline <- H. noteShow $ DTC. addUTCTime 90 now
@@ -469,10 +439,9 @@ shelleyTestnet testnetOptions H.Conf {..} = do
469
439
{ configurationFile = alonzoSpecFile
470
440
, shelleyGenesisFile = tempAbsPath </> " genesis/shelley/genesis.json"
471
441
, testnetMagic
472
- -- TODO: return some useful data here !!
473
442
, poolNodes = [ ]
474
443
, wallets = [ ]
475
- , bftNodes = [ ]
444
+ , bftNodes = allNodeRuntimes
476
445
, delegators = [ ]
477
446
}
478
447
0 commit comments