Skip to content

Commit 0074be1

Browse files
smelcpalas
authored andcommitted
Test the CLI's "query proposals" command (#6045)
Co-authored-by: Pablo Lamela <[email protected]>
1 parent 809bd6a commit 0074be1

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,9 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
435435
H.noteM_ $ execCli' execConfig [ eraName, "query", "treasury" ]
436436

437437
TestQueryProposalsCmd -> do
438-
-- TODO @cardano-cli team
439-
pure ()
438+
-- query proposals
439+
-- Tested further in Cardano.Testnet.Test.Gov.ProposeNewConstitution.hprop_ledger_events_propose_new_constitution
440+
H.noteM_ $ execCli' execConfig [ eraName, "query", "proposals", "--all-proposals" ]
440441

441442
TestQueryLedgerPeerSnapshotCmd -> do
442443
-- TODO @cardano-cli team

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ import Prelude
2323

2424
import Control.Monad
2525
import Control.Monad.State.Strict (StateT)
26+
import qualified Data.Aeson as Aeson
27+
import qualified Data.Aeson.Lens as Aeson
2628
import Data.Default.Class
2729
import Data.Maybe
2830
import Data.Maybe.Strict
2931
import Data.String
3032
import qualified Data.Text as Text
33+
import Data.Text.Encoding (decodeUtf8)
34+
import qualified Data.Vector as Vector
3135
import GHC.Exts (IsList (..))
3236
import Lens.Micro
3337
import System.Directory (makeAbsolute)
@@ -104,6 +108,8 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
104108

105109
-- Create Conway constitution
106110
gov <- H.createDirectoryIfMissing $ work </> "governance"
111+
proposalAnchorFile <- H.note $ gov </> "sample-proposal-anchor"
112+
constitutionFile <- H.note $ gov </> "sample-constitution"
107113
constitutionActionFp <- H.note $ gov </> "constitution.action"
108114

109115
let proposalAnchorDataIpfsHash = "QmexFJuEn5RtnHEqpxDcqrazdHPzAwe7zs2RxHLfMH5gBz"
@@ -242,6 +248,11 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
242248

243249
waitForGovActionVotes epochStateView (EpochInterval 1)
244250

251+
txid <- execCli' execConfig [ eraName, "transaction", "txid", "--tx-file", unFile signedProposalTx ]
252+
253+
let txNoNewline = Text.unpack (Text.strip (Text.pack txid))
254+
H.noteShow_ txNoNewline
255+
245256
-- Count votes before checking for ratification. It may happen that the proposal gets removed after
246257
-- ratification because of a long waiting time, so we won't be able to access votes.
247258
govState <- getGovState epochStateView ceo
@@ -263,6 +274,73 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
263274
()
264275
(\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState)
265276

277+
proposalsJSON :: Aeson.Value <- execCliStdoutToJson execConfig
278+
[ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline
279+
, "--governance-action-index", "0"
280+
]
281+
282+
-- Display JSON returned in case of failure
283+
H.note_ $ Text.unpack . decodeUtf8 $ prettyPrintJSON proposalsJSON
284+
285+
-- Check that the proposals array has only one element and fetch it
286+
proposalsArray <- H.evalMaybe $ proposalsJSON ^? Aeson._Array
287+
length proposalsArray === 1
288+
let proposal = proposalsArray Vector.! 0
289+
290+
-- Check TxId returned is the same as the one we used
291+
proposalsTxId <- H.evalMaybe $ proposal ^? Aeson.key "actionId" . Aeson.key "txId" . Aeson._String
292+
proposalsTxId === Text.pack txNoNewline
293+
294+
-- Check that committeeVotes is an empty object
295+
proposalsCommitteeVotes <- H.evalMaybe $ proposal ^? Aeson.key "committeeVotes" . Aeson._Object
296+
proposalsCommitteeVotes === mempty
297+
298+
-- Check that dRepVotes has the expected number of votes
299+
proposalsDRepVotes <- H.evalMaybe $ proposal ^? Aeson.key "dRepVotes" . Aeson._Object
300+
length proposalsDRepVotes === numVotes
301+
302+
-- Fetch proposalProcedure and anchor
303+
proposalsProcedure <- H.evalMaybe $ proposal ^? Aeson.key "proposalProcedure"
304+
proposalsAnchor <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "anchor"
305+
306+
-- Check the dataHash of the anchor is the expected one
307+
proposalsAnchorDataHash <- H.evalMaybe $ proposalsAnchor ^? Aeson.key "dataHash" . Aeson._String
308+
proposalsAnchorDataHash === Text.pack proposalAnchorDataHash
309+
310+
-- Check the url of the anchor is the expected one
311+
proposalsAnchorUrl <- H.evalMaybe $ proposalsAnchor ^? Aeson.key "url" . Aeson._String
312+
proposalsAnchorUrl === Text.pack proposalAnchorUrl
313+
314+
-- Check the deposit amount is the expected one
315+
proposalsDeposit <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "deposit" . Aeson._Integer
316+
proposalsDeposit === 1_000_000
317+
318+
-- Ensure there is only one non-null content in the proposalProcedure and fetch it
319+
proposalsContents <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "govAction" . Aeson.key "contents" . Aeson._Array
320+
let nonEmptyContents = Vector.filter (/= Aeson.Null) proposalsContents
321+
length nonEmptyContents === 1
322+
let firstContent = nonEmptyContents Vector.! 0
323+
324+
-- Check the constitution hash and url are the expected ones
325+
proposalsConstitutionAnchor <- H.evalMaybe $ firstContent ^? Aeson.key "anchor"
326+
proposalsConstitutionAnchorDataHash <- H.evalMaybe $ proposalsConstitutionAnchor ^? Aeson.key "dataHash" . Aeson._String
327+
proposalsConstitutionAnchorDataHash === Text.pack constitutionHash
328+
329+
proposalsConstitutionAnchorUrl <- H.evalMaybe $ proposalsConstitutionAnchor ^? Aeson.key "url" . Aeson._String
330+
proposalsConstitutionAnchorUrl === Text.pack constitutionAnchorUrl
331+
332+
-- Check the constitution script hash is the expected one
333+
proposalsScriptHash <- H.evalMaybe $ firstContent ^? Aeson.key "script" . Aeson._String
334+
proposalsScriptHash === Text.pack constitutionScriptHash
335+
336+
-- Check the tag of the govAction is "NewConstitution"
337+
proposalsTag <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "govAction" . Aeson.key "tag" . Aeson._String
338+
proposalsTag === "NewConstitution"
339+
340+
-- Check the stake pool votes are empty
341+
proposalsStakePoolVotes <- H.evalMaybe $ proposal ^? Aeson.key "stakePoolVotes" . Aeson._Object
342+
proposalsStakePoolVotes === mempty
343+
266344
foldBlocksCheckConstitutionWasRatified
267345
:: String -- submitted constitution hash
268346
-> String -- submitted guard rail script hash

0 commit comments

Comments
 (0)