From 51b64c394846c9f00a74f9d7fe9515d599f8cd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 8 Jan 2025 09:46:23 +0100 Subject: [PATCH 1/3] drep id: support key hash --- .../src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs | 2 +- .../src/Cardano/CLI/EraBased/Options/Governance/DRep.hs | 2 +- .../src/Cardano/CLI/EraBased/Run/Governance/DRep.hs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs index a877a3ba38..db99949016 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs @@ -42,7 +42,7 @@ data GovernanceDRepKeyGenCmdArgs era data GovernanceDRepIdCmdArgs era = GovernanceDRepIdCmdArgs { eon :: !(ConwayEraOnwards era) - , vkeySource :: !(VerificationKeyOrFile DRepKey) + , vkeySource :: !(VerificationKeyOrHashOrFile DRepKey) , idOutputFormat :: !IdOutputFormat , mOutFile :: !(Maybe (File () Out)) } diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs index 8dfc867370..4f57fb9d03 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs @@ -75,7 +75,7 @@ pGovernanceDRepKeyIdCmd era = do $ Opt.info ( fmap GovernanceDRepIdCmd $ GovernanceDRepIdCmdArgs w - <$> pDRepVerificationKeyOrFile + <$> pDRepVerificationKeyOrHashOrFile <*> pDRepIdOutputFormat <*> optional pOutputFile ) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs index 2fc2bbd809..84a63241c4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -83,14 +83,14 @@ runGovernanceDRepIdCmd , idOutputFormat , mOutFile } = do - drepVerKey <- + drepVerKeyHash <- modifyError ReadFileError $ - readVerificationKeyOrTextEnvFile AsDRepKey vkeySource + readVerificationKeyOrHashOrTextEnvFile AsDRepKey vkeySource content <- pure $ case idOutputFormat of - IdOutputFormatHex -> serialiseToRawBytesHex $ verificationKeyHash drepVerKey - IdOutputFormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 $ verificationKeyHash drepVerKey + IdOutputFormatHex -> serialiseToRawBytesHex drepVerKeyHash + IdOutputFormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 drepVerKeyHash lift (writeByteStringOutput mOutFile content) & onLeft (left . WriteFileError) From 63258306fc6a38305be17843d0b7a794c6392de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 8 Jan 2025 09:46:30 +0100 Subject: [PATCH 2/3] Adapt golden files --- cardano-cli/test/cardano-cli-golden/files/golden/help.cli | 3 +++ .../files/golden/help/compatible_conway_governance_drep_id.cli | 3 +++ .../files/golden/help/conway_governance_drep_id.cli | 3 +++ .../files/golden/help/latest_governance_drep_id.cli | 3 +++ 4 files changed, 12 insertions(+) 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 169448001a..6ea71ec9c0 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -7087,6 +7087,7 @@ Usage: cardano-cli conway governance drep key-gen --verification-key-file FILEPA Usage: cardano-cli conway governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] @@ -9107,6 +9108,7 @@ Usage: cardano-cli latest governance drep key-gen --verification-key-file FILEPA Usage: cardano-cli latest governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] @@ -11729,6 +11731,7 @@ Usage: cardano-cli compatible conway governance drep key-gen --verification-key- Usage: cardano-cli compatible conway governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/compatible_conway_governance_drep_id.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/compatible_conway_governance_drep_id.cli index 4ef7ba9f57..029942854e 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/compatible_conway_governance_drep_id.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/compatible_conway_governance_drep_id.cli @@ -1,6 +1,7 @@ Usage: cardano-cli compatible conway governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] @@ -12,6 +13,8 @@ Available options: DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILEPATH Filepath of the DRep verification key. + --drep-key-hash HASH DRep verification key hash (either Bech32-encoded or + hex-encoded). --output-format STRING Optional drep id output format. Accepted output formats are "hex" and "bech32" (default is "bech32"). --out-file FILEPATH The output file. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_id.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_id.cli index 7a6466a689..e9c2947bec 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_id.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_id.cli @@ -1,6 +1,7 @@ Usage: cardano-cli conway governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] @@ -12,6 +13,8 @@ Available options: DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILEPATH Filepath of the DRep verification key. + --drep-key-hash HASH DRep verification key hash (either Bech32-encoded or + hex-encoded). --output-format STRING Optional drep id output format. Accepted output formats are "hex" and "bech32" (default is "bech32"). --out-file FILEPATH The output file. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_drep_id.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_drep_id.cli index 0cbbf1fc1d..307f2729ca 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_drep_id.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_drep_id.cli @@ -1,6 +1,7 @@ Usage: cardano-cli latest governance drep id ( --drep-verification-key STRING | --drep-verification-key-file FILEPATH + | --drep-key-hash HASH ) [--output-format STRING] [--out-file FILEPATH] @@ -12,6 +13,8 @@ Available options: DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILEPATH Filepath of the DRep verification key. + --drep-key-hash HASH DRep verification key hash (either Bech32-encoded or + hex-encoded). --output-format STRING Optional drep id output format. Accepted output formats are "hex" and "bech32" (default is "bech32"). --out-file FILEPATH The output file. From 9f7eb2d31ae7f25ecf9fe673d4550099246c202a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 8 Jan 2025 10:01:12 +0100 Subject: [PATCH 3/3] drep id: golden test new key hash support --- .../Test/Golden/Governance/DRep.hs | 18 ++++++++++++++++++ .../files/golden/governance/drep/drep.id.hash | 1 + 2 files changed, 19 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep.id.hash diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs index 3e1dcd4736..7bdb93bdf4 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -122,6 +122,24 @@ hprop_golden_governance_drep_id_hex = H.diffFileVsGoldenFile idFile idGold +-- | Execute me with: +-- @cabal test cardano-cli-golden --test-options '-p "/golden governance drep id hash/"'@ +hprop_golden_governance_drep_id_hash :: Property +hprop_golden_governance_drep_id_hash = propertyOnce $ do + idGold <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep.id.hash" + + output <- + execCardanoCLI + [ "conway" + , "governance" + , "drep" + , "id" + , "--drep-key-hash" + , "c1a342f0dfb82b93ca2e6b406bacb04802f7d56a99d8f95a80a8b6c5" + ] + + H.diffVsGoldenFile output idGold + hprop_golden_governance_drep_extended_key_signing :: Property hprop_golden_governance_drep_extended_key_signing = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep.id.hash b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep.id.hash new file mode 100644 index 0000000000..39c85c3ccf --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep.id.hash @@ -0,0 +1 @@ +drep1cx359uxlhq4e8j3wddqxht9sfqp004t2n8v0jk5q4zmv27sh0h5 \ No newline at end of file