Skip to content

Commit b092ee3

Browse files
committed
cardano-testnet | Refactor: use KeyPair in registerSingleSpo
1 parent a29bd5d commit b092ee3

File tree

2 files changed

+59
-56
lines changed
  • cardano-testnet

2 files changed

+59
-56
lines changed

cardano-testnet/src/Testnet/Process/Cli/SPO.hs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ checkStakePoolRegistered
5252
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
5353
=> TmpAbsolutePath
5454
-> ExecConfig
55-
-> FilePath -- ^ Stake pool cold verification key file
55+
-> File (VKey StakeKey) In -- ^ Stake pool cold verification key file
5656
-> FilePath -- ^ Output file path of stake pool info
5757
-> m String -- ^ Stake pool ID
58-
checkStakePoolRegistered tempAbsP execConfig poolColdVkeyFp outputFp =
58+
checkStakePoolRegistered tempAbsP execConfig (File poolColdVkeyFp) outputFp =
5959
GHC.withFrozenCallStack $ do
6060
let tempAbsPath' = unTmpAbsPath tempAbsP
6161
oFpAbs = tempAbsPath' </> outputFp
@@ -160,11 +160,11 @@ createStakeDelegationCertificate
160160
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
161161
=> TmpAbsolutePath
162162
-> ShelleyBasedEra era
163-
-> FilePath -- ^ Delegate stake verification key file
163+
-> File (VKey StakeKey) In -- ^ Delegate stake verification key file
164164
-> String -- ^ Pool id
165165
-> FilePath
166166
-> m ()
167-
createStakeDelegationCertificate tempAbsP sbe delegatorStakeVerKey poolId outputFp =
167+
createStakeDelegationCertificate tempAbsP sbe (File delegatorStakeVerKey) poolId outputFp =
168168
GHC.withFrozenCallStack $ do
169169
let tempAbsPath' = unTmpAbsPath tempAbsP
170170
execCli_
@@ -179,11 +179,11 @@ createStakeKeyRegistrationCertificate
179179
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
180180
=> TmpAbsolutePath
181181
-> AnyShelleyBasedEra
182-
-> FilePath -- ^ Stake verification key file
182+
-> File (VKey StakeKey) In -- ^ Stake verification key file
183183
-> Int -- ^ deposit amount used only in Conway
184184
-> FilePath -- ^ Output file path
185185
-> m ()
186-
createStakeKeyRegistrationCertificate tempAbsP asbe stakeVerKey deposit outputFp = GHC.withFrozenCallStack $ do
186+
createStakeKeyRegistrationCertificate tempAbsP asbe (File stakeVerKey) deposit outputFp = GHC.withFrozenCallStack $ do
187187
AnyShelleyBasedEra sbe <- return asbe
188188
let tempAbsPath' = unTmpAbsPath tempAbsP
189189
extraArgs = monoidForEraInEon @ConwayEraOnwards (toCardanoEra sbe) $
@@ -251,16 +251,12 @@ registerSingleSpo
251251
-> ExecConfig
252252
-> (TxIn, FilePath, String)
253253
-> m ( String
254-
, FilePath
255-
, FilePath
256-
, FilePath
257-
, FilePath
254+
, KeyPair StakeKey
255+
, KeyPair VrfKey
258256
) -- ^ Result tuple:
259257
-- 1. String: Registered stake pool ID
260-
-- 2. FilePath: Stake pool cold signing key
261-
-- 3. FilePath: Stake pool cold verification key
262-
-- 4. FilePath: Stake pool VRF signing key
263-
-- 5. FilePath: Stake pool VRF verification key
258+
-- 2. Stake pool cold keys
259+
-- 3. Stake pool VRF keys
264260
registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile socketPath termEpoch testnetMag execConfig
265261
(fundingInput, fundingSigninKey, changeAddr) = GHC.withFrozenCallStack $ do
266262
workDir <- H.note tempAbsPath'
@@ -276,48 +272,53 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
276272
let spoReqDir = workDir </> "spo-"<> show identifier <> "-requirements"
277273

278274
H.createDirectoryIfMissing_ spoReqDir
279-
let poolOwnerstakeVkeyFp = spoReqDir </> "pool-owner-stake.vkey"
280-
poolOwnerstakeSKeyFp = spoReqDir </> "pool-owner-stake.skey"
275+
let poolOwnerStakeKeys = KeyPair
276+
{ verificationKey = File $ spoReqDir </> "pool-owner-stake.vkey"
277+
, signingKey = File $ spoReqDir </> "pool-owner-stake.skey"
278+
}
281279

282-
cliStakeAddressKeyGen
283-
$ KeyPair (File poolOwnerstakeVkeyFp) (File poolOwnerstakeSKeyFp)
280+
cliStakeAddressKeyGen poolOwnerStakeKeys
284281

