Skip to content

Commit

Permalink
Merge pull request #488 from input-output-hk/smelc/new-create-staked
Browse files Browse the repository at this point in the history
Add create-testnet-data command
  • Loading branch information
smelc authored Dec 5, 2023
2 parents 3b06b42 + 9075f99 commit 5fcbb56
Show file tree
Hide file tree
Showing 24 changed files with 1,307 additions and 241 deletions.
3 changes: 3 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ library
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Address
Cardano.CLI.EraBased.Run.Address.Info
Cardano.CLI.EraBased.Run.CreateTestnetData
Cardano.CLI.EraBased.Run.Genesis
Cardano.CLI.EraBased.Run.Governance
Cardano.CLI.EraBased.Run.Governance.Actions
Expand Down Expand Up @@ -340,6 +341,7 @@ test-suite cardano-cli-golden
, cardano-ledger-byron
, cborg
, containers
, directory
, filepath
, hedgehog ^>= 1.3
, hedgehog-extras ^>= 0.4.7.0
Expand All @@ -360,6 +362,7 @@ test-suite cardano-cli-golden
Test.Golden.Byron.UpdateProposal
Test.Golden.Byron.Vote
Test.Golden.Byron.Witness
Test.Golden.CreateTestnetData
Test.Golden.Conway.Transaction.Assemble
Test.Golden.EraBased.Governance.AnswerPoll
Test.Golden.EraBased.Governance.CreatePoll
Expand Down
18 changes: 18 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Genesis
, GenesisCreateCmdArgs (..)
, GenesisCreateCardanoCmdArgs (..)
, GenesisCreateStakedCmdArgs (..)
, GenesisCreateTestNetDataCmdArgs (..)
, GenesisKeyGenGenesisCmdArgs (..)
, GenesisKeyGenDelegateCmdArgs (..)
, GenesisKeyGenUTxOCmdArgs (..)
Expand All @@ -27,6 +28,7 @@ data GenesisCmds era
= GenesisCreate !GenesisCreateCmdArgs
| GenesisCreateCardano !GenesisCreateCardanoCmdArgs
| GenesisCreateStaked !GenesisCreateStakedCmdArgs
| GenesisCreateTestNetData !GenesisCreateTestNetDataCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO !GenesisKeyGenUTxOCmdArgs
Expand Down Expand Up @@ -81,6 +83,20 @@ data GenesisCreateStakedCmdArgs = GenesisCreateStakedCmdArgs
, mStakePoolRelaySpecFile :: !(Maybe FilePath) -- ^ Relay specification filepath
} deriving Show

data GenesisCreateTestNetDataCmdArgs = GenesisCreateTestNetDataCmdArgs
{ specShelley :: !(Maybe FilePath) -- ^ Path to the @genesis-shelley@ file to use. If unspecified, a default one will be used if omitted.
, 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.
, numStakeDelegators :: !Word -- ^ The number of delegators to pools to create and write to disk.
, 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.
, supplyDelegated :: !(Maybe Lovelace) -- ^ The number of Lovelace to distribute over delegating stake holders.
, networkId :: !NetworkId -- ^ The network ID to use.
, systemStart :: !(Maybe SystemStart) -- ^ The genesis start time.
, outputDir :: !FilePath -- ^ Directory where to write credentials and files.
} deriving Show

data GenesisKeyGenGenesisCmdArgs = GenesisKeyGenGenesisCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
Expand Down Expand Up @@ -122,6 +138,8 @@ renderGenesisCmds = \case
"genesis create-cardano"
GenesisCreateStaked {} ->
"genesis create-staked"
GenesisCreateTestNetData {} ->
"genesis create-testnet-data"
GenesisKeyGenGenesis {} ->
"genesis key-gen-genesis"
GenesisKeyGenDelegate {} ->
Expand Down
87 changes: 87 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ pGenesisCmds envCli =
[ "Create a staked Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, Just
$ subParser "create-testnet-data"
$ Opt.info (pGenesisCreateTestNetData envCli)
$ Opt.progDesc
$ mconcat
[ "Create data to use for starting a testnet."
]
, Just
$ subParser "hash"
$ Opt.info pGenesisHash
Expand Down Expand Up @@ -191,6 +198,86 @@ pGenesisCreateStaked envCli =
<*> pStuffedUtxoCount
<*> Opt.optional pRelayJsonFp

pGenesisCreateTestNetData :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData envCli =
fmap GenesisCreateTestNetData $ GenesisCreateTestNetDataCmdArgs
<$> (optional $ pSpecFile "shelley")
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
<*> pSupplyDelegated
<*> pNetworkId envCli
<*> pMaybeSystemStart
<*> pOutputDir
where
pSpecFile era = Opt.strOption $ mconcat
[ Opt.long $ "spec-" <> era
, Opt.metavar "FILE"
, Opt.help $ "The " <> era <> " specification file to use as input. A default one is generated if omitted."
]
pNumGenesisKeys = Opt.option Opt.auto $ mconcat
[ Opt.long "genesis-keys"
, Opt.metavar "INT"
, Opt.help "The number of genesis keys to make (default is 3)."
, Opt.value 3
]
pNumPools :: Parser Word
pNumPools =
Opt.option Opt.auto $ mconcat
[ Opt.long "pools"
, Opt.metavar "INT"
, Opt.help "The number of stake pool credential sets to make (default is 0)."
, Opt.value 0
]
pNumStakeDelegs :: Parser Word
pNumStakeDelegs =
Opt.option Opt.auto $ mconcat
[ Opt.long "stake-delegators"
, Opt.metavar "INT"
, Opt.help "The number of stake delegator credential sets to make (default is 0)."
, Opt.value 0
]
pNumStuffedUtxoCount :: Parser Word
pNumStuffedUtxoCount =
Opt.option Opt.auto $ mconcat
[ Opt.long "stuffed-utxo"
, Opt.metavar "INT"
, Opt.help "The number of fake UTxO entries to generate (default is 0)."
, Opt.value 0
]
pNumUtxoKeys :: Parser Word
pNumUtxoKeys =
Opt.option Opt.auto $ mconcat
[ Opt.long "utxo-keys"
, Opt.metavar "INT"
, Opt.help "The number of UTxO keys to make (default is 0)."
, Opt.value 0
]
pSupply :: Parser (Maybe Lovelace)
pSupply =
Opt.optional $ fmap Lovelace $ Opt.option Opt.auto $ mconcat
[ Opt.long "supply"
, Opt.metavar "LOVELACE"
, Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, non-delegating stake holders. Defaults to 1 million Ada (i.e. 10^12 Lovelace)."
, Opt.value 1000000000000
]
pSupplyDelegated :: Parser (Maybe Lovelace)
pSupplyDelegated =
Opt.optional $ fmap Lovelace $ Opt.option Opt.auto $ mconcat
[ Opt.long "supply-delegated"
, Opt.metavar "LOVELACE"
, Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, delegating stake holders. Defaults to 1 million Ada (i.e. 10^12 Lovelace)."
, Opt.value 1000000000000
]
pOutputDir = Opt.strOption $ mconcat
[ Opt.long "out-dir"
, Opt.metavar "DIR"
, Opt.help "The directory where to generate the data. Created if not existing."
]

pGenesisHash :: Parser (GenesisCmds era)
pGenesisHash =
GenesisHashFile <$> pGenesisFile "The genesis file."
Expand Down
Loading

0 comments on commit 5fcbb56

Please sign in to comment.