From 4eed9312a37a1341160cf5d58fc038d5f352ca42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 15 Nov 2023 10:29:26 +0100 Subject: [PATCH 1/5] conway stake-address: add test that --key-reg-deposit-amt is mandatory --- .../StakeAddress/RegistrationCertificate.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs index 179ff1c49c..ef026483cf 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs @@ -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" -} @@ -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 + ] From fefc1cef04be679a96073f7a3ec0e55b92003313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 15 Nov 2023 11:09:29 +0100 Subject: [PATCH 2/5] Detail: capitalize execDetailCardanoCLI like other exec* functions --- cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs | 2 +- .../Golden/Shelley/StakeAddress/RegistrationCertificate.hs | 2 +- .../test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs index 5c8f24afdd..daf04b18ad 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs @@ -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 diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs index ef026483cf..197ec3af8b 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs @@ -73,7 +73,7 @@ hprop_golden_shelley_stake_address_registration_certificate_missing_reg_deposit keyGenStakingVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/stake_keys/verification_key" registrationCertFile <- noteTempFile tempDir "registration.cert" - void $ execDetailCardanoCli + 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 diff --git a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs index f3331e534f..e18e0a36b0 100644 --- a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs +++ b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Util.hs @@ -3,7 +3,7 @@ module Test.Cardano.CLI.Util , checkTextEnvelopeFormat , equivalence , execCardanoCLI - , execDetailCardanoCli + , execDetailCardanoCLI , tryExecCardanoCLI , propertyOnce , withSnd @@ -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) From 0c06b548d289a6914b9f4367c4f92d4726a5a175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 15 Nov 2023 11:32:16 +0100 Subject: [PATCH 3/5] stake-address registration-certificate: make -key-reg-deposit-amt mandatory in conway --- .../CLI/EraBased/Options/StakeAddress.hs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs index f972ee4e1c..616351eda6 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs @@ -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 From 8ee0898d27b7c9bf9220523771cebdb5af53874a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 15 Nov 2023 11:32:20 +0100 Subject: [PATCH 4/5] Adapt golden files --- cardano-cli/test/cardano-cli-golden/files/golden/help.cli | 2 +- .../help/conway_stake-address_registration-certificate.cli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 62eff7084b..170dd7dc15 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -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 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_registration-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_registration-certificate.cli index e1915f0c67..410dcf4bf4 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_registration-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_registration-certificate.cli @@ -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 From e79703a4294ac9da871ad0dcfb01b745aeb95d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 15 Nov 2023 11:48:23 +0100 Subject: [PATCH 5/5] Adapt comments in corresponding Run function --- cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs index 740d4fd66e..ab1d45586a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs @@ -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 @@ -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