285282
poolownerstakeaddr <- filter (/= '\n')
286283
<$> execCli
287284
[ "latest", "stake-address", "build"
288-
, "--stake-verification-key-file", poolOwnerstakeVkeyFp
285+
, "--stake-verification-key-file", verificationKeyFp poolOwnerStakeKeys
289286
, "--testnet-magic", show @Int testnetMag
290287
]
291288

292289
-- 2. Generate stake pool owner payment key pair
293-
let poolOwnerPaymentVkeyFp = spoReqDir </> "pool-owner-payment.vkey"
294-
poolOwnerPaymentSkeyFp = spoReqDir </> "pool-owner-payment.skey"
295-
cliAddressKeyGen
296-
$ KeyPair (File poolOwnerPaymentVkeyFp) (File poolOwnerPaymentSkeyFp)
290+
let poolOwnerPaymentKeys = KeyPair
291+
{ verificationKey = File $ spoReqDir </> "pool-owner-payment.vkey"
292+
, signingKey = File $ spoReqDir </> "pool-owner-payment.skey"
293+
}
294+
cliAddressKeyGen poolOwnerPaymentKeys
297295

298296
poolowneraddresswstakecred <-
299297
execCli [ "latest", "address", "build"
300-
, "--payment-verification-key-file", poolOwnerPaymentVkeyFp
301-
, "--stake-verification-key-file", poolOwnerstakeVkeyFp
298+
, "--payment-verification-key-file", verificationKeyFp poolOwnerPaymentKeys
299+
, "--stake-verification-key-file", verificationKeyFp poolOwnerStakeKeys
302300
, "--testnet-magic", show @Int testnetMag
303301
]
304302

305303
-- 3. Generate pool cold keys
306-
let poolColdVkeyFp = spoReqDir </> "pool-cold.vkey"
307-
poolColdSkeyFp = spoReqDir </> "pool-cold.skey"
304+
let poolColdKeys = KeyPair
305+
{ verificationKey = File $ spoReqDir </> "pool-cold.vkey"
306+
, signingKey = File $ spoReqDir </> "pool-cold.skey"
307+
}
308308

309309
execCli_
310310
[ "latest", "node", "key-gen"
311-
, "--cold-verification-key-file", poolColdVkeyFp
312-
, "--cold-signing-key-file", poolColdSkeyFp
311+
, "--cold-verification-key-file", verificationKeyFp poolColdKeys
312+
, "--cold-signing-key-file", signingKeyFp poolColdKeys
313313
, "--operational-certificate-issue-counter-file", spoReqDir </> "operator.counter"
314314
]
315315

316316
-- 4. Generate VRF keys
317-
let vrfVkeyFp = spoReqDir </> "pool-vrf.vkey"
318-
vrfSkeyFp = spoReqDir </> "pool-vrf.skey"
319-
cliNodeKeyGenVrf
320-
$ KeyPair (File vrfVkeyFp) (File vrfSkeyFp)
317+
let vrfKeys = KeyPair
318+
{ verificationKey = File $ spoReqDir </> "pool-vrf.vkey"
319+
, signingKey = File $ spoReqDir </> "pool-vrf.skey"
320+
}
321+
cliNodeKeyGenVrf vrfKeys
321322

322323
-- 5. Create registration certificate
323324
let poolRegCertFp = spoReqDir </> "registration.cert"
@@ -330,10 +331,10 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
330331
, "--pool-pledge", "0"
331332
, "--pool-cost", "0"
332333
, "--pool-margin", "0"
333-
, "--cold-verification-key-file", poolColdVkeyFp
334-
, "--vrf-verification-key-file", vrfVkeyFp
335-
, "--reward-account-verification-key-file", poolOwnerstakeVkeyFp
336-
, "--pool-owner-stake-verification-key-file", poolOwnerstakeVkeyFp
334+
, "--cold-verification-key-file", verificationKeyFp poolColdKeys
335+
, "--vrf-verification-key-file", verificationKeyFp vrfKeys
336+
, "--reward-account-verification-key-file", verificationKeyFp poolOwnerStakeKeys
337+
, "--pool-owner-stake-verification-key-file", verificationKeyFp poolOwnerStakeKeys
337338
, "--out-file", poolRegCertFp
338339
]
339340

@@ -342,7 +343,7 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
342343

343344
-- Create pledger registration certificate
344345
createStakeKeyRegistrationCertificate tap asbe
345-
poolOwnerstakeVkeyFp
346+
(verificationKey poolOwnerStakeKeys)
346347
400_000
347348
(workDir </> "pledger.regcert")
348349

