Skip to content

Commit fa3e340

Browse files
committed
Refactor function to delegate to automatic DReps
1 parent 6268c52 commit fa3e340

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/LedgerEvents/Gov/PredefinedAbstainDRep.hs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
{-# LANGUAGE TypeApplications #-}
88

99
module Cardano.Testnet.Test.LedgerEvents.Gov.PredefinedAbstainDRep
10-
( hprop_check_predefined_abstain_drep
10+
( AutomaticDRepFlag(..)
11+
, hprop_check_predefined_abstain_drep
1112
, delegateToAutomaticDRep
1213
, desiredPoolNumberProposalTest
1314
, getDesiredPoolNumberValue
@@ -120,37 +121,22 @@ hprop_check_predefined_abstain_drep = H.integrationWorkspace "test-activity" $ \
120121
void $ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "firstProposal"
121122
wallet0 Nothing [(1, "yes")] newNumberOfDesiredPools 3 (Just initialDesiredNumberOfPools) 10
122123

123-
-- Take the last two stake delegators and delegate them to "Abstain".
124-
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain1"
125-
wallet1 (defaultDelegatorStakeKeyPair 2)
126-
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain2"
127-
wallet2 (defaultDelegatorStakeKeyPair 3)
124+
-- Take the last two stake delegators and delegate them to "AlwaysAbstainDRep".
125+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain1"
126+
AlwaysAbstainDRep wallet1 (defaultDelegatorStakeKeyPair 2)
127+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe gov "delegateToAbstain2"
128+
AlwaysAbstainDRep wallet2 (defaultDelegatorStakeKeyPair 3)
128129

129130
-- Do some other proposal and vote yes with first DRep only
130131
-- and assert the new proposal passes now.
131132
let newNumberOfDesiredPools2 = newNumberOfDesiredPools + 1
132133
void $ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "secondProposal"
133134
wallet0 Nothing [(1, "yes")] newNumberOfDesiredPools2 0 (Just newNumberOfDesiredPools2) 10
134135

135-
-- | Delegates a staking key pair to the "always abstain" automated DRep
136-
delegateToAlwaysAbstain
137-
:: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m)
138-
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
139-
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
140-
-- using the 'getEpochStateView' function.
141-
-> FilePath -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'.
142-
-> FilePath -- ^ Path to the cardano-node unix socket file.
143-
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
144-
-> FilePath -- ^ Base directory path where generated files will be stored.
145-
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
146-
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
147-
-> StakingKeyPair -- ^ Staking key pair used for delegation.
148-
-> m ()
149-
delegateToAlwaysAbstain execConfig epochStateView configurationFile socketPath sbe work prefix =
150-
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
151-
"--always-abstain"
136+
-- | Which automatic DRep to delegate to
137+
data AutomaticDRepFlag = AlwaysAbstainDRep
138+
| NoConfidenceDRep
152139

153-
-- | Delegates a staking key pair to an automatic DRep.
154140
delegateToAutomaticDRep
155141
:: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m)
156142
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
@@ -161,13 +147,11 @@ delegateToAutomaticDRep
161147
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
162148
-> FilePath -- ^ Base directory path where generated files will be stored.
163149
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
164-
-> String -- ^ Additional command-line argument for the delegation.
150+
-> AutomaticDRepFlag -- ^ Which type of automatic DRep to delegate to.
165151
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
166152
-> StakingKeyPair -- ^ Staking key pair used for delegation.
167153
-> m ()
168-
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
169-
flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do
170-
154+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do
171155
let era = toCardanoEra sbe
172156
cEra = AnyCardanoEra era
173157

@@ -177,7 +161,9 @@ delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath s
177161
let voteDelegationCertificatePath = baseDir </> "delegation-certificate.delegcert"
178162
void $ H.execCli' execConfig
179163
[ "conway", "stake-address", "vote-delegation-certificate"
180-
, flag
164+
, case flag of
165+
AlwaysAbstainDRep -> "--always-abstain"
166+
NoConfidenceDRep -> "--always-no-confidence"
181167
, "--stake-verification-key-file", vKeyFile
182168
, "--out-file", voteDelegationCertificatePath
183169
]

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/LedgerEvents/Gov/PredefinedNoConfidenceDRep.hs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import qualified Cardano.Ledger.Conway.Governance as L
1818
import qualified Cardano.Ledger.Shelley.LedgerState as L
1919
import Cardano.Testnet
2020
import Cardano.Testnet.Test.LedgerEvents.Gov.PredefinedAbstainDRep
21-
(delegateToAutomaticDRep, desiredPoolNumberProposalTest,
22-
getDesiredPoolNumberValue, voteChangeProposal)
21+
(desiredPoolNumberProposalTest,
22+
getDesiredPoolNumberValue, voteChangeProposal, delegateToAutomaticDRep, AutomaticDRepFlag (..))
2323

2424
import Prelude
2525

@@ -109,11 +109,11 @@ hprop_check_predefined_no_confidence_drep = H.integrationWorkspace "test-activit
109109
firstProposalInfo <- desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "firstProposal"
110110
wallet1 Nothing [(3, "yes")] newNumberOfDesiredPools 0 (Just newNumberOfDesiredPools) 10
111111

112-
-- Take the last two stake delegators and delegate them to "No Confidence".
113-
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe gov "delegateToNoConfidence1"
114-
wallet2 (defaultDelegatorStakeKeyPair 2)
115-
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe gov "delegateToNoConfidence2"
116-
wallet2 (defaultDelegatorStakeKeyPair 3)
112+
-- Take the last two stake delegators and delegate them to "No Confidence" automatic DRep.
113+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work
114+
"delegateToNoConfidence1" NoConfidenceDRep wallet2 (defaultDelegatorStakeKeyPair 2)
115+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work
116+
"delegateToNoConfidence2" NoConfidenceDRep wallet2 (defaultDelegatorStakeKeyPair 3)
117117

118118
-- Do some other proposal and vote yes with all the DReps
119119
-- and assert the new proposal does NOT pass.
@@ -317,24 +317,6 @@ makeUpdateConstitutionalCommitteeProposal execConfig epochStateView configuratio
317317

318318
return (governanceActionTxId, governanceActionIndex)
319319

320-
-- | Delegate a staking key pair to the automated no confidence DRep.
321-
delegateToAlwaysNoConfidence
322-
:: (MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m, HasCallStack)
323-
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
324-
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
325-
-- using the 'getEpochStateView' function.
326-
-> FilePath -- ^ Path to the node configuration file as returned by 'cardanoTestnetDefault'.
327-
-> FilePath -- ^ Path to the cardano-node unix socket file.
328-
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
329-
-> FilePath -- ^ Base directory path where generated files will be stored.
330-
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
331-
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
332-
-> StakingKeyPair -- ^ Staking key pair used for delegation.
333-
-> m ()
334-
delegateToAlwaysNoConfidence execConfig epochStateView configurationFile socketPath sbe work prefix =
335-
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
336-
"--always-no-confidence"
337-
338320
-- Run a no confidence motion and check the result. Vote "yes" with 3 SPOs. Check the no
339321
-- confidence motion passes.
340322
testNoConfidenceProposal

0 commit comments

Comments
 (0)