Skip to content

Commit 429bc3a

Browse files
committed
Finish implementation of Predefined No Confidence DRep test
1 parent e11bbcf commit 429bc3a

File tree

3 files changed

+254
-74
lines changed

3 files changed

+254
-74
lines changed

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

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ import GHC.Stack (HasCallStack, callStack)
3434
import Lens.Micro ((^.))
3535
import System.FilePath ((</>))
3636

37+
import qualified Testnet.Components.DReps as DRep
3738
import Testnet.Components.DReps (createCertificatePublicationTxBody, createVotingTxBody,
38-
generateVoteFiles, retrieveTransactionId, signTx, submitTx)
39+
retrieveTransactionId, signTx, submitTx)
3940
import Testnet.Components.Query (EpochStateView, findLargestUtxoForPaymentKey,
4041
getCurrentEpochNo, getEpochStateView, getGovState, getMinDRepDeposit)
41-
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
42+
import qualified Testnet.Components.SPO as SPO
43+
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair, defaultSPOKeys)
4244
import qualified Testnet.Process.Cli as P
4345
import qualified Testnet.Process.Run as H
4446
import qualified Testnet.Property.Utils as H
@@ -210,8 +212,6 @@ desiredPoolNumberProposalTest
210212
-> m (String, Word32)
211213
desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo work prefix
212214
wallet previousProposalInfo votes change expected epochsToWait = do
213-
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
214-
215215
baseDir <- H.createDirectoryIfMissing $ work </> prefix
216216

217217
let propVotes :: [DefaultDRepVote]
@@ -222,8 +222,8 @@ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socket
222222
makeDesiredPoolNumberChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
223223
ceo baseDir "proposal" previousProposalInfo (fromIntegral change) wallet
224224

225-
voteChangeProposal execConfig epochStateView sbe baseDir "vote"
226-
governanceActionTxId governanceActionIndex propVotes wallet
225+
voteChangeProposal execConfig epochStateView ceo baseDir "vote"
226+
governanceActionTxId governanceActionIndex propVotes [] wallet
227227

228228
(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
229229
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp
@@ -331,38 +331,60 @@ makeDesiredPoolNumberChangeProposal execConfig epochStateView configurationFile
331331
-- a default DRep (from the ones created by 'cardanoTestnetDefault')
332332
type DefaultDRepVote = (String, Int)
333333

334+
-- A pair of a vote string (i.e: "yes", "no", or "abstain") and the number of
335+
-- a default SPO (from the ones created by 'cardanoTestnetDefault')
336+
type DefaultSPOVote = (String, Int)
337+
334338
-- | Create and issue votes for (or against) a government proposal with default
335-
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') using @cardano-cli@.
339+
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') and
340+
-- default Stake Pool Operatorsusing using @cardano-cli@.
336341
voteChangeProposal :: (MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m)
337342
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
338343
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
339344
-- using the 'getEpochStateView' function.
340-
-> ShelleyBasedEra ConwayEra -- ^ The Shelley-based witness for ConwayEra (i.e: ShelleyBasedEraConway).
345+
-> ConwayEraOnwards ConwayEra -- ^ The @ConwayEraOnwards@ witness for the Conway era.
341346
-> FilePath -- ^ Base directory path where the subdirectory with the intermediate files will be created.
342347
-> String -- ^ Name for the subdirectory that will be created for storing the intermediate files.
343348
-> String -- ^ Transaction id of the governance action to vote.
344349
-> Word32 -- ^ Index of the governance action to vote in the transaction.
345350
-> [DefaultDRepVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
351+
-> [DefaultSPOVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
346352
-> PaymentKeyInfo -- ^ Wallet that will pay for the transactions
347353
-> m ()
348-
voteChangeProposal execConfig epochStateView sbe work prefix
349-
governanceActionTxId governanceActionIndex votes wallet = do
354+
voteChangeProposal execConfig epochStateView ceo work prefix
355+
governanceActionTxId governanceActionIndex drepVotes spoVotes wallet = do
350356
baseDir <- H.createDirectoryIfMissing $ work </> prefix
351357

352-
let era = toCardanoEra sbe
358+
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
359+
era = toCardanoEra sbe
353360
cEra = AnyCardanoEra era
354361

355-
voteFiles <- generateVoteFiles execConfig baseDir "vote-files"
356-
governanceActionTxId governanceActionIndex
357-
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- votes]
362+
drepVoteFiles <- DRep.generateVoteFiles execConfig baseDir "drep-vote-files"
363+
governanceActionTxId governanceActionIndex
364+
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- drepVotes]
365+
366+
spoVoteFiles <- SPO.generateVoteFiles ceo execConfig baseDir "spo-vote-files"
367+
governanceActionTxId governanceActionIndex
368+
[(defaultSPOKeys idx, vote) | (vote, idx) <- spoVotes]
369+
370+
let voteFiles = drepVoteFiles ++ spoVoteFiles
358371

359372
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
360373
voteFiles wallet
361374

362375
voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp
363-
(paymentKeyInfoPair wallet:[defaultDRepKeyPair n | (_, n) <- votes])
376+
(paymentKeyInfoPair wallet:
377+
[defaultDRepKeyPair n | (_, n) <- drepVotes] ++
378+
[defaultSPOColdKeyPair n | (_, n) <- drepVotes]
379+
)
364380
submitTx execConfig cEra voteTxFp
365381

382+
defaultSPOColdKeyPair :: Int -> PaymentKeyPair
383+
defaultSPOColdKeyPair n = PaymentKeyPair { paymentVKey = poolNodeKeysColdVkey spoKeys
384+
, paymentSKey = poolNodeKeysColdSkey spoKeys
385+
}
386+
where spoKeys = defaultSPOKeys n
387+
366388
-- | Obtains the @desiredPoolNumberValue@ from the protocol parameters.
367389
-- The @desiredPoolNumberValue@ or (@k@ in the spec) is the protocol parameter
368390
-- that defines what is the optimal number of SPOs. It is a tradeoff between

0 commit comments

Comments
 (0)