Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-testnet-data: add --drep-keys flag #565

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/'@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I always forget how this is done... Maybe we should add this to the CONTRIBUTING.md?

Copy link
Contributor

@carbolymer carbolymer Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should add it somewhere too. I think this is the best place: https://github.com/input-output-hk/cardano-node-wiki/wiki/Running-tests
We can link from CONTRIBUTING.md to it then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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