Skip to content

Commit 1d34a01

Browse files
committed
Refactor function to delegate to automatic DReps
1 parent 59a2463 commit 1d34a01

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
@@ -118,37 +119,22 @@ hprop_check_predefined_abstain_drep = H.integrationWorkspace "test-activity" $ \
118119
void $ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo gov "firstProposal"
119120
wallet0 Nothing [(1, "yes")] newNumberOfDesiredPools initialDesiredNumberOfPools 2
120121

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

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

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

151-
-- | Delegates a staking key pair to an automatic DRep.
152138
delegateToAutomaticDRep
153139
:: (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m)
154140
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
@@ -159,13 +145,11 @@ delegateToAutomaticDRep
159145
-> ShelleyBasedEra ConwayEra -- ^ The Shelley based era witness for ConwayEra
160146
-> FilePath -- ^ Base directory path where generated files will be stored.
161147
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
162-
-> String -- ^ Additional command-line argument for the delegation.
148+
-> AutomaticDRepFlag -- ^ Which type of automatic DRep to delegate to.
163149
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
164150
-> StakingKeyPair -- ^ Staking key pair used for delegation.
165151
-> m ()
166-
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix
167-
flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do
168-
152+
delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath sbe work prefix flag payingWallet skeyPair@(StakingKeyPair vKeyFile _sKeyFile) = do
169153
let era = toCardanoEra sbe
170154
cEra = AnyCardanoEra era
171155

@@ -175,7 +159,9 @@ delegateToAutomaticDRep execConfig epochStateView configurationFile socketPath s
175159
let voteDelegationCertificatePath = baseDir </> "delegation-certificate.delegcert"
176160
void $ H.execCli' execConfig
177161
[ "conway", "stake-address", "vote-delegation-certificate"
178-
, flag
162+
, case flag of
163+
AlwaysAbstainDRep -> "--always-abstain"
164+
NoConfidenceDRep -> "--always-no-confidence"
179165
, "--stake-verification-key-file", vKeyFile
180166
, "--out-file", voteDelegationCertificatePath
181167
]

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 newNumberOfDesiredPools 3
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)