diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 90146c2766..ee5f7a1a2b 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -75,6 +75,7 @@ library Cardano.CLI.EraBased.Commands.Governance.Actions Cardano.CLI.EraBased.Commands.Governance.Committee Cardano.CLI.EraBased.Commands.Governance.DRep + Cardano.CLI.EraBased.Commands.Governance.Poll Cardano.CLI.EraBased.Commands.Governance.Query Cardano.CLI.EraBased.Commands.Governance.Vote Cardano.CLI.EraBased.Commands.Key @@ -91,6 +92,7 @@ library Cardano.CLI.EraBased.Options.Governance.Actions Cardano.CLI.EraBased.Options.Governance.Committee Cardano.CLI.EraBased.Options.Governance.DRep + Cardano.CLI.EraBased.Options.Governance.Poll Cardano.CLI.EraBased.Options.Governance.Query Cardano.CLI.EraBased.Options.Governance.Vote Cardano.CLI.EraBased.Options.Key @@ -108,6 +110,7 @@ library Cardano.CLI.EraBased.Run.Governance.Actions Cardano.CLI.EraBased.Run.Governance.Committee Cardano.CLI.EraBased.Run.Governance.DRep + Cardano.CLI.EraBased.Run.Governance.Poll Cardano.CLI.EraBased.Run.Governance.Query Cardano.CLI.EraBased.Run.Governance.Vote Cardano.CLI.EraBased.Run.Key @@ -361,6 +364,9 @@ test-suite cardano-cli-golden Test.Golden.Byron.UpdateProposal Test.Golden.Byron.Vote Test.Golden.Byron.Witness + Test.Golden.EraBased.Governance.AnswerPoll + Test.Golden.EraBased.Governance.CreatePoll + Test.Golden.EraBased.Governance.VerifyPoll Test.Golden.ErrorsSpec Test.Golden.Governance.Action Test.Golden.Governance.Committee @@ -376,9 +382,6 @@ test-suite cardano-cli-golden Test.Golden.Shelley.Genesis.KeyGenGenesis Test.Golden.Shelley.Genesis.KeyGenUtxo Test.Golden.Shelley.Genesis.KeyHash - Test.Golden.Shelley.Governance.AnswerPoll - Test.Golden.Shelley.Governance.CreatePoll - Test.Golden.Shelley.Governance.VerifyPoll Test.Golden.Shelley.Key.ConvertCardanoAddressKey Test.Golden.Shelley.Metadata.StakePoolMetadata Test.Golden.Shelley.MultiSig.Address diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs index 79033712e8..1532c01e9c 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs @@ -13,6 +13,7 @@ import Cardano.CLI.EraBased.Commands.Governance.Actions import Cardano.CLI.EraBased.Commands.Governance.Committee import Cardano.CLI.EraBased.Commands.Governance.DRep import Cardano.CLI.EraBased.Commands.Governance.Query +import Cardano.CLI.EraBased.Commands.Governance.Poll import Cardano.CLI.EraBased.Commands.Governance.Vote import Cardano.CLI.Types.Common @@ -36,6 +37,8 @@ data GovernanceCmds era (GovernanceCommitteeCmds era) | GovernanceDRepCmds (GovernanceDRepCmds era) + | GovernancePollCmds + (GovernancePollCmds era) | GovernanceVoteCmds (GovernanceVoteCmds era) | GovernanceQueryCmds @@ -55,6 +58,8 @@ renderGovernanceCmds = \case renderGovernanceCommitteeCmds cmds GovernanceDRepCmds cmds -> renderGovernanceDRepCmds cmds + GovernancePollCmds cmds -> + renderGovernancePollCmds cmds GovernanceVoteCmds cmds -> renderGovernanceVoteCmds cmds GovernanceQueryCmds cmds -> diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Poll.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Poll.hs new file mode 100644 index 0000000000..e2a6886e6d --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Poll.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE LambdaCase #-} + +module Cardano.CLI.EraBased.Commands.Governance.Poll + ( GovernancePollCmds(..) , renderGovernancePollCmds) where + +import Cardano.Api +import Cardano.Api.Shelley + +import Data.Text (Text) + +data GovernancePollCmds era + = GovernanceCreatePoll -- ^ Create a SPO poll + (BabbageEraOnwards era) {- TODO smelc, use BabbageEraOnly here instead -} + Text -- ^ Prompt + [Text] -- ^ Choices + (Maybe Word) -- ^ Nonce + (File GovernancePoll Out) + | GovernanceAnswerPoll -- ^ Answer a SPO poll + (BabbageEraOnwards era) {- TODO smelc, use BabbageEraOnly here instead -} + (File GovernancePoll In) -- ^ Poll file + (Maybe Word) -- ^ Answer index + (Maybe (File () Out)) -- ^ Tx file + | GovernanceVerifyPoll -- ^ Verify answer to a given SPO poll + (BabbageEraOnwards era) {- TODO smelc, use BabbageEraOnly here instead -} + (File GovernancePoll In) -- Poll file + (File (Tx ()) In) -- Tx file + (Maybe (File () Out)) -- Tx file + + +renderGovernancePollCmds :: () + => GovernancePollCmds era + -> Text +renderGovernancePollCmds = \case + GovernanceCreatePoll {} -> "governance create-poll" + GovernanceAnswerPoll {} -> "governance answer-poll" + GovernanceVerifyPoll {} -> "governance verify-poll" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs index 09ac10b52a..aa9bebb41b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs @@ -15,6 +15,7 @@ import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.EraBased.Options.Governance.Actions import Cardano.CLI.EraBased.Options.Governance.Committee import Cardano.CLI.EraBased.Options.Governance.DRep +import Cardano.CLI.EraBased.Options.Governance.Poll import Cardano.CLI.EraBased.Options.Governance.Query import Cardano.CLI.EraBased.Options.Governance.Vote import Cardano.CLI.Types.Common @@ -39,6 +40,7 @@ pGovernanceCmds era envCli = , fmap GovernanceActionCmds <$> pGovernanceActionCmds era , fmap GovernanceCommitteeCmds <$> pGovernanceCommitteeCmds era , fmap GovernanceDRepCmds <$> pGovernanceDRepCmds era + , fmap GovernancePollCmds <$> pGovernancePollCmds era , fmap GovernanceVoteCmds <$> pGovernanceVoteCmds era ] diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Poll.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Poll.hs new file mode 100644 index 0000000000..369aea2563 --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Poll.hs @@ -0,0 +1,73 @@ +module Cardano.CLI.EraBased.Options.Governance.Poll + ( pGovernancePollCmds, + ) +where + +import Cardano.Api + +import Cardano.CLI.EraBased.Commands.Governance.Poll (GovernancePollCmds (..)) +import Cardano.CLI.EraBased.Options.Common +import Cardano.Prelude (catMaybes, isInfixOf) + +import Control.Monad (when) +import Data.Foldable +import Options.Applicative hiding (help, str) +import qualified Options.Applicative as Opt + +pGovernancePollCmds :: () + => CardanoEra era + -> Maybe (Parser (GovernancePollCmds era)) +pGovernancePollCmds era = + case parsers of + [] -> Nothing + _ -> Just $ asum parsers + where + parsers = + catMaybes + [ subParser "create-poll" + <$> ( Opt.info + <$> pGovernanceCreatePoll era + <*> pure (Opt.progDesc "Create an SPO poll") + ), + subParser "answer-poll" + <$> ( Opt.info + <$> pGovernanceAnswerPoll era + <*> pure (Opt.progDesc "Answer an SPO poll") + ), + subParser "verify-poll" + <$> ( Opt.info + <$> pGovernanceVerifyPoll era + <*> pure (Opt.progDesc "Verify an answer to a given SPO poll") + ) + ] + +pGovernanceCreatePoll :: CardanoEra era -> Maybe (Parser (GovernancePollCmds era)) +pGovernanceCreatePoll era = do + w <- forEraMaybeEon era + when ("BabbageEraOnwardsConway" `isInfixOf` show w) Nothing -- TODO smelc remove this when BabbageEraBabbageOnly is introduced + pure $ + GovernanceCreatePoll w + <$> pPollQuestion + <*> some pPollAnswer + <*> optional pPollNonce + <*> pOutputFile + +pGovernanceAnswerPoll :: CardanoEra era -> Maybe (Parser (GovernancePollCmds era)) +pGovernanceAnswerPoll era = do + w <- forEraMaybeEon era + when ("BabbageEraOnwardsConway" `isInfixOf` show w) Nothing -- TODO smelc remove this when BabbageEraBabbageOnly is introduced + pure $ + GovernanceAnswerPoll w + <$> pPollFile + <*> optional pPollAnswerIndex + <*> optional pOutputFile + +pGovernanceVerifyPoll :: CardanoEra era -> Maybe (Parser (GovernancePollCmds era)) +pGovernanceVerifyPoll era = do + w <- forEraMaybeEon era + when ("BabbageEraOnwardsConway" `isInfixOf` show w) Nothing -- TODO smelc remove this when BabbageEraBabbageOnly is introduced + pure $ + GovernanceVerifyPoll w + <$> pPollFile + <*> pPollTxFile + <*> optional pOutputFile diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs index 6fb79dcf15..60045fcf0b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs @@ -31,6 +31,7 @@ import Cardano.CLI.Types.Errors.CmdError import Control.Monad.Trans.Except import Control.Monad.Trans.Except.Extra (firstExceptT) import Data.Function ((&)) +import Cardano.CLI.EraBased.Run.Governance.Poll (runGovernancePollCmds) runAnyEraCommand :: () => AnyEraCommand @@ -95,6 +96,10 @@ runGovernanceCmds = \case GovernanceDRepCmds cmds -> runGovernanceDRepCmds cmds + GovernancePollCmds cmds -> + runGovernancePollCmds cmds + & firstExceptT CmdGovernanceCmdError + GovernanceVoteCmds cmds -> runGovernanceVoteCmds cmds diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Poll.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Poll.hs new file mode 100644 index 0000000000..ef42f893b0 --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Poll.hs @@ -0,0 +1,170 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Cardano.CLI.EraBased.Run.Governance.Poll + ( runGovernancePollCmds + ) where + +import Cardano.Api +import Cardano.Api.Shelley +import qualified Cardano.Api.Shelley as Api + +import Cardano.CLI.EraBased.Commands.Governance.Poll +import Cardano.CLI.Read +import Cardano.CLI.Types.Errors.GovernanceCmdError + +import Control.Monad +import Control.Monad.IO.Class +import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Except (ExceptT) +import Control.Monad.Trans.Except.Extra +import qualified Data.ByteString.Char8 as BSC +import Data.Function ((&)) +import Data.String (fromString) +import Data.Text (Text) +import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text +import qualified Data.Text.IO as Text +import qualified Data.Text.Read as Text +import qualified System.IO as IO +import System.IO (stderr, stdin, stdout) + + +runGovernancePollCmds :: GovernancePollCmds era -> ExceptT GovernanceCmdError IO () +runGovernancePollCmds = \case + GovernanceCreatePoll w prompt choices nonce out -> + runGovernanceCreatePoll w prompt choices nonce out + GovernanceAnswerPoll w poll ix mOutFile -> + runGovernanceAnswerPoll w poll ix mOutFile + GovernanceVerifyPoll w poll metadata mOutFile -> + runGovernanceVerifyPoll w poll metadata mOutFile + +runGovernanceCreatePoll + :: BabbageEraOnwards era + -> Text + -> [Text] + -> Maybe Word + -> File GovernancePoll Out + -> ExceptT GovernanceCmdError IO () +runGovernanceCreatePoll _w govPollQuestion govPollAnswers govPollNonce out = do + let poll = GovernancePoll{ govPollQuestion, govPollAnswers, govPollNonce } + + let description = fromString $ "An on-chain poll for SPOs: " <> Text.unpack govPollQuestion + firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $ + writeFileTextEnvelope out (Just description) poll + + let metadata = asTxMetadata poll + & metadataToJson TxMetadataJsonDetailedSchema + + let outPath = unFile out & Text.encodeUtf8 . Text.pack + + liftIO $ do + BSC.hPutStrLn stderr $ mconcat + [ "Poll created successfully.\n" + , "Please submit a transaction using the resulting metadata.\n" + ] + BSC.hPutStrLn stdout (prettyPrintJSON metadata) + BSC.hPutStrLn stderr $ mconcat + [ "\n" + , "Hint (1): Use '--json-metadata-detailed-schema' and '--metadata-json-file' " + , "from the build or build-raw commands.\n" + , "Hint (2): You can redirect the standard output of this command to a JSON " + , "file to capture metadata.\n\n" + , "Note: A serialized version of the poll suitable for sharing with " + , "participants has been generated at '" <> outPath <> "'." + ] + +runGovernanceAnswerPoll + :: BabbageEraOnwards era + -> File GovernancePoll In + -> Maybe Word -- ^ Answer index + -> Maybe (File () Out) -- ^ Output file + -> ExceptT GovernanceCmdError IO () +runGovernanceAnswerPoll _ pollFile maybeChoice mOutFile = do + poll <- firstExceptT GovernanceCmdTextEnvReadError . newExceptT $ + readFileTextEnvelope AsGovernancePoll pollFile + + choice <- case maybeChoice of + Nothing -> do + askInteractively poll + Just ix -> do + validateChoice poll ix + liftIO $ BSC.hPutStrLn stderr $ Text.encodeUtf8 $ Text.intercalate "\n" + [ govPollQuestion poll + , "→ " <> (govPollAnswers poll !! fromIntegral ix) + , "" + ] + pure ix + + let pollAnswer = GovernancePollAnswer + { govAnsPoll = hashGovernancePoll poll + , govAnsChoice = choice + } + let metadata = + metadataToJson TxMetadataJsonDetailedSchema (asTxMetadata pollAnswer) + + liftIO $ BSC.hPutStrLn stderr $ mconcat + [ "Poll answer created successfully.\n" + , "Please submit a transaction using the resulting metadata.\n" + , "To be valid, the transaction must also be signed using a valid key\n" + , "identifying your stake pool (e.g. your cold key).\n" + ] + + lift (writeByteStringOutput mOutFile (prettyPrintJSON metadata)) + & onLeft (left . GovernanceCmdWriteFileError) + + liftIO $ BSC.hPutStrLn stderr $ mconcat + [ "\n" + , "Hint (1): Use '--json-metadata-detailed-schema' and '--metadata-json-file' " + , "from the build or build-raw commands.\n" + , "Hint (2): You can redirect the standard output of this command to a JSON " + , "file to capture metadata." + ] + where + validateChoice :: GovernancePoll -> Word -> ExceptT GovernanceCmdError IO () + validateChoice GovernancePoll{govPollAnswers} ix = do + let maxAnswerIndex = length govPollAnswers - 1 + when (fromIntegral ix > maxAnswerIndex) $ left $ + GovernanceCmdPollOutOfBoundAnswer maxAnswerIndex + + askInteractively :: GovernancePoll -> ExceptT GovernanceCmdError IO Word + askInteractively poll@GovernancePoll{govPollQuestion, govPollAnswers} = do + liftIO $ BSC.hPutStrLn stderr $ Text.encodeUtf8 $ Text.intercalate "\n" + ( govPollQuestion + : [ "[" <> textShow ix <> "] " <> answer + | (ix :: Int, answer) <- zip [0..] govPollAnswers + ] + ) + liftIO $ BSC.hPutStrLn stderr "" + liftIO $ BSC.hPutStr stderr "Please indicate an answer (by index): " + txt <- liftIO $ Text.hGetLine stdin + liftIO $ BSC.hPutStrLn stderr "" + case Text.decimal txt of + Right (choice, rest) | Text.null rest -> + choice <$ validateChoice poll choice + _ -> + left GovernanceCmdPollInvalidChoice + +runGovernanceVerifyPoll + :: BabbageEraOnwards era + -> File GovernancePoll In + -> File (Api.Tx ()) In + -> Maybe (File () Out) -- ^ Output file + -> ExceptT GovernanceCmdError IO () +runGovernanceVerifyPoll _ pollFile txFile mOutFile = do + poll <- firstExceptT GovernanceCmdTextEnvReadError . newExceptT $ + readFileTextEnvelope AsGovernancePoll pollFile + + txFileOrPipe <- liftIO $ fileOrPipe (unFile txFile) + tx <- firstExceptT GovernanceCmdCddlError . newExceptT $ + readFileTx txFileOrPipe + + signatories <- firstExceptT GovernanceCmdVerifyPollError . newExceptT $ pure $ + verifyPollAnswer poll tx + + liftIO $ IO.hPutStrLn stderr $ "Found valid poll answer with " <> show (length signatories) <> " signatories" + + lift (writeByteStringOutput mOutFile (prettyPrintJSON signatories)) + & onLeft (left . GovernanceCmdWriteFileError) diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs index cbcd49069d..723f908e63 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs @@ -35,19 +35,6 @@ data LegacyGovernanceCmds [VerificationKeyFile In] ProtocolParametersUpdate (Maybe FilePath) - | GovernanceCreatePoll - Text -- Prompt - [Text] -- Choices - (Maybe Word) -- Nonce - (File GovernancePoll Out) - | GovernanceAnswerPoll - (File GovernancePoll In) -- Poll file - (Maybe Word) -- Answer index - (Maybe (File () Out)) -- Tx file - | GovernanceVerifyPoll - (File GovernancePoll In) -- Poll file - (File (Tx ()) In) -- Tx file - (Maybe (File () Out)) -- Tx file deriving Show renderLegacyGovernanceCmds :: LegacyGovernanceCmds -> Text @@ -57,7 +44,4 @@ renderLegacyGovernanceCmds = \case GovernanceMIRTransfer _ _ _ TransferToTreasury -> "governance create-mir-certificate transfer-to-treasury" GovernanceMIRTransfer _ _ _ TransferToReserves -> "governance create-mir-certificate transfer-to-reserves" GovernanceUpdateProposal {} -> "governance create-update-proposal" - GovernanceCreatePoll{} -> "governance create-poll" - GovernanceAnswerPoll{} -> "governance answer-poll" - GovernanceVerifyPoll{} -> "governance verify-poll" diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs index 0413c2b53c..cfb2674f77 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs @@ -1028,15 +1028,6 @@ pGovernanceCmds envCli = , subParser "create-update-proposal" $ Opt.info pUpdateProposal $ Opt.progDesc "Create an update proposal" - , subParser "create-poll" - $ Opt.info pGovernanceCreatePoll - $ Opt.progDesc "Create an SPO poll" - , subParser "answer-poll" - $ Opt.info pGovernanceAnswerPoll - $ Opt.progDesc "Answer an SPO poll" - , subParser "verify-poll" - $ Opt.info pGovernanceVerifyPoll - $ Opt.progDesc "Verify an answer to a given SPO poll" ] where mirCertParsers :: Parser LegacyGovernanceCmds @@ -1095,28 +1086,6 @@ pGovernanceCmds envCli = <*> pProtocolParametersUpdate <*> optional pCostModels - pGovernanceCreatePoll :: Parser LegacyGovernanceCmds - pGovernanceCreatePoll = - GovernanceCreatePoll - <$> pPollQuestion - <*> some pPollAnswer - <*> optional pPollNonce - <*> pOutputFile - - pGovernanceAnswerPoll :: Parser LegacyGovernanceCmds - pGovernanceAnswerPoll = - GovernanceAnswerPoll - <$> pPollFile - <*> optional pPollAnswerIndex - <*> optional pOutputFile - - pGovernanceVerifyPoll :: Parser LegacyGovernanceCmds - pGovernanceVerifyPoll = - GovernanceVerifyPoll - <$> pPollFile - <*> pPollTxFile - <*> optional pOutputFile - pGenesisCmds :: EnvCli -> Parser LegacyGenesisCmds pGenesisCmds envCli = asum diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs index fc30ca90ac..5a5799a2b3 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs @@ -1,7 +1,6 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.CLI.Legacy.Run.Governance @@ -11,32 +10,20 @@ module Cardano.CLI.Legacy.Run.Governance import Cardano.Api import qualified Cardano.Api.Ledger as Ledger import Cardano.Api.Shelley -import qualified Cardano.Api.Shelley as Api import Cardano.CLI.EraBased.Run.Governance import Cardano.CLI.Legacy.Commands.Governance -import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.GovernanceCmdError import Cardano.CLI.Types.Key import Control.Monad -import Control.Monad.IO.Class -import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra import Data.Aeson (eitherDecode) -import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Lazy as LB import Data.Function ((&)) -import Data.String (fromString) -import Data.Text (Text) import qualified Data.Text as Text -import qualified Data.Text.Encoding as Text -import qualified Data.Text.IO as Text -import qualified Data.Text.Read as Text -import qualified System.IO as IO -import System.IO (stderr, stdin, stdout) runLegacyGovernanceCmds :: LegacyGovernanceCmds -> ExceptT GovernanceCmdError IO () runLegacyGovernanceCmds = \case @@ -48,12 +35,6 @@ runLegacyGovernanceCmds = \case runLegacyGovernanceGenesisKeyDelegationCertificate sbe genVk genDelegVk vrfVk out GovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp -> runLegacyGovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp - GovernanceCreatePoll prompt choices nonce out -> - runLegacyGovernanceCreatePoll prompt choices nonce out - GovernanceAnswerPoll poll ix mOutFile -> - runLegacyGovernanceAnswerPoll poll ix mOutFile - GovernanceVerifyPoll poll metadata mOutFile -> - runLegacyGovernanceVerifyPoll poll metadata mOutFile runLegacyGovernanceMIRCertificatePayStakeAddrs :: EraInEon ShelleyToBabbageEra @@ -163,128 +144,3 @@ runLegacyGovernanceUpdateProposal upFile eNo genVerKeyFiles upPprams mCostModelF firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $ writeLazyByteStringFile upFile $ textEnvelopeToJSON Nothing upProp - -runLegacyGovernanceCreatePoll - :: Text - -> [Text] - -> Maybe Word - -> File GovernancePoll Out - -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceCreatePoll govPollQuestion govPollAnswers govPollNonce out = do - let poll = GovernancePoll{ govPollQuestion, govPollAnswers, govPollNonce } - - let description = fromString $ "An on-chain poll for SPOs: " <> Text.unpack govPollQuestion - firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $ - writeFileTextEnvelope out (Just description) poll - - let metadata = asTxMetadata poll - & metadataToJson TxMetadataJsonDetailedSchema - - let outPath = unFile out & Text.encodeUtf8 . Text.pack - - liftIO $ do - BSC.hPutStrLn stderr $ mconcat - [ "Poll created successfully.\n" - , "Please submit a transaction using the resulting metadata.\n" - ] - BSC.hPutStrLn stdout (prettyPrintJSON metadata) - BSC.hPutStrLn stderr $ mconcat - [ "\n" - , "Hint (1): Use '--json-metadata-detailed-schema' and '--metadata-json-file' " - , "from the build or build-raw commands.\n" - , "Hint (2): You can redirect the standard output of this command to a JSON " - , "file to capture metadata.\n\n" - , "Note: A serialized version of the poll suitable for sharing with " - , "participants has been generated at '" <> outPath <> "'." - ] - -runLegacyGovernanceAnswerPoll - :: File GovernancePoll In - -> Maybe Word -- ^ Answer index - -> Maybe (File () Out) -- ^ Output file - -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceAnswerPoll pollFile maybeChoice mOutFile = do - poll <- firstExceptT GovernanceCmdTextEnvReadError . newExceptT $ - readFileTextEnvelope AsGovernancePoll pollFile - - choice <- case maybeChoice of - Nothing -> do - askInteractively poll - Just ix -> do - validateChoice poll ix - liftIO $ BSC.hPutStrLn stderr $ Text.encodeUtf8 $ Text.intercalate "\n" - [ govPollQuestion poll - , "→ " <> (govPollAnswers poll !! fromIntegral ix) - , "" - ] - pure ix - - let pollAnswer = GovernancePollAnswer - { govAnsPoll = hashGovernancePoll poll - , govAnsChoice = choice - } - let metadata = - metadataToJson TxMetadataJsonDetailedSchema (asTxMetadata pollAnswer) - - liftIO $ BSC.hPutStrLn stderr $ mconcat - [ "Poll answer created successfully.\n" - , "Please submit a transaction using the resulting metadata.\n" - , "To be valid, the transaction must also be signed using a valid key\n" - , "identifying your stake pool (e.g. your cold key).\n" - ] - - lift (writeByteStringOutput mOutFile (prettyPrintJSON metadata)) - & onLeft (left . GovernanceCmdWriteFileError) - - liftIO $ BSC.hPutStrLn stderr $ mconcat - [ "\n" - , "Hint (1): Use '--json-metadata-detailed-schema' and '--metadata-json-file' " - , "from the build or build-raw commands.\n" - , "Hint (2): You can redirect the standard output of this command to a JSON " - , "file to capture metadata." - ] - where - validateChoice :: GovernancePoll -> Word -> ExceptT GovernanceCmdError IO () - validateChoice GovernancePoll{govPollAnswers} ix = do - let maxAnswerIndex = length govPollAnswers - 1 - when (fromIntegral ix > maxAnswerIndex) $ left $ - GovernanceCmdPollOutOfBoundAnswer maxAnswerIndex - - askInteractively :: GovernancePoll -> ExceptT GovernanceCmdError IO Word - askInteractively poll@GovernancePoll{govPollQuestion, govPollAnswers} = do - liftIO $ BSC.hPutStrLn stderr $ Text.encodeUtf8 $ Text.intercalate "\n" - ( govPollQuestion - : [ "[" <> textShow ix <> "] " <> answer - | (ix :: Int, answer) <- zip [0..] govPollAnswers - ] - ) - liftIO $ BSC.hPutStrLn stderr "" - liftIO $ BSC.hPutStr stderr "Please indicate an answer (by index): " - txt <- liftIO $ Text.hGetLine stdin - liftIO $ BSC.hPutStrLn stderr "" - case Text.decimal txt of - Right (choice, rest) | Text.null rest -> - choice <$ validateChoice poll choice - _ -> - left GovernanceCmdPollInvalidChoice - -runLegacyGovernanceVerifyPoll - :: File GovernancePoll In - -> File (Api.Tx ()) In - -> Maybe (File () Out) -- ^ Output file - -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceVerifyPoll pollFile txFile mOutFile = do - poll <- firstExceptT GovernanceCmdTextEnvReadError . newExceptT $ - readFileTextEnvelope AsGovernancePoll pollFile - - txFileOrPipe <- liftIO $ fileOrPipe (unFile txFile) - tx <- firstExceptT GovernanceCmdCddlError . newExceptT $ - readFileTx txFileOrPipe - - signatories <- firstExceptT GovernanceCmdVerifyPollError . newExceptT $ pure $ - verifyPollAnswer poll tx - - liftIO $ IO.hPutStrLn stderr $ "Found valid poll answer with " <> show (length signatories) <> " signatories" - - lift (writeByteStringOutput mOutFile (prettyPrintJSON signatories)) - & onLeft (left . GovernanceCmdWriteFileError) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/AnswerPoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/AnswerPoll.hs new file mode 100644 index 0000000000..b4485892b8 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/AnswerPoll.hs @@ -0,0 +1,77 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Test.Golden.EraBased.Governance.AnswerPoll where + +import Control.Monad (void) + +import Test.Cardano.CLI.Util + +import Hedgehog (Property) +import qualified Hedgehog as H +import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H +import qualified Hedgehog.Extras.Test.Golden as H + +{- HLINT ignore "Use camelCase" -} + +hprop_golden_governanceAnswerPollNeg1Invalid :: Property +hprop_golden_governanceAnswerPollNeg1Invalid = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + outFile <- H.noteTempFile tempDir "answer-file.json" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "answer-poll" + , "--poll-file", pollFile + , "--answer", "-1" + , "--out-file", outFile + ] + + H.assertFileMissing outFile + + either (const H.success) (const H.failure) result + +hprop_golden_governanceAnswerPoll0 :: Property +hprop_golden_governanceAnswerPoll0 = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + goldenAnswerFile <- H.note "test/cardano-cli-golden/files/golden/governance/polls/basic.answer.0.json" + outFile <- H.noteTempFile tempDir "answer-file.json" + + void $ execCardanoCLI + [ "babbage", "governance", "answer-poll" + , "--poll-file", pollFile + , "--answer", "0" + , "--out-file", outFile + ] + + H.diffFileVsGoldenFile outFile goldenAnswerFile + +hprop_golden_governanceAnswerPollPos1 :: Property +hprop_golden_governanceAnswerPollPos1 = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + goldenAnswerFile <- H.note "test/cardano-cli-golden/files/golden/governance/polls/basic.answer.1.json" + outFile <- H.noteTempFile tempDir "answer-file.json" + + void $ execCardanoCLI + [ "babbage", "governance", "answer-poll" + , "--poll-file", pollFile + , "--answer", "1" + , "--out-file", outFile + ] + + H.diffFileVsGoldenFile outFile goldenAnswerFile + +hprop_golden_governanceAnswerPollPos2Invalid :: Property +hprop_golden_governanceAnswerPollPos2Invalid = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + outFile <- H.noteTempFile tempDir "answer-file.json" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "answer-poll" + , "--poll-file", pollFile + , "--answer", "2" + , "--out-file", outFile + ] + + H.assertFileMissing outFile + + either (const H.success) (const H.failure) result diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/CreatePoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs similarity index 71% rename from cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/CreatePoll.hs rename to cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs index 96ad904e68..169e27d07e 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/CreatePoll.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs @@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module Test.Golden.Shelley.Governance.CreatePoll where +module Test.Golden.EraBased.Governance.CreatePoll where import Control.Monad (void) @@ -13,13 +13,13 @@ import qualified Hedgehog.Extras.Test.File as H {- HLINT ignore "Use camelCase" -} -hprop_golden_shelleyGovernanceCreatePoll :: Property -hprop_golden_shelleyGovernanceCreatePoll = +hprop_golden_governanceCreatePoll :: Property +hprop_golden_governanceCreatePoll = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do pollFile <- noteTempFile tempDir "poll.json" stdout <- execCardanoCLI - [ "legacy", "governance", "create-poll" + [ "babbage", "governance", "create-poll" , "--question", "Pineapples on pizza?" , "--answer", "yes" , "--answer", "no" @@ -27,19 +27,19 @@ hprop_golden_shelleyGovernanceCreatePoll = ] void $ H.readFile pollFile - noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/create/basic.json" + noteInputFile "test/cardano-cli-golden/files/input/governance/create/basic.json" >>= H.readFile >>= (H.===) stdout H.assertFileOccurences 1 "GovernancePoll" pollFile H.assertEndsWithSingleNewline pollFile -hprop_golden_shelleyGovernanceCreateLongPoll :: Property -hprop_golden_shelleyGovernanceCreateLongPoll = +hprop_golden_governanceCreateLongPoll :: Property +hprop_golden_governanceCreateLongPoll = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do pollFile <- noteTempFile tempDir "poll.json" stdout <- execCardanoCLI - [ "legacy", "governance", "create-poll" + [ "babbage", "governance", "create-poll" , "--question", "What is the most adequate topping to put on a pizza (please consider all possibilities and take time to answer)?" , "--answer", "pineapples" , "--answer", "only traditional topics should go on a pizza, this isn't room for jokes" @@ -47,7 +47,7 @@ hprop_golden_shelleyGovernanceCreateLongPoll = ] void $ H.readFile pollFile - noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/create/long-text.json" + noteInputFile "test/cardano-cli-golden/files/input/governance/create/long-text.json" >>= H.readFile >>= (H.===) stdout H.assertFileOccurences 1 "GovernancePoll" pollFile diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs new file mode 100644 index 0000000000..c3be9464d9 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/VerifyPoll.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} + +module Test.Golden.EraBased.Governance.VerifyPoll where + +import Cardano.Api + +import Cardano.CLI.Types.Key (VerificationKeyOrFile (..), + readVerificationKeyOrTextEnvFile) + +import Control.Monad.IO.Class (liftIO) +import qualified Data.ByteString.Char8 as BSC + +import Test.Cardano.CLI.Util + +import Hedgehog (Property) +import qualified Hedgehog as H +import qualified Hedgehog.Internal.Property as H +import qualified Hedgehog.Extras as H + +{- HLINT ignore "Use camelCase" -} + +hprop_golden_governanceVerifyPoll :: Property +hprop_golden_governanceVerifyPoll = propertyOnce $ do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + txFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/verify/valid" + goldenVkFile <- VerificationKeyFilePath . File <$> + H.note "test/cardano-cli-golden/files/golden/governance/cold.vk" + + stdout <- BSC.pack <$> execCardanoCLI + [ "babbage", "governance", "verify-poll" + , "--poll-file", pollFile + , "--tx-file", txFile + ] + + liftIO (readVerificationKeyOrTextEnvFile AsStakePoolKey goldenVkFile) >>= \case + Left e -> + H.failWith Nothing (displayError e) + Right vk -> do + let expected = prettyPrintJSON $ serialiseToRawBytesHexText <$> [verificationKeyHash vk] + H.assert $ expected `BSC.isInfixOf` stdout + +hprop_golden_governanceVerifyPollMismatch :: Property +hprop_golden_governanceVerifyPollMismatch = propertyOnce $ do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + txFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/verify/mismatch" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "verify-poll" + , "--poll-file", pollFile + , "--tx-file", txFile + ] + + either (const H.success) (H.failWith Nothing) result + +hprop_golden_governanceVerifyPollNoAnswer :: Property +hprop_golden_governanceVerifyPollNoAnswer = propertyOnce $ do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + txFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/verify/none" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "verify-poll" + , "--poll-file", pollFile + , "--tx-file", txFile + ] + + either (const H.success) (H.failWith Nothing) result + +hprop_golden_governanceVerifyPollMalformedAnswer :: Property +hprop_golden_governanceVerifyPollMalformedAnswer = propertyOnce $ do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + txFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/verify/malformed" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "verify-poll" + , "--poll-file", pollFile + , "--tx-file", txFile + ] + + either (const H.success) (H.failWith Nothing) result + +hprop_golden_governanceVerifyPollInvalidAnswer :: Property +hprop_golden_governanceVerifyPollInvalidAnswer = propertyOnce $ do + pollFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/polls/basic.json" + txFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/verify/invalid" + + result <- tryExecCardanoCLI + [ "babbage", "governance", "verify-poll" + , "--poll-file", pollFile + , "--tx-file", txFile + ] + + either (const H.success) (H.failWith Nothing) result diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/AnswerPoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/AnswerPoll.hs deleted file mode 100644 index fcf4658534..0000000000 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/AnswerPoll.hs +++ /dev/null @@ -1,77 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Test.Golden.Shelley.Governance.AnswerPoll where - -import Control.Monad (void) - -import Test.Cardano.CLI.Util - -import Hedgehog (Property) -import qualified Hedgehog as H -import qualified Hedgehog.Extras.Test.Base as H -import qualified Hedgehog.Extras.Test.File as H -import qualified Hedgehog.Extras.Test.Golden as H - -{- HLINT ignore "Use camelCase" -} - -hprop_golden_shelleyGovernanceAnswerPollNeg1Invalid :: Property -hprop_golden_shelleyGovernanceAnswerPollNeg1Invalid = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - outFile <- H.noteTempFile tempDir "answer-file.json" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "answer-poll" - , "--poll-file", pollFile - , "--answer", "-1" - , "--out-file", outFile - ] - - H.assertFileMissing outFile - - either (const H.success) (const H.failure) result - -hprop_golden_shelleyGovernanceAnswerPoll0 :: Property -hprop_golden_shelleyGovernanceAnswerPoll0 = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - expectedAnswerFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.0.json" - outFile <- H.noteTempFile tempDir "answer-file.json" - - void $ execCardanoCLI - [ "legacy", "governance", "answer-poll" - , "--poll-file", pollFile - , "--answer", "0" - , "--out-file", outFile - ] - - H.diffFileVsGoldenFile outFile expectedAnswerFile - -hprop_golden_shelleyGovernanceAnswerPollPos1 :: Property -hprop_golden_shelleyGovernanceAnswerPollPos1 = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - expectedAnswerFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.1.json" - outFile <- H.noteTempFile tempDir "answer-file.json" - - void $ execCardanoCLI - [ "legacy", "governance", "answer-poll" - , "--poll-file", pollFile - , "--answer", "1" - , "--out-file", outFile - ] - - H.diffFileVsGoldenFile outFile expectedAnswerFile - -hprop_golden_shelleyGovernanceAnswerPollPos2Invalid :: Property -hprop_golden_shelleyGovernanceAnswerPollPos2Invalid = propertyOnce . H.moduleWorkspace "governance-answer-poll" $ \tempDir -> do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - outFile <- H.noteTempFile tempDir "answer-file.json" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "answer-poll" - , "--poll-file", pollFile - , "--answer", "2" - , "--out-file", outFile - ] - - H.assertFileMissing outFile - - either (const H.success) (const H.failure) result diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/VerifyPoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/VerifyPoll.hs deleted file mode 100644 index 488a7e9564..0000000000 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Governance/VerifyPoll.hs +++ /dev/null @@ -1,92 +0,0 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} - -module Test.Golden.Shelley.Governance.VerifyPoll where - -import Cardano.Api - -import Cardano.CLI.Types.Key (VerificationKeyOrFile (..), - readVerificationKeyOrTextEnvFile) - -import Control.Monad.IO.Class (liftIO) -import qualified Data.ByteString.Char8 as BSC - -import Test.Cardano.CLI.Util - -import Hedgehog (Property) -import qualified Hedgehog as H -import qualified Hedgehog.Internal.Property as H - -{- HLINT ignore "Use camelCase" -} - -hprop_golden_shelleyGovernanceVerifyPoll :: Property -hprop_golden_shelleyGovernanceVerifyPoll = propertyOnce $ do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - txFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/verify/valid" - vkFile <- VerificationKeyFilePath . File <$> - noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/cold.vk" - - stdout <- BSC.pack <$> execCardanoCLI - [ "legacy", "governance", "verify-poll" - , "--poll-file", pollFile - , "--tx-file", txFile - ] - - liftIO (readVerificationKeyOrTextEnvFile AsStakePoolKey vkFile) >>= \case - Left e -> - H.failWith Nothing (displayError e) - Right vk -> do - let expected = prettyPrintJSON $ serialiseToRawBytesHexText <$> [verificationKeyHash vk] - H.assert $ expected `BSC.isInfixOf` stdout - -hprop_golden_shelleyGovernanceVerifyPollMismatch :: Property -hprop_golden_shelleyGovernanceVerifyPollMismatch = propertyOnce $ do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - txFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/verify/mismatch" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "verify-poll" - , "--poll-file", pollFile - , "--tx-file", txFile - ] - - either (const H.success) (H.failWith Nothing) result - -hprop_golden_shelleyGovernanceVerifyPollNoAnswer :: Property -hprop_golden_shelleyGovernanceVerifyPollNoAnswer = propertyOnce $ do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - txFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/verify/none" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "verify-poll" - , "--poll-file", pollFile - , "--tx-file", txFile - ] - - either (const H.success) (H.failWith Nothing) result - -hprop_golden_shelleyGovernanceVerifyPollMalformedAnswer :: Property -hprop_golden_shelleyGovernanceVerifyPollMalformedAnswer = propertyOnce $ do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - txFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/verify/malformed" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "verify-poll" - , "--poll-file", pollFile - , "--tx-file", txFile - ] - - either (const H.success) (H.failWith Nothing) result - -hprop_golden_shelleyGovernanceVerifyPollInvalidAnswer :: Property -hprop_golden_shelleyGovernanceVerifyPollInvalidAnswer = propertyOnce $ do - pollFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json" - txFile <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/governance/verify/invalid" - - result <- tryExecCardanoCLI - [ "legacy", "governance", "verify-poll" - , "--poll-file", pollFile - , "--tx-file", txFile - ] - - either (const H.success) (H.failWith Nothing) result diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/cold.vk b/cardano-cli/test/cardano-cli-golden/files/golden/governance/cold.vk similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/cold.vk rename to cardano-cli/test/cardano-cli-golden/files/golden/governance/cold.vk diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.0.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/basic.answer.0.json similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.0.json rename to cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/basic.answer.0.json diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.1.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/basic.answer.1.json similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.answer.1.json rename to cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/basic.answer.1.json 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 83bec9c30c..c4ef0af43c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -4970,7 +4970,13 @@ Usage: cardano-cli babbage genesis hash --genesis FILE Compute the hash of a genesis file -Usage: cardano-cli babbage governance (create-mir-certificate | action) +Usage: cardano-cli babbage governance + ( create-mir-certificate + | action + | create-poll + | answer-poll + | verify-poll + ) Governance commands. @@ -5043,6 +5049,25 @@ Usage: cardano-cli babbage governance action create-protocol-parameters-update - Create a protocol parameters update. +Usage: cardano-cli babbage governance create-poll --question STRING + (--answer STRING) + [--nonce UINT] + --out-file FILE + + Create an SPO poll + +Usage: cardano-cli babbage governance answer-poll --poll-file FILE + [--answer INT] + [--out-file FILE] + + Answer an SPO poll + +Usage: cardano-cli babbage governance verify-poll --poll-file FILE + --tx-file FILE + [--out-file FILE] + + Verify an answer to a given SPO poll + Usage: cardano-cli babbage node ( key-gen | key-gen-KES @@ -7695,7 +7720,13 @@ Usage: cardano-cli latest genesis hash --genesis FILE Compute the hash of a genesis file -Usage: cardano-cli latest governance (create-mir-certificate | action) +Usage: cardano-cli latest governance + ( create-mir-certificate + | action + | create-poll + | answer-poll + | verify-poll + ) Governance commands. @@ -7768,6 +7799,25 @@ Usage: cardano-cli latest governance action create-protocol-parameters-update -- Create a protocol parameters update. +Usage: cardano-cli latest governance create-poll --question STRING + (--answer STRING) + [--nonce UINT] + --out-file FILE + + Create an SPO poll + +Usage: cardano-cli latest governance answer-poll --poll-file FILE + [--answer INT] + [--out-file FILE] + + Answer an SPO poll + +Usage: cardano-cli latest governance verify-poll --poll-file FILE + --tx-file FILE + [--out-file FILE] + + Verify an answer to a given SPO poll + Usage: cardano-cli latest node ( key-gen | key-gen-KES @@ -8648,9 +8698,6 @@ Usage: cardano-cli legacy governance ( create-mir-certificate | create-genesis-key-delegation-certificate | create-update-proposal - | create-poll - | answer-poll - | verify-poll ) Governance commands @@ -8777,25 +8824,6 @@ Usage: cardano-cli legacy governance create-update-proposal --out-file FILE Create an update proposal -Usage: cardano-cli legacy governance create-poll --question STRING - (--answer STRING) - [--nonce UINT] - --out-file FILE - - Create an SPO poll - -Usage: cardano-cli legacy governance answer-poll --poll-file FILE - [--answer INT] - [--out-file FILE] - - Answer an SPO poll - -Usage: cardano-cli legacy governance verify-poll --poll-file FILE - --tx-file FILE - [--out-file FILE] - - Verify an answer to a given SPO poll - Usage: cardano-cli legacy genesis ( key-gen-genesis | key-gen-delegate @@ -9959,9 +9987,6 @@ Usage: cardano-cli governance ( create-mir-certificate | create-genesis-key-delegation-certificate | create-update-proposal - | create-poll - | answer-poll - | verify-poll ) Governance commands @@ -10088,25 +10113,6 @@ Usage: cardano-cli governance create-update-proposal --out-file FILE Create an update proposal -Usage: cardano-cli governance create-poll --question STRING - (--answer STRING) - [--nonce UINT] - --out-file FILE - - Create an SPO poll - -Usage: cardano-cli governance answer-poll --poll-file FILE - [--answer INT] - [--out-file FILE] - - Answer an SPO poll - -Usage: cardano-cli governance verify-poll --poll-file FILE - --tx-file FILE - [--out-file FILE] - - Verify an answer to a given SPO poll - Usage: cardano-cli genesis ( key-gen-genesis | key-gen-delegate diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli index c46b2145a0..1ca4e1eec5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli @@ -1,4 +1,10 @@ -Usage: cardano-cli babbage governance (create-mir-certificate | action) +Usage: cardano-cli babbage governance + ( create-mir-certificate + | action + | create-poll + | answer-poll + | verify-poll + ) Governance commands. @@ -9,3 +15,6 @@ Available commands: create-mir-certificate Create an MIR (Move Instantaneous Rewards) certificate action Governance action commands. + create-poll Create an SPO poll + answer-poll Answer an SPO poll + verify-poll Verify an answer to a given SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_answer-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_answer-poll.cli similarity index 61% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/governance_answer-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_answer-poll.cli index 5b98ca49e6..010c8f307d 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_answer-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_answer-poll.cli @@ -1,6 +1,6 @@ -Usage: cardano-cli governance answer-poll --poll-file FILE - [--answer INT] - [--out-file FILE] +Usage: cardano-cli babbage governance answer-poll --poll-file FILE + [--answer INT] + [--out-file FILE] Answer an SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_create-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-poll.cli similarity index 57% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/governance_create-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-poll.cli index 1549cb8231..a2ae7fbd74 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_create-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-poll.cli @@ -1,7 +1,7 @@ -Usage: cardano-cli governance create-poll --question STRING - (--answer STRING) - [--nonce UINT] - --out-file FILE +Usage: cardano-cli babbage governance create-poll --question STRING + (--answer STRING) + [--nonce UINT] + --out-file FILE Create an SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_verify-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_verify-poll.cli similarity index 61% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/governance_verify-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_verify-poll.cli index 30915e6559..1ee21545fd 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance_verify-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_verify-poll.cli @@ -1,6 +1,6 @@ -Usage: cardano-cli governance verify-poll --poll-file FILE - --tx-file FILE - [--out-file FILE] +Usage: cardano-cli babbage governance verify-poll --poll-file FILE + --tx-file FILE + [--out-file FILE] Verify an answer to a given SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/governance.cli index d06eba4ede..4d83c87bcb 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/governance.cli @@ -2,9 +2,6 @@ Usage: cardano-cli governance ( create-mir-certificate | create-genesis-key-delegation-certificate | create-update-proposal - | create-poll - | answer-poll - | verify-poll ) Governance commands @@ -18,6 +15,3 @@ Available commands: create-genesis-key-delegation-certificate Create a genesis key delegation certificate create-update-proposal Create an update proposal - create-poll Create an SPO poll - answer-poll Answer an SPO poll - verify-poll Verify an answer to a given SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli index 4e78e466fa..9833a1a374 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli @@ -1,4 +1,10 @@ -Usage: cardano-cli latest governance (create-mir-certificate | action) +Usage: cardano-cli latest governance + ( create-mir-certificate + | action + | create-poll + | answer-poll + | verify-poll + ) Governance commands. @@ -9,3 +15,6 @@ Available commands: create-mir-certificate Create an MIR (Move Instantaneous Rewards) certificate action Governance action commands. + create-poll Create an SPO poll + answer-poll Answer an SPO poll + verify-poll Verify an answer to a given SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_answer-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_answer-poll.cli similarity index 87% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_answer-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_answer-poll.cli index 0c788de0f2..6f74d1dfff 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_answer-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_answer-poll.cli @@ -1,4 +1,4 @@ -Usage: cardano-cli legacy governance answer-poll --poll-file FILE +Usage: cardano-cli latest governance answer-poll --poll-file FILE [--answer INT] [--out-file FILE] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_create-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-poll.cli similarity index 89% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_create-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-poll.cli index 18a3e7f2b2..aae43025f8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_create-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-poll.cli @@ -1,4 +1,4 @@ -Usage: cardano-cli legacy governance create-poll --question STRING +Usage: cardano-cli latest governance create-poll --question STRING (--answer STRING) [--nonce UINT] --out-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_verify-poll.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_verify-poll.cli similarity index 87% rename from cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_verify-poll.cli rename to cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_verify-poll.cli index 32671bada3..8fa45ec966 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance_verify-poll.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_verify-poll.cli @@ -1,4 +1,4 @@ -Usage: cardano-cli legacy governance verify-poll --poll-file FILE +Usage: cardano-cli latest governance verify-poll --poll-file FILE --tx-file FILE [--out-file FILE] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance.cli index b8aa60f019..1ac6d67f4c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_governance.cli @@ -2,9 +2,6 @@ Usage: cardano-cli legacy governance ( create-mir-certificate | create-genesis-key-delegation-certificate | create-update-proposal - | create-poll - | answer-poll - | verify-poll ) Governance commands @@ -18,6 +15,3 @@ Available commands: create-genesis-key-delegation-certificate Create a genesis key delegation certificate create-update-proposal Create an update proposal - create-poll Create an SPO poll - answer-poll Answer an SPO poll - verify-poll Verify an answer to a given SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/create/basic.json b/cardano-cli/test/cardano-cli-golden/files/input/governance/create/basic.json similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/create/basic.json rename to cardano-cli/test/cardano-cli-golden/files/input/governance/create/basic.json diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/create/long-text.json b/cardano-cli/test/cardano-cli-golden/files/input/governance/create/long-text.json similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/create/long-text.json rename to cardano-cli/test/cardano-cli-golden/files/input/governance/create/long-text.json diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json b/cardano-cli/test/cardano-cli-golden/files/input/governance/polls/basic.json similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/polls/basic.json rename to cardano-cli/test/cardano-cli-golden/files/input/governance/polls/basic.json diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/verify/valid b/cardano-cli/test/cardano-cli-golden/files/input/governance/verify/valid similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/shelley/governance/verify/valid rename to cardano-cli/test/cardano-cli-golden/files/input/governance/verify/valid