Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align create-constitution anchor flags with other anchor flags #460

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: こんにちは"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, testing this as well!

]

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