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

Correct conway parser, so that --key-reg-deposit-amt is mandatory #456

Merged
merged 5 commits into from
Nov 16, 2023
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
33 changes: 23 additions & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,29 @@ pStakeAddressRegistrationCertificateCmd :: ()
=> CardanoEra era
-> Maybe (Parser (StakeAddressCmds era))
pStakeAddressRegistrationCertificateCmd era = do
w <- forEraMaybeEon era
pure
$ subParser "registration-certificate"
$ Opt.info
( StakeAddressRegistrationCertificateCmd w
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
)
$ Opt.progDesc "Create a stake address registration certificate"
forEraInEonMaybe era $ \sbe ->
caseShelleyToBabbageOrConwayEraOnwards
(\shelleyToBabbage -> subParser "registration-certificate"
$ Opt.info
( StakeAddressRegistrationCertificateCmd (shelleyToBabbageEraToShelleyBasedEra shelleyToBabbage)
<$> pStakeIdentifier
<*> optional pKeyRegistDeposit
<*> pOutputFile
)
desc
)
(\conwayOnwards -> subParser "registration-certificate"
$ Opt.info
( StakeAddressRegistrationCertificateCmd (conwayEraOnwardsToShelleyBasedEra conwayOnwards)
<$> pStakeIdentifier
<*> fmap Just pKeyRegistDeposit
<*> pOutputFile
)
desc
)
sbe
where
desc = Opt.progDesc "Create a stake address registration certificate"

pStakeAddressDeregistrationCertificateCmd :: ()
=> CardanoEra era
Expand Down
8 changes: 5 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ runStakeAddressRegistrationCertificateCmd sbe stakeIdentifier mDeposit oFp = do
createRegistrationCertRequirements :: ()
=> ShelleyBasedEra era
-> StakeCredential
-> Maybe Lovelace
-> Maybe Lovelace -- ^ Deposit required in conway era
-> Either StakeAddressRegistrationError (StakeAddressRequirements era)
createRegistrationCertRequirements sbe stakeCred mdeposit =
case sbe of
Expand All @@ -162,8 +162,10 @@ createRegistrationCertRequirements sbe stakeCred mdeposit =
return $ StakeAddrRegistrationPreConway ShelleyToBabbageEraBabbage stakeCred
ShelleyBasedEraConway ->
case mdeposit of
-- TODO: This error constructor will never be called
Nothing -> Left StakeAddressRegistrationDepositRequired
Nothing ->
-- This case is made impossible by the parser, that distinguishes between Conway
-- and pre-Conway.
Left StakeAddressRegistrationDepositRequired
Just dep ->
return $ StakeAddrRegistrationConway ConwayEraOnwardsConway dep stakeCred

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ hprop_golden_HelpCmds =
H.noteShow_ usage
let expectedCmdHelpFp = "test/cardano-cli-golden/files/golden/help" </> Text.unpack (Text.intercalate "_" usage) <> ".cli"

cmdHelp <- filterAnsi . third <$> H.execDetailCardanoCli (fmap Text.unpack usage)
cmdHelp <- filterAnsi . third <$> H.execDetailCardanoCLI (fmap Text.unpack usage)

H.diffVsGoldenFile cmdHelp expectedCmdHelpFp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Test.Cardano.CLI.Util

import Hedgehog
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.Process as H
import qualified Hedgehog.Extras.Test.Golden as H
import qualified Hedgehog.Extras.Test.Process as H

{- HLINT ignore "Use camelCase" -}

Expand Down Expand Up @@ -67,3 +67,15 @@ hprop_golden_shelley_stake_address_registration_certificate_with_build_raw = pro

goldenFile2 <- H.note "test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json"
H.diffFileVsGoldenFile txRawFile goldenFile2

hprop_golden_shelley_stake_address_registration_certificate_missing_reg_deposit :: Property
hprop_golden_shelley_stake_address_registration_certificate_missing_reg_deposit = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
keyGenStakingVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/stake_keys/verification_key"
registrationCertFile <- noteTempFile tempDir "registration.cert"

void $ execDetailCardanoCLI
[ "conway", "stake-address", "registration-certificate"
, "--staking-verification-key-file", keyGenStakingVerificationKeyFile
-- , "--key-reg-deposit-amt", "2000000" This argument being mandatory in conway, the call should fail
, "--out-file", registrationCertFile
]
2 changes: 1 addition & 1 deletion cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6598,7 +6598,7 @@ Usage: cardano-cli conway stake-address registration-certificate
| --stake-script-file FILE
| --stake-address ADDRESS
)
[--key-reg-deposit-amt NATURAL]
--key-reg-deposit-amt NATURAL
--out-file FILE

Create a stake address registration certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Usage: cardano-cli conway stake-address registration-certificate
| --stake-script-file FILE
| --stake-address ADDRESS
)
[--key-reg-deposit-amt NATURAL]
--key-reg-deposit-amt NATURAL
--out-file FILE

Create a stake address registration certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Test.Cardano.CLI.Util
, checkTextEnvelopeFormat
, equivalence
, execCardanoCLI
, execDetailCardanoCli
, execDetailCardanoCLI
, tryExecCardanoCLI
, propertyOnce
, withSnd
Expand Down Expand Up @@ -64,13 +64,13 @@ execCardanoCLI = GHC.withFrozenCallStack $ H.execFlex "cardano-cli" "CARDANO_CLI
-- | Execute cardano-cli via the command line, expecting it to fail.
--
-- Waits for the process to finish and returns the exit code, stdout and stderr.
execDetailCardanoCli
execDetailCardanoCLI
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
=> [String]
-- ^ Arguments to the CLI command
-> m (IO.ExitCode, String, String)
-- ^ Captured stdout
execDetailCardanoCli = GHC.withFrozenCallStack $ execDetailFlex H.defaultExecConfig "cardano-cli" "CARDANO_CLI"
execDetailCardanoCLI = GHC.withFrozenCallStack $ execDetailFlex H.defaultExecConfig "cardano-cli" "CARDANO_CLI"

procFlex'
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
Expand Down