Skip to content

Commit

Permalink
Merge pull request #565 from IntersectMBO/smelc/create-testnet-data-d…
Browse files Browse the repository at this point in the history
…rep-keys-1

create-testnet-data: add --drep-keys flag
  • Loading branch information
smelc authored Jan 15, 2024
2 parents 3793d9c + 1695d07 commit f6e7226
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 25 deletions.
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ data GenesisCreateTestNetDataCmdArgs = GenesisCreateTestNetDataCmdArgs
, numGenesisKeys :: !Word -- ^ The number of genesis keys credentials to create and write to disk.
, numPools :: !Word -- ^ The number of stake pools credentials to create and write to disk.
, stakeDelegators :: !StakeDelegators -- ^ The number of delegators to pools to create.
, numDrepKeys :: !Word -- ^ The number of DRep keys to create. Right now they receive neither delegation nor are registrated. This will come later.
, numStuffedUtxo :: !Word -- ^ The number of UTxO accounts to make. They are "stuffed" because the credentials are not written to disk.
, numUtxoKeys :: !Word -- ^ The number of UTxO credentials to create and write to disk.
, supply :: !(Maybe Lovelace) -- ^ The number of Lovelace to distribute over initial, non-delegating stake holders.
Expand Down
9 changes: 9 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pGenesisCreateTestNetData envCli =
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
<*> pNumDReps
<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
Expand Down Expand Up @@ -232,6 +233,14 @@ pGenesisCreateTestNetData envCli =
, Opt.help "The number of stake pool credential sets to make (default is 0)."
, Opt.value 0
]
pNumDReps :: Parser Word
pNumDReps =
Opt.option Opt.auto $ mconcat
[ Opt.long "drep-keys"
, Opt.metavar "INT"
, Opt.help "The number of DRep credentials to make (default is 0)."
, Opt.value 0
]
pNumStakeDelegs :: Parser StakeDelegators
pNumStakeDelegs =
pNumOnDiskStakeDelegators <|> pNumTransientStakeDelegs
Expand Down
12 changes: 12 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/CreateTestnetData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import Cardano.Api.Shelley
import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Node as Cmd
import Cardano.CLI.EraBased.Run.Address (runAddressKeyGenCmd)
import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.EraBased.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd,
runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd)
Expand Down Expand Up @@ -187,6 +189,7 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
, numGenesisKeys
, numPools
, stakeDelegators
, numDrepKeys
, numStuffedUtxo
, numUtxoKeys
, supply
Expand Down Expand Up @@ -238,6 +241,15 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs

writeREADME poolsDir poolsREADME

-- DReps
forM_ [ 1 .. numDrepKeys ] $ \index -> do
let drepDir = outputDir </> "drep-keys" </> "drep" <> show index
vkeyFile = File @(VerificationKey ()) $ drepDir </> "drep.vkey"
skeyFile = File @(SigningKey ()) $ drepDir </> "drep.skey"
cmd = DRep.GovernanceDRepKeyGenCmdArgs ConwayEraOnwardsConway vkeyFile skeyFile
liftIO $ createDirectoryIfMissing True drepDir
firstExceptT GenesisCmdFileError $ DRep.runGovernanceDRepKeyGenCmd cmd

-- Stake delegators
case stakeDelegators of
OnDisk _ ->
Expand Down
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

module Cardano.CLI.EraBased.Run.Governance.DRep
( runGovernanceDRepCmds
, runGovernanceDRepKeyGenCmd
) where

import Cardano.Api
Expand Down Expand Up @@ -39,7 +40,7 @@ runGovernanceDRepCmds :: ()
runGovernanceDRepCmds = \case
Cmd.GovernanceDRepKeyGenCmd args ->
runGovernanceDRepKeyGenCmd args
& firstExceptT CmdGovernanceCmdError
& firstExceptT (CmdGovernanceCmdError . GovernanceCmdWriteFileError)

Cmd.GovernanceDRepIdCmd args ->
runGovernanceDRepIdCmd args
Expand All @@ -59,12 +60,12 @@ runGovernanceDRepCmds = \case

