Skip to content

Commit 6fa52d3

Browse files
committed
cardano-testnet | Refactor: use function for creating registration certificate
1 parent 0e9b91e commit 6fa52d3

File tree

9 files changed

+97
-186
lines changed

9 files changed

+97
-186
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ createScriptStakeRegistrationCertificate
200200
=> TmpAbsolutePath
201201
-> AnyCardanoEra
202202
-> FilePath -- ^ Script file
203-
-> Int -- ^ Registration deposit amount used only in Conway
203+
-> L.Coin -- ^ Registration deposit amount used only in Conway
204204
-> FilePath -- ^ Output file path
205205
-> m ()
206-
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile deposit outputFp =
206+
createScriptStakeRegistrationCertificate tempAbsP (AnyCardanoEra cEra) scriptFile (L.Coin deposit) outputFp =
207207
GHC.withFrozenCallStack $ do
208208
let tempAbsPath' = unTmpAbsPath tempAbsP
209209
extraArgs = monoidForEraInEon @ConwayEraOnwards cEra $
@@ -221,10 +221,10 @@ createStakeKeyDeregistrationCertificate
221221
=> TmpAbsolutePath
222222
-> ShelleyBasedEra era
223223
-> File (VKey StakeKey) In -- ^ Stake verification key file
224-
-> Int -- ^ deposit amount used only in Conway
224+
-> L.Coin -- ^ deposit amount used only in Conway
225225
-> FilePath -- ^ Output file path
226226
-> m ()
227-
createStakeKeyDeregistrationCertificate tempAbsP sbe (File stakeVerKey) deposit outputFp =
227+
createStakeKeyDeregistrationCertificate tempAbsP sbe (File stakeVerKey) (L.Coin deposit) outputFp =
228228
GHC.withFrozenCallStack $ do
229229
let tempAbsPath' = unTmpAbsPath tempAbsP
230230
extraArgs = monoidForEraInEon @ConwayEraOnwards (toCardanoEra sbe) $

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

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,21 @@ module Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
99
) where
1010

1111
import Cardano.Api as Api
12-
import Cardano.Api.Ledger (Coin (..), EpochInterval (..))
1312

14-
import qualified Cardano.Crypto.Hash as L
15-
import qualified Cardano.Ledger.Conway.Governance as L
16-
import qualified Cardano.Ledger.Conway.Governance as Ledger
17-
import qualified Cardano.Ledger.Hashes as L
18-
import qualified Cardano.Ledger.Shelley.LedgerState as L
1913
import Cardano.Testnet
2014

2115
import Prelude
2216

2317
import Control.Monad
24-
import Control.Monad.State.Strict (StateT)
2518
import Data.Default.Class
26-
import Data.Maybe
27-
import Data.Maybe.Strict
28-
import Data.String
2919
import qualified Data.Text as Text
30-
import GHC.Exts (IsList (..))
31-
import Lens.Micro
3220
import System.FilePath ((</>))
3321

3422
import Testnet.Components.Configuration
3523
import Testnet.Components.Query
36-
import Testnet.Defaults
37-
import Testnet.EpochStateProcessing (waitForGovActionVotes)
38-
import Testnet.Process.Cli.DRep
3924
import Testnet.Process.Cli.Keys
40-
import Testnet.Process.Cli.Transaction
25+
import Testnet.Process.Cli.SPO (createStakeKeyDeregistrationCertificate,
26+
createStakeKeyRegistrationCertificate)
4127
import Testnet.Process.Run (execCli', execCliAny, mkExecConfig)
4228
import Testnet.Property.Util (integrationWorkspace)
4329
import Testnet.Start.Types
@@ -83,33 +69,16 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
8369
H.note_ $ "Socketpath: " <> unFile socketPath
8470
H.note_ $ "Foldblocks config file: " <> unFile configurationFile
8571

86-
-- Create Conway constitution
87-
gov <- H.createDirectoryIfMissing $ work </> "governance"
88-
89-
let stakeVkeyFp = gov </> "stake.vkey"
90-
stakeSKeyFp = gov </> "stake.skey"
91-
stakeCertFp = gov </> "stake.regcert"
92-
stakeCertDeregFp = gov </> "stake.deregcert"
93-
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
94-
, signingKey = File stakeSKeyFp
95-
}
96-
97-
cliStakeAddressKeyGen stakeKeys
98-
99-
keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
10072
-- Register stake address
101-
void $ execCli' execConfig
102-
[ eraName, "stake-address", "registration-certificate"
103-
, "--stake-verification-key-file", stakeVkeyFp
104-
, "--key-reg-deposit-amt", keyDepositStr
105-
, "--out-file", stakeCertFp
106-
]
107-
108-
stakeAddress <- H.noteM $ execCli' execConfig
109-
[ eraName, "stake-address", "build"
110-
, "--stake-verification-key-file", stakeVkeyFp
111-
, "--out-file", "/dev/stdout"
112-
]
73+
let stakeCertFp = work </> "stake.regcert"
74+
stakeCertDeregFp = work </> "stake.deregcert"
75+
stakeKeys = KeyPair { verificationKey = File $ work </> "stake.vkey"
76+
, signingKey = File $ work </> "stake.skey"
77+
}
78+
cliStakeAddressKeyGen stakeKeys
79+
keyDeposit <- getKeyDeposit epochStateView ceo
80+
createStakeKeyRegistrationCertificate
81+
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
11382

