Skip to content

Commit

Permalink
Use hashDrepMetadata from cardano-api
Browse files Browse the repository at this point in the history
* The simplified hashDRepMetadata no longer checks for the size of the DRep metadata, instead it only return the hash of the file given by the user.
* Remove no longer needed errors.
* Update golden tests  to use test vector from CIP 119
* Upgrate cardano-api-9.1.0.0
  • Loading branch information
CarlosLopezDeLara authored and carbolymer committed Jul 19, 2024
1 parent c8b1f8d commit 9aedc74
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-06-23T23:01:13Z
, cardano-haskell-packages 2024-07-02T19:42:00Z
, cardano-haskell-packages 2024-07-19T12:00:49Z

packages:
cardano-cli
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ library
binary,
bytestring,
canonical-json,
cardano-api ^>=9.0,
cardano-api ^>=9.1,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.1.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ runGenesisCreateTestNetDataCmd
} = do
liftIO $ createDirectoryIfMissing False outputDir
shelleyGenesisInit <- maybeReadAndDecodeGenesisFileSpec specShelley shelleyGenesisDefaults
alonzoGenesis <- maybeReadAndDecodeGenesisFileSpec specAlonzo alonzoGenesisDefaults
alonzoGenesis <- maybeReadAndDecodeGenesisFileSpec specAlonzo (alonzoGenesisDefaults BabbageEra) -- FIXED in https://github.com/IntersectMBO/cardano-cli/pull/812
conwayGenesis <- maybeReadAndDecodeGenesisFileSpec specConway conwayGenesisDefaults

-- Read NetworkId either from file or from the flag. Flag overrides template file.
Expand Down
5 changes: 1 addition & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ runGovernanceDRepMetadataHashCmd
, mOutFile
} = do
metadataBytes <- firstExceptT ReadFileError $ newExceptT (readByteStringFile metadataFile)
(_metadata, metadataHash) <-
firstExceptT GovernanceCmdDRepMetadataValidationError
. hoistEither
$ validateAndHashDRepMetadata metadataBytes
let (_metadata, metadataHash) = hashDRepMetadata metadataBytes
firstExceptT WriteFileError
. newExceptT
. writeByteStringOutput mOutFile
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ readScriptDatumOrFile
:: ScriptDatumOrFile witctx
-> ExceptT ScriptDataError IO (ScriptDatum witctx)
readScriptDatumOrFile (ScriptDatumOrFileForTxIn df) =
ScriptDatumForTxIn
ScriptDatumForTxIn . Just
<$> readScriptDataOrFile df
readScriptDatumOrFile InlineDatumPresentAtTxIn = pure InlineScriptDatum
readScriptDatumOrFile NoScriptDatumOrFileForMint = pure NoScriptDatumForMint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ data GovernanceCmdError
| GovernanceCmdDecoderError !DecoderError
| GovernanceCmdVerifyPollError !GovernancePollError
| GovernanceCmdWriteFileError !(FileError ())
| GovernanceCmdDRepMetadataValidationError !DRepMetadataValidationError
| -- Legacy - remove me after cardano-cli transitions to new era based structure
GovernanceCmdMIRCertNotSupportedInConway
| GovernanceCmdGenesisDelegationNotSupportedInConway
Expand Down Expand Up @@ -111,8 +110,6 @@ instance Error GovernanceCmdError where
pretty $ renderGovernancePollError pollError
GovernanceCmdWriteFileError fileError ->
"Cannot write file: " <> prettyError fileError
GovernanceCmdDRepMetadataValidationError e ->
"DRep metadata validation error: " <> prettyError e
GovernanceCmdMIRCertNotSupportedInConway ->
"MIR certificates are not supported in Conway era onwards."
GovernanceCmdGenesisDelegationNotSupportedInConway ->
Expand Down
19 changes: 19 additions & 0 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ hprop_golden_governance_drep_metadata_hash = propertyOnce . H.moduleWorkspace "t

H.diffFileVsGoldenFile outputDRepMetadataHash goldenDRepMetadataHash

-- Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance drep metadata hash cip119/"'@
hprop_golden_governance_drep_metadata_hash_cip119 :: Property
hprop_golden_governance_drep_metadata_hash_cip119 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
goldenDRepMetadataHashCip119 <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_metadata_hash_cip119"

--Use jsonld file from test vector of CIP119 https://github.com/cardano-foundation/CIPs/blob/master/CIP-0119/test-vector.md
drepMetadataFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/drep.jsonld"

outputDRepMetadataHashCip119 <- H.noteTempFile tempDir "drep-metadata-hash-cip119.txt"

void $ execCardanoCLI
[ "conway", "governance", "drep", "metadata-hash"
, "--drep-metadata-file", drepMetadataFile
, "--out-file", outputDRepMetadataHashCip119
]

H.diffFileVsGoldenFile outputDRepMetadataHashCip119 goldenDRepMetadataHashCip119

hprop_golden_governance_drep_registration_certificate_vkey_file :: Property
hprop_golden_governance_drep_registration_certificate_vkey_file = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
drepVKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/drep.vkey"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a14a5ad4f36bddc00f92ddb39fd9ac633c0fd43f8bfa57758f9163d10ef916de
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"@context": {
"CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#",
"CIP119": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0119/README.md#",
"hashAlgorithm": "CIP100:hashAlgorithm",
"body": {
"@id": "CIP119:body",
"@context": {
"references": {
"@id": "CIP119:references",
"@container": "@set",
"@context": {
"GovernanceMetadata": "CIP100:GovernanceMetadataReference",
"Other": "CIP100:OtherReference",
"label": "CIP100:reference-label",
"uri": "CIP100:reference-uri"
}
},
"paymentAddress": "CIP119:paymentAddress",
"givenName": "CIP119:givenName",
"image": {
"@id": "CIP119:image",
"@context": {
"ImageObject": "https://schema.org/ImageObject"
}
},
"objectives": "CIP119:objectives",
"motivations": "CIP119:motivations",
"qualifications": "CIP119:qualifications"
}
}
},
"hahsAlgorithm": "blake2b-256",
"body": {
"paymentAddress": "addr1q86dnpkva4mm859c8ur7tjxn57zgsu6vg8pdetkdve3fsacnq7twy06u2ev5759vutpjgzfryx0ud8hzedhzerava35qwh3x34",
"givenName": "Ryan Williams",
"image": {
"@type": "ImageObject",
"contentUrl": "https://avatars.githubusercontent.com/u/44342099?v=4",
"sha256": "2a21e4f7b20c8c72f573707b068fb8fc6d8c64d5035c4e18ecae287947fe2b2e"
},
"objectives": "Buy myself an island.",
"motivations": "I really would like to own an island.",
"qualifications": "I have my 100m swimming badge, so I would be qualified to be able to swim around island.",
"references": [
{
"@type": "Other",
"label": "A cool island for Ryan",
"uri": "https://www.google.com/maps/place/World's+only+5th+order+recursive+island/@62.6511465,-97.7946829,15.75z/data=!4m14!1m7!3m6!1s0x5216a167810cee39:0x11431abdfe4c7421!2sWorld's+only+5th+order+recursive+island!8m2!3d62.651114!4d-97.7872244!16s%2Fg%2F11spwk2b6n!3m5!1s0x5216a167810cee39:0x11431abdfe4c7421!8m2!3d62.651114!4d-97.7872244!16s%2Fg%2F11spwk2b6n?authuser=0&entry=ttu"
},
{
"@type": "Link",
"label": "Ryan's Twitter",
"uri": "https://twitter.com/Ryun1_"
}
]
}
}
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9aedc74

Please sign in to comment.