Skip to content

Commit 87aa5e6

Browse files
authored
Merge pull request IntersectMBO#5658 from IntersectMBO/mgalazyn/add/use-env-var-for-testnet-magic
Use environment variable for network magic instead of CLI arg in testnet tests
2 parents 4f1d0d6 + 19925a5 commit 87aa5e6

File tree

13 files changed

+21
-111
lines changed

13 files changed

+21
-111
lines changed

cardano-testnet/src/Testnet/Components/SPO.hs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ checkStakePoolRegistered
4141
=> TmpAbsolutePath
4242
-> ExecConfig
4343
-> FilePath -- ^ Stake pool cold verification key file
44-
-> CardanoTestnetOptions
4544
-> FilePath -- ^ Output file path of stake pool info
4645
-> m String -- ^ Stake pool ID
47-
checkStakePoolRegistered tempAbsP execConfig poolColdVkeyFp cTestnetOpts outputFp =
46+
checkStakePoolRegistered tempAbsP execConfig poolColdVkeyFp outputFp =
4847
GHC.withFrozenCallStack $ do
4948
let tempAbsPath' = unTmpAbsPath tempAbsP
50-
testnetMag = cardanoTestnetMagic cTestnetOpts
5149
oFpAbs = tempAbsPath' </> outputFp
5250

5351
stakePoolId' <- filter ( /= '\n') <$>
@@ -58,7 +56,6 @@ checkStakePoolRegistered tempAbsP execConfig poolColdVkeyFp cTestnetOpts outputF
5856
-- Check to see if stake pool was registered
5957
void $ execCli' execConfig
6058
[ "query", "stake-pools"
61-
, "--testnet-magic", show @Int testnetMag
6259
, "--out-file", oFpAbs
6360
]
6461

@@ -78,14 +75,12 @@ checkStakeKeyRegistered
7875
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
7976
=> TmpAbsolutePath
8077
-> ExecConfig
81-
-> CardanoTestnetOptions
8278
-> String -- ^ Stake address
8379
-> FilePath -- ^ Output file path of stake address info
8480
-> m DelegationsAndRewards
85-
checkStakeKeyRegistered tempAbsP execConfig cTestnetOpts stakeAddr outputFp =
81+
checkStakeKeyRegistered tempAbsP execConfig stakeAddr outputFp =
8682
GHC.withFrozenCallStack $ do
8783
let tempAbsPath' = unTmpAbsPath tempAbsP
88-
testnetMag = cardanoTestnetMagic cTestnetOpts
8984
oFpAbs = tempAbsPath' </> outputFp
9085

9186
sAddr <- case deserialiseAddress AsStakeAddress $ Text.pack stakeAddr of
@@ -95,7 +90,6 @@ checkStakeKeyRegistered tempAbsP execConfig cTestnetOpts stakeAddr outputFp =
9590
void $ execCli' execConfig
9691
[ "query", "stake-address-info"
9792
, "--address", stakeAddr
98-
, "--testnet-magic", show @Int testnetMag
9993
, "--out-file", oFpAbs
10094
]
10195