11483
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
11584
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
@@ -132,7 +101,7 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
132101
[ eraName, "transaction", "sign"
133102
, "--tx-body-file", stakeCertTxBodyFp
134103
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0
135-
, "--signing-key-file", stakeSKeyFp
104+
, "--signing-key-file", signingKeyFp stakeKeys
136105
, "--out-file", stakeCertTxSignedFp
137106
]
138107

@@ -143,22 +112,9 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
143112

144113
H.noteShowM_ $ waitForBlocks epochStateView 1
145114

146-
do
147-
(_, stdout', stderr') <- execCliAny execConfig
148-
[ eraName, "query", "stake-address-info"
149-
, "--address", stakeAddress
150-
, "--out-file", "/dev/stdout"
151-
]
152-
H.note_ stdout'
153-
H.note_ stderr'
154-
155115
-- deregister stake address
156-
void $ execCli' execConfig
157-
[ eraName, "stake-address", "deregistration-certificate"
158-
, "--stake-verification-key-file", stakeVkeyFp
159-
, "--key-reg-deposit-amt", keyDepositStr
160-
, "--out-file", stakeCertDeregFp
161-
]
116+
createStakeKeyDeregistrationCertificate
117+
tempAbsPath sbe (verificationKey stakeKeys) keyDeposit stakeCertDeregFp
162118

163119
stakeCertDeregTxBodyFp <- H.note $ work </> "stake.deregistration.txbody"
164120
stakeCertDeregTxSignedFp <- H.note $ work </> "stake.deregistration.tx"
@@ -181,7 +137,7 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
181137
[ eraName, "transaction", "sign"
182138
, "--tx-body-file", stakeCertDeregTxBodyFp
183139
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
184-
, "--signing-key-file", stakeSKeyFp
140+
, "--signing-key-file", signingKeyFp stakeKeys
185141
, "--out-file", stakeCertDeregTxSignedFp
186142
]
187143

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Testnet.EpochStateProcessing (waitForGovActionVotes)
4242
import qualified Testnet.Process.Cli.DRep as DRep
4343
import Testnet.Process.Cli.Keys
4444
import qualified Testnet.Process.Cli.SPO as SPO
45+
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
4546
import Testnet.Process.Cli.Transaction
4647
import Testnet.Process.Run (execCli', mkExecConfig)
4748
import Testnet.Property.Util (integrationWorkspace)
@@ -119,23 +120,16 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
119120

120121
let ccColdSKeyFp n = gov </> "cc-" <> show n <> "-cold.skey"
121122
ccColdVKeyFp n = gov </> "cc-" <> show n <> "-cold.vkey"
122-
stakeVkeyFp = gov </> "stake.vkey"
123-
stakeSKeyFp = gov </> "stake.skey"
124123
stakeCertFp = gov </> "stake.regcert"
124+
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
125+
, signingKey = File $ gov </> "stake.skey"
126+
}
125127

