From 79cca8e2e2c56ce5eebe3d030e0a0c14bb662fc9 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Tue, 9 Jan 2024 12:31:13 +0100 Subject: [PATCH 1/4] Enable registration of scripts as DReps --- .../CLI/EraBased/Commands/Governance/DRep.hs | 2 +- .../Cardano/CLI/EraBased/Options/Common.hs | 4 +- .../CLI/EraBased/Options/Governance/DRep.hs | 2 +- .../CLI/EraBased/Run/Governance/DRep.hs | 37 +++++++++++-------- .../Test/Golden/Governance/DRep.hs | 20 ++++++++-- .../drep_registration_certificate_script.json | 5 +++ .../cardano-cli-golden/files/golden/help.cli | 3 +- ...vernance_drep_registration-certificate.cli | 5 ++- ..._stake-and-vote-delegation-certificate.cli | 3 +- ...ke-address_vote-delegation-certificate.cli | 3 +- 10 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate_script.json 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 01d1f1e4ef..49d5aab84a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/DRep.hs @@ -48,7 +48,7 @@ data GovernanceDRepIdCmdArgs era = data GovernanceDRepRegistrationCertificateCmdArgs era = GovernanceDRepRegistrationCertificateCmdArgs { eon :: !(ConwayEraOnwards era) - , drepVkeyHashSource :: !(VerificationKeyOrHashOrFile DRepKey) + , drepHashSource :: !DRepHashSource , deposit :: !Lovelace , mAnchor :: !(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era)))) , outFile :: !(File () Out) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 722d64d930..02dc0c9b39 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -3051,9 +3051,7 @@ pDRepScriptHash = Opt.option scriptHashReader $ mconcat [ Opt.long "drep-script-hash" , Opt.metavar "HASH" - , Opt.help $ mconcat - [ "DRep script hash (hex-encoded)." - ] + , Opt.help "DRep script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash ...\"." ] pDRepVerificationKeyOrHashOrFile 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 3891b7a8c6..6145fc7ddd 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs @@ -102,7 +102,7 @@ pRegistrationCertificateCmd era = do mkParser w = fmap GovernanceDRepRegistrationCertificateCmd $ GovernanceDRepRegistrationCertificateCmdArgs w - <$> pDRepVerificationKeyOrHashOrFile + <$> pDRepHashSource <*> pKeyRegistDeposit <*> pDRepMetadata <*> 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 4234c4a49c..3fa08d5b22 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -104,24 +104,31 @@ runGovernanceDRepRegistrationCertificateCmd :: () runGovernanceDRepRegistrationCertificateCmd Cmd.GovernanceDRepRegistrationCertificateCmdArgs { eon = w - , drepVkeyHashSource + , drepHashSource , deposit , mAnchor , outFile - } = do - DRepKeyHash drepKeyHash <- firstExceptT RegistrationReadError - . newExceptT - $ readVerificationKeyOrHashOrFile AsDRepKey drepVkeyHashSource - let drepCred = Ledger.KeyHashObj $ conwayEraOnwardsConstraints w drepKeyHash - req = DRepRegistrationRequirements w drepCred deposit - registrationCert = makeDrepRegistrationCertificate req mAnchor - description = Just @TextEnvelopeDescr "DRep Key Registration Certificate" - - firstExceptT RegistrationWriteFileError - . newExceptT - . writeLazyByteStringFile outFile - $ conwayEraOnwardsConstraints w - $ textEnvelopeToJSON description registrationCert + } = + conwayEraOnwardsConstraints w $ do + drepCred <- + case drepHashSource of + DRepHashSourceScript (ScriptHash scriptHash) -> + return $ Ledger.ScriptHashObj scriptHash + DRepHashSourceVerificationKey drepVkeyHashSource -> do + DRepKeyHash drepKeyHash <- + firstExceptT RegistrationReadError + . newExceptT + $ readVerificationKeyOrHashOrFile AsDRepKey drepVkeyHashSource + return $ Ledger.KeyHashObj $ conwayEraOnwardsConstraints w drepKeyHash + let req = DRepRegistrationRequirements w drepCred deposit + registrationCert = makeDrepRegistrationCertificate req mAnchor + description = Just @TextEnvelopeDescr "DRep Key Registration Certificate" + + firstExceptT RegistrationWriteFileError + . newExceptT + . writeLazyByteStringFile outFile + $ conwayEraOnwardsConstraints w + $ textEnvelopeToJSON description registrationCert runGovernanceDRepRetirementCertificateCmd :: () => Cmd.GovernanceDRepRetirementCertificateCmdArgs era 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 6917916d7b..5a6347a6c5 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 @@ -8,13 +8,10 @@ module Test.Golden.Governance.DRep where #endif import Control.Monad - -#ifdef UNIX import Data.Bits ((.&.)) import GHC.Stack (withFrozenCallStack) import Numeric (showOct) import System.Posix.Files (fileMode, getFileStatus) -#endif import Test.Cardano.CLI.Util (execCardanoCLI, noteInputFile, noteTempFile, propertyOnce) @@ -206,3 +203,20 @@ hprop_golden_governance_drep_registration_certificate_id_bech32 = propertyOnce . ] H.diffFileVsGoldenFile outFile goldenFile + +hprop_golden_governance_drep_registration_certificate_script_hash :: Property +hprop_golden_governance_drep_registration_certificate_script_hash = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate_script.json" + + outFile <- H.noteTempFile tempDir "drep-reg-cert.txt" + + void $ execCardanoCLI + [ "conway", "governance", "drep", "registration-certificate" + , "--drep-script-hash", "00000000000000000000000000000000000000000000000000000003" + , "--key-reg-deposit-amt", "0" + , "--drep-metadata-url", "dummy-url" + , "--drep-metadata-hash", "52e69500a92d80f2126c836a4903dc582006709f004cf7a28ed648f732dff8d2" + , "--out-file", outFile + ] + + H.diffFileVsGoldenFile outFile goldenFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate_script.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate_script.json new file mode 100644 index 0000000000..21cd0d468e --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate_script.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateConway", + "description": "DRep Key Registration Certificate", + "cborHex": "84108201581c0000000000000000000000000000000000000000000000000000000300826964756d6d792d75726c582052e69500a92d80f2126c836a4903dc582006709f004cf7a28ed648f732dff8d2" +} 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 5abc2fa18c..4e541fa7bf 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6338,7 +6338,8 @@ Usage: cardano-cli conway governance drep id Generate a drep id. Usage: cardano-cli conway governance drep registration-certificate - ( --drep-verification-key STRING + ( --drep-script-hash HASH + | --drep-verification-key STRING | --drep-verification-key-file FILE | --drep-key-hash HASH ) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli index 0c1ea76729..b41ca6b38e 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli @@ -1,5 +1,6 @@ Usage: cardano-cli conway governance drep registration-certificate - ( --drep-verification-key STRING + ( --drep-script-hash HASH + | --drep-verification-key STRING | --drep-verification-key-file FILE | --drep-key-hash HASH ) @@ -11,6 +12,8 @@ Usage: cardano-cli conway governance drep registration-certificate Create a registration certificate. Available options: + --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with + "cardano-cli conway governance hash ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli index 22f3aceff6..2001acdc72 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli @@ -34,7 +34,8 @@ Available options: --stake-pool-id STAKE_POOL_ID Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). - --drep-script-hash HASH DRep script hash (hex-encoded). + --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with + "cardano-cli conway governance hash ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli index 2ba6ee4fd3..edeeaa8018 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli @@ -23,7 +23,8 @@ Available options: Filepath of the staking verification key. --stake-script-file FILE Filepath of the staking script. --stake-address ADDRESS Target stake address (bech32 format). - --drep-script-hash HASH DRep script hash (hex-encoded). + --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with + "cardano-cli conway governance hash ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE From 0fe848abff5ec57ed62c45ad4d988feede5652e3 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Tue, 9 Jan 2024 13:38:19 +0100 Subject: [PATCH 2/4] Rework `governance hash` command: separate scripts and anchors --- .../CLI/EraBased/Commands/Governance/Hash.hs | 37 +++++++----- .../Cardano/CLI/EraBased/Options/Common.hs | 8 +-- .../CLI/EraBased/Options/Governance/Hash.hs | 56 ++++++++++++++----- .../CLI/EraBased/Run/Governance/Hash.hs | 40 +++++++++---- .../CLI/Types/Errors/GovernanceHashError.hs | 4 ++ .../Test/Golden/Governance/Action.hs | 8 +-- .../Test/Golden/Governance/Committee.hs | 2 +- .../cardano-cli-golden/files/golden/help.cli | 21 +++++-- ..._governance_action_create-constitution.cli | 5 +- .../conway_governance_action_create-info.cli | 2 +- ...governance_action_create-no-confidence.cli | 2 +- ...tion_create-protocol-parameters-update.cli | 2 +- ...ance_action_create-treasury-withdrawal.cli | 2 +- ...way_governance_action_update-committee.cli | 2 +- ...vernance_drep_registration-certificate.cli | 2 +- .../golden/help/conway_governance_hash.cli | 15 ++--- .../conway_governance_hash_anchor-data.cli | 15 +++++ .../help/conway_governance_hash_script.cli | 9 +++ .../help/conway_governance_vote_create.cli | 3 +- ..._stake-and-vote-delegation-certificate.cli | 2 +- ...ke-address_vote-delegation-certificate.cli | 2 +- .../Test/Cli/Governance/Hash.hs | 4 +- 22 files changed, 167 insertions(+), 76 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs index b517b5a4bc..31742d48fb 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Hash.hs @@ -1,12 +1,13 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} - module Cardano.CLI.EraBased.Commands.Governance.Hash ( GovernanceHashCmds (..), - GovernanceHashCmdArgs (..), - GovernanceHashSource (..), + GovernanceHashAnchorDataCmdArgs (..), + GovernanceHashScriptCmdArgs (..), + GovernanceAnchorDataHashSource (..), renderGovernanceHashCmds ) where @@ -16,21 +17,31 @@ import Cardano.CLI.Types.Common import Data.Text (Text) -newtype GovernanceHashCmds era = GovernanceHashCmd (GovernanceHashCmdArgs era) +data GovernanceHashCmds era + = GovernanceHashAnchorDataCmd !(GovernanceHashAnchorDataCmdArgs era) + | GovernanceHashScriptCmd !(GovernanceHashScriptCmdArgs era) -data GovernanceHashCmdArgs era - = GovernanceHashCmdArgs { +data GovernanceHashAnchorDataCmdArgs era + = GovernanceHashAnchorDataCmdArgs { eon :: !(ConwayEraOnwards era) - , toHash :: !GovernanceHashSource + , toHash :: !GovernanceAnchorDataHashSource , moutFile :: !(Maybe (File () Out)) -- ^ The output file to which the hash is written } deriving Show -data GovernanceHashSource - = GovernanceHashSourceBinaryFile (File ProposalText In) - | GovernanceHashSourceTextFile (File ProposalText In) - | GovernanceHashSourceText Text +data GovernanceAnchorDataHashSource + = GovernanceAnchorDataHashSourceBinaryFile (File ProposalText In) + | GovernanceAnchorDataHashSourceTextFile (File ProposalText In) + | GovernanceAnchorDataHashSourceText Text deriving Show +data GovernanceHashScriptCmdArgs era + = GovernanceHashScriptCmdArgs { + eon :: !(ConwayEraOnwards era) + , toHash :: !ScriptFile + , moutFile :: !(Maybe (File () Out)) -- ^ The output file to which the hash is written + } deriving Show + renderGovernanceHashCmds :: GovernanceHashCmds era -> Text -renderGovernanceHashCmds = - \case GovernanceHashCmd {} -> "governance hash" +renderGovernanceHashCmds = \case + GovernanceHashAnchorDataCmd {} -> "governance hash anchor-data" + GovernanceHashScriptCmd {} -> "governance hash script" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 02dc0c9b39..cdb0d12bbf 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -883,7 +883,7 @@ pConstitutionHash = Opt.option readSafeHash $ mconcat [ Opt.long "constitution-hash" , Opt.metavar "HASH" - , Opt.help "Hash of the constitution data (obtain it with \"cardano-cli conway governance hash ...\")." + , Opt.help "Hash of the constitution data (obtain it with \"cardano-cli conway governance hash anchor-data ...\")." ] pUrl :: String -> String -> Parser Ledger.Url @@ -3029,7 +3029,7 @@ pVoteAnchorDataHash = Opt.option readSafeHash $ mconcat [ Opt.long "anchor-data-hash" , Opt.metavar "HASH" - , Opt.help "Hash of the vote anchor data (obtain it with \"cardano-cli conway governance hash ...\")." + , Opt.help "Hash of the vote anchor data (obtain it with \"cardano-cli conway governance hash anchor-data ...\")." ] pAlwaysNoConfidence :: Parser () @@ -3051,7 +3051,7 @@ pDRepScriptHash = Opt.option scriptHashReader $ mconcat [ Opt.long "drep-script-hash" , Opt.metavar "HASH" - , Opt.help "DRep script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash ...\"." + , Opt.help "DRep script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"." ] pDRepVerificationKeyOrHashOrFile @@ -3113,7 +3113,7 @@ pAnchorDataHash = Opt.option readSafeHash $ mconcat [ Opt.long "anchor-data-hash" , Opt.metavar "HASH" - , Opt.help "Proposal anchor data hash (obtain it with \"cardano-cli conway governance hash ...\")" + , Opt.help "Proposal anchor data hash (obtain it with \"cardano-cli conway governance hash anchor-data ...\")" ] pPreviousGovernanceAction :: Parser (Maybe (TxId, Word32)) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs index e2ee76e17d..530f1a1447 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs @@ -3,13 +3,11 @@ module Cardano.CLI.EraBased.Options.Governance.Hash ( - pGovernanceHashCmds + pGovernanceHashCmds, ) where import Cardano.Api -import Cardano.CLI.EraBased.Commands.Governance.Hash - (GovernanceHashCmdArgs (GovernanceHashCmdArgs)) import qualified Cardano.CLI.EraBased.Commands.Governance.Hash as Cmd import Cardano.CLI.EraBased.Options.Common @@ -17,25 +15,39 @@ import Data.Foldable import Options.Applicative import qualified Options.Applicative as Opt -pGovernanceHashCmds :: () +pGovernanceHashCmds + :: CardanoEra era + -> Maybe (Parser (Cmd.GovernanceHashCmds era)) +pGovernanceHashCmds era = + subInfoParser "hash" + ( Opt.progDesc + $ mconcat + [ "Compute the hash to pass to the various --*-hash arguments of governance commands." + ] + ) + [ pGovernanceHashAnchorDataCmd era + , pGovernanceHashScriptCmd era + ] + +pGovernanceHashAnchorDataCmd :: () => CardanoEra era -> Maybe (Parser (Cmd.GovernanceHashCmds era)) -pGovernanceHashCmds era = do +pGovernanceHashAnchorDataCmd era = do eon <- forEraMaybeEon era return - $ subParser "hash" + $ subParser "anchor-data" $ Opt.info - ( fmap Cmd.GovernanceHashCmd - (GovernanceHashCmdArgs eon - <$> pGovernanceHashSource + ( fmap Cmd.GovernanceHashAnchorDataCmd + (Cmd.GovernanceHashAnchorDataCmdArgs eon + <$> pGovernanceAnchorDataHashSource <*> optional pOutputFile)) - $ Opt.progDesc "Compute the hash to pass to the various --*-hash arguments of governance commands." + $ Opt.progDesc "Compute the hash of some anchor data." -pGovernanceHashSource :: Parser Cmd.GovernanceHashSource -pGovernanceHashSource = +pGovernanceAnchorDataHashSource :: Parser Cmd.GovernanceAnchorDataHashSource +pGovernanceAnchorDataHashSource = asum [ - Cmd.GovernanceHashSourceText + Cmd.GovernanceAnchorDataHashSourceText <$> Opt.strOption ( mconcat [ Opt.long "text" @@ -43,8 +55,22 @@ pGovernanceHashSource = , Opt.help "Text to hash as UTF-8" ] ) - , Cmd.GovernanceHashSourceBinaryFile + , Cmd.GovernanceAnchorDataHashSourceBinaryFile <$> pFileInDirection "file-binary" "Binary file to hash" - , Cmd.GovernanceHashSourceTextFile + , Cmd.GovernanceAnchorDataHashSourceTextFile <$> pFileInDirection "file-text" "Text file to hash" ] + +pGovernanceHashScriptCmd :: () + => CardanoEra era + -> Maybe (Parser (Cmd.GovernanceHashCmds era)) +pGovernanceHashScriptCmd era = do + eon <- forEraMaybeEon era + return + $ subParser "script" + $ Opt.info + ( fmap Cmd.GovernanceHashScriptCmd + (Cmd.GovernanceHashScriptCmdArgs eon + <$> pScript + <*> optional pOutputFile)) + $ Opt.progDesc "Compute the hash of a script." diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs index f7c7e02bc2..ca9fd7003a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Hash.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -15,6 +16,8 @@ module Cardano.CLI.EraBased.Run.Governance.Hash import Cardano.Api import qualified Cardano.CLI.EraBased.Commands.Governance.Hash as Cmd +import Cardano.CLI.Read +import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.CmdError import Cardano.CLI.Types.Errors.GovernanceCmdError import Cardano.CLI.Types.Errors.GovernanceHashError @@ -34,28 +37,32 @@ import qualified Data.Text.IO as Text runGovernanceHashCmds :: () => Cmd.GovernanceHashCmds era -> ExceptT CmdError IO () -runGovernanceHashCmds (Cmd.GovernanceHashCmd args)= - runGovernanceHashCmd args +runGovernanceHashCmds = \case + + Cmd.GovernanceHashAnchorDataCmd args -> + runGovernanceHashAnchorDataCmd args + & firstExceptT (CmdGovernanceCmdError . GovernanceCmdHashError) + + Cmd.GovernanceHashScriptCmd args -> + runGovernanceHashScriptCmd args & firstExceptT (CmdGovernanceCmdError . GovernanceCmdHashError) -runGovernanceHashCmd :: () - => Cmd.GovernanceHashCmdArgs era +runGovernanceHashAnchorDataCmd :: () + => Cmd.GovernanceHashAnchorDataCmdArgs era -> ExceptT GovernanceHashError IO () -runGovernanceHashCmd Cmd.GovernanceHashCmdArgs { toHash, moutFile } = - -- TODO @smelc we probably want an option to write the computed hash to a file - -- This can be done in a separate PR +runGovernanceHashAnchorDataCmd Cmd.GovernanceHashAnchorDataCmdArgs { toHash, moutFile } = case toHash of - Cmd.GovernanceHashSourceBinaryFile fp -> do + Cmd.GovernanceAnchorDataHashSourceBinaryFile fp -> do let path = unFile fp bytes <- handleIOExceptT (GovernanceHashReadFileError path) $ BS.readFile path let hash = Ledger.hashAnchorData $ Ledger.AnchorData bytes printHash hash - Cmd.GovernanceHashSourceTextFile fp -> do + Cmd.GovernanceAnchorDataHashSourceTextFile fp -> do let path = unFile fp text <- handleIOExceptT (GovernanceHashReadFileError path) $ Text.readFile path let hash = Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 text printHash hash - Cmd.GovernanceHashSourceText text -> do + Cmd.GovernanceAnchorDataHashSourceText text -> do let hash = Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 text printHash hash where @@ -65,3 +72,16 @@ runGovernanceHashCmd Cmd.GovernanceHashCmdArgs { toHash, moutFile } = newExceptT $ writeTextOutput moutFile text where text = hashToTextAsHex . extractHash $ hash + +runGovernanceHashScriptCmd :: () + => Cmd.GovernanceHashScriptCmdArgs era + -> ExceptT GovernanceHashError IO () +runGovernanceHashScriptCmd Cmd.GovernanceHashScriptCmdArgs { Cmd.toHash = ScriptFile toHash, moutFile } = do + ScriptInAnyLang _ script <- + readFileScriptInAnyLang toHash + & firstExceptT (GovernanceHashReadScriptError toHash) + firstExceptT GovernanceHashWriteFileError + . newExceptT + . writeTextOutput moutFile . serialiseToRawBytesHexText $ hashScript script + + diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs index f23257591d..b24af608e1 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceHashError.hs @@ -6,11 +6,13 @@ module Cardano.CLI.Types.Errors.GovernanceHashError import Cardano.Api import Cardano.Api.Pretty +import Cardano.CLI.Read (ScriptDecodeError) import Cardano.Prelude (Exception (displayException), IOException) data GovernanceHashError = GovernanceHashReadFileError !FilePath !IOException | GovernanceHashWriteFileError !(FileError ()) + | GovernanceHashReadScriptError !FilePath !(FileError ScriptDecodeError) deriving Show instance Error GovernanceHashError where @@ -19,3 +21,5 @@ instance Error GovernanceHashError where "Cannot read " <> pretty filepath <> ": " <> pretty (displayException exc) GovernanceHashWriteFileError fileErr -> prettyError fileErr + GovernanceHashReadScriptError filepath err -> + "Cannot read script at " <> pretty filepath <> ": " <> prettyError err diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs index 0863496bcb..8439d36ca7 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs @@ -27,11 +27,11 @@ hprop_golden_governance_action_create_constitution = redactedActionFile <- noteTempFile tempDir "create-constitution.action.redacted" proposalHash <- execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", "whatever"] constitutionHash <- execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", "something else"] void $ execCardanoCLI @@ -63,7 +63,7 @@ hprop_golden_conway_governance_action_view_constitution_json = -- We go through a file for the hash, to test --out-file void $ execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", "whatever " , "--out-file", hashFile ] @@ -71,7 +71,7 @@ hprop_golden_conway_governance_action_view_constitution_json = proposalHash <- H.readFile hashFile constitutionHash <- execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", "nonAsciiInput: 你好 and some more: こんにちは" ] diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs index 1ad6179269..59517e919c 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs @@ -158,7 +158,7 @@ hprop_golden_governanceUpdateCommittee = outFile <- H.noteTempFile tempDir "answer-file.json" proposalHash <- execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--file-text", ccProposal ] H.note_ proposalHash 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 4e541fa7bf..218f6cdf6b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6365,16 +6365,25 @@ Usage: cardano-cli conway governance drep metadata-hash --drep-metadata-file FIL Calculate the hash of a metadata file. -Usage: cardano-cli conway governance hash - ( --text TEXT - | --file-binary FILE - | --file-text FILE - ) - [--out-file FILE] +Usage: cardano-cli conway governance hash (anchor-data | script) Compute the hash to pass to the various --*-hash arguments of governance commands. +Usage: cardano-cli conway governance hash anchor-data + ( --text TEXT + | --file-binary FILE + | --file-text FILE + ) + [--out-file FILE] + + Compute the hash of some anchor data. + +Usage: cardano-cli conway governance hash script --script-file FILE + [--out-file FILE] + + Compute the hash of a script. + Usage: cardano-cli conway governance vote (create | view) Vote commands. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-constitution.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-constitution.cli index 6173f056db..d334ebba64 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-constitution.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-constitution.cli @@ -34,9 +34,10 @@ Available options: Action index of the previous governance action. --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --constitution-url TEXT Constitution URL. --constitution-hash HASH Hash of the constitution data (obtain it with - "cardano-cli conway governance hash ..."). + "cardano-cli conway governance hash anchor-data + ..."). --out-file FILE Output filepath of the constitution. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli index 4fee528551..325a29f118 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-info.cli @@ -23,7 +23,7 @@ Available options: Stake verification key hash (hex-encoded). --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --out-file FILE Path to action file to be used later on with build or build-raw -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-no-confidence.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-no-confidence.cli index 111c30641c..bdf1e21420 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-no-confidence.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-no-confidence.cli @@ -28,7 +28,7 @@ Available options: Stake verification key hash (hex-encoded). --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --prev-governance-action-tx-id TXID Txid of the previous governance action. --prev-governance-action-index WORD32 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-protocol-parameters-update.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-protocol-parameters-update.cli index 3eb9690196..3cf5cd0522 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-protocol-parameters-update.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-protocol-parameters-update.cli @@ -70,7 +70,7 @@ Available options: Stake verification key hash (hex-encoded). --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --prev-governance-action-tx-id TXID Txid of the previous governance action. --prev-governance-action-index WORD32 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-treasury-withdrawal.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-treasury-withdrawal.cli index 34f2e1e103..04460a20aa 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-treasury-withdrawal.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_create-treasury-withdrawal.cli @@ -32,7 +32,7 @@ Available options: Stake verification key hash (hex-encoded). --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --funds-receiving-stake-verification-key STRING Stake verification key (Bech32 or hex-encoded). --funds-receiving-stake-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli index 2ac2a04cc4..846aa5e33a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli @@ -39,7 +39,7 @@ Available options: Stake verification key hash (hex-encoded). --anchor-url TEXT Anchor URL --anchor-data-hash HASH Proposal anchor data hash (obtain it with - "cardano-cli conway governance hash ...") + "cardano-cli conway governance hash anchor-data ...") --remove-cc-cold-verification-key STRING Constitutional Committee cold key (hex-encoded). --remove-cc-cold-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli index b41ca6b38e..e01467f4de 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_registration-certificate.cli @@ -13,7 +13,7 @@ Usage: cardano-cli conway governance drep registration-certificate Available options: --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with - "cardano-cli conway governance hash ...". + "cardano-cli conway governance hash script ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli index 6c0be02032..e248a9f124 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli @@ -1,16 +1,11 @@ -Usage: cardano-cli conway governance hash - ( --text TEXT - | --file-binary FILE - | --file-text FILE - ) - [--out-file FILE] +Usage: cardano-cli conway governance hash (anchor-data | script) Compute the hash to pass to the various --*-hash arguments of governance commands. Available options: - --text TEXT Text to hash as UTF-8 - --file-binary FILE Binary file to hash - --file-text FILE Text file to hash - --out-file FILE The output file. -h,--help Show this help text + +Available commands: + anchor-data Compute the hash of some anchor data. + script Compute the hash of a script. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli new file mode 100644 index 0000000000..b8a6902c74 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli @@ -0,0 +1,15 @@ +Usage: cardano-cli conway governance hash anchor-data + ( --text TEXT + | --file-binary FILE + | --file-text FILE + ) + [--out-file FILE] + + Compute the hash of some anchor data. + +Available options: + --text TEXT Text to hash as UTF-8 + --file-binary FILE Binary file to hash + --file-text FILE Text file to hash + --out-file FILE The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli new file mode 100644 index 0000000000..b4cccda3ed --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli @@ -0,0 +1,9 @@ +Usage: cardano-cli conway governance hash script --script-file FILE + [--out-file FILE] + + Compute the hash of a script. + +Available options: + --script-file FILE Filepath of the script. + --out-file FILE The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli index 184d1c203b..509027cb2a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli @@ -42,6 +42,7 @@ Available options: --cc-hot-key-hash STRING Constitutional Committee key hash (hex-encoded). --anchor-url TEXT Vote anchor URL --anchor-data-hash HASH Hash of the vote anchor data (obtain it with - "cardano-cli conway governance hash ..."). + "cardano-cli conway governance hash anchor-data + ..."). --out-file FILE Output filepath of the vote. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli index 2001acdc72..d68afda1ae 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_stake-and-vote-delegation-certificate.cli @@ -35,7 +35,7 @@ Available options: Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with - "cardano-cli conway governance hash ...". + "cardano-cli conway governance hash script ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli index edeeaa8018..dbfc7c4ee7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_stake-address_vote-delegation-certificate.cli @@ -24,7 +24,7 @@ Available options: --stake-script-file FILE Filepath of the staking script. --stake-address ADDRESS Target stake address (bech32 format). --drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with - "cardano-cli conway governance hash ...". + "cardano-cli conway governance hash script ...". --drep-verification-key STRING DRep verification key (Bech32 or hex-encoded). --drep-verification-key-file FILE diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs index 32c3cef9e4..3acb2ecb86 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs @@ -27,12 +27,12 @@ governance_hash_trip_fun input = hashFile <- noteTempFile tempDir "hash.txt" hash <- execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", input ] void $ execCardanoCLI - [ "conway", "governance", "hash" + [ "conway", "governance", "hash", "anchor-data" , "--text", input , "--out-file", hashFile ] From dddef9d5f4c7d846b636736cfa534db4c12e56cb Mon Sep 17 00:00:00 2001 From: carlhammann <102371507+carlhammann@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:01:04 +0100 Subject: [PATCH 3/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Hurlin Reintroduce accidentally deleted cpp --- .../src/Cardano/CLI/EraBased/Options/Governance/Hash.hs | 4 ++-- .../test/cardano-cli-golden/Test/Golden/Governance/DRep.hs | 3 +++ cardano-cli/test/cardano-cli-golden/files/golden/help.cli | 5 +++-- .../files/golden/help/conway_governance_hash.cli | 6 ++++-- .../golden/help/conway_governance_hash_anchor-data.cli | 3 ++- .../files/golden/help/conway_governance_hash_script.cli | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs index 530f1a1447..35e1d13824 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Hash.hs @@ -41,7 +41,7 @@ pGovernanceHashAnchorDataCmd era = do (Cmd.GovernanceHashAnchorDataCmdArgs eon <$> pGovernanceAnchorDataHashSource <*> optional pOutputFile)) - $ Opt.progDesc "Compute the hash of some anchor data." + $ Opt.progDesc "Compute the hash of some anchor data (to then pass it to other governance commands)." pGovernanceAnchorDataHashSource :: Parser Cmd.GovernanceAnchorDataHashSource pGovernanceAnchorDataHashSource = @@ -73,4 +73,4 @@ pGovernanceHashScriptCmd era = do (Cmd.GovernanceHashScriptCmdArgs eon <$> pScript <*> optional pOutputFile)) - $ Opt.progDesc "Compute the hash of a script." + $ Opt.progDesc "Compute the hash of a script (to then pass it to other governance commands)." 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 5a6347a6c5..40947e1b55 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 @@ -8,10 +8,13 @@ module Test.Golden.Governance.DRep where #endif import Control.Monad + +#ifdef UNIX import Data.Bits ((.&.)) import GHC.Stack (withFrozenCallStack) import Numeric (showOct) import System.Posix.Files (fileMode, getFileStatus) +#endif import Test.Cardano.CLI.Util (execCardanoCLI, noteInputFile, noteTempFile, propertyOnce) 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 218f6cdf6b..dd1ce763dd 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6377,12 +6377,13 @@ Usage: cardano-cli conway governance hash anchor-data ) [--out-file FILE] - Compute the hash of some anchor data. + Compute the hash of some anchor data (to then pass it to other governance + commands). Usage: cardano-cli conway governance hash script --script-file FILE [--out-file FILE] - Compute the hash of a script. + Compute the hash of a script (to then pass it to other governance commands). Usage: cardano-cli conway governance vote (create | view) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli index e248a9f124..2582fb1680 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash.cli @@ -7,5 +7,7 @@ Available options: -h,--help Show this help text Available commands: - anchor-data Compute the hash of some anchor data. - script Compute the hash of a script. + anchor-data Compute the hash of some anchor data (to then pass it + to other governance commands). + script Compute the hash of a script (to then pass it to + other governance commands). diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli index b8a6902c74..9c04ea0f5a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_anchor-data.cli @@ -5,7 +5,8 @@ Usage: cardano-cli conway governance hash anchor-data ) [--out-file FILE] - Compute the hash of some anchor data. + Compute the hash of some anchor data (to then pass it to other governance + commands). Available options: --text TEXT Text to hash as UTF-8 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli index b4cccda3ed..9ed3e296c3 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_hash_script.cli @@ -1,7 +1,7 @@ Usage: cardano-cli conway governance hash script --script-file FILE [--out-file FILE] - Compute the hash of a script. + Compute the hash of a script (to then pass it to other governance commands). Available options: --script-file FILE Filepath of the script. From f8f652c7eaa6dd7f66e7d299544b7869866595a0 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 12 Jan 2024 15:48:07 +0100 Subject: [PATCH 4/4] Add golden test: `conway governance hash script` --- cardano-cli/cardano-cli.cabal | 1 + .../Test/Golden/Governance/Hash.hs | 26 +++++++++++++++++++ .../golden/governance/hash/foo.script.hash | 1 + .../files/input/governance/hash/foo.script | 5 ++++ 4 files changed, 33 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 725e005bbb..0f5dc594e2 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -373,6 +373,7 @@ test-suite cardano-cli-golden Test.Golden.Governance.Action Test.Golden.Governance.Committee Test.Golden.Governance.DRep + Test.Golden.Governance.Hash Test.Golden.Governance.StakeAddress Test.Golden.Governance.Vote Test.Golden.Help diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs new file mode 100644 index 0000000000..d8ca07a41a --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs @@ -0,0 +1,26 @@ +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} +{-# HLINT ignore "Use camelCase" #-} +module Test.Golden.Governance.Hash where +import Control.Monad + +import Test.Cardano.CLI.Util + +import Hedgehog (Property) +import qualified Hedgehog.Extras as H +import qualified Hedgehog.Extras.Test.Golden as H + + +hprop_golden_governance_hash_script :: Property +hprop_golden_governance_hash_script = + H.propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + scriptFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/hash/foo.script" + hashFile <- H.noteTempFile tempDir "foo.script.hash" + hashGold <- H.note "test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash" + + void $ execCardanoCLI + [ "conway", "governance", "hash", "script" + , "--script-file", scriptFile + , "--out-file", hashFile + ] + + H.diffFileVsGoldenFile hashFile hashGold diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash b/cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash new file mode 100644 index 0000000000..67040a92f1 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash @@ -0,0 +1 @@ +7dde1be4d1a2f617ac343dd7ef0388cf497c19ba8dab653a5b9eb1e2 \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script b/cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script new file mode 100644 index 0000000000..9511b2d5a0 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script @@ -0,0 +1,5 @@ +{ + "type": "PlutusScriptV3", + "description": "", + "cborHex": "587458720101003232232322230033006900191480148888888888888888040300422590018c00a442b2600a005180044c010004300322590018c00a4432005225333573466e3c00801c60002600c0061800912c800c6001221801c80148a400644440064c0100042323001001223300330020020011" +}