Skip to content

Commit f05f73b

Browse files
committed
Check result of proposals query
1 parent 9d8a227 commit f05f73b

File tree

1 file changed

+76
-58
lines changed

1 file changed

+76
-58
lines changed

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

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ 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 Data.Vector (Vector)
35+
import qualified Data.Vector as Vector
3136
import GHC.Exts (IsList (..))
3237
import Lens.Micro
3338
import System.FilePath ((</>))
@@ -103,7 +108,9 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
103108
-- Create Conway constitution
104109
gov <- H.createDirectoryIfMissing $ work </> "governance"
105110
proposalAnchorFile <- H.note $ gov </> "sample-proposal-anchor"
111+
let proposalAnchorUrl = "https://tinyurl.com/3wrwb2as"
106112
constitutionFile <- H.note $ gov </> "sample-constitution"
113+
let constitutionAnchorUrl = "https://tinyurl.com/2pahcy6z"
107114
constitutionActionFp <- H.note $ gov </> "constitution.action"
108115

109116
H.writeFile proposalAnchorFile $
@@ -175,9 +182,9 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
175182
, "--testnet"
176183
, "--governance-action-deposit", show minDRepDeposit
177184
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
178-
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
185+
, "--anchor-url", proposalAnchorUrl
179186
, "--anchor-data-hash", proposalAnchorDataHash
180-
, "--constitution-url", "https://tinyurl.com/2pahcy6z"
187+
, "--constitution-url", constitutionAnchorUrl
181188
, "--constitution-hash", constitutionHash
182189
, "--constitution-script-hash", constitutionScriptHash
183190
, "--out-file", constitutionActionFp
@@ -230,7 +237,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
230237
-- H.noteM_ $ execCli' execConfig [ eraName, "query", "gov-state" ]
231238
let txNoNewline = Text.unpack (Text.strip (Text.pack txid))
232239
H.noteShow_ txNoNewline
233-
H.noteM_ $ execCli' execConfig [ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline
240+
H.noteM_ $ execCli' execConfig [ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline
234241
, "--governance-action-index", "0" ]
235242
-- Command returned:
236243
--
@@ -257,61 +264,72 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new
257264
()
258265
(\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState)
259266