126-
cliStakeAddressKeyGen
127-
$ KeyPair { verificationKey = File stakeVkeyFp
128-
, signingKey = File stakeSKeyFp
129-
}
130-
131-
keyDepositStr <- show . L.unCoin <$> getKeyDeposit epochStateView ceo
132-
-- Register stake address
133-
void $ execCli' execConfig
134-
[ eraName, "stake-address", "registration-certificate"
135-
, "--stake-verification-key-file", stakeVkeyFp
136-
, "--key-reg-deposit-amt", keyDepositStr
137-
, "--out-file", stakeCertFp
138-
]
128+
-- Register new stake address
129+
cliStakeAddressKeyGen stakeKeys
130+
keyDeposit <- getKeyDeposit epochStateView ceo
131+
createStakeKeyRegistrationCertificate
132+
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
139133

140134
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
141135
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
@@ -156,7 +150,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
156150
[ eraName, "transaction", "sign"
157151
, "--tx-body-file", stakeCertTxBodyFp
158152
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
159-
, "--signing-key-file", stakeSKeyFp
153+
, "--signing-key-file", signingKeyFp stakeKeys
160154
, "--out-file", stakeCertTxSignedFp
161155
]
162156

@@ -191,7 +185,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
191185
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
192186
, "--anchor-data-hash", proposalAnchorDataHash
193187
, "--governance-action-deposit", show minGovActDeposit
194-
, "--deposit-return-stake-verification-key-file", stakeVkeyFp
188+
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
195189
, "--threshold", "0.2"
196190
, "--out-file", updateCommitteeFp
197191
]

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Testnet.Components.Query
3636
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
3737
import Testnet.Process.Cli.DRep
3838
import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen)
39+
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
3940
import Testnet.Process.Cli.Transaction
4041
import Testnet.Process.Run (execCli', mkExecConfig)
4142
import Testnet.Property.Util (integrationWorkspace)
@@ -89,23 +90,15 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP
8990

9091
gov <- H.createDirectoryIfMissing $ work </> "governance"
9192

92-
let stakeVkeyFp = gov </> "stake.vkey"
93-
stakeSKeyFp = gov </> "stake.skey"
94-
stakeCertFp = gov </> "stake.regcert"
95-
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
96-
, signingKey = File stakeSKeyFp
93+
-- Register stake address
94+
let stakeCertFp = gov </> "stake.regcert"
95+
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
96+
, signingKey = File $ gov </> "stake.skey"
9797
}
98-
9998
cliStakeAddressKeyGen stakeKeys
100-
101-
-- Register stake address
102-
103-
void $ execCli' execConfig
104-
[ eraName, "stake-address", "registration-certificate"
105-
, "--stake-verification-key-file", stakeVkeyFp
106-
, "--key-reg-deposit-amt", show @Int 0 -- TODO: why this needs to be 0????
107-
, "--out-file", stakeCertFp
108-
]
99+
keyDeposit <- getKeyDeposit epochStateView ceo
100+
createStakeKeyRegistrationCertificate
101+
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
109102

110103
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
111104
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
@@ -126,7 +119,7 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP
126119
[ eraName, "transaction", "sign"
127120
, "--tx-body-file", stakeCertTxBodyFp
128121
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
129-
, "--signing-key-file", stakeSKeyFp
122+
, "--signing-key-file", signingKeyFp stakeKeys
130123
, "--out-file", stakeCertTxSignedFp
131124
]
132125

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Cardano.Testnet.Test.Gov.GovActionTimeout
1111
) where
1212

1313
import Cardano.Api as Api
14-
import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval, unEpochInterval))
14+
import Cardano.Api.Ledger (EpochInterval (..))
1515

1616
import Cardano.Testnet
1717

@@ -26,6 +26,7 @@ import System.FilePath ((</>))
2626
import Testnet.Components.Query
2727
import Testnet.Process.Cli.DRep (makeActivityChangeProposal)
2828
import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen)
29+
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
2930
import Testnet.Process.Run (execCli', mkExecConfig)
3031
import Testnet.Property.Util (integrationWorkspace)
3132
import Testnet.Start.Types
@@ -85,23 +86,16 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
8586
govActionLifetime <- getGovActionLifetime epochStateView ceo
8687
H.note_ $ "govActionLifetime: " <> show govActionLifetime
8788

88-
let stakeVkeyFp = gov </> "stake.vkey"
89-
stakeSKeyFp = gov </> "stake.skey"
90-
stakeCertFp = gov </> "stake.regcert"
91-
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
92-
, signingKey = File stakeSKeyFp
93-
}
94-
89+
-- Register stake address
90+
let stakeCertFp = gov </> "stake.regcert"
91+
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
92+
, signingKey = File $ gov </> "stake.skey"
93+
}
9594
cliStakeAddressKeyGen stakeKeys
95+
keyDeposit <- getKeyDeposit epochStateView ceo
96+
createStakeKeyRegistrationCertificate
97+
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
9698

