Skip to content

Commit

Permalink
Add SPO key default paths and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Apr 29, 2024
1 parent 43782a9 commit a406ca3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
52 changes: 49 additions & 3 deletions cardano-testnet/src/Testnet/Components/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Testnet.Components.SPO
, createStakeKeyDeregistrationCertificate
, decodeEraUTxO
, registerSingleSpo
, generateVoteFiles
) where

import qualified Cardano.Api.Ledger as L
Expand All @@ -32,21 +33,24 @@ import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as Text
import Data.Word (Word32)
import GHC.Stack (HasCallStack)
import qualified GHC.Stack as GHC
import Lens.Micro
import System.FilePath.Posix ((</>))

import Testnet.Components.DReps (VoteFile)
import Testnet.Filepath
import Testnet.Process.Cli
import Testnet.Process.Cli hiding (File, unFile)
import qualified Testnet.Process.Run as H
import Testnet.Process.Run (execCli, execCli', execCli_)
import Testnet.Property.Utils
import Testnet.Runtime (PoolNodeKeys (poolNodeKeysColdVkey))
import Testnet.Start.Types

import Hedgehog
import Hedgehog.Extras (ExecConfig)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras as H

checkStakePoolRegistered
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
Expand Down Expand Up @@ -401,3 +405,45 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s
poolColdVkeyFp
currentRegistedPoolsJson
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)


-- | Generates Stake Pool Operator (SPO) voting files (without signing)
-- using @cardano-cli@.
--
-- This function takes the following parameters:
--
-- * 'execConfig': Specifies the CLI execution configuration.
-- * 'work': Base directory path where the voting files and directories will be
-- stored.
-- * 'prefix': Name for the subfolder that will be created under 'work' to store
-- the output voting files.
-- * 'governanceActionTxId': Transaction ID string of the governance action.
-- * 'governanceActionIndex': Index of the governance action.
-- * 'allVotes': List of tuples where each tuple contains a 'PoolNodeKeys'
-- representing the SPO keys and a 'String' representing the
-- vote type (i.e: "yes", "no", or "abstain").
--
-- Returns a list of generated @File VoteFile In@ representing the paths to
-- the generated voting files.
generateVoteFiles :: (MonadTest m, MonadIO m, MonadCatch m)
=> H.ExecConfig
-> FilePath
-> String
-> String
-> Word32
-> [(PoolNodeKeys, [Char])]
-> m [File VoteFile In]
generateVoteFiles execConfig work prefix governanceActionTxId governanceActionIndex allVotes = do
baseDir <- H.createDirectoryIfMissing $ work </> prefix
forM (zip [(1 :: Integer)..] allVotes) $ \(idx, (spoKeys, vote)) -> do
let path = File (baseDir </> "vote-" <> show idx)
void $ H.execCli' execConfig
[ "conway", "governance", "vote", "create"
, "--" ++ vote
, "--governance-action-tx-id", governanceActionTxId
, "--governance-action-index", show @Word32 governanceActionIndex
, "--cold-verification-key-file", poolNodeKeysColdVkey spoKeys
, "--out-file", unFile path
]
return path

18 changes: 16 additions & 2 deletions cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ module Testnet.Defaults
, defaultDRepVkeyFp
, defaultDRepSkeyFp
, defaultDRepKeyPair
, defaultDelegatorStakeKeyPair
, defaultShelleyGenesis
, defaultGenesisFilepath
, defaultYamlHardforkViaConfig
, defaultMainnetTopology
, plutusV3NonSpendingScript
, plutusV3SpendingScript
, defaultDelegatorStakeKeyPair
, defaultSPOKeys
) where

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

import Test.Cardano.Ledger.Core.Rational
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), StakingKeyPair (StakingKeyPair))
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..),
StakingKeyPair (StakingKeyPair))
import Testnet.Start.Types

{- HLINT ignore "Use underscore" -}
Expand Down Expand Up @@ -515,6 +517,18 @@ defaultDRepSkeyFp n = "drep-keys" </> ("drep" <> show n) </> "drep.skey"
defaultDRepKeyPair :: Int -> PaymentKeyPair
defaultDRepKeyPair n = PaymentKeyPair (defaultDRepVkeyFp n) (defaultDRepSkeyFp n)

-- | The relative path to SPO key pairs in directories created by cardano-testnet
defaultSPOKeys :: Int -> PoolNodeKeys
defaultSPOKeys n =
PoolNodeKeys
{ poolNodeKeysColdVkey = "pools-keys" </> "pool" ++ show n </> "cold.vkey"
, poolNodeKeysColdSkey = "pools-keys" </> "pool" ++ show n </> "cold.skey"
, poolNodeKeysVrfVkey = "pools-keys" </> "pool" ++ show n </> "vrf.vkey"
, poolNodeKeysVrfSkey = "pools-keys" </> "pool" ++ show n </> "vrf.skey"
, poolNodeKeysStakingVkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.vkey"
, poolNodeKeysStakingSkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.skey"
}

-- | The relative path to stake delegator stake keys in directories created by cardano-testnet
defaultDelegatorStakeVkeyFp
:: Int -- ^ The Stake delegator index (starts at 1)
Expand Down

0 comments on commit a406ca3

Please sign in to comment.