Skip to content

Commit 924729e

Browse files
committed
Refactor cardanoTestnet to no longer use GenesisOption
Since `createTestnetEnv` is now responsible for creating the sandbox environment, `cardanoTestnet` no longer needs Genesis information. This commit removes the dependency, and gets the needed information from the sandbox environment instead.
1 parent 46cbb65 commit 924729e

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

cardano-testnet/src/Parsers/Run.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ runCardanoOptions CardanoTestnetCliOptions
8787
createTestnetEnv
8888
testnetOptions genesisOptions def
8989
conf
90-
cardanoTestnet testnetOptions genesisOptions conf
90+
cardanoTestnet testnetOptions conf
9191
UserProvidedEnv nodeEnvPath ->
9292
-- Run cardano-testnet in the sandbox provided by the user
9393
-- In that case, 'cardanoOutputDir' is not used
9494
runTestnet (UserProvidedEnv nodeEnvPath) $ \conf ->
9595
cardanoTestnet
9696
testnetOptions
97-
genesisOptions
9897
conf{updateTimestamps=updateTimestamps}

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,10 @@ createTestnetEnv
208208
cardanoTestnet :: ()
209209
=> HasCallStack
210210
=> CardanoTestnetOptions -- ^ The options to use
211-
-> GenesisOptions
212211
-> Conf -- ^ Path to the test sandbox
213212
-> H.Integration TestnetRuntime
214213
cardanoTestnet
215214
testnetOptions
216-
GenesisOptions{genesisTestnetMagic=testnetMagic}
217215
Conf
218216
{ tempAbsPath=TmpAbsolutePath tmpAbsPath
219217
, updateTimestamps
@@ -225,9 +223,15 @@ cardanoTestnet
225223
} = testnetOptions
226224
nPools = cardanoNumPools testnetOptions
227225
nodeConfigFile = tmpAbsPath </> "configuration.yaml"
226+
byronGenesisFile = tmpAbsPath </> "byron-genesis.json"
227+
shelleyGenesisFile = tmpAbsPath </> "shelley-genesis.json"
228228

229229
H.note_ OS.os
230230

231+
eShelley <- H.readJsonFile shelleyGenesisFile
232+
shelleyGenesis@ShelleyGenesis{sgNetworkMagic} <- H.leftFail eShelley
233+
let testnetMagic :: Int = fromIntegral sgNetworkMagic
234+
231235
wallets <- forM [1..3] $ \idx -> do
232236
let utxoKeys@KeyPair{verificationKey} = makePathsAbsolute $ Defaults.defaultUtxoKeys idx
233237
let paymentAddrFile = tmpAbsPath </> "utxo-keys" </> "utxo" <> show idx </> "utxo.addr"
@@ -306,9 +310,6 @@ cardanoTestnet
306310
-- This is a QoL feature so that users who edit their configuration files don't
307311
-- have to manually set up the start times themselves.
308312
when (updateTimestamps == UpdateTimestamps) $ do
309-
let byronGenesisFile = tmpAbsPath </> "byron-genesis.json"
310-
shelleyGenesisFile = tmpAbsPath </> "shelley-genesis.json"
311-
312313
currentTime <- H.noteShowIO DTC.getCurrentTime
313314
startTime <- H.noteShow $ DTC.addUTCTime startTimeOffsetSeconds currentTime
314315

@@ -318,11 +319,9 @@ cardanoTestnet
318319
let byronGenesis = byronGenesis'{gdStartTime = startTime}
319320
H.lbsWriteFile byronGenesisFile $ canonicalEncodePretty byronGenesis
320321

321-
-- Update start time in Shelley genesis file
322-
eShelley <- H.readJsonFile shelleyGenesisFile
323-
shelleyGenesis' :: ShelleyGenesis <- H.leftFail eShelley
324-
let shelleyGenesis = shelleyGenesis'{sgSystemStart = startTime}
325-
H.lbsWriteFile shelleyGenesisFile $ A.encodePretty shelleyGenesis
322+
-- Update start time in Shelley genesis file (which has been read already)
323+
let shelleyGenesis' = shelleyGenesis{sgSystemStart = startTime}
324+
H.lbsWriteFile shelleyGenesisFile $ A.encodePretty shelleyGenesis'
326325

327326
eTestnetNodes <- H.forConcurrently (zip [1..] portNumbersWithNodeOptions) $ \(i, (nodeOptions, port)) -> do
328327
let nodeName = Defaults.defaultNodeName i
@@ -426,7 +425,7 @@ createAndRunTestnet testnetOptions genesisOptions conf = do
426425
createTestnetEnv
427426
testnetOptions genesisOptions def
428427
conf
429-
cardanoTestnet testnetOptions genesisOptions conf
428+
cardanoTestnet testnetOptions conf
430429

431430
-- | Retry an action when `NodeAddressAlreadyInUseError` gets thrown from an action
432431
retryOnAddressInUseError

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/DumpConfig.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ hprop_dump_config = integrationRetryWorkspace 2 "dump-config-files" $ \tmpDir ->
6969
H.lbsWriteFile shelleyGenesisFile $ encodePretty shelleyGenesis
7070

7171
-- Run testnet with generated config
72-
runtime <- cardanoTestnet testnetOptions genesisOptions conf
72+
runtime <- cardanoTestnet testnetOptions conf
7373

7474
nodesProduceBlocks tmpDir runtime

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat
112112
, testnetNodes
113113
, wallets=wallet0:_wallet1:_
114114
, configurationFile
115-
} <- cardanoTestnet fastTestnetOptions genesisOptions conf
115+
} <- cardanoTestnet fastTestnetOptions conf
116116

117117
poolNode1 <- H.headM testnetNodes
118118
poolSprocket1 <- H.noteShow $ nodeSprocket poolNode1

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/MainnetParams.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ hprop_mainnet_params = integrationRetryWorkspace 2 "mainnet-params" $ \tmpDir ->
4545
TestnetRuntime
4646
{ testnetNodes
4747
, testnetMagic
48-
} <- cardanoTestnet testnetOptions genesisOptions conf
48+
} <- cardanoTestnet testnetOptions conf
4949

5050
-- Get a running node
5151
TestnetNode{nodeSprocket} <- H.headM testnetNodes

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/P2PTopology.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ hprop_p2p_topology = integrationRetryWorkspace 2 "p2p-topology" $ \tmpDir -> H.r
4343
(_topology :: P2P.NetworkTopology NodeId) <- H.leftFail eTopology
4444

4545
-- Run testnet with generated config
46-
runtime <- cardanoTestnet testnetOptions genesisOptions conf
46+
runtime <- cardanoTestnet testnetOptions conf
4747

4848
nodesProduceBlocks tmpDir runtime

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/UpdateTimeStamps.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ hprop_update_time_stamps = integrationRetryWorkspace 2 "update-time-stamps" $ \t
4545
H.threadDelay $ double2Int $ realToFrac startTimeOffsetSeconds * 1_000_000 * 1.2
4646

4747
-- Run testnet and specify to update time stamps before starting
48-
runtime <- cardanoTestnet
49-
testnetOptions
50-
genesisOptions
51-
conf{updateTimestamps = UpdateTimestamps}
48+
runtime <- cardanoTestnet testnetOptions conf{updateTimestamps = UpdateTimestamps}
5249

5350
nodesProduceBlocks tmpDir runtime

0 commit comments

Comments
 (0)