97-
keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
98-
-- Register stake address
99-
void $ execCli' execConfig
100-
[ eraName, "stake-address", "registration-certificate"
101-
, "--stake-verification-key-file", stakeVkeyFp
102-
, "--key-reg-deposit-amt", keyDepositStr
103-
, "--out-file", stakeCertFp
104-
]
10599

106100
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
107101
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
@@ -122,7 +116,7 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
122116
[ eraName, "transaction", "sign"
123117
, "--tx-body-file", stakeCertTxBodyFp
124118
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet1
125-
, "--signing-key-file", stakeSKeyFp
119+
, "--signing-key-file", signingKeyFp stakeKeys
126120
, "--out-file", stakeCertTxSignedFp
127121
]
128122

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Cardano.Testnet.Test.Gov.InfoAction
1313

1414
import Cardano.Api as Api
1515
import Cardano.Api.Error (displayError)
16-
import Cardano.Api.Ledger (Coin (..), EpochInterval (EpochInterval))
16+
import Cardano.Api.Ledger (EpochInterval (EpochInterval))
1717
import Cardano.Api.Shelley
1818

1919
import Cardano.Ledger.Conway.Governance (RatifyState (..))
@@ -36,6 +36,7 @@ import System.FilePath ((</>))
3636
import Testnet.Components.Query
3737
import Testnet.Defaults
3838
import Testnet.Process.Cli.Keys
39+
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
3940
import Testnet.Process.Run (execCli', mkExecConfig)
4041
import Testnet.Property.Util (integrationRetryWorkspace)
4142
import Testnet.Start.Types
@@ -93,23 +94,15 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
9394
[ "hash", "anchor-data", "--file-text", proposalAnchorFile
9495
]
9596

96-
let stakeVkeyFp = gov </> "stake.vkey"
97-
stakeSKeyFp = gov </> "stake.skey"
98-
stakeCertFp = gov </> "stake.regcert"
99-
stakeKeys = KeyPair { verificationKey = File stakeVkeyFp
100-
, signingKey = File stakeSKeyFp
97+
-- Register stake address
98+
let stakeCertFp = gov </> "stake.regcert"
99+
stakeKeys = KeyPair { verificationKey = File $ gov </> "stake.vkey"
100+
, signingKey = File $ gov </> "stake.skey"
101101
}
102-
103102
cliStakeAddressKeyGen stakeKeys
104-
105-
-- Register stake address
106-
keyDepositStr <- show . unCoin <$> getKeyDeposit epochStateView ceo
107-
void $ execCli' execConfig
108-
[ eraName, "stake-address", "registration-certificate"
109-
, "--stake-verification-key-file", stakeVkeyFp
110-
, "--key-reg-deposit-amt", keyDepositStr
111-
, "--out-file", stakeCertFp
112-
]
103+
keyDeposit <- getKeyDeposit epochStateView ceo
104+
createStakeKeyRegistrationCertificate
105+
tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
113106

114107
stakeCertTxBodyFp <- H.note $ work </> "stake.registration.txbody"
115108
stakeCertTxSignedFp <- H.note $ work </> "stake.registration.tx"
@@ -130,7 +123,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
130123
[ eraName, "transaction", "sign"
131124
, "--tx-body-file", stakeCertTxBodyFp
132125
, "--signing-key-file", signingKeyFp $ paymentKeyInfoPair wallet0
133-
, "--signing-key-file", stakeSKeyFp
126+
, "--signing-key-file", signingKeyFp stakeKeys
134127
, "--out-file", stakeCertTxSignedFp
135128
]
136129

@@ -145,7 +138,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
145138
[ eraName, "governance", "action", "create-info"
146139
, "--testnet"
147140
, "--governance-action-deposit", show @Int 1_000_000 -- TODO: Get this from the node
148-
, "--deposit-return-stake-verification-key-file", stakeVkeyFp
141+
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
149142
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
150143
, "--anchor-data-hash", proposalAnchorDataHash
151144
, "--out-file", infoActionFp

0 commit comments

Comments
 (0)