260-
H.noteM_ $ execCli' execConfig [ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline
261-
, "--governance-action-index", "0" ]
262-
-- Command returned:
263-
--
264-
-- [
265-
-- {
266-
-- "actionId": {
267-
-- "govActionIx": 0,
268-
-- "txId": "d3877f2694dcd3853abf44506977cbd25f94a26cf887e426f601b29fffb256c3"
269-
-- },
270-
-- "committeeVotes": {},
271-
-- "dRepVotes": {
272-
-- "keyHash-11885af93181919dd2749bf828de656045c78f5d5f511055eec54306": "VoteNo",
273-
-- "keyHash-42cdea9e46396ad3f145b7834c16675ec7962c11648b5c031210ceb1": "VoteYes",
274-
-- "keyHash-8453f733cb6e3d873993c9e94a423b3e4385547381f10a1f4da0b995": "VoteYes",
275-
-- "keyHash-85454551839aab47b09f25e75deff03403047d081ab5ecff6243cb0f": "Abstain",
276-
-- "keyHash-adbcfc9e9bcede4ab2db8d7d85d6f556fa57fa6e2897b31592d9819c": "VoteNo",
277-
-- "keyHash-bbe6163dd619fa83ae1ee3a061639cc50b8305e1d97f2837458fa995": "VoteYes",
278-
-- "keyHash-c4f60d2624acb06de54db22fb25e59818ee62d3e7c2464974d9af728": "Abstain",
279-
-- "keyHash-ec9ac276b3727015dfef084ad251ff6925353581b33e3453bda9fb2f": "VoteNo",
280-
-- "keyHash-f6173095513bf9a575f91251649280890ca9d3849859f28179ec2a63": "VoteYes"
281-
-- },
282-
-- "expiresAfter": 2,
283-
-- "proposalProcedure": {
284-
-- "anchor": {
285-
-- "dataHash": "0ddee8482655dcaf1471243432069483a029bce680457d01f547f6b5f097d73f",
286-
-- "url": "https://tinyurl.com/3wrwb2as"
287-
-- },
288-
-- "deposit": 1000000,
289-
-- "govAction": {
290-
-- "contents": [
291-
-- null,
292-
-- {
293-
-- "anchor": {
294-
-- "dataHash": "c9247db6ab4e0d795bec6aed1b565f92f056d235f777329df546689ca834c46e",
295-
-- "url": "https://tinyurl.com/2pahcy6z"
296-
-- },
297-
-- "script": "186e32faa80a26810392fda6d559c7ed4721a65ce1c9d4ef3e1c87b4"
298-
-- }
299-
-- ],
300-
-- "tag": "NewConstitution"
301-
-- },
302-
-- "returnAddr": {
303-
-- "credential": {
304-
-- "keyHash": "74c5f83aa5ff896923939329a1e46aadc193a44894ef6a9e969a2e22"
305-
-- },
306-
-- "network": "Testnet"
307-
-- }
308-
-- },
309-
-- "proposedIn": 1,
310-
-- "stakePoolVotes": {}
311-
-- }
312-
-- ]
313-
314-
assert False
267+
proposalsJSON :: Aeson.Value <- execCliStdoutToJson execConfig
268+
[ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline
269+
, "--governance-action-index", "0"
270+
]
271+
272+
-- Display JSON returned in case of failure
273+
H.note_ $ Text.unpack . decodeUtf8 $ prettyPrintJSON proposalsJSON
274+
275+
-- Check that the proposals array has only one element and fetch it
276+
proposalsArray <- H.evalMaybe $ proposalsJSON ^? Aeson._Array
277+
length proposalsArray === 1
278+
let proposal = proposalsArray Vector.! 0
279+
280+
-- Check TxId returned is the same as the one we used
281+
proposalsTxId <- H.evalMaybe $ proposal ^? Aeson.key "actionId" . Aeson.key "txId" . Aeson._String
282+
proposalsTxId === Text.pack txNoNewline
283+
284+
-- Check that committeeVotes is an empty object
285+
proposalsCommitteeVotes <- H.evalMaybe $ proposal ^? Aeson.key "committeeVotes" . Aeson._Object
286+
proposalsCommitteeVotes === mempty
287+
288+
-- Check that dRepVotes has the expected number of votes
289+
proposalsDRepVotes <- H.evalMaybe $ proposal ^? Aeson.key "dRepVotes" . Aeson._Object
290+
length proposalsDRepVotes === numVotes
291+
292+
-- Fetch proposalProcedure and anchor
293+
proposalsProcedure <- H.evalMaybe $ proposal ^? Aeson.key "proposalProcedure"
294+
proposalsAnchor <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "anchor"
295+
296+
-- Check the dataHash of the anchor is the expected one
297+
proposalsAnchorDataHash <- H.evalMaybe $ proposalsAnchor ^? Aeson.key "dataHash" . Aeson._String
298+
proposalsAnchorDataHash === Text.pack proposalAnchorDataHash
299+
300+
-- Check the url of the anchor is the expected one
301+
proposalsAnchorUrl <- H.evalMaybe $ proposalsAnchor ^? Aeson.key "url" . Aeson._String
302+
proposalsAnchorUrl === Text.pack proposalAnchorUrl
303+
304+
-- Check the deposit amount is the expected one
305+
proposalsDeposit <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "deposit" . Aeson._Integer
306+
proposalsDeposit === 1_000_000
307+
308+
-- Ensure there is only one non-null content in the proposalProcedure and fetch it
309+
proposalsContents :: Vector Aeson.Value <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "govAction" . Aeson.key "contents" . Aeson._Array
310+
let nonEmptyContents = filter (/= Aeson.Null) $ Vector.toList proposalsContents
311+
length nonEmptyContents === 1
312+
let firstContent = head nonEmptyContents
313+
314+
-- Check the constitution hash and url are the expected ones
315+
proposalsConstitutionAnchor <- H.evalMaybe $ firstContent ^? Aeson.key "anchor"
316+
proposalsConstitutionAnchorDataHash <- H.evalMaybe $ proposalsConstitutionAnchor ^? Aeson.key "dataHash" . Aeson._String
317+
proposalsConstitutionAnchorDataHash === Text.pack constitutionHash
318+
319+
proposalsConstitutionAnchorUrl <- H.evalMaybe $ proposalsConstitutionAnchor ^? Aeson.key "url" . Aeson._String
320+
proposalsConstitutionAnchorUrl === Text.pack constitutionAnchorUrl
321+
322+
-- Check the constitution script hash is the expected one
323+
proposalsScriptHash <- H.evalMaybe $ firstContent ^? Aeson.key "script" . Aeson._String
324+
proposalsScriptHash === Text.pack constitutionScriptHash
325+
326+
-- Check the tag of the govAction is "NewConstitution"
327+
proposalsTag <- H.evalMaybe $ proposalsProcedure ^? Aeson.key "govAction" . Aeson.key "tag" . Aeson._String
328+
proposalsTag === "NewConstitution"
329+
330+
-- Check the stake pool votes are empty
331+
proposalsStakePoolVotes <- H.evalMaybe $ proposal ^? Aeson.key "stakePoolVotes" . Aeson._Object
332+
proposalsStakePoolVotes === mempty
315333

316334
foldBlocksCheckConstitutionWasRatified
317335
:: String -- submitted constitution hash

0 commit comments

Comments
 (0)