@@ -273,7 +267,6 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
273267
void $ execCli' execConfig
274268
[ "transaction", "build"
275269
, eraFlag
276-
, "--testnet-magic", show @Int testnetMag
277270
, "--change-address", changeAddr
278271
, "--tx-in", Text.unpack $ renderTxIn fundingInput
279272
, "--tx-out", poolowneraddresswstakecred <> "+" <> show @Int 5_000_000
@@ -300,7 +293,6 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
300293
void $ execCli' execConfig
301294
[ "transaction", "submit"
302295
, "--tx-file", pledgeAndPoolRegistrationTx
303-
, "--testnet-magic", show @Int testnetMag
304296
]
305297
-- TODO: Currently we can't propagate the error message thrown by checkStakeKeyRegistered when using byDurationM
306298
-- Instead we wait 15 seconds
@@ -310,7 +302,6 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
310302
checkStakeKeyRegistered
311303
tap
312304
execConfig
313-
cTestnetOptions
314305
poolownerstakeaddr
315306
("spo-"<> show identifier <> "-requirements" </> "pledger.stake.info")
316307

@@ -324,7 +315,6 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
324315
tap
325316
execConfig
326317
poolColdVkeyFp
327-
cTestnetOptions
328318
currentRegistedPoolsJson
329319
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
330320

cardano-testnet/src/Testnet/Process/Run.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ mkExecConfig :: ()
146146
=> MonadIO m
147147
=> FilePath
148148
-> IO.Sprocket
149+
-> Int -- ^ Network id
149150
-> m ExecConfig
150-
mkExecConfig tempBaseAbsPath sprocket = do
151+
mkExecConfig tempBaseAbsPath sprocket networkId = do
151152
env' <- H.evalIO IO.getEnvironment
152153

153154
noteShow H.ExecConfig
154155
{ H.execConfigEnv = Last $ Just $
155156
[ ("CARDANO_NODE_SOCKET_PATH", IO.sprocketArgumentName sprocket)
157+
, ("CARDANO_NODE_NETWORK_ID", show networkId)
156158
]
157159
-- The environment must be passed onto child process on Windows in order to
158160
-- successfully start that process.
@@ -186,9 +188,6 @@ resourceAndIOExceptionHandlers = [ Handler $ return . ProcessIOException
186188
]
187189

188190

189-
190-
191-
192191
procFlexNew
193192
:: String
194193
-- ^ Cabal package name corresponding to the executable

cardano-testnet/src/Testnet/Property/Checks.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ prop_spos_in_ledger_state
3939
-> m ()
4040
prop_spos_in_ledger_state output tNetOptions execConfig =
4141
GHC.withFrozenCallStack $ do
42-
let testnetMag = cardanoTestnetMagic tNetOptions
43-
numExpectedPools = length $ cardanoNodes tNetOptions
42+
let numExpectedPools = length $ cardanoNodes tNetOptions
4443

4544
void $ execCli' execConfig
4645
[ "query", "stake-pools"
47-
, "--testnet-magic", show @Int testnetMag
4846
, "--out-file", output
4947
]
5048

cardano-testnet/src/Testnet/Property/Utils.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ waitUntilEpoch fp testnetMagic execConfig desiredEpoch = do
103103

104104
void $ H.execCli' execConfig
105105
[ "query", "tip"
106-
, "--testnet-magic", show @Int testnetMagic
107106
, "--out-file", fp
108107
]
109108

@@ -123,17 +122,14 @@ queryTip
123122
:: (MonadCatch m, MonadIO m, MonadTest m, HasCallStack)
124123
=> QueryTipOutput
125124
-- ^ Output file
126-
-> Int
127-
-- ^ Testnet magic
128125
-> ExecConfig
129126
-> m QueryTipLocalStateOutput
130-
queryTip (QueryTipOutput fp) testnetMag execConfig = do
127+
queryTip (QueryTipOutput fp) execConfig = do
131128
exists <- H.evalIO $ doesFileExist fp
132129
when exists $ H.evalIO $ removeFile fp
133130

134131
void $ H.execCli' execConfig
135132
[ "query", "tip"
136-
, "--testnet-magic", show @Int testnetMag
137133
, "--out-file", fp
138134
]
139135

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do
346346

347347
let tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tmpAbsPath
348348

349-
execConfig <- H.headM (poolSprockets runtime) >>= H.mkExecConfig tempBaseAbsPath
349+
node1sprocket <- H.headM $ poolSprockets runtime
350+
execConfig <- H.mkExecConfig tempBaseAbsPath node1sprocket testnetMagic
350351

351352
forM_ wallets $ \wallet -> do
352353
H.cat $ paymentSKey $ paymentKeyInfoPair wallet
@@ -356,7 +357,6 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do
356357
[ "query", "utxo"
357358
, "--address", Text.unpack $ paymentKeyInfoAddr wallet
358359
, "--cardano-mode"
359-
, "--testnet-magic", show @Int testnetMagic
360360
]
361361

362362
H.note_ utxos

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
7979
, configurationFile
8080
} <- cardanoTestnet cTestnetOptions conf
8181

82-
execConfig <- H.headM (poolSprockets tr) >>= H.mkExecConfig tempBaseAbsPath
82+
node1sprocket <- H.headM $ poolSprockets tr
83+
execConfig <- H.mkExecConfig tempBaseAbsPath node1sprocket testnetMagic
8384

8485
let sbe = shelleyBasedEra @BabbageEra
8586

@@ -90,7 +91,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
9091
[ "conway", "query", "utxo"
9192
, "--address", utxoAddr
9293
, "--cardano-mode"
93-
, "--testnet-magic", show @Int testnetMagic
9494
, "--out-file", work </> "utxo-1.json"
9595
]
9696

@@ -157,7 +157,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
157157
[ "query", "utxo"
158158
, "--address", utxoAddr
159159
, "--cardano-mode"
160-
, "--testnet-magic", show @Int testnetMagic
161160
, "--out-file", work </> "utxo-2.json"
162161
]
163162

@@ -173,7 +172,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
173172
void $ execCli' execConfig
174173
[ "transaction", "build"
175174
, eraFlag
176-
, "--testnet-magic", show @Int testnetMagic
177175
, "--change-address", testDelegatorPaymentAddr -- NB: A large balance ends up at our test delegator's address
178176
, "--tx-in", Text.unpack $ renderTxIn txin2
179177
, "--tx-out", utxoAddr <> "+" <> show @Int 5_000_000
@@ -198,7 +196,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
198196
void $ execCli' execConfig
199197
[ "transaction", "submit"
200198
, "--tx-file", delegRegTestDelegatorTxFp
201-
, "--testnet-magic", show @Int testnetMagic
202199
]
203200

204201
threadDelay 15_000000
@@ -209,7 +206,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
209206
void $ checkStakeKeyRegistered
210207
tempAbsPath
211208
execConfig
212-
cTestnetOptions
213209
testDelegatorStakeAddress
214210
testDelegatorStakeAddressInfoOutFp
215211

@@ -287,7 +283,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
287283
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
288284
void $ execCli' execConfig
289285
[ "query", "tip"
290-
, "--testnet-magic", show @Int testnetMagic
291286
, "--out-file", work </> "current-tip.json"
292287
]
293288

@@ -309,7 +304,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
309304
H.byDeadlineM 5 leadershipScheduleDeadline "Failed to query for leadership schedule" $ do
310305
void $ execCli' execConfig
311306
[ "query", "leadership-schedule"
312-
, "--testnet-magic", show @Int testnetMagic
313307
, "--genesis", shelleyGenesisFile tr
314308
, "--stake-pool-id", stakePoolIdNewSpo
315309
, "--vrf-signing-key-file", vrfSkey
@@ -361,7 +355,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
361355
H.byDeadlineM 5 leadershipScheduleDeadline "Failed to query for leadership schedule" $ do
362356
void $ execCli' execConfig
363357
[ "query", "leadership-schedule"
364-
, "--testnet-magic", show @Int testnetMagic
365358
, "--genesis", shelleyGenesisFile tr
366359
, "--stake-pool-id", stakePoolIdNewSpo
367360
, "--vrf-signing-key-file", vrfSkey

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,13 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \
6565
} <- cardanoTestnet options conf
6666

6767
poolNode1 <- H.headM poolNodes
68-
6968
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
70-
71-
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1
72-
69+
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
7370
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
7471

7572
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
7673
void $ execCli' execConfig
7774
[ "query", "tip"
78-
, "--testnet-magic", show @Int testnetMagic
7975
, "--out-file", work </> "current-tip.json"
8076
]
8177

@@ -91,7 +87,6 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \
9187

9288
result <- execCli' execConfig
9389
[ "query", "stake-snapshot"
94-
, "--testnet-magic", show @Int testnetMagic
9590
, "--all-stake-pools"
9691
]
9792

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/Transaction.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA
6969
} <- cardanoTestnet options conf
7070

7171
poolNode1 <- H.headM poolNodes
72-
7372
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
74-
75-
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1
73+
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
7674

7775

7876
txbodyFp <- H.note $ work </> "tx.body"
@@ -82,7 +80,6 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA
8280
[ "babbage", "query", "utxo"
8381
, "--address", Text.unpack $ paymentKeyInfoAddr $ head wallets
8482
, "--cardano-mode"
85-
, "--testnet-magic", show @Int testnetMagic
8683
, "--out-file", work </> "utxo-1.json"
8784
]
8885

@@ -92,7 +89,6 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA
9289

9390
void $ execCli' execConfig
9491
[ "babbage", "transaction", "build"
95-
, "--testnet-magic", show @Int testnetMagic
9692
, "--change-address", Text.unpack $ paymentKeyInfoAddr $ head wallets
9793
, "--tx-in", Text.unpack $ renderTxIn txin1
9894
, "--tx-out", Text.unpack (paymentKeyInfoAddr (head wallets)) <> "+" <> show @Int 5_000_001
@@ -101,15 +97,13 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA
10197

10298
void $ execCli' execConfig
10399
[ "babbage", "transaction", "sign"
104-
, "--testnet-magic", show @Int testnetMagic
105100
, "--tx-body-file", txbodyFp
106101
, "--signing-key-file", paymentSKey $ paymentKeyInfoPair $ wallets !! 0
107102
, "--out-file", txbodySignedFp
108103
]
109104

110105
void $ execCli' execConfig
111106
[ "babbage", "transaction", "submit"
112-
, "--testnet-magic", show @Int testnetMagic
113107
, "--tx-file", txbodySignedFp
114108
]
115109

@@ -118,7 +112,6 @@ hprop_transaction = H.integrationRetryWorkspace 0 "babbage-transaction" $ \tempA
118112
[ "babbage", "query", "utxo"
119113
, "--address", Text.unpack $ paymentKeyInfoAddr $ head wallets
120114
, "--cardano-mode"
121-
, "--testnet-magic", show @Int testnetMagic
122115
, "--out-file", work </> "utxo-2.json"
123116
]
124117

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t
6565
} <- cardanoTestnet options conf
6666

6767
poolNode1 <- H.headM poolNodes
68-
6968
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
70-
71-
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1
69+
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
7270

7371
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
7472

7573
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
7674
void $ execCli' execConfig
7775
[ "query", "tip"
78-
, "--testnet-magic", show @Int testnetMagic
7976
, "--out-file", work </> "current-tip.json"
8077
]
8178

@@ -91,7 +88,6 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t
9188

9289
result <- execCli' execConfig
9390
[ "query", "stake-snapshot"
94-
, "--testnet-magic", show @Int testnetMagic
9591
, "--all-stake-pools"
9692
]
9793

0 commit comments

Comments
 (0)