runGovernanceDRepKeyGenCmd :: ()
=> Cmd.GovernanceDRepKeyGenCmdArgs era
-> ExceptT GovernanceCmdError IO ()
-> ExceptT (FileError ()) IO ()
runGovernanceDRepKeyGenCmd
Cmd.GovernanceDRepKeyGenCmdArgs
{ vkeyFile
, skeyFile
} = firstExceptT GovernanceCmdWriteFileError $ do
} = do
skey <- liftIO $ generateSigningKey AsDRepKey
let vkey = getVerificationKey skey
newExceptT $ writeLazyByteStringFile skeyFile (textEnvelopeToJSON (Just skeyDesc) skey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Use camelCase" -}

-- | A function to create the arguments, so that they are shared
-- between the two tests, except for the possibly transient ones.
mkArguments :: String -> [String]
mkArguments outputDir =
["conway", "genesis", "create-testnet-data"
, "--genesis-keys", "2"
, "--utxo-keys", "3"
, "--out-dir", outputDir
, "--testnet-magic", "42"
, "--pools", "2"
, "--drep-keys", "5"
]

-- | Given a root directory, returns files within this root (recursively)
tree :: FilePath -> IO [FilePath]
tree root = do
Expand All @@ -26,22 +39,16 @@ tree root = do
subTrees <- mapM tree subs
return $ files ++ concat subTrees

-- | This test tests the non-transient case, i.e. it maximizes the files
-- that can be written to disk. Execute this test with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data/'@
hprop_golden_create_testnet_data :: Property
hprop_golden_create_testnet_data =
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do

let outputDir = tempDir </> "out"

void $
execCardanoCLI
["conway", "genesis", "create-testnet-data"
, "--genesis-keys", "2"
, "--utxo-keys", "3"
, "--out-dir", outputDir
, "--testnet-magic", "42"
, "--pools", "2"
, "--stake-delegators", "4"
]
void $ execCardanoCLI $ mkArguments outputDir <> ["--stake-delegators", "4"]

generated <- liftIO $ tree outputDir
-- Sort output for stability, and make relative to avoid storing
Expand All @@ -54,23 +61,17 @@ hprop_golden_create_testnet_data =

H.diffVsGoldenFile generated'' "test/cardano-cli-golden/files/golden/conway/create-testnet-data.out"

-- | This test tests the transient case, i.e. it writes strictly
-- less things to disk than 'hprop_golden_create_testnet_data'. Execute this test with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data transient stake delegators/'@
hprop_golden_create_testnet_data_transient_stake_delegators :: Property
hprop_golden_create_testnet_data_transient_stake_delegators =
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do

let outputDir = tempDir </> "out"

void $
execCardanoCLI
["conway", "genesis", "create-testnet-data"
, "--genesis-keys", "2"
, "--utxo-keys", "3"
, "--out-dir", outputDir
, "--testnet-magic", "42"
, "--pools", "2"
, "--stake-delegators", "4"
]
void $ execCardanoCLI $ mkArguments outputDir <> ["--transient-stake-delegators", "4"]

-- We just test that the command doesn't crash when we execute a different path.
-- For the golden part of this test, we are anyway covered by 'hprop_golden_create_testnet_data'
-- that generates strictly more stuff.
-- that generates strictly more stuff.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ delegate-keys/delegate2/opcert.cert
delegate-keys/delegate2/opcert.counter
delegate-keys/delegate2/vrf.skey
delegate-keys/delegate2/vrf.vkey
drep-keys/drep1/drep.skey
drep-keys/drep1/drep.vkey
drep-keys/drep2/drep.skey
drep-keys/drep2/drep.vkey
drep-keys/drep3/drep.skey
drep-keys/drep3/drep.vkey
drep-keys/drep4/drep.skey
drep-keys/drep4/drep.vkey
drep-keys/drep5/drep.skey
drep-keys/drep5/drep.vkey
genesis-keys/README.md
genesis-keys/genesis1/key.skey
genesis-keys/genesis1/key.vkey
Expand Down Expand Up @@ -64,4 +74,4 @@ utxo-keys/utxo1/utxo.vkey
utxo-keys/utxo2/utxo.skey
utxo-keys/utxo2/utxo.vkey
utxo-keys/utxo3/utxo.skey
utxo-keys/utxo3/utxo.vkey
utxo-keys/utxo3/utxo.vkey
7 changes: 7 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Usage: cardano-cli shelley genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -1423,6 +1424,7 @@ Usage: cardano-cli allegra genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -2579,6 +2581,7 @@ Usage: cardano-cli mary genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -3719,6 +3722,7 @@ Usage: cardano-cli alonzo genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -4883,6 +4887,7 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -6065,6 +6070,7 @@ Usage: cardano-cli conway genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down Expand Up @@ -7581,6 +7587,7 @@ Usage: cardano-cli latest genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli allegra genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli alonzo genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli conway genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli latest genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli mary genesis create-testnet-data [--spec-shelley FILE]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--drep-keys INT]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--supply LOVELACE]
Expand All @@ -28,6 +29,8 @@ Available options:
The number of stake delegator credential sets to make
(default is 0). The credentials are NOT written to
disk.
--drep-keys INT The number of DRep credentials to make (default is
0).
--stuffed-utxo INT The number of fake UTxO entries to generate (default
is 0).
--utxo-keys INT The number of UTxO keys to make (default is 0).
Expand Down
Loading

0 comments on commit f6e7226

Please sign in to comment.