Skip to content

Commit 8d6c008

Browse files
committed
Finish implementation of Predefined No Confidence DRep test
1 parent 759a0c6 commit 8d6c008

File tree

5 files changed

+311
-72
lines changed

5 files changed

+311
-72
lines changed

cardano-testnet/src/Testnet/Components/SPO.hs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Testnet.Components.SPO
1414
, createStakeKeyDeregistrationCertificate
1515
, decodeEraUTxO
1616
, registerSingleSpo
17+
, generateVoteFiles
1718
) where
1819

1920
import qualified Cardano.Api.Ledger as L
@@ -32,21 +33,24 @@ import qualified Data.Map.Strict as Map
3233
import Data.Set (Set)
3334
import qualified Data.Set as Set
3435
import qualified Data.Text as Text
36+
import Data.Word (Word32)
3537
import GHC.Stack (HasCallStack)
3638
import qualified GHC.Stack as GHC
3739
import Lens.Micro
3840
import System.FilePath.Posix ((</>))
3941

42+
import Testnet.Components.DReps (VoteFile)
4043
import Testnet.Filepath
41-
import Testnet.Process.Cli
44+
import Testnet.Process.Cli hiding (File, unFile)
45+
import qualified Testnet.Process.Run as H
4246
import Testnet.Process.Run (execCli, execCli', execCli_)
4347
import Testnet.Property.Utils
48+
import Testnet.Runtime (PoolNodeKeys (poolNodeKeysColdVkey))
4449
import Testnet.Start.Types
4550

4651
import Hedgehog
4752
import Hedgehog.Extras (ExecConfig)
48-
import qualified Hedgehog.Extras.Test.Base as H
49-
import qualified Hedgehog.Extras.Test.File as H
53+
import qualified Hedgehog.Extras as H
5054

5155
checkStakePoolRegistered
5256
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
@@ -401,3 +405,45 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s
401405
poolColdVkeyFp
402406
currentRegistedPoolsJson
403407
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
408+
409+
410+
-- | Generates Stake Pool Operator (SPO) voting files (without signing)
411+
-- using @cardano-cli@.
412+
--
413+
-- This function takes the following parameters:
414+
--
415+
-- * 'execConfig': Specifies the CLI execution configuration.
416+
-- * 'work': Base directory path where the voting files and directories will be
417+
-- stored.
418+
-- * 'prefix': Name for the subfolder that will be created under 'work' to store
419+
-- the output voting files.
420+
-- * 'governanceActionTxId': Transaction ID string of the governance action.
421+
-- * 'governanceActionIndex': Index of the governance action.
422+
-- * 'allVotes': List of tuples where each tuple contains a 'PoolNodeKeys'
423+
-- representing the SPO keys and a 'String' representing the
424+
-- vote type (i.e: "yes", "no", or "abstain").
425+
--
426+
-- Returns a list of generated @File VoteFile In@ representing the paths to
427+
-- the generated voting files.
428+
generateVoteFiles :: (MonadTest m, MonadIO m, MonadCatch m)
429+
=> H.ExecConfig
430+
-> FilePath
431+
-> String
432+
-> String
433+
-> Word32
434+
-> [(PoolNodeKeys, [Char])]
435+
-> m [File VoteFile In]
436+
generateVoteFiles execConfig work prefix governanceActionTxId governanceActionIndex allVotes = do
437+
baseDir <- H.createDirectoryIfMissing $ work </> prefix
438+
forM (zip [(1 :: Integer)..] allVotes) $ \(idx, (spoKeys, vote)) -> do
439+
let path = File (baseDir </> "vote-" <> show idx)
440+
void $ H.execCli' execConfig
441+
[ "conway", "governance", "vote", "create"
442+
, "--" ++ vote
443+
, "--governance-action-tx-id", governanceActionTxId
444+
, "--governance-action-index", show @Word32 governanceActionIndex
445+
, "--cold-verification-key-file", poolNodeKeysColdVkey spoKeys
446+
, "--out-file", unFile path
447+
]
448+
return path
449+

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Testnet.Defaults
2424
, defaultMainnetTopology
2525
, plutusV3NonSpendingScript
2626
, plutusV3SpendingScript
27+
, defaultSPOKeys
2728
) where
2829

2930
import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), pshow)
@@ -72,7 +73,8 @@ import Numeric.Natural
7273
import System.FilePath ((</>))
7374

7475
import Test.Cardano.Ledger.Core.Rational
75-
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), StakingKeyPair (StakingKeyPair))
76+
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..),
77+
StakingKeyPair (StakingKeyPair))
7678
import Testnet.Start.Types
7779

7880
{- HLINT ignore "Use underscore" -}
@@ -515,15 +517,27 @@ defaultDRepSkeyFp n = "drep-keys" </> ("drep" <> show n) </> "drep.skey"
515517
defaultDRepKeyPair :: Int -> PaymentKeyPair
516518
defaultDRepKeyPair n = PaymentKeyPair (defaultDRepVkeyFp n) (defaultDRepSkeyFp n)
517519

