Skip to content

Commit

Permalink
Merge pull request #460 from input-output-hk/smelc/governance-create-…
Browse files Browse the repository at this point in the history
…constution-align-flags-with-420

Align create-constitution anchor flags with other anchor flags
  • Loading branch information
smelc authored Nov 17, 2023
2 parents 4dcfd59 + 77236d7 commit fa7f72a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data GovernanceActionCreateConstitutionCmdArgs era
, proposalUrl :: !ProposalUrl
, proposalHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, constitutionUrl :: !ConstitutionUrl
, constitutionHashSource :: !ConstitutionHashSource
, constitutionHash :: !(Ledger.SafeHash Crypto.StandardCrypto Ledger.AnchorData)
, outFile :: !(File () Out)
} deriving Show

Expand Down
23 changes: 3 additions & 20 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -875,31 +875,14 @@ catCommands = \case
pConstitutionUrl :: Parser ConstitutionUrl
pConstitutionUrl =
ConstitutionUrl
<$> pUrl "constitution-anchor-url" "Constitution anchor URL."

pConstitutionHashSource :: Parser ConstitutionHashSource
pConstitutionHashSource =
asum
[ ConstitutionHashSourceText
<$> Opt.strOption
( mconcat
[ Opt.long "constitution-anchor-metadata"
, Opt.metavar "TEXT"
, Opt.help "Constitution anchor contents as UTF-8 encoded text."
]
)
, ConstitutionHashSourceFile
<$> pFileInDirection "constitution-anchor-metadata-file" "Constitution anchor contents as a text file."
, ConstitutionHashSourceHash
<$> pConstitutionHash
]
<$> pUrl "constitution-url" "Constitution URL."

pConstitutionHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pConstitutionHash =
Opt.option readSafeHash $ mconcat
[ Opt.long "constitution-anchor-metadata-hash"
[ Opt.long "constitution-hash"
, Opt.metavar "HASH"
, Opt.help "Hash of the constitution anchor data."
, Opt.help "Hash of the constitution data (obtain it with \"cardano-cli conway governance hash ...\")."
]

pUrl :: String -> String -> Parser Ledger.Url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pGovernanceActionNewConstitutionCmd era = do
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pConstitutionUrl
<*> pConstitutionHashSource
<*> pConstitutionHash
<*> pFileOutDirection "out-file" "Output filepath of the constitution."
)
$ Opt.progDesc "Create a constitution."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ runGovernanceActionCreateConstitutionCmd
, Cmd.proposalUrl
, Cmd.proposalHash
, Cmd.constitutionUrl
, Cmd.constitutionHashSource
, Cmd.constitutionHash
, Cmd.outFile
} = do

Expand All @@ -157,10 +157,6 @@ runGovernanceActionCreateConstitutionCmd
, Ledger.anchorDataHash = proposalHash
}

constitutionHash <-
constitutionHashSourceToHash constitutionHashSource
& firstExceptT GovernanceActionsCmdConstitutionError

let prevGovActId = Ledger.maybeToStrictMaybe $ uncurry createPreviousGovernanceActionId <$> mPrevGovernanceActionId
constitutionAnchor = Ledger.Anchor
{ Ledger.anchorUrl = unConstitutionUrl constitutionUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ hprop_golden_governance_action_create_constitution =

proposalHash <- execCardanoCLI
[ "conway", "governance", "hash"
, "--text", "whatever "]
, "--text", "whatever"]

constitutionHash <- execCardanoCLI
[ "conway", "governance", "hash"
, "--text", "something else"]

void $ execCardanoCLI
[ "conway", "governance", "action", "create-constitution"
Expand All @@ -39,8 +43,8 @@ hprop_golden_governance_action_create_constitution =
, "--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."
, "--constitution-url", "constitution-dummy-url"
, "--constitution-hash", constitutionHash
]

goldenActionFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden"
Expand All @@ -67,6 +71,11 @@ hprop_golden_conway_governance_action_view_constitution_json =

proposalHash <- H.readFile hashFile

constitutionHash <- execCardanoCLI
[ "conway", "governance", "hash"
, "--text", "nonAsciiInput: 你好 and some more: こんにちは"
]

void $ execCardanoCLI
[ "conway", "governance", "action", "create-constitution"
, "--mainnet"
Expand All @@ -75,8 +84,8 @@ hprop_golden_conway_governance_action_view_constitution_json =
, "--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."
, "--constitution-url", "http://my-great-constitution.rocks"
, "--constitution-hash", constitutionHash
]

goldenActionViewFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/view/create-constitution.action.view"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
null,
{
"anchor": {
"dataHash": "42cb2e410023679943d26c23ce2b5046eb7dfc5883c69fb91cc8a3c9c9a99a99",
"url": "constitution-dummy-url"
"dataHash": "913844423a72d4ff4cffe1ca2bed8e7f354dba7563df9e630e5b6a86fa72659a",
"url": "http://my-great-constitution.rocks"
}
}
],
Expand Down
7 changes: 2 additions & 5 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -5923,11 +5923,8 @@ Usage: cardano-cli conway governance action create-constitution
--governance-action-index WORD32]
--anchor-url TEXT
--anchor-data-hash HASH
--constitution-anchor-url TEXT
( --constitution-anchor-metadata TEXT
| --constitution-anchor-metadata-file FILE
| --constitution-anchor-metadata-hash HASH
)
--constitution-url TEXT
--constitution-hash HASH
--out-file FILE

Create a constitution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ Usage: cardano-cli conway governance action create-constitution
--governance-action-index WORD32]
--anchor-url TEXT
--anchor-data-hash HASH
--constitution-anchor-url TEXT
( --constitution-anchor-metadata TEXT
| --constitution-anchor-metadata-file FILE
| --constitution-anchor-metadata-hash HASH
)
--constitution-url TEXT
--constitution-hash HASH
--out-file FILE

Create a constitution.
Expand All @@ -37,13 +34,8 @@ Available options:
--anchor-url TEXT Anchor URL
--anchor-data-hash HASH Proposal anchor data hash (obtain it with
"cardano-cli conway governance hash ...")
--constitution-anchor-url TEXT
Constitution anchor URL.
--constitution-anchor-metadata TEXT
Constitution anchor contents as UTF-8 encoded text.
--constitution-anchor-metadata-file FILE
Constitution anchor contents as a text file.
--constitution-anchor-metadata-hash HASH
Hash of the constitution anchor data.
--constitution-url TEXT Constitution URL.
--constitution-hash HASH Hash of the constitution data (obtain it with
"cardano-cli conway governance hash ...").
--out-file FILE Output filepath of the constitution.
-h,--help Show this help text

0 comments on commit fa7f72a

Please sign in to comment.