Skip to content

Commit 1b8b52a

Browse files
committed
Finish implementation of Predefined No Confidence DRep test
1 parent b507659 commit 1b8b52a

File tree

3 files changed

+255
-75
lines changed

3 files changed

+255
-75
lines changed

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ import GHC.Stack (callStack)
3232
import Lens.Micro ((^?))
3333
import System.FilePath ((</>))
3434

35+
import qualified Testnet.Components.DReps as DRep
3536
import Testnet.Components.DReps (createCertificatePublicationTxBody, createVotingTxBody,
36-
generateVoteFiles, retrieveTransactionId, signTx, submitTx)
37+
retrieveTransactionId, signTx, submitTx)
3738
import Testnet.Components.Query (EpochStateView, findLargestUtxoForPaymentKey,
3839
getCurrentEpochNo, getEpochStateView, getMinDRepDeposit)
39-
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
40+
import qualified Testnet.Components.SPO as SPO
41+
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair, defaultSPOKeys)
4042
import qualified Testnet.Process.Cli as P
4143
import qualified Testnet.Process.Run as H
4244
import qualified Testnet.Property.Utils as H
@@ -51,7 +53,7 @@ import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
5153
-- @desiredNumberOfPools@ parameter) to check that it fails, when the first DRep votes "yes" and the
5254
-- last two vote "no". Later we chack that if we change the stake holders under the DReps that vote
5355
-- "no" to delegate to the automate "always abstain" DRep, the same kind of proposal passes.
54-
--
56+
--
5557
-- This test is meant to ensure that delegating to "always abstain" has the desired effect of
5658
-- counting as abstaining for the stake delegated.
5759
--
@@ -205,8 +207,6 @@ desiredPoolNumberProposalTest
205207
-> m (String, Word32)
206208
desiredPoolNumberProposalTest execConfig epochStateView configurationFile socketPath ceo work prefix
207209
wallet previousProposalInfo votes change expected epochsToWait = do
208-
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
209-
210210
baseDir <- H.createDirectoryIfMissing $ work </> prefix
211211

212212
let propVotes :: [DefaultDRepVote]
@@ -217,8 +217,8 @@ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socket
217217
makeDesiredPoolNumberChangeProposal execConfig epochStateView (File configurationFile) (File socketPath)
218218
ceo baseDir "proposal" previousProposalInfo (fromIntegral change) wallet
219219

220-
voteChangeProposal execConfig epochStateView sbe baseDir "vote"
221-
governanceActionTxId governanceActionIndex propVotes wallet
220+
voteChangeProposal execConfig epochStateView ceo baseDir "vote"
221+
governanceActionTxId governanceActionIndex propVotes [] wallet
222222

223223
(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
224224
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp
@@ -324,38 +324,60 @@ makeDesiredPoolNumberChangeProposal execConfig epochStateView configurationFile
324324
-- a default DRep (from the ones created by 'cardanoTestnetDefault')
325325
type DefaultDRepVote = (String, Int)
326326

327+
-- A pair of a vote string (i.e: "yes", "no", or "abstain") and the number of
328+
-- a default SPO (from the ones created by 'cardanoTestnetDefault')
329+
type DefaultSPOVote = (String, Int)
330+
327331
-- | Create and issue votes for (or against) a government proposal with default
328-
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') using @cardano-cli@.
332+
-- Delegate Representative (DReps created by 'cardanoTestnetDefault') and
333+
-- default Stake Pool Operatorsusing using @cardano-cli@.
329334
voteChangeProposal :: (MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m)
330335
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
331336
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
332337
-- using the 'getEpochStateView' function.
333-
-> ShelleyBasedEra ConwayEra -- ^ The Shelley-based witness for ConwayEra (i.e: ShelleyBasedEraConway).
338+
-> ConwayEraOnwards ConwayEra -- ^ The @ConwayEraOnwards@ witness for the Conway era.
334339
-> FilePath -- ^ Base directory path where the subdirectory with the intermediate files will be created.
335340
-> String -- ^ Name for the subdirectory that will be created for storing the intermediate files.
336341
-> String -- ^ Transaction id of the governance action to vote.
337342
-> Word32 -- ^ Index of the governance action to vote in the transaction.
338343
-> [DefaultDRepVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
344+
-> [DefaultSPOVote] -- ^ List of votes to issue as pairs of the vote and the number of DRep that votes it.
339345
-> PaymentKeyInfo -- ^ Wallet that will pay for the transactions
340346
-> m ()
341-
voteChangeProposal execConfig epochStateView sbe work prefix
342-
governanceActionTxId governanceActionIndex votes wallet = do
347+
voteChangeProposal execConfig epochStateView ceo work prefix
348+
governanceActionTxId governanceActionIndex drepVotes spoVotes wallet = do
343349
baseDir <- H.createDirectoryIfMissing $ work </> prefix
344350

345-
let era = toCardanoEra sbe
351+
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
352+
era = toCardanoEra sbe
346353
cEra = AnyCardanoEra era
347354

348-
voteFiles <- generateVoteFiles execConfig baseDir "vote-files"
349-
governanceActionTxId governanceActionIndex
350-
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- votes]
355+
drepVoteFiles <- DRep.generateVoteFiles execConfig baseDir "drep-vote-files"
356+
governanceActionTxId governanceActionIndex
357+
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- drepVotes]
358+
359+
spoVoteFiles <- SPO.generateVoteFiles ceo execConfig baseDir "spo-vote-files"
360+
governanceActionTxId governanceActionIndex
361+
[(defaultSPOKeys idx, vote) | (vote, idx) <- spoVotes]
362+
363+
let voteFiles = drepVoteFiles ++ spoVoteFiles
351364

352365
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
353366
voteFiles wallet
354367

355368
voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp
356-
(paymentKeyInfoPair wallet:[defaultDRepKeyPair n | (_, n) <- votes])
369+
(paymentKeyInfoPair wallet:
370+
[defaultDRepKeyPair n | (_, n) <- drepVotes] ++
371+
[defaultSPOColdKeyPair n | (_, n) <- drepVotes]
372+
)
357373
submitTx execConfig cEra voteTxFp
358374

375+
defaultSPOColdKeyPair :: Int -> PaymentKeyPair
376+
defaultSPOColdKeyPair n = PaymentKeyPair { paymentVKey = poolNodeKeysColdVkey spoKeys
377+
, paymentSKey = poolNodeKeysColdSkey spoKeys
378+
}
379+
where spoKeys = defaultSPOKeys n
380+
359381
-- | Obtains the @desiredPoolNumberValue@ from the protocol parameters.
360382
-- The @desiredPoolNumberValue@ or (@k@ in the spec) is the protocol parameter
361383
-- that defines what is the optimal number of SPOs. It is a tradeoff between

0 commit comments

Comments
 (0)