Skip to content

Commit 8bdf6b5

Browse files
committed
Repeated certs test
1 parent 8430590 commit 8bdf6b5

File tree

11 files changed

+240
-80
lines changed

11 files changed

+240
-80
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ test-suite cardano-testnet-test
173173
Cardano.Testnet.Test.Cli.Babbage.Transaction
174174
Cardano.Testnet.Test.Cli.Conway.DRepRetirement
175175
Cardano.Testnet.Test.Cli.Conway.Plutus
176+
Cardano.Testnet.Test.Cli.Conway.RepeatedCertificatesInTransaction
176177
Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
177178
Cardano.Testnet.Test.Cli.KesPeriodInfo
178179
Cardano.Testnet.Test.Cli.Queries

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

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{-# LANGUAGE GADTs #-}
22
{-# LANGUAGE NumericUnderscores #-}
3+
{-# LANGUAGE RankNTypes #-}
34
{-# LANGUAGE TypeApplications #-}
45

56

67
module Testnet.Components.SPO
78
( checkStakeKeyRegistered
8-
, convertToEraFlag
99
, createScriptStakeRegistrationCertificate
1010
, createStakeDelegationCertificate
1111
, createStakeKeyRegistrationCertificate
12+
, createStakeKeyDeregistrationCertificate
1213
, decodeEraUTxO
1314
, registerSingleSpo
1415
) where
@@ -22,7 +23,7 @@ import qualified Data.Map.Strict as Map
2223
import Data.Set (Set)
2324
import qualified Data.Set as Set
2425
import qualified Data.Text as Text
25-
import GHC.Stack (HasCallStack)
26+
import GHC.Stack (HasCallStack, withFrozenCallStack)
2627
import qualified GHC.Stack as GHC
2728
import System.FilePath.Posix ((</>))
2829

@@ -118,9 +119,9 @@ createStakeDelegationCertificate
118119
createStakeDelegationCertificate tempAbsP anyCera delegatorStakeVerKey poolId outputFp =
119120
GHC.withFrozenCallStack $ do
120121
let tempAbsPath' = unTmpAbsPath tempAbsP
121-
void $ execCli
122-
[ "stake-address", "delegation-certificate"
123-
, convertToEraFlag anyCera
122+
execCli_
123+
[ anyEraToString anyCera
124+
, "stake-address", "delegation-certificate"
124125
, "--stake-verification-key-file", delegatorStakeVerKey
125126
, "--stake-pool-id", poolId
126127
, "--out-file", tempAbsPath' </> outputFp
@@ -131,18 +132,23 @@ createStakeKeyRegistrationCertificate
131132
=> TmpAbsolutePath
132133
-> AnyCardanoEra
133134
-> FilePath -- ^ Stake verification key file
135+
-> Int -- ^ deposit amount used only in Conway
134136
-> FilePath -- ^ Output file path
135137
-> m ()
136-
createStakeKeyRegistrationCertificate tempAbsP anyCEra stakeVerKey outputFp =
137-
GHC.withFrozenCallStack $ do
138-
let tempAbsPath' = unTmpAbsPath tempAbsP
139-
140-
void $ execCli
141-
[ "stake-address", "registration-certificate"
142-
, convertToEraFlag anyCEra
143-
, "--stake-verification-key-file", stakeVerKey
144-
, "--out-file", tempAbsPath' </> outputFp
145-
]
138+
createStakeKeyRegistrationCertificate tempAbsP (AnyCardanoEra cEra) stakeVerKey deposit outputFp = GHC.withFrozenCallStack $ do
139+
sbe <- requireEon ShelleyEra cEra
140+
let tempAbsPath' = unTmpAbsPath tempAbsP
141+
extraArgs = caseShelleyToBabbageOrConwayEraOnwards
142+
(const [])
143+
(const ["--key-reg-deposit-amt", show deposit])
144+
sbe
145+
execCli_ $
146+
[ eraToString cEra
147+
, "stake-address", "registration-certificate"
148+
, "--stake-verification-key-file", stakeVerKey
149+
, "--out-file", tempAbsPath' </> outputFp
150+
]
151+
<> extraArgs
146152

147153
createScriptStakeRegistrationCertificate
148154
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
@@ -155,20 +161,39 @@ createScriptStakeRegistrationCertificate
155161
createScriptStakeRegistrationCertificate tempAbsP anyCEra scriptFile deposit outputFp =
156162
GHC.withFrozenCallStack $ do
157163
let tempAbsPath' = unTmpAbsPath tempAbsP
158-
159-
void $ execCli
164+
execCli_
160165
[ anyEraToString anyCEra
161166
, "stake-address", "registration-certificate"
162167
, "--stake-script-file", scriptFile
163168
, "--key-reg-deposit-amt", show deposit
164169
, "--out-file", tempAbsPath' </> outputFp
165170
]
166171

167-
168-
-- TODO: Remove me and replace with new era based commands
169-
-- i.e "conway", "babbage" etc
170-
convertToEraFlag :: AnyCardanoEra -> String
171-
convertToEraFlag era = "--" <> anyEraToString era <> "-era"
172+
createStakeKeyDeregistrationCertificate
173+
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
174+
=> TmpAbsolutePath
175+
-> AnyCardanoEra
176+
-> FilePath -- ^ Stake verification key file
177+
-> Int -- ^ deposit amount used only in Conway
178+
-> FilePath -- ^ Output file path
179+
-> m ()
180+
createStakeKeyDeregistrationCertificate tempAbsP (AnyCardanoEra cEra) stakeVerKey deposit outputFp =
181+
GHC.withFrozenCallStack $ do
182+
sbe <- requireEon ShelleyEra cEra
183+
let tempAbsPath' = unTmpAbsPath tempAbsP
184+
extraArgs = caseShelleyToBabbageOrConwayEraOnwards
185+
(const [])
186+
(const ["--key-reg-deposit-amt", show deposit])
187+
sbe
188+
189+
execCli_ $
190+
[ eraToString cEra
191+
, "stake-address"
192+
, "deregistration-certificate"
193+
, "--stake-verification-key-file", stakeVerKey
194+
, "--out-file", tempAbsPath' </> outputFp
195+
]
196+
<> extraArgs
172197

173198
-- | Related documentation: https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/stake-pool-operations/8_register_stakepool.md
174199
registerSingleSpo
@@ -192,7 +217,6 @@ registerSingleSpo
192217
registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions execConfig
193218
(fundingInput, fundingSigninKey, changeAddr) = GHC.withFrozenCallStack $ do
194219
let testnetMag = cardanoTestnetMagic cTestnetOptions
195-
eraFlag= convertToEraFlag $ cardanoNodeEra cTestnetOptions
196220

197221
workDir <- H.note tempAbsPath'
198222

@@ -251,11 +275,12 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
251275

252276
-- 5. Create registration certificate
253277
let poolRegCertFp = spoReqDir </> "registration.cert"
278+
let era = cardanoNodeEra cTestnetOptions
254279

255280
-- The pledge, pool cost and pool margin can all be 0
256281
execCli_
257-
[ "stake-pool", "registration-certificate"
258-
, "--babbage-era"
282+
[ anyEraToString era
283+
, "stake-pool", "registration-certificate"
259284
, "--testnet-magic", show @Int testnetMag
260285
, "--pool-pledge", "0"
261286
, "--pool-cost", "0"
@@ -272,15 +297,14 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
272297

273298
-- Create pledger registration certificate
274299

275-
createStakeKeyRegistrationCertificate
276-
tap
277-
(cardanoNodeEra cTestnetOptions)
300+
createStakeKeyRegistrationCertificate tap era
278301
poolOwnerstakeVkeyFp
302+
2_000_000
279303
(workDir </> "pledger.regcert")
280304

281305
void $ execCli' execConfig
282-
[ "transaction", "build"
283-
, eraFlag
306+
[ anyEraToString era
307+
, "transaction", "build"
284308
, "--change-address", changeAddr
285309
, "--tx-in", Text.unpack $ renderTxIn fundingInput
286310
, "--tx-out", poolowneraddresswstakecred <> "+" <> show @Int 5_000_000
@@ -332,3 +356,17 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
332356
currentRegistedPoolsJson
333357
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
334358

359+
360+
requireEon :: forall eon era minEra m. Eon eon
361+
=> MonadTest m
362+
=> CardanoEra minEra -- ^ minimal required era i.e. for 'ConwayEraOnwards' eon it's 'Conway'
363+
-> CardanoEra era -- ^ node era
364+
-> m (eon era)
365+
-- TODO: implement 'Bounded' for `Some eon` and remove 'minEra'
366+
requireEon minEra era = withFrozenCallStack $
367+
maybe
368+
(H.note_ errorMessage >> failure)
369+
pure
370+
(forEraMaybeEon era)
371+
where
372+
errorMessage = "Required at least " <> eraToString minEra <> ". Tried to execute in " <> eraToString era <> "."

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE BlockArguments #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE DisambiguateRecordFields #-}
43
{-# LANGUAGE NamedFieldPuns #-}
54
{-# LANGUAGE NumericUnderscores #-}
@@ -135,6 +134,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
135134
tempAbsPath
136135
(cardanoNodeEra cTestnetOptions)
137136
testDelegatorVkeyFp
137+
2_000_000
138138
testDelegatorRegCertFp
139139

140140
-- Test stake address deleg cert
@@ -161,12 +161,12 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
161161
UTxO utxo2 <- H.noteShowM $ decodeEraUTxO sbe utxo2Json
162162
txin2 <- H.noteShow =<< H.headM (Map.keys utxo2)
163163

164-
let eraFlag = convertToEraFlag $ cardanoNodeEra cTestnetOptions
164+
let eraString = anyEraToString $ cardanoNodeEra cTestnetOptions
165165
delegRegTestDelegatorTxBodyFp = work </> "deleg-register-test-delegator.txbody"
166166

167167
void $ execCli' execConfig
168-
[ "transaction", "build"
169-
, eraFlag
168+
[ eraString
169+
, "transaction", "build"
170170
, "--change-address", testDelegatorPaymentAddr -- NB: A large balance ends up at our test delegator's address
171171
, "--tx-in", Text.unpack $ renderTxIn txin2
172172
, "--tx-out", utxoAddr <> "+" <> show @Int 5_000_000

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE DisambiguateRecordFields #-}
32
{-# LANGUAGE LambdaCase #-}
43
{-# LANGUAGE NamedFieldPuns #-}

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
{-# LANGUAGE ScopedTypeVariables #-}
88
{-# LANGUAGE TypeApplications #-}
99

10-
#if __GLASGOW_HASKELL__ >= 908
11-
{-# OPTIONS_GHC -Wno-x-partial #-}
12-
#endif
13-
14-
{- HLINT ignore "Use head" -}
15-
1610
module Cardano.Testnet.Test.Cli.Conway.DRepRetirement
1711
( hprop_drep_retirement
1812
) where
@@ -64,7 +58,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
6458
TestnetRuntime
6559
{ testnetMagic
6660
, poolNodes
67-
, wallets
61+
, wallets=wallet0:_
6862
, configurationFile
6963
}
7064
<- cardanoTestnetDefault fastTestnetOptions conf
@@ -111,7 +105,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
111105
, "--out-file", drepCertFile n
112106
]
113107

114-
txin1 <- findLargestUtxoForPaymentKey epochStateView sbe $ wallets !! 0
108+
txin1 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
115109

116110
-- Submit registration certificates
117111
drepRegTxbodyFp <- H.note $ work </> "drep.registration.txbody"
@@ -120,7 +114,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
120114
H.noteM_ $ H.execCli' execConfig
121115
[ "conway", "transaction", "build"
122116
, "--tx-in", Text.unpack $ renderTxIn txin1
123-
, "--change-address", Text.unpack $ paymentKeyInfoAddr $ wallets !! 0
117+
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
124118
, "--certificate-file", drepCertFile 1
125119
, "--certificate-file", drepCertFile 2
126120
, "--certificate-file", drepCertFile 3
@@ -131,7 +125,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
131125
H.noteM_ $ H.execCli' execConfig
132126
[ "conway", "transaction", "sign"
133127
, "--tx-body-file", drepRegTxbodyFp
134-
, "--signing-key-file", paymentSKey $ paymentKeyInfoPair $ wallets !! 0
128+
, "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0
135129
, "--signing-key-file", drepSKeyFp 1
136130
, "--signing-key-file", drepSKeyFp 2
137131
, "--signing-key-file", drepSKeyFp 3
@@ -161,20 +155,20 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
161155

162156
H.noteM_ $ H.execCli' execConfig
163157
[ "conway", "query", "utxo"
164-
, "--address", Text.unpack $ paymentKeyInfoAddr $ wallets !! 0
158+
, "--address", Text.unpack $ paymentKeyInfoAddr wallet0
165159
, "--cardano-mode"
166160
, "--out-file", work </> "utxo-11.json"
167161
]
168162

169-
txin2 <- findLargestUtxoForPaymentKey epochStateView sbe $ wallets !! 0
163+
txin2 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
170164

171165
drepRetirementRegTxbodyFp <- H.note $ work </> "drep.retirement.txbody"
172166
drepRetirementRegTxSignedFp <- H.note $ work </> "drep.retirement.tx"
173167

174168
H.noteM_ $ H.execCli' execConfig
175169
[ "conway", "transaction", "build"
176170
, "--tx-in", Text.unpack $ renderTxIn txin2
177-
, "--change-address", Text.unpack $ paymentKeyInfoAddr $ wallets !! 0
171+
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
178172
, "--certificate-file", dreprRetirementCertFile
179173
, "--witness-override", "2"
180174
, "--out-file", drepRetirementRegTxbodyFp
@@ -183,7 +177,7 @@ hprop_drep_retirement = H.integrationRetryWorkspace 2 "drep-retirement" $ \tempA
183177
H.noteM_ $ H.execCli' execConfig
184178
[ "conway", "transaction", "sign"
185179
, "--tx-body-file", drepRetirementRegTxbodyFp
186-
, "--signing-key-file", paymentSKey $ paymentKeyInfoPair $ wallets !! 0
180+
, "--signing-key-file", paymentSKey $ paymentKeyInfoPair wallet0
187181
, "--signing-key-file", drepSKeyFp 1
188182
, "--out-file", drepRetirementRegTxSignedFp
189183
]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
{- HLINT ignore "Redundant id" -}
1111
{- HLINT ignore "Redundant return" -}
1212
{- HLINT ignore "Use head" -}
13-
{- HLINT ignore "Use let" -}
1413

1514
module Cardano.Testnet.Test.Cli.Conway.Plutus
1615
( hprop_plutus_v3

0 commit comments

Comments
 (0)