520+
-- | The relative path to SPO key pairs in directories created by cardano-testnet
521+
defaultSPOKeys :: Int -> PoolNodeKeys
522+
defaultSPOKeys n =
523+
PoolNodeKeys
524+
{ poolNodeKeysColdVkey = "pools-keys" </> "pool" ++ show n </> "cold.vkey"
525+
, poolNodeKeysColdSkey = "pools-keys" </> "pool" ++ show n </> "cold.skey"
526+
, poolNodeKeysVrfVkey = "pools-keys" </> "pool" ++ show n </> "vrf.vkey"
527+
, poolNodeKeysVrfSkey = "pools-keys" </> "pool" ++ show n </> "vrf.skey"
528+
, poolNodeKeysStakingVkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.vkey"
529+
, poolNodeKeysStakingSkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.skey"
530+
}
531+
518532
-- | The relative path to stake delegator stake keys in directories created by cardano-testnet
519533
defaultDelegatorStakeVkeyFp
520-
:: Int -- ^The Stake delegator index (starts at 1)
534+
:: Int -- ^ The Stake delegator index (starts at 1)
521535
-> FilePath
522536
defaultDelegatorStakeVkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.vkey"
523537

524538
-- | The relative path to stake delegator stake secret keys in directories created by cardano-testnet
525539
defaultDelegatorStakeSkeyFp
526-
:: Int -- ^The Stake delegator index (starts at 1)
540+
:: Int -- ^ The Stake delegator index (starts at 1)
527541
-> FilePath
528542
defaultDelegatorStakeSkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.skey"
529543

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

Lines changed: 27 additions & 9 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
@@ -209,7 +211,7 @@ desiredPoolNumberProposalTest execConfig epochStateView configurationFile socket
209211
ceo baseDir "proposal" previousProposalInfo (fromIntegral change) wallet
210212

211213
voteChangeProposal execConfig epochStateView sbe baseDir "vote"
212-
governanceActionTxId governanceActionIndex propVotes wallet
214+
governanceActionTxId governanceActionIndex propVotes [] wallet
213215

214216
(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
215217
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp
@@ -319,26 +321,42 @@ voteChangeProposal :: (MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m)
319321
-> FilePath
320322
-> String
321323
-> Word32
322-
-> [([Char], Int)]
324+
-> [(String, Int)]
325+
-> [(String, Int)]
323326
-> PaymentKeyInfo
324327
-> m ()
325-
voteChangeProposal execConfig epochStateView sbe work prefix governanceActionTxId governanceActionIndex votes wallet = do
328+
voteChangeProposal execConfig epochStateView sbe work prefix governanceActionTxId governanceActionIndex drepVotes spoVotes wallet = do
326329
baseDir <- H.createDirectoryIfMissing $ work </> prefix
327330

328331
let era = toCardanoEra sbe
329332
cEra = AnyCardanoEra era
330333

331-
voteFiles <- generateVoteFiles execConfig baseDir "vote-files"
332-
governanceActionTxId governanceActionIndex
333-
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- votes]
334+
drepVoteFiles <- DRep.generateVoteFiles execConfig baseDir "drep-vote-files"
335+
governanceActionTxId governanceActionIndex
336+
[(defaultDRepKeyPair idx, vote) | (vote, idx) <- drepVotes]
337+
338+
spoVoteFiles <- SPO.generateVoteFiles execConfig baseDir "spo-vote-files"
339+
governanceActionTxId governanceActionIndex
340+
[(defaultSPOKeys idx, vote) | (vote, idx) <- spoVotes]
341+
342+
let voteFiles = drepVoteFiles ++ spoVoteFiles
334343

335344
voteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe baseDir "vote-tx-body"
336345
voteFiles wallet
337346

338347
voteTxFp <- signTx execConfig cEra baseDir "signed-vote-tx" voteTxBodyFp
339-
(paymentKeyInfoPair wallet:[defaultDRepKeyPair n | (_, n) <- votes])
348+
(paymentKeyInfoPair wallet:
349+
[defaultDRepKeyPair n | (_, n) <- drepVotes] ++
350+
[defaultSPOColdKeyPair n | (_, n) <- drepVotes]
351+
)
340352
submitTx execConfig cEra voteTxFp
341353

354+
defaultSPOColdKeyPair :: Int -> PaymentKeyPair
355+
defaultSPOColdKeyPair n = PaymentKeyPair { paymentVKey = poolNodeKeysColdVkey spoKeys
356+
, paymentSKey = poolNodeKeysColdSkey spoKeys
357+
}
358+
where spoKeys = defaultSPOKeys n
359+
342360
getDesiredPoolNumberValue :: (MonadTest m, MonadCatch m, MonadIO m) => H.ExecConfig -> m Integer
343361
getDesiredPoolNumberValue execConfig = do
344362
govStateString <- H.execCli' execConfig

0 commit comments

Comments
 (0)