@@ -365,8 +366,8 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
365366
, "--tx-body-file", workDir </> "pledge-registration-cert.txbody"
366367
, "--testnet-magic", show @Int testnetMag
367368
, "--signing-key-file", fundingSigninKey
368-
, "--signing-key-file", poolOwnerstakeSKeyFp
369-
, "--signing-key-file", poolColdSkeyFp
369+
, "--signing-key-file", signingKeyFp poolOwnerStakeKeys
370+
, "--signing-key-file", signingKeyFp poolColdKeys
370371
, "--out-file", pledgeAndPoolRegistrationTx
371372
]
372373

@@ -397,9 +398,9 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
397398
poolId <- checkStakePoolRegistered
398399
tap
399400
execConfig
400-
poolColdVkeyFp
401+
(verificationKey poolColdKeys)
401402
currentRegistedPoolsJson
402-
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
403+
return (poolId, poolColdKeys, vrfKeys)
403404

404405
-- | Generates Stake Pool Operator (SPO) voting files, using @cardano-cli@.
405406
--

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,30 +112,32 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
112112
let testStakeDelegator = work </> "test-delegator"
113113

114114
H.createDirectoryIfMissing_ testStakeDelegator
115-
let testDelegatorVkeyFp = testStakeDelegator </> "test-delegator.vkey"
116-
testDelegatorSKeyFp = testStakeDelegator </> "test-delegator.skey"
117-
testDelegatorPaymentVKeyFp = testStakeDelegator </> "test-delegator-payment.vkey"
118-
testDelegatorPaymentSKeyFp = testStakeDelegator </> "test-delegator-payment.skey"
115+
let testDelegatorKeys = KeyPair
116+
{ signingKey = File $ testStakeDelegator </> "test-delegator.skey"
117+
, verificationKey = File $ testStakeDelegator </> "test-delegator.vkey"
118+
}
119+
testDelegatorPaymentKeys = KeyPair
120+
{ signingKey = File $ testStakeDelegator </> "test-delegator-payment.skey"
121+
, verificationKey = File $ testStakeDelegator </> "test-delegator-payment.vkey"
122+
}
119123
testDelegatorRegCertFp = testStakeDelegator </> "test-delegator.regcert"
120124
testDelegatorDelegCert = testStakeDelegator </> "test-delegator.delegcert"
121125

122-
cliStakeAddressKeyGen
123-
$ KeyPair (File testDelegatorVkeyFp) (File testDelegatorSKeyFp)
124-
cliAddressKeyGen
125-
$ KeyPair (File testDelegatorPaymentVKeyFp) (File testDelegatorPaymentSKeyFp)
126+
cliStakeAddressKeyGen testDelegatorKeys
127+
cliAddressKeyGen testDelegatorPaymentKeys
126128

127129
-- NB: We must include the stake credential
128130
testDelegatorPaymentAddr <- execCli
129131
[ "latest", "address", "build"
130132
, "--testnet-magic", show @Int testnetMagic
131-
, "--payment-verification-key-file", testDelegatorPaymentVKeyFp
132-
, "--stake-verification-key-file", testDelegatorVkeyFp
133+
, "--payment-verification-key-file", verificationKeyFp testDelegatorPaymentKeys
134+
, "--stake-verification-key-file", verificationKeyFp testDelegatorKeys
133135
]
134136
testDelegatorStakeAddress
135137
<- filter (/= '\n')
136138
<$> execCli
137139
[ "latest", "stake-address", "build"
138-
, "--stake-verification-key-file", testDelegatorVkeyFp
140+
, "--stake-verification-key-file", verificationKeyFp testDelegatorKeys
139141
, "--testnet-magic", show @Int testnetMagic
140142
]
141143

@@ -144,15 +146,15 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
144146
createStakeKeyRegistrationCertificate
145147
tempAbsPath
146148
(cardanoNodeEra cTestnetOptions)
147-
testDelegatorVkeyFp
149+
(verificationKey testDelegatorKeys)
148150
keyDeposit
149151
testDelegatorRegCertFp
150152

151153
-- Test stake address deleg cert
152154
createStakeDelegationCertificate
153155
tempAbsPath
154156
sbe
155-
testDelegatorVkeyFp
157+
(verificationKey testDelegatorKeys)
156158
stakePoolId
157159
testDelegatorDelegCert
158160

@@ -192,7 +194,7 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
192194
, "--tx-body-file", delegRegTestDelegatorTxBodyFp
193195
, "--testnet-magic", show @Int testnetMagic
194196
, "--signing-key-file", utxoSKeyFile
195-
, "--signing-key-file", testDelegatorSKeyFp
197+
, "--signing-key-file", signingKeyFp testDelegatorKeys
196198
, "--out-file", delegRegTestDelegatorTxFp
197199
]
198200

0 commit comments

Comments
 (0)