From 6b34b7a7d686983919e476e23ea1545f4bd1ef72 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 13 Oct 2023 16:30:27 +0200 Subject: [PATCH 1/5] Refactor friendly JSON and YAML --- .../Cardano/CLI/EraBased/Run/Transaction.hs | 12 ++- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 74 ++++++++----------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 2c9feabdff..a702e3dfbd 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -34,8 +34,7 @@ import Cardano.Api.Shelley import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd import Cardano.CLI.EraBased.Run.Genesis -import Cardano.CLI.Json.Friendly (friendlyTxBodyJson, friendlyTxBodyYaml, friendlyTxJson, - friendlyTxYaml) +import Cardano.CLI.Json.Friendly (friendlyTxBody, friendlyTx, FriendlyFormat (..)) import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.BootstrapWitnessError @@ -1185,16 +1184,15 @@ runTransactionViewCmd -- is arguably not part of the transaction body. firstExceptT TxCmdWriteFileError . newExceptT $ case outputFormat of - TxViewOutputFormatYaml -> friendlyTxBodyYaml mOutFile era txbody - TxViewOutputFormatJson -> friendlyTxBodyJson mOutFile era txbody + TxViewOutputFormatYaml -> friendlyTxBody FriendlyYaml mOutFile era txbody + TxViewOutputFormatJson -> friendlyTxBody FriendlyJson mOutFile era txbody InputTxFile (File txFilePath) -> do txFile <- liftIO $ fileOrPipe txFilePath InAnyCardanoEra era tx <- lift (readFileTx txFile) & onLeft (left . TxCmdCddlError) firstExceptT TxCmdWriteFileError . newExceptT $ case outputFormat of - TxViewOutputFormatYaml -> friendlyTxYaml mOutFile era tx - TxViewOutputFormatJson -> friendlyTxJson mOutFile era tx - + TxViewOutputFormatYaml -> friendlyTx FriendlyYaml mOutFile era tx + TxViewOutputFormatJson -> friendlyTx FriendlyJson mOutFile era tx -- ---------------------------------------------------------------------------- -- Witness commands diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 5129ff7c41..e7dd5b8f89 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -12,6 +12,11 @@ -- | User-friendly pretty-printing for textual user interfaces (TUI) module Cardano.CLI.Json.Friendly (friendlyTxYaml, friendlyTxBodyYaml, friendlyTxJson, friendlyTxBodyJson) where +module Cardano.CLI.Json.Friendly + ( friendlyTx + , friendlyTxBody + , FriendlyFormat(..) + ) where import Cardano.Api as Api import Cardano.Api.Byron (KeyWitness (ByronKeyWitness)) @@ -45,67 +50,48 @@ import GHC.Unicode (isAlphaNum) import qualified Data.Aeson.Encode.Pretty as Aeson import Control.Monad.Trans (MonadIO) -jsonConfig :: Aeson.Config -jsonConfig = Aeson.defConfig {Aeson.confCompare = compare} +data FriendlyFormat = FriendlyJson | FriendlyYaml -friendlyTxJson :: - (MonadIO m) - => Maybe (File () Out) - -> CardanoEra era - -> Tx era +friendly :: + (MonadIO m, Aeson.ToJSON a) + => FriendlyFormat + -> Maybe (File () Out) + -> a -> m (Either (FileError e) ()) -friendlyTxJson mOutFile era = - cardanoEraConstraints era $ - writeLazyByteStringOutput mOutFile . - Aeson.encodePretty' jsonConfig . - object . - friendlyTx era +friendly FriendlyJson mOutFile = writeLazyByteStringOutput mOutFile . Aeson.encodePretty' jsonConfig +friendly FriendlyYaml mOutFile = writeByteStringOutput mOutFile . Yaml.encodePretty yamlConfig -friendlyTxBodyJson :: - (MonadIO m) - => Maybe (File () Out) - -> CardanoEra era - -> TxBody era - -> m (Either (FileError e) ()) -friendlyTxBodyJson mOutFile era = - cardanoEraConstraints era $ - writeLazyByteStringOutput mOutFile . - Aeson.encodePretty' jsonConfig . - object . - friendlyTxBody era +jsonConfig :: Aeson.Config +jsonConfig = Aeson.defConfig {Aeson.confCompare = compare} yamlConfig :: Yaml.Config yamlConfig = Yaml.defConfig & setConfCompare compare -friendlyTxYaml :: +friendlyTx :: (MonadIO m) - => Maybe (File () Out) + => FriendlyFormat + -> Maybe (File () Out) -> CardanoEra era -> Tx era -> m (Either (FileError e) ()) -friendlyTxYaml mOutFile era = +friendlyTx format mOutFile era = cardanoEraConstraints era $ - writeByteStringOutput mOutFile . - Yaml.encodePretty yamlConfig . - object . - friendlyTx era + friendly format mOutFile . object . friendlyTxImpl era -friendlyTxBodyYaml :: +friendlyTxBody :: (MonadIO m) - => Maybe (File () Out) + => FriendlyFormat + -> Maybe (File () Out) -> CardanoEra era -> TxBody era -> m (Either (FileError e) ()) -friendlyTxBodyYaml mOutFile era = +friendlyTxBody format mOutFile era = cardanoEraConstraints era $ - writeByteStringOutput mOutFile . - Yaml.encodePretty yamlConfig . - object . - friendlyTxBody era + friendly format mOutFile . object . friendlyTxBodyImpl era -friendlyTx :: IsCardanoEra era => CardanoEra era -> Tx era -> [Aeson.Pair] -friendlyTx era (Tx body witnesses) = - ("witnesses" .= map friendlyKeyWitness witnesses) : friendlyTxBody era body +friendlyTxImpl :: IsCardanoEra era => CardanoEra era -> Tx era -> [Aeson.Pair] +friendlyTxImpl era (Tx body witnesses) = + ("witnesses" .= map friendlyKeyWitness witnesses) : friendlyTxBodyImpl era body friendlyKeyWitness :: KeyWitness era -> Aeson.Value friendlyKeyWitness = @@ -117,8 +103,8 @@ friendlyKeyWitness = ShelleyKeyWitness _era (Shelley.WitVKey key signature) -> ["key" .= textShow key, "signature" .= textShow signature] -friendlyTxBody :: IsCardanoEra era => CardanoEra era -> TxBody era -> [Aeson.Pair] -friendlyTxBody +friendlyTxBodyImpl :: IsCardanoEra era => CardanoEra era -> TxBody era -> [Aeson.Pair] +friendlyTxBodyImpl era (TxBody TxBodyContent From 2aab646c7f752bae6fa15e070e66dee4315bd8a0 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 13 Oct 2023 16:30:52 +0200 Subject: [PATCH 2/5] Add "governance action view" command formatting --- .../EraBased/Commands/Governance/Actions.hs | 13 ++++++ .../Cardano/CLI/EraBased/Options/Common.hs | 12 ++++++ .../EraBased/Options/Governance/Actions.hs | 17 ++++++++ .../CLI/EraBased/Run/Governance/Actions.hs | 24 +++++++++++ .../Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 42 ++++++++++++++++--- cardano-cli/src/Cardano/CLI/Parser.hs | 13 ++++++ cardano-cli/src/Cardano/CLI/Read.hs | 8 ++-- cardano-cli/src/Cardano/CLI/Types/Common.hs | 5 +++ 9 files changed, 125 insertions(+), 11 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs index 9af15fa3f5..8eff11d89f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs @@ -9,6 +9,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions , GovernanceActionCreateConstitutionCmdArgs(..) , GovernanceActionCreateNoConfidenceCmdArgs(..) , GovernanceActionInfoCmdArgs(..) + , GovernanceActionViewCmdArgs(..) , GovernanceActionProtocolParametersUpdateCmdArgs(..) , GovernanceActionTreasuryWithdrawalCmdArgs(..) , renderGovernanceActionCmds @@ -33,6 +34,7 @@ data GovernanceActionCmds era | GovernanceActionProtocolParametersUpdateCmd !(GovernanceActionProtocolParametersUpdateCmdArgs era) | GovernanceActionTreasuryWithdrawalCmd !(GovernanceActionTreasuryWithdrawalCmdArgs era) | GovernanceActionInfoCmd !(GovernanceActionInfoCmdArgs era) + | GovernanceActionViewCmd !(GovernanceActionViewCmdArgs era) deriving Show data GoveranceActionUpdateCommitteeCmdArgs era @@ -110,6 +112,14 @@ data GovernanceActionTreasuryWithdrawalCmdArgs era , outFile :: !(File () Out) } deriving Show +data GovernanceActionViewCmdArgs era + = GovernanceActionViewCmdArgs + { eon :: !(ConwayEraOnwards era) + , actionFile :: !(ProposalFile In) + , outFormat :: !GovernanceActionViewOutputFormat + , mOutFile :: !(Maybe (File () Out)) + } deriving Show + renderGovernanceActionCmds :: GovernanceActionCmds era -> Text renderGovernanceActionCmds = ("governance action " <>) . \case GovernanceActionCreateConstitutionCmd {} -> @@ -130,6 +140,9 @@ renderGovernanceActionCmds = ("governance action " <>) . \case GovernanceActionInfoCmd {} -> "create-info" + GovernanceActionViewCmd {} -> + "view" + data AnyStakeIdentifier = AnyStakeKey (VerificationKeyOrHashOrFile StakeKey) | AnyStakePoolKey (VerificationKeyOrHashOrFile StakePoolKey) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index a246f53328..de393ee5fa 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -1606,6 +1606,18 @@ pTxViewOutputFormat = , Opt.value TxViewOutputFormatJson ] +pGovernanceActionViewOutputFormat :: Parser GovernanceActionViewOutputFormat +pGovernanceActionViewOutputFormat = + Opt.option readGovernanceActionViewOutputFormat $ mconcat + [ Opt.long "output-format" + , Opt.metavar "STRING" + , Opt.help $ mconcat + [ "Optional governance action view output format. Accepted output formats are \"json\" " + , "and \"yaml\" (default is \"json\")." + ] + , Opt.value GovernanceActionViewOutputFormatJson + ] + pMaybeOutputFile :: Parser (Maybe (File content Out)) pMaybeOutputFile = optional $ fmap File $ Opt.strOption $ mconcat diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs index 5e6aedf194..0e93b0cb6f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs @@ -37,8 +37,25 @@ pGovernanceActionCmds era = , pGovernanceActionNoConfidenceCmd era , pGovernanceActionProtocolParametersUpdateCmd era , pGovernanceActionTreasuryWithdrawalCmd era + , pGovernanceActionViewCmd era ] +pGovernanceActionViewCmd + :: CardanoEra era + -> Maybe (Parser (Cmd.GovernanceActionCmds era)) +pGovernanceActionViewCmd era = do + eon <- forEraMaybeEon era + return + $ subParser "view" + $ Opt.info + ( fmap Cmd.GovernanceActionViewCmd + $ Cmd.GovernanceActionViewCmdArgs eon + <$> pFileInDirection "action-file" "Path to action file." + <*> pGovernanceActionViewOutputFormat + <*> pMaybeOutputFile + ) + $ Opt.progDesc "View a governance action." + pGovernanceActionNewInfoCmd :: CardanoEra era -> Maybe (Parser (Cmd.GovernanceActionCmds era)) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index eaa0906e3b..afdf7d8f96 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -18,6 +18,7 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Governance.Actions import qualified Cardano.CLI.EraBased.Commands.Governance.Actions as Cmd +import Cardano.CLI.Json.Friendly import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.GovernanceActionsError @@ -52,6 +53,29 @@ runGovernanceActionCmds = \case GovernanceActionInfoCmd args -> runGovernanceActionInfoCmd args + GovernanceActionViewCmd args -> + runGovernanceActionViewCmd args + +runGovernanceActionViewCmd :: () + => GovernanceActionViewCmdArgs era + -> ExceptT GovernanceActionsError IO () +runGovernanceActionViewCmd + Cmd.GovernanceActionViewCmdArgs + { Cmd.outFormat + , Cmd.actionFile + , Cmd.mOutFile + , Cmd.eon + } = do + proposal <- firstExceptT GovernanceActionsCmdReadTextEnvelopeFileError . newExceptT $ readProposal eon actionFile + firstExceptT GovernanceActionsCmdWriteFileError . newExceptT $ + friendlyProposal + (case outFormat of + GovernanceActionViewOutputFormatJson -> FriendlyJson + GovernanceActionViewOutputFormatYaml -> FriendlyYaml) + mOutFile + eon + proposal + runGovernanceActionInfoCmd :: () => GovernanceActionInfoCmdArgs era -> ExceptT GovernanceActionsError IO () diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index a702e3dfbd..fae4b7ad46 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -34,7 +34,7 @@ import Cardano.Api.Shelley import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd import Cardano.CLI.EraBased.Run.Genesis -import Cardano.CLI.Json.Friendly (friendlyTxBody, friendlyTx, FriendlyFormat (..)) +import Cardano.CLI.Json.Friendly (FriendlyFormat (..), friendlyTx, friendlyTxBody) import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.BootstrapWitnessError diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index e7dd5b8f89..959d8b66f5 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -11,10 +11,10 @@ {-# LANGUAGE TypeOperators #-} -- | User-friendly pretty-printing for textual user interfaces (TUI) -module Cardano.CLI.Json.Friendly (friendlyTxYaml, friendlyTxBodyYaml, friendlyTxJson, friendlyTxBodyJson) where module Cardano.CLI.Json.Friendly ( friendlyTx , friendlyTxBody + , friendlyProposal , FriendlyFormat(..) ) where @@ -22,16 +22,19 @@ import Cardano.Api as Api import Cardano.Api.Byron (KeyWitness (ByronKeyWitness)) import qualified Cardano.Api.Ledger as Ledger import Cardano.Api.Shelley (Address (ShelleyAddress), Hash (..), - KeyWitness (ShelleyBootstrapWitness, ShelleyKeyWitness), ShelleyLedgerEra, - StakeAddress (..), fromShelleyPaymentCredential, fromShelleyStakeReference, - toShelleyLovelace, toShelleyStakeCredential) + KeyWitness (ShelleyBootstrapWitness, ShelleyKeyWitness), Proposal (Proposal), + ShelleyLedgerEra, StakeAddress (..), fromShelleyPaymentCredential, + fromShelleyStakeReference, toShelleyLovelace, toShelleyStakeCredential) +import qualified Cardano.Ledger.Conway.Governance as Gov import qualified Cardano.Ledger.Conway.TxCert as ConwayLedger import qualified Cardano.Ledger.Credential as Shelley import qualified Cardano.Ledger.Shelley.API as Shelley +import Control.Monad.Trans (MonadIO) import Data.Aeson (Value (..), object, toJSON, (.=)) import qualified Data.Aeson as Aeson +import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Aeson.Key as Aeson import qualified Data.Aeson.Types as Aeson import qualified Data.ByteString.Char8 as BSC @@ -47,8 +50,6 @@ import Data.Yaml.Pretty (setConfCompare) import qualified Data.Yaml.Pretty as Yaml import GHC.Real (denominator) import GHC.Unicode (isAlphaNum) -import qualified Data.Aeson.Encode.Pretty as Aeson -import Control.Monad.Trans (MonadIO) data FriendlyFormat = FriendlyJson | FriendlyYaml @@ -89,6 +90,35 @@ friendlyTxBody format mOutFile era = cardanoEraConstraints era $ friendly format mOutFile . object . friendlyTxBodyImpl era +friendlyProposal :: + (MonadIO m) + => FriendlyFormat + -> Maybe (File () Out) + -> ConwayEraOnwards era + -> Proposal era + -> m (Either (FileError e) ()) +friendlyProposal format mOutFile era = + conwayEraOnwardsConstraints era $ + friendly format mOutFile . object . friendlyProposalImpl era + +friendlyProposalImpl :: IsCardanoEra era => ConwayEraOnwards era -> Proposal era -> [Aeson.Pair] +friendlyProposalImpl + era + (Proposal + (Gov.ProposalProcedure + { Gov.pProcDeposit + , Gov.pProcReturnAddr + , Gov.pProcGovAction + , Gov.pProcAnchor + } + ) + ) = conwayEraOnwardsConstraints era + [ "deposit" .= pProcDeposit + , "return address" .= pProcReturnAddr + , "governance action" .= pProcGovAction + , "anchor" .= pProcAnchor + ] + friendlyTxImpl :: IsCardanoEra era => CardanoEra era -> Tx era -> [Aeson.Pair] friendlyTxImpl era (Tx body witnesses) = ("witnesses" .= map friendlyKeyWitness witnesses) : friendlyTxBodyImpl era body diff --git a/cardano-cli/src/Cardano/CLI/Parser.hs b/cardano-cli/src/Cardano/CLI/Parser.hs index 9ca817b72c..c4932c7985 100644 --- a/cardano-cli/src/Cardano/CLI/Parser.hs +++ b/cardano-cli/src/Cardano/CLI/Parser.hs @@ -11,6 +11,7 @@ module Cardano.CLI.Parser , readStringOfMaxLength , readURIOfMaxLength , eDNSName + , readGovernanceActionViewOutputFormat ) where import Cardano.CLI.Types.Common @@ -62,6 +63,18 @@ readTxViewOutputFormat = do , ". Accepted output formats are \"json\" and \"yaml\"." ] +readGovernanceActionViewOutputFormat :: Opt.ReadM GovernanceActionViewOutputFormat +readGovernanceActionViewOutputFormat = do + s <- Opt.str @String + case s of + "json" -> pure GovernanceActionViewOutputFormatJson + "yaml" -> pure GovernanceActionViewOutputFormatYaml + _ -> + fail $ mconcat + [ "Invalid governance action view output format: " <> show s + , ". Accepted output formats are \"json\" and \"yaml\"." + ] + readURIOfMaxLength :: Int -> Opt.ReadM Text readURIOfMaxLength maxLen = Text.pack <$> readStringOfMaxLength maxLen diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index db3fbd1b60..499fa84616 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -59,6 +59,7 @@ module Cardano.CLI.Read , readTxGovernanceActions , constitutionHashSourceToHash , proposalHashSourceToHash + , readProposal -- * FileOrPipe , FileOrPipe @@ -826,15 +827,14 @@ readTxGovernanceActions _ [] = return $ Right [] readTxGovernanceActions era files = runExceptT $ do w <- forEraMaybeEon era & hoistMaybe (ConstitutionNotSupportedInEra $ cardanoEraConstraints era $ AnyCardanoEra era) - newExceptT $ sequence <$> mapM (readProposal w) files + newExceptT $ sequence <$> mapM (fmap (first ConstitutionErrorFile) . readProposal w) files readProposal :: ConwayEraOnwards era -> ProposalFile In - -> IO (Either ConstitutionError (Proposal era)) + -> IO (Either (FileError TextEnvelopeError) (Proposal era)) readProposal w fp = - first ConstitutionErrorFile - <$> conwayEraOnwardsConstraints w (readFileTextEnvelope AsProposal fp) + conwayEraOnwardsConstraints w (readFileTextEnvelope AsProposal fp) constitutionHashSourceToHash :: () => ConstitutionHashSource diff --git a/cardano-cli/src/Cardano/CLI/Types/Common.hs b/cardano-cli/src/Cardano/CLI/Types/Common.hs index b8b162b52a..1e2e5c8bf9 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Common.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Common.hs @@ -27,6 +27,7 @@ module Cardano.CLI.Types.Common , GenesisDir(..) , GenesisFile (..) , GenesisKeyFile(..) + , GovernanceActionViewOutputFormat(..) , InputTxBodyOrTxFile (..) , KeyOutputFormat(..) , MetadataFile(..) @@ -465,6 +466,10 @@ data TxViewOutputFormat | TxViewOutputFormatYaml deriving Show +data GovernanceActionViewOutputFormat + = GovernanceActionViewOutputFormatJson + | GovernanceActionViewOutputFormatYaml + deriving Show -- -- Shelley CLI flag/option data types -- From 02276bd755b6bdfb256d2391bd3cee16d22f000f Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 13 Oct 2023 16:32:34 +0200 Subject: [PATCH 3/5] Add cli golden tests for "governance action view" --- .../test/cardano-cli-golden/files/golden/help.cli | 7 +++++++ .../files/golden/help/conway_governance_action.cli | 2 ++ .../golden/help/conway_governance_action_view.cli | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_view.cli 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 60374b282f..a0887e6100 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -5972,6 +5972,7 @@ Usage: cardano-cli conway governance action | create-no-confidence | create-protocol-parameters-update | create-treasury-withdrawal + | view ) Governance action commands. @@ -6157,6 +6158,12 @@ Usage: cardano-cli conway governance action create-treasury-withdrawal Create a treasury withdrawal. +Usage: cardano-cli conway governance action view --action-file FILE + [--output-format STRING] + [--out-file FILE] + + View a governance action. + Usage: cardano-cli conway governance committee ( key-gen-cold | key-gen-hot diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli index cf9ca37671..7013a7c29f 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action.cli @@ -5,6 +5,7 @@ Usage: cardano-cli conway governance action | create-no-confidence | create-protocol-parameters-update | create-treasury-withdrawal + | view ) Governance action commands. @@ -21,3 +22,4 @@ Available commands: Create a protocol parameters update. create-treasury-withdrawal Create a treasury withdrawal. + view View a governance action. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_view.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_view.cli new file mode 100644 index 0000000000..03fd0dfd67 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_view.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli conway governance action view --action-file FILE + [--output-format STRING] + [--out-file FILE] + + View a governance action. + +Available options: + --action-file FILE Path to action file. + --output-format STRING Optional governance action view output format. + Accepted output formats are "json" and "yaml" + (default is "json"). + --out-file FILE Optional output file. Default is to write to stdout. + -h,--help Show this help text From d61602eff1a50b57bd5c0c8f53aabadaec50feb5 Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 13 Oct 2023 17:03:01 +0200 Subject: [PATCH 4/5] Add golden tests for "governance action view" --- .../Test/Golden/Governance/Action.hs | 78 +++++++++++++++++++ .../view/create-constitution.action.view | 25 ++++++ .../action/view/create-info.action.view | 16 ++++ .../action/view/update-committee.action.view | 15 ++++ .../files/input/governance/stake-address.skey | 5 ++ .../files/input/governance/stake-address.vkey | 5 ++ 6 files changed, 144 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.skey create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.vkey 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 b92e012763..19c350c67b 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 @@ -48,3 +48,81 @@ hprop_golden_governanceActionCreateConstitution = H.assertFileOccurences 1 "Governance proposal" actionFile H.assertEndsWithSingleNewline actionFile + +hprop_golden_conway_governance_action_view_constitution_json :: Property +hprop_golden_conway_governance_action_view_constitution_json = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" + + actionFile <- noteTempFile tempDir "action" + + void $ execCardanoCLI + [ "conway", "governance", "action", "create-constitution" + , "--mainnet" + , "--proposal-anchor-metadata", "eda258650888d4a7f8ac1127cfa136962f527f341c99db49929c79ae" + , "--proposal-anchor-url", "proposal-dummy-url" + , "--governance-action-deposit", "10" + , "--stake-verification-key-file", stakeAddressVKeyFile + , "--out-file", actionFile + , "--constitution-anchor-url", "constitution-dummy-url" + , "--constitution-anchor-metadata", "This is a test constitution." + ] + + goldenActionViewFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view" + actionView <- execCardanoCLI + [ "conway", "governance", "action", "view" + , "--action-file", actionFile + ] + H.diffVsGoldenFile actionView goldenActionViewFile + +hprop_golden_conway_governance_action_view_update_committee_yaml :: Property +hprop_golden_conway_governance_action_view_update_committee_yaml = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" + + actionFile <- noteTempFile tempDir "action" + + void $ execCardanoCLI + [ "conway", "governance", "action", "update-committee" + , "--mainnet" + , "--governance-action-deposit", "10" + , "--stake-verification-key-file", stakeAddressVKeyFile + , "--proposal-anchor-url", "proposal-dummy-url" + , "--proposal-anchor-metadata", "eda258650888d4a7f8ac1127cfa136962f527f341c99db49929c79ae" + , "--quorum", "0.61" + , "--out-file", actionFile + ] + + goldenActionViewFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view" + actionView <- execCardanoCLI + [ "conway", "governance", "action", "view" + , "--action-file", actionFile + , "--output-format", "yaml" + ] + H.diffVsGoldenFile actionView goldenActionViewFile + +hprop_golden_conway_governance_action_view_create_info_json_outfile :: Property +hprop_golden_conway_governance_action_view_create_info_json_outfile = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" + + actionFile <- noteTempFile tempDir "action" + + void $ execCardanoCLI + [ "conway", "governance", "action", "create-info" + , "--testnet" + , "--governance-action-deposit", "10" + , "--stake-verification-key-file", stakeAddressVKeyFile + , "--proposal-anchor-url", "proposal-dummy-url" + , "--proposal-anchor-metadata", "eda258650888d4a7f8ac1127cfa136962f527f341c99db49929c79ae" + , "--out-file", actionFile + ] + + actionViewFile <- noteTempFile tempDir "action-view" + goldenActionViewFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view" + void $ execCardanoCLI + [ "conway", "governance", "action", "view" + , "--action-file", actionFile + , "--out-file", actionViewFile + ] + H.diffFileVsGoldenFile actionViewFile goldenActionViewFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view new file mode 100644 index 0000000000..df2c2c4bed --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view @@ -0,0 +1,25 @@ +{ + "anchor": { + "dataHash": "04c36ab926c8d0e6b37d03c781bdf0214b67f65af6eb1241459d17209a0bf784", + "url": "proposal-dummy-url" + }, + "deposit": 10, + "governance action": { + "contents": [ + null, + { + "anchor": { + "dataHash": "42cb2e410023679943d26c23ce2b5046eb7dfc5883c69fb91cc8a3c9c9a99a99", + "url": "constitution-dummy-url" + } + } + ], + "tag": "NewConstitution" + }, + "return address": { + "credential": { + "keyHash": "8f4a3466a404c11eb410313015b88e447d81b60089e25f611600e605" + }, + "network": "Mainnet" + } +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view new file mode 100644 index 0000000000..287ddec4f2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view @@ -0,0 +1,16 @@ +{ + "anchor": { + "dataHash": "04c36ab926c8d0e6b37d03c781bdf0214b67f65af6eb1241459d17209a0bf784", + "url": "proposal-dummy-url" + }, + "deposit": 10, + "governance action": { + "tag": "InfoAction" + }, + "return address": { + "credential": { + "keyHash": "8f4a3466a404c11eb410313015b88e447d81b60089e25f611600e605" + }, + "network": "Testnet" + } +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view new file mode 100644 index 0000000000..e8b331ebdc --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view @@ -0,0 +1,15 @@ +anchor: + dataHash: 04c36ab926c8d0e6b37d03c781bdf0214b67f65af6eb1241459d17209a0bf784 + url: proposal-dummy-url +deposit: 10 +governance action: + contents: + - null + - [] + - {} + - 0.61 + tag: UpdateCommittee +return address: + credential: + keyHash: 8f4a3466a404c11eb410313015b88e447d81b60089e25f611600e605 + network: Mainnet diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.skey b/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.skey new file mode 100644 index 0000000000..dee1c48e05 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.skey @@ -0,0 +1,5 @@ +{ + "type": "StakeSigningKeyShelley_ed25519", + "description": "Stake Signing Key", + "cborHex": "5820226ac6cf686bdd3e9d5934b2ac8ae8fc7c19c0b2910ac6b808359207fab68599" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.vkey b/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.vkey new file mode 100644 index 0000000000..0be271c89f --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/stake-address.vkey @@ -0,0 +1,5 @@ +{ + "type": "StakeVerificationKeyShelley_ed25519", + "description": "Stake Verification Key", + "cborHex": "5820a593d821195a27907841d73bd7ddca8777da9dd0bf34c7168b1eff75af8c2881" +} From f88da54c07581f27cc44fe1c7b5008b8177079ea Mon Sep 17 00:00:00 2001 From: Carl Hammann Date: Fri, 13 Oct 2023 17:39:44 +0200 Subject: [PATCH 5/5] Remove redundant constraint --- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 959d8b66f5..e19412ca8b 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -101,7 +101,7 @@ friendlyProposal format mOutFile era = conwayEraOnwardsConstraints era $ friendly format mOutFile . object . friendlyProposalImpl era -friendlyProposalImpl :: IsCardanoEra era => ConwayEraOnwards era -> Proposal era -> [Aeson.Pair] +friendlyProposalImpl :: ConwayEraOnwards era -> Proposal era -> [Aeson.Pair] friendlyProposalImpl era (Proposal