Skip to content

Commit ee8501c

Browse files
authored
Merge pull request #6017 from IntersectMBO/mgalazyn/test/add-stake-address-registration-deregistration-test
cardano-testnet | Add stake address registration/deregistration test
2 parents 4184f92 + 6fa52d3 commit ee8501c

27 files changed

+414
-269
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,31 @@ test-suite cardano-testnet-test
183183

184184
main-is: cardano-testnet-test.hs
185185

186-
other-modules: Cardano.Testnet.Test.Cli.LeadershipSchedule
187-
Cardano.Testnet.Test.Cli.StakeSnapshot
188-
Cardano.Testnet.Test.Cli.Transaction
189-
Cardano.Testnet.Test.Cli.Conway.Plutus
186+
other-modules: Cardano.Testnet.Test.Cli.Conway.Plutus
190187
Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
191188
Cardano.Testnet.Test.Cli.KesPeriodInfo
189+
Cardano.Testnet.Test.Cli.LeadershipSchedule
192190
Cardano.Testnet.Test.Cli.Query
193191
Cardano.Testnet.Test.Cli.QuerySlotNumber
192+
Cardano.Testnet.Test.Cli.StakeSnapshot
193+
Cardano.Testnet.Test.Cli.Transaction
194+
Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
194195
Cardano.Testnet.Test.FoldEpochState
195196
Cardano.Testnet.Test.Gov.CommitteeAddNew
196197
Cardano.Testnet.Test.Gov.DRepActivity
197198
Cardano.Testnet.Test.Gov.DRepDeposit
198199
Cardano.Testnet.Test.Gov.DRepRetirement
200+
Cardano.Testnet.Test.Gov.GovActionTimeout
199201
Cardano.Testnet.Test.Gov.InfoAction
200202
Cardano.Testnet.Test.Gov.NoConfidence
201203
Cardano.Testnet.Test.Gov.PParamChangeFailsSPO
204+
Cardano.Testnet.Test.Gov.PredefinedAbstainDRep
202205
Cardano.Testnet.Test.Gov.ProposeNewConstitution
203206
Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO
204-
Cardano.Testnet.Test.Gov.GovActionTimeout
205207
Cardano.Testnet.Test.Gov.TreasuryDonation
206208
Cardano.Testnet.Test.Gov.TreasuryGrowth
207209
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
208210
Cardano.Testnet.Test.Misc
209-
Cardano.Testnet.Test.Gov.PredefinedAbstainDRep
210211
Cardano.Testnet.Test.Node.Shutdown
211212
Cardano.Testnet.Test.SanityCheck
212213
Cardano.Testnet.Test.SubmitApi.Transaction

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Testnet.Components.Query
3737
, checkDRepState
3838
, assertNewEpochState
3939
, getGovActionLifetime
40+
, getKeyDeposit
4041
) where
4142

4243
import Cardano.Api as Api
@@ -48,7 +49,6 @@ import Cardano.Ledger.Api (ConwayGovState)
4849
import qualified Cardano.Ledger.Api as L
4950
import qualified Cardano.Ledger.Coin as L
5051
import qualified Cardano.Ledger.Conway.Governance as L
51-
import Cardano.Ledger.Conway.PParams (ConwayEraPParams)
5252
import qualified Cardano.Ledger.Conway.PParams as L
5353
import qualified Cardano.Ledger.Shelley.LedgerState as L
5454
import qualified Cardano.Ledger.UTxO as L
@@ -571,11 +571,22 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta
571571
-- The @govActionLifetime@ or governance action maximum lifetime in epochs is
572572
-- the number of epochs such that a governance action submitted during an epoch @e@
573573
-- expires if it is still not ratified as of the end of epoch: @e + govActionLifetime + 1@.
574-
getGovActionLifetime :: (ConwayEraPParams (ShelleyLedgerEra era), H.MonadAssertion m, MonadTest m, MonadIO m)
574+
getGovActionLifetime :: (H.MonadAssertion m, MonadTest m, MonadIO m)
575575
=> EpochStateView
576576
-> ConwayEraOnwards era
577577
-> m EpochInterval
578-
getGovActionLifetime epochStateView ceo = do
578+
getGovActionLifetime epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
579579
govState :: ConwayGovState era <- getGovState epochStateView ceo
580580
return $ govState ^. L.cgsCurPParamsL
581581
. L.ppGovActionLifetimeL
582+
583+
-- | Obtains the key registration deposit from the protocol parameters.
584+
getKeyDeposit :: (H.MonadAssertion m, MonadTest m, MonadIO m)
585+
=> EpochStateView
586+
-> ConwayEraOnwards era
587+
-> m L.Coin
588+
getKeyDeposit epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
589+
govState :: ConwayGovState era <- getGovState epochStateView ceo
590+
return $ govState ^. L.cgsCurPParamsL
591+
. L.ppKeyDepositL
592+

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import qualified Cardano.Api.Shelley as Api
4444
import Cardano.Ledger.Alonzo.Core (PParams (..))
4545
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
4646
import qualified Cardano.Ledger.Alonzo.Genesis as Ledger
47-
import qualified Cardano.Ledger.Api as L
4847
import Cardano.Ledger.BaseTypes
4948
import qualified Cardano.Ledger.BaseTypes as Ledger
5049
import Cardano.Ledger.Binary.Version ()
@@ -388,8 +387,7 @@ defaultShelleyGenesis asbe startTime maxSupply options = do
388387
-- TODO: find out why this actually degrates network stability - turned off for now
389388
-- securityParam = ceiling $ fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
390389
pVer = eraToProtocolVersion asbe
391-
-- TODO: Remove after merging https://github.com/IntersectMBO/cardano-node/pull/6017
392-
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults & L.ppKeyDepositL .~ 0
390+
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults
393391
protocolParamsWithPVer = protocolParams & ppProtocolVersionL' .~ pVer
394392
Api.shelleyGenesisDefaults
395393
{ Api.sgActiveSlotsCoeff = unsafeBoundedRational activeSlotsCoeff

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Testnet.Process.Cli.DRep
1717
) where
1818

1919
import Cardano.Api hiding (Certificate, TxBody)
20+
import Cardano.Api.Experimental (Some (..))
2021
import Cardano.Api.Ledger (EpochInterval (EpochInterval, unEpochInterval))
2122

2223
import Cardano.Testnet (maybeExtractGovernanceActionIndex)
@@ -239,7 +240,7 @@ registerDRep execConfig epochStateView ceo work prefix wallet = do
239240
drepRegTxBody <- createCertificatePublicationTxBody execConfig epochStateView sbe baseDir "reg-cert-txbody"
240241
drepRegCert wallet
241242
drepSignedRegTx <- signTx execConfig cEra baseDir "signed-reg-tx"
242-
drepRegTxBody [SomeKeyPair drepKeyPair, SomeKeyPair $ paymentKeyInfoPair wallet]
243+
drepRegTxBody [Some drepKeyPair, Some $ paymentKeyInfoPair wallet]
243244
submitTx execConfig cEra drepSignedRegTx
244245

245246
return drepKeyPair
@@ -286,8 +287,8 @@ delegateToDRep execConfig epochStateView sbe work prefix
286287

287288
-- Sign transaction
288289
repRegSignedRegTx1 <- signTx execConfig cEra baseDir "signed-reg-tx"
289-
repRegTxBody1 [ SomeKeyPair $ paymentKeyInfoPair payingWallet
290-
, SomeKeyPair skeyPair]
290+
repRegTxBody1 [ Some $ paymentKeyInfoPair payingWallet
291+
, Some skeyPair]
291292

292293
-- Submit transaction
293294
submitTx execConfig cEra repRegSignedRegTx1
@@ -398,7 +399,7 @@ makeActivityChangeProposal execConfig epochStateView ceo work
398399
]
399400

400401
signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal"
401-
(File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet]
402+
(File proposalBody) [Some $ paymentKeyInfoPair wallet]
402403

403404
submitTx execConfig cEra signedProposalTx
404405

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

Lines changed: 54 additions & 54 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,12 +179,11 @@ createStakeKeyRegistrationCertificate
179179
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
180180
=> TmpAbsolutePath
181181
-> AnyShelleyBasedEra
182-
-> FilePath -- ^ Stake verification key file
183-
-> Int -- ^ deposit amount used only in Conway
182+
-> File (VKey StakeKey) In -- ^ Stake verification key file
183+
-> L.Coin -- ^ deposit amount used only in Conway
184184
-> FilePath -- ^ Output file path
185185
-> m ()
186-
createStakeKeyRegistrationCertificate tempAbsP asbe stakeVerKey deposit outputFp = GHC.withFrozenCallStack $ do
187-
AnyShelleyBasedEra sbe <- return asbe
186+
createStakeKeyRegistrationCertificate tempAbsP (AnyShelleyBasedEra sbe) (File stakeVerKey) (L.Coin deposit) outputFp = GHC.withFrozenCallStack $ do
188187
let tempAbsPath' = unTmpAbsPath tempAbsP
189188
extraArgs = monoidForEraInEon @ConwayEraOnwards (toCardanoEra sbe) $
190189
const ["--key-reg-deposit-amt", show deposit]
@@ -201,10 +200,10 @@ createScriptStakeRegistrationCertificate
201200
=> TmpAbsolutePath
202201
-> AnyCardanoEra
203202
-> FilePath -- ^ Script file
204-
-> Int -- ^ Registration deposit amount used only in Conway
203+
-> L.Coin -- ^ Registration deposit amount used only in Conway
205204
-> FilePath -- ^ Output file path
206205
-> m ()
207-
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile deposit outputFp =
206+
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile (L.Coin deposit) outputFp =
208207
GHC.withFrozenCallStack $ do
209208
let tempAbsPath' = unTmpAbsPath tempAbsP
210209
extraArgs = monoidForEraInEon @ConwayEraOnwards cEra $
@@ -221,11 +220,11 @@ createStakeKeyDeregistrationCertificate
221220
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
222221
=> TmpAbsolutePath
223222
-> ShelleyBasedEra era
224-
-> FilePath -- ^ Stake verification key file
225-
-> Int -- ^ deposit amount used only in Conway
223+
-> File (VKey StakeKey) In -- ^ Stake verification key file
224+
-> L.Coin -- ^ deposit amount used only in Conway
226225
-> FilePath -- ^ Output file path
227226
-> m ()
228-
createStakeKeyDeregistrationCertificate tempAbsP sbe stakeVerKey deposit outputFp =
227+
createStakeKeyDeregistrationCertificate tempAbsP sbe (File stakeVerKey) (L.Coin deposit) outputFp =
229228
GHC.withFrozenCallStack $ do
230229
let tempAbsPath' = unTmpAbsPath tempAbsP
231230
extraArgs = monoidForEraInEon @ConwayEraOnwards (toCardanoEra sbe) $
@@ -248,21 +247,18 @@ registerSingleSpo
248247
-> SocketPath
249248
-> EpochNo -- ^ Termination epoch
250249
-> Int -- ^ Testnet magic
250+
-> L.Coin -- ^ key deposit
251251
-> ExecConfig
252-
-> (TxIn, FilePath, String)
252+
-> (TxIn, File (SKey PaymentKey) In, 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
264-
registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile socketPath termEpoch testnetMag execConfig
265-
(fundingInput, fundingSigninKey, changeAddr) = GHC.withFrozenCallStack $ do
258+
-- 2. Stake pool cold keys
259+
-- 3. Stake pool VRF keys
260+
registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile socketPath termEpoch testnetMag keyDeposit execConfig
261+
(fundingInput, File fundingSigninKey, changeAddr) = GHC.withFrozenCallStack $ do
266262
workDir <- H.note tempAbsPath'
267263

268264
-- In order to register a stake pool we need two certificates:
@@ -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,21 +331,20 @@ 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

340341
-- Create pledge delegation certificate
341342
-- NB: Pledger and owner can be the same
342343

343344
-- Create pledger registration certificate
344-
345345
createStakeKeyRegistrationCertificate tap asbe
346-
poolOwnerstakeVkeyFp
347-
0
346+
(verificationKey poolOwnerStakeKeys)
347+
keyDeposit
348348
(workDir </> "pledger.regcert")
349349

350350
void $ execCli' execConfig
@@ -366,8 +366,8 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
366366
, "--tx-body-file", workDir </> "pledge-registration-cert.txbody"
367367
, "--testnet-magic", show @Int testnetMag
368368
, "--signing-key-file", fundingSigninKey
369-
, "--signing-key-file", poolOwnerstakeSKeyFp
370-
, "--signing-key-file", poolColdSkeyFp
369+
, "--signing-key-file", signingKeyFp poolOwnerStakeKeys
370+
, "--signing-key-file", signingKeyFp poolColdKeys
371371
, "--out-file", pledgeAndPoolRegistrationTx
372372
]
373373

@@ -398,9 +398,9 @@ registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigF
398398
poolId <- checkStakePoolRegistered
399399
tap
400400
execConfig
401-
poolColdVkeyFp
401+
(verificationKey poolColdKeys)
402402
currentRegistedPoolsJson
403-
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
403+
return (poolId, poolColdKeys, vrfKeys)
404404

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Testnet.Process.Cli.Transaction
1515
) where
1616

1717
import Cardano.Api hiding (Certificate, TxBody)
18+
import Cardano.Api.Experimental (Some (..))
1819
import Cardano.Api.Ledger (Coin (unCoin))
1920

2021
import Prelude
@@ -146,14 +147,14 @@ signTx
146147
-> FilePath -- ^ Base directory path where the signed transaction file will be stored.
147148
-> String -- ^ Prefix for the output signed transaction file name. The extension will be @.tx@.
148149
-> File TxBody In -- ^ Transaction body to be signed, obtained using 'createCertificatePublicationTxBody' or similar.
149-
-> [SomeKeyPair] -- ^ List of key pairs used for signing the transaction.
150+
-> [Some KeyPair] -- ^ List of key pairs used for signing the transaction.
150151
-> m (File SignedTx In)
151152
signTx execConfig cEra work prefix txBody signatoryKeyPairs = do
152153
let signedTx = File (work </> prefix <> ".tx")
153154
void $ execCli' execConfig $
154155
[ anyEraToString cEra, "transaction", "sign"
155156
, "--tx-body-file", unFile txBody
156-
] ++ (concat [["--signing-key-file", signingKeyFp kp] | SomeKeyPair kp <- signatoryKeyPairs]) ++
157+
] ++ (concat [["--signing-key-file", signingKeyFp kp] | Some kp <- signatoryKeyPairs]) ++
157158
[ "--out-file", unFile signedTx
158159
]
159160
return signedTx

0 commit comments

Comments
 (0)