From 71322b1244dd7c20bf3b34b5dc8de07d00cc1f86 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 18 Dec 2024 20:37:21 +0100 Subject: [PATCH 1/9] Add temporary stanza to `cardano-api` --- cabal.project | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cabal.project b/cabal.project index 153325bf20..53b954aac6 100644 --- a/cabal.project +++ b/cabal.project @@ -19,6 +19,13 @@ index-state: packages: cardano-cli +source-repository-package + type: git + location: https://github.com/IntersectMBO/cardano-api + subdir: cardano-api + tag: 4168561fc05d522c51e0c764647fd752b42344f4 + --sha256: sha256-zZ/Cpbyoi1ZdTwPUXTXbRtIVvKGkkXkl6Ma4rKGnjUE= + program-options ghc-options: -Werror From 74540f72cb8af67168788f4789fd5af01e7db49f Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 18 Dec 2024 15:00:41 +0100 Subject: [PATCH 2/9] Unify use of `carryHashChecks` --- .../CLI/EraBased/Run/Governance/Actions.hs | 46 ++++++++----------- .../Types/Errors/GovernanceActionsError.hs | 34 ++++---------- 2 files changed, 26 insertions(+), 54 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index f414df01ed..6a4e6be34c 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -22,10 +22,9 @@ import Cardano.CLI.EraBased.Commands.Governance.Actions import qualified Cardano.CLI.EraBased.Commands.Governance.Actions as Cmd import Cardano.CLI.Json.Friendly import Cardano.CLI.Read -import Cardano.CLI.Run.Hash (getByteStringFromURL, httpsAndIpfsSchemes) +import Cardano.CLI.Run.Hash (carryHashChecks) import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.GovernanceActionsError -import Cardano.CLI.Types.Errors.HashCmdError (FetchURLError) import Cardano.CLI.Types.Key import Control.Monad @@ -103,7 +102,7 @@ runGovernanceActionInfoCmd , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck let sbe = convert eon govAction = InfoAct @@ -113,10 +112,6 @@ runGovernanceActionInfoCmd conwayEraOnwardsConstraints eon $ writeFileTextEnvelope outFile (Just "Info proposal") proposalProcedure -fetchURLErrorToGovernanceActionError - :: AnchorDataTypeCheck -> ExceptT FetchURLError IO a -> ExceptT GovernanceActionsError IO a -fetchURLErrorToGovernanceActionError adt = withExceptT (GovernanceActionsProposalFetchURLError adt) - -- TODO: Conway era - update with new ledger types from cardano-ledger-conway-1.7.0.0 runGovernanceActionCreateNoConfidenceCmd :: forall era @@ -145,7 +140,7 @@ runGovernanceActionCreateNoConfidenceCmd , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck let sbe = convert eon previousGovernanceAction = @@ -198,7 +193,7 @@ runGovernanceActionCreateConstitutionCmd , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck let prevGovActId = L.maybeToStrictMaybe $ @@ -217,7 +212,7 @@ runGovernanceActionCreateConstitutionCmd sbe = convert eon proposalProcedure = createProposalProcedure sbe networkId deposit depositStakeCredential govAct proposalAnchor - carryHashChecks checkConstitutionHash constitutionAnchor ConstitutionCheck + carryHashChecksWrapper checkConstitutionHash constitutionAnchor ConstitutionCheck firstExceptT GovernanceActionsCmdWriteFileError . newExceptT $ conwayEraOnwardsConstraints eon $ @@ -261,7 +256,7 @@ runGovernanceActionUpdateCommitteeCmd , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck oldCommitteeKeyHashes <- forM oldCommitteeVkeySource $ \vkeyOrHashOrTextFile -> modifyError GovernanceActionsCmdReadFileError $ @@ -371,7 +366,7 @@ runGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams' = do , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck let govAct = UpdatePParams @@ -442,7 +437,7 @@ runGovernanceActionTreasuryWithdrawalCmd , L.anchorDataHash = proposalHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck depositStakeCredential <- firstExceptT GovernanceActionsReadStakeCredErrror $ @@ -499,7 +494,7 @@ runGovernanceActionHardforkInitCmd , L.anchorDataHash } - carryHashChecks checkProposalHash proposalAnchor ProposalCheck + carryHashChecksWrapper checkProposalHash proposalAnchor ProposalCheck let sbe = convert eon govActIdentifier = @@ -519,7 +514,7 @@ runGovernanceActionHardforkInitCmd -- | Check the hash of the anchor data against the hash in the anchor if -- checkHash is set to CheckHash. -carryHashChecks +carryHashChecksWrapper :: MustCheckHash a -- ^ Whether to check the hash or not (CheckHash for checking or TrustHash for not checking) -> L.Anchor L.StandardCrypto @@ -527,16 +522,11 @@ carryHashChecks -> AnchorDataTypeCheck -- ^ The type of anchor data to check (for error reporting purpouses) -> ExceptT GovernanceActionsError IO () -carryHashChecks checkHash anchor checkType = - case checkHash of - CheckHash -> do - anchorData <- - L.AnchorData - <$> fetchURLErrorToGovernanceActionError - checkType - (getByteStringFromURL httpsAndIpfsSchemes $ L.urlToText $ L.anchorUrl anchor) - let hash = L.hashAnchorData anchorData - when (hash /= L.anchorDataHash anchor) $ - left $ - GovernanceActionsMismatchedHashError checkType (L.anchorDataHash anchor) hash - TrustHash -> pure () +carryHashChecksWrapper checkHash anchor checkType = + firstExceptT (GovernanceActionsHashCheckError checkType) $ + carryHashChecks + ( PotentiallyCheckedAnchor + { pcaMustCheck = checkHash + , pcaAnchor = anchor + } + ) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs index 8f95d996e8..6b98ea4ae9 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs @@ -7,14 +7,11 @@ module Cardano.CLI.Types.Errors.GovernanceActionsError where import Cardano.Api -import qualified Cardano.Api.Ledger as L import Cardano.CLI.Read -import Cardano.CLI.Types.Errors.HashCmdError (FetchURLError) +import Cardano.CLI.Types.Errors.HashCmdError (HashCheckError) import Cardano.CLI.Types.Errors.StakeCredentialError -import Control.Exception (displayException) - data GovernanceActionsError = GovernanceActionsCmdConstitutionError ConstitutionError | GovernanceActionsCmdProposalError ProposalError @@ -24,18 +21,11 @@ data GovernanceActionsError | GovernanceActionsCmdReadTextEnvelopeFileError (FileError TextEnvelopeError) | GovernanceActionsCmdWriteFileError (FileError ()) | GovernanceActionsValueUpdateProtocolParametersNotFound AnyShelleyBasedEra - | GovernanceActionsMismatchedHashError - AnchorDataTypeCheck - -- ^ Type of anchor data that we were checking - !(L.SafeHash L.StandardCrypto L.AnchorData) - -- ^ Expected hash - !(L.SafeHash L.StandardCrypto L.AnchorData) - -- ^ Actual hash - | GovernanceActionsProposalFetchURLError + | GovernanceActionsHashCheckError AnchorDataTypeCheck -- ^ Type of anchor data that we were checking - FetchURLError - -- ^ Error that occurred while fetching the anchor data + HashCheckError + -- ^ The error that occurred while checking the hash deriving Show instance Error GovernanceActionsError where @@ -56,19 +46,11 @@ instance Error GovernanceActionsError where "Protocol parameters update value for" <+> pretty expectedShelleyEra <+> "was not found." GovernanceActionsReadStakeCredErrror e -> prettyError e - GovernanceActionsMismatchedHashError adt expectedHash actualHash -> - "Hashes do not match while checking" - <+> pretty (anchorDataTypeCheckName adt) - <+> "hashes!" - <> "\nExpected:" - <+> pretty (show (L.extractHash expectedHash)) - <> "\n Actual:" - <+> pretty (show (L.extractHash actualHash)) - GovernanceActionsProposalFetchURLError adt fetchErr -> - "Error while checking" + GovernanceActionsHashCheckError adt hashCheckErr -> + "Error while checking hash for" <+> pretty (anchorDataTypeCheckName adt) - <+> "hash:" - <+> pretty (displayException fetchErr) + <> ":" + <+> prettyException hashCheckErr data AnchorDataTypeCheck = ProposalCheck From e80339276bbaf8b72ab3182202301251ef904871 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 18 Dec 2024 20:28:40 +0100 Subject: [PATCH 3/9] Add metadata checks for CIP-0108 and CIP-0119 --- .../CLI/EraBased/Run/Governance/Actions.hs | 1 + .../CLI/EraBased/Run/Governance/Committee.hs | 4 +-- .../CLI/EraBased/Run/Governance/DRep.hs | 9 ++++-- .../CLI/EraBased/Run/Governance/Vote.hs | 4 ++- .../CLI/EraBased/Transaction/HashCheck.hs | 30 ++++++++++++++----- cardano-cli/src/Cardano/CLI/Run/Hash.hs | 24 ++++++++++----- .../Cardano/CLI/Types/Errors/HashCmdError.hs | 2 ++ 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index 6a4e6be34c..ec1532a67c 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -525,6 +525,7 @@ carryHashChecksWrapper carryHashChecksWrapper checkHash anchor checkType = firstExceptT (GovernanceActionsHashCheckError checkType) $ carryHashChecks + validateGovActionAnchorData ( PotentiallyCheckedAnchor { pcaMustCheck = checkHash , pcaAnchor = anchor diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index 7dee0445e9..c8a66d04a2 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -17,7 +17,7 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Governance.Committee import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as Cmd import Cardano.CLI.Read (readVerificationKeySource) -import Cardano.CLI.Run.Hash (carryHashChecks) +import Cardano.CLI.Run.Hash (carryHashChecksWithoutValidating) import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Types.Common (PotentiallyCheckedAnchor (..)) import Cardano.CLI.Types.Errors.GovernanceCommitteeError @@ -178,7 +178,7 @@ runGovernanceCommitteeColdKeyResignationCertificate readVerificationKeySource AsCommitteeColdKey unCommitteeColdKeyHash vkeyColdKeySource mapM_ - (withExceptT GovernanceCommitteeHashCheckError . carryHashChecks) + (withExceptT GovernanceCommitteeHashCheckError . carryHashChecksWithoutValidating) anchor makeCommitteeColdkeyResignationCertificate diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs index 2fc2bbd809..dbcf574874 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -17,6 +17,7 @@ where import Cardano.Api import qualified Cardano.Api.Ledger as L +import Cardano.Api.Shelley (DRepMetadata (DRepMetadata)) import qualified Cardano.CLI.Commands.Hash as Cmd import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as Cmd @@ -115,7 +116,9 @@ runGovernanceDRepRegistrationCertificateCmd drepCred <- modifyError RegistrationReadError $ readDRepCredential drepHashSource mapM_ - (withExceptT RegistrationDRepHashCheckError . carryHashChecks) + ( withExceptT RegistrationDRepHashCheckError + . carryHashChecks (validateDRepAnchorData . DRepMetadata) + ) mAnchor let req = DRepRegistrationRequirements w drepCred deposit @@ -164,7 +167,9 @@ runGovernanceDRepUpdateCertificateCmd } = conwayEraOnwardsConstraints w $ do mapM_ - (withExceptT GovernanceDRepHashCheckError . carryHashChecks) + ( withExceptT GovernanceDRepHashCheckError + . carryHashChecks (validateDRepAnchorData . DRepMetadata) + ) mAnchor drepCredential <- modifyError GovernanceCmdKeyReadError $ readDRepCredential drepHashSource let updateCertificate = diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs index cff860d6c5..55a3e51564 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs @@ -64,7 +64,9 @@ runGovernanceVoteCreateCmd mAnchor mapM_ - (withExceptT GovernanceVoteCmdResignationCertHashCheckError . carryHashChecks) + ( withExceptT GovernanceVoteCmdResignationCertHashCheckError + . carryHashChecks validateGovActionAnchorData + ) mAnchor' voteProcedure <- case mAnchor' of diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Transaction/HashCheck.hs b/cardano-cli/src/Cardano/CLI/EraBased/Transaction/HashCheck.hs index aabc37fbe9..2fcfd3705c 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Transaction/HashCheck.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Transaction/HashCheck.hs @@ -8,7 +8,9 @@ module Cardano.CLI.EraBased.Transaction.HashCheck where import Cardano.Api (Certificate (..), ExceptT, except, firstExceptT, - getAnchorDataFromCertificate, getAnchorDataFromGovernanceAction, withExceptT) + getAnchorDataFromCertificate, getAnchorDataFromGovernanceAction, + isDRepRegOrUpdateCert, validateDRepAnchorData, validateGovActionAnchorData, + withExceptT) import qualified Cardano.Api.Ledger as L import qualified Cardano.Api.Shelley as Shelley @@ -17,12 +19,15 @@ import Cardano.CLI.Types.Common (MustCheckHash (..), PotentiallyChecke import Cardano.CLI.Types.Errors.TxCmdError (TxCmdError (..)) import Control.Monad (forM_) +import Data.ByteString (ByteString) -- | Check the hash of the anchor data against the hash in the anchor -checkAnchorMetadataHash :: L.Anchor L.StandardCrypto -> ExceptT TxCmdError IO () -checkAnchorMetadataHash anchor = +checkAnchorMetadataHash + :: (ByteString -> Either String ()) -> L.Anchor L.StandardCrypto -> ExceptT TxCmdError IO () +checkAnchorMetadataHash validationFunction anchor = firstExceptT (TxCmdHashCheckError $ L.anchorUrl anchor) $ carryHashChecks + validationFunction ( PotentiallyCheckedAnchor { pcaMustCheck = CheckHash , pcaAnchor = anchor @@ -34,7 +39,15 @@ checkAnchorMetadataHash anchor = checkCertificateHashes :: Certificate era -> ExceptT TxCmdError IO () checkCertificateHashes cert = do mAnchor <- withExceptT TxCmdPoolMetadataHashError $ except $ getAnchorDataFromCertificate cert - maybe (return mempty) checkAnchorMetadataHash mAnchor + maybe + (return mempty) + ( checkAnchorMetadataHash + ( if isDRepRegOrUpdateCert cert + then validateDRepAnchorData . Shelley.DRepMetadata + else const $ return () + ) + ) + mAnchor -- | Find references to anchor data in voting procedures and check the hashes are valid -- and they match the linked data. @@ -45,7 +58,7 @@ checkVotingProcedureHashes eon (Shelley.VotingProcedures (L.VotingProcedures vot forM_ voterMap ( mapM $ \(L.VotingProcedure _ mAnchor) -> - forM_ mAnchor checkAnchorMetadataHash + forM_ mAnchor $ checkAnchorMetadataHash validateGovActionAnchorData ) -- | Find references to anchor data in proposals and check the hashes are valid @@ -62,7 +75,10 @@ checkProposalHashes ) ) = Shelley.shelleyBasedEraConstraints eon $ do - checkAnchorMetadataHash anchor - maybe (return ()) checkAnchorMetadataHash (getAnchorDataFromGovernanceAction govAction) + checkAnchorMetadataHash validateGovActionAnchorData anchor + maybe + (return ()) + (checkAnchorMetadataHash validateGovActionAnchorData) + (getAnchorDataFromGovernanceAction govAction) -- Only the `NewConstitution` governance action contains a checkable hash with a corresponding URL. diff --git a/cardano-cli/src/Cardano/CLI/Run/Hash.hs b/cardano-cli/src/Cardano/CLI/Run/Hash.hs index deff090ded..4465d83103 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Hash.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Hash.hs @@ -10,6 +10,7 @@ module Cardano.CLI.Run.Hash ( runHashCmds , getByteStringFromURL , carryHashChecks + , carryHashChecksWithoutValidating , allSchemes , httpsAndIpfsSchemes ) @@ -196,20 +197,29 @@ runHashScriptCmd Cmd.HashScriptCmdArgs{Cmd.toHash = File toHash, mOutFile} = do . serialiseToRawBytesHexText $ hashScript script +-- | Same as 'carryHashChecksWithoutValidating' but without using a custom validation function. +carryHashChecksWithoutValidating + :: PotentiallyCheckedAnchor anchorType (L.Anchor L.StandardCrypto) + -> ExceptT HashCheckError IO () +carryHashChecksWithoutValidating = carryHashChecks (const $ Right ()) + -- | Check the hash of the anchor data against the hash in the anchor if -- checkHash is set to CheckHash. carryHashChecks - :: PotentiallyCheckedAnchor anchorType (L.Anchor L.StandardCrypto) + :: (BS8.ByteString -> Either String ()) + -- ^ A function to validate the anchor data + -> PotentiallyCheckedAnchor anchorType (L.Anchor L.StandardCrypto) -- ^ The information about anchor data and whether to check the hash (see 'PotentiallyCheckedAnchor') -> ExceptT HashCheckError IO () -carryHashChecks potentiallyCheckedAnchor = +carryHashChecks validateAnchorData potentiallyCheckedAnchor = case pcaMustCheck potentiallyCheckedAnchor of CheckHash -> do - anchorData <- - L.AnchorData - <$> withExceptT - FetchURLError - (getByteStringFromURL httpsAndIpfsSchemes $ L.urlToText $ L.anchorUrl anchor) + anchorBS <- + withExceptT + FetchURLError + (getByteStringFromURL httpsAndIpfsSchemes $ L.urlToText $ L.anchorUrl anchor) + withExceptT ValidationError $ liftEither $ validateAnchorData anchorBS + let anchorData = L.AnchorData anchorBS let hash = L.hashAnchorData anchorData when (hash /= L.anchorDataHash anchor) $ left $ diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs index e896961c97..6ae5bafa98 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs @@ -84,6 +84,7 @@ data HashCheckError (L.SafeHash L.StandardCrypto L.AnchorData) -- ^ The actual DRep metadata hash. | FetchURLError FetchURLError + | ValidationError String deriving Show instance Exception HashCheckError where @@ -95,3 +96,4 @@ instance Exception HashCheckError where <> "\n Actual: " <> show (L.extractHash actualHash) displayException (FetchURLError fetchErr) = displayException fetchErr + displayException (ValidationError err) = "Validation error: " <> err From 4a42749b26763fa377aaea79aa04653997ef1f38 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 19 Dec 2024 17:28:49 +0100 Subject: [PATCH 4/9] Fix DRep tests --- .gitattributes | 2 + .../input/example_drep_reg_anchor_data.json | 58 +++++++++++++++++++ .../Test/Cardano/CLI/Hash.hs | 18 ++++-- .../Test/Cli/Governance/DRep.hs | 24 ++++---- .../input/example_drep_reg_anchor_data.json | 58 +++++++++++++++++++ 5 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json create mode 100644 cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json diff --git a/.gitattributes b/.gitattributes index 891dbb3826..92ae0b4c2c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,9 @@ cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data.txt -text cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data2.txt -text +cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json -text cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt -text cardano-cli/test/cardano-cli-test/files/input/example_anchor_data2.txt -text +cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.alonzo.spec.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.byron.spec.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.conway.spec.json -text diff --git a/cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json b/cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json new file mode 100644 index 0000000000..c1b312d419 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json @@ -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" + } + } + }, + "hashAlgorithm": "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_" + } + ] + } +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs index e42a2ae89d..dd1b2d90e5 100644 --- a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs +++ b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs @@ -11,6 +11,10 @@ module Test.Cardano.CLI.Hash , exampleAnchorDataIpfsHash , exampleAnchorDataIpfsHash2 , tamperBase16Hash + , exampleDRepRegAnchorHash + , exampleDRepRegAnchorIpfsHash + , exampleDRepRegAnchorPathTest + , exampleDRepRegAnchorPathGolden ) where @@ -37,21 +41,25 @@ import Network.Wai.Handler.Warp (defaultSettings, openFreePort, runSet import Hedgehog as H import Hedgehog.Internal.Source (HasCallStack) -exampleAnchorDataHash, exampleAnchorDataHash2 :: String +exampleAnchorDataHash, exampleAnchorDataHash2, exampleDRepRegAnchorHash :: String exampleAnchorDataHash = "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" exampleAnchorDataHash2 = "8b4fda934272320ec8d11ba5a7904ab74686a8ec97f2c1331b68d11e28bda26f" +exampleDRepRegAnchorHash = "15a1c724bfbb8c0a0e84e2e359525017aefb8914ecc219bb9ad469368f14975d" -exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2 :: String +exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2, exampleDRepRegAnchorPathGolden :: String exampleAnchorDataPathGolden = "test/cardano-cli-golden/files/input/example_anchor_data.txt" exampleAnchorDataPathGolden2 = "test/cardano-cli-golden/files/input/example_anchor_data2.txt" +exampleDRepRegAnchorPathGolden = "test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json" -exampleAnchorDataPathTest, exampleAnchorDataPathTest2 :: String +exampleAnchorDataPathTest, exampleAnchorDataPathTest2, exampleDRepRegAnchorPathTest :: String exampleAnchorDataPathTest = "test/cardano-cli-test/files/input/example_anchor_data.txt" -exampleAnchorDataPathTest2 = "test/cardano-cli-golden/files/input/example_anchor_data2.txt" +exampleAnchorDataPathTest2 = "test/cardano-cli-test/files/input/example_anchor_data2.txt" +exampleDRepRegAnchorPathTest = "test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json" -exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2 :: String +exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2, exampleDRepRegAnchorIpfsHash :: String exampleAnchorDataIpfsHash = "QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" exampleAnchorDataIpfsHash2 = "QmdTJ4PabgSabg8K1Z4MNXnSVM8bjJnAikC3rVWfPVExQj" +exampleDRepRegAnchorIpfsHash = "Qmb6vATFuc2o9zeFEseTvKZiqGRvuYoZRT5SNZN6L88Les" -- | Tamper with the base16 hash by adding one to the first character tamperBase16Hash :: String -> Maybe String diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs index c0e2cde7d7..f5f6f354df 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs @@ -9,8 +9,8 @@ import Control.Monad import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (exampleDRepRegAnchorHash, exampleDRepRegAnchorIpfsHash, + exampleDRepRegAnchorPathTest, serveFilesWhile, tamperBase16Hash) import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, propertyOnce) @@ -96,7 +96,7 @@ hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleDRepRegAnchorHash -- We run the test with the altered base_golden_governance_drep_registration_certificate_vkey_file alteredHash @@ -105,7 +105,7 @@ hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails hprop_golden_governance_drep_registration_certificate_vkey_file :: Property hprop_golden_governance_drep_registration_certificate_vkey_file = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governance_drep_registration_certificate_vkey_file exampleAnchorDataHash tempDir + base_golden_governance_drep_registration_certificate_vkey_file exampleDRepRegAnchorHash tempDir base_golden_governance_drep_registration_certificate_vkey_file :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -127,12 +127,12 @@ base_golden_governance_drep_registration_certificate_vkey_file hash tempDir = do outFile <- H.noteTempFile tempDir "drep-reg-cert.txt" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleDRepRegAnchorIpfsHash] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, exampleDRepRegAnchorPathTest)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -146,7 +146,7 @@ base_golden_governance_drep_registration_certificate_vkey_file hash tempDir = do , "--key-reg-deposit-amt" , "0" , "--drep-metadata-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleDRepRegAnchorIpfsHash , "--drep-metadata-hash" , hash , "--check-drep-metadata-hash" @@ -159,7 +159,7 @@ hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails :: Pr hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleDRepRegAnchorHash -- We run the test with the modified hash base_golden_governance_drep_update_certificate_vkey_file alteredHash @@ -168,7 +168,7 @@ hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails = hprop_golden_governance_drep_update_certificate_vkey_file :: Property hprop_golden_governance_drep_update_certificate_vkey_file = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governance_drep_update_certificate_vkey_file exampleAnchorDataHash tempDir + base_golden_governance_drep_update_certificate_vkey_file exampleDRepRegAnchorHash tempDir base_golden_governance_drep_update_certificate_vkey_file :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -190,12 +190,12 @@ base_golden_governance_drep_update_certificate_vkey_file hash tempDir = do outFile <- H.noteTempFile tempDir "drep-upd-cert.txt" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleDRepRegAnchorIpfsHash] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, exampleDRepRegAnchorPathTest)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -207,7 +207,7 @@ base_golden_governance_drep_update_certificate_vkey_file hash tempDir = do , "--drep-verification-key-file" , drepVKeyFile , "--drep-metadata-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleDRepRegAnchorIpfsHash , "--drep-metadata-hash" , hash , "--check-drep-metadata-hash" diff --git a/cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json b/cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json new file mode 100644 index 0000000000..c1b312d419 --- /dev/null +++ b/cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json @@ -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" + } + } + }, + "hashAlgorithm": "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_" + } + ] + } +} \ No newline at end of file From 9493a3f94a34ad5e431412c2e236dbce2175ae7f Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 19 Dec 2024 18:40:55 +0100 Subject: [PATCH 5/9] Fix Vote tests --- .gitattributes | 4 + .../input/example_gov_action_anchor1.json | 76 +++++++++++++++++++ .../input/example_gov_action_anchor2.json | 73 ++++++++++++++++++ .../Test/Cardano/CLI/Hash.hs | 49 +++++++++++- .../Test/Cli/Governance/Vote.hs | 15 ++-- .../input/example_gov_action_anchor1.json | 76 +++++++++++++++++++ .../input/example_gov_action_anchor2.json | 73 ++++++++++++++++++ 7 files changed, 355 insertions(+), 11 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json create mode 100644 cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json create mode 100644 cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor2.json diff --git a/.gitattributes b/.gitattributes index 92ae0b4c2c..cc4488494f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,13 @@ cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data.txt -text cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data2.txt -text cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json -text +cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json -text +cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json -text cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt -text cardano-cli/test/cardano-cli-test/files/input/example_anchor_data2.txt -text cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json -text +cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json -text +cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor2.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.alonzo.spec.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.byron.spec.json -text cardano-cli/test/cardano-cli-test/files/input/check-node-configuration/genesis.conway.spec.json -text diff --git a/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json b/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json new file mode 100644 index 0000000000..46c70f22a2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json @@ -0,0 +1,76 @@ +{ + "@context": { + "@language": "en-us", + "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", + "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", + "hashAlgorithm": "CIP100:hashAlgorithm", + "body": { + "@id": "CIP108:body", + "@context": { + "references": { + "@id": "CIP108:references", + "@container": "@set", + "@context": { + "GovernanceMetadata": "CIP100:GovernanceMetadataReference", + "Other": "CIP100:OtherReference", + "label": "CIP100:reference-label", + "uri": "CIP100:reference-uri", + "referenceHash": { + "@id": "CIP108:referenceHash", + "@context": { + "hashDigest": "CIP108:hashDigest", + "hashAlgorithm": "CIP100:hashAlgorithm" + } + } + } + }, + "title": "CIP108:title", + "abstract": "CIP108:abstract", + "motivation": "CIP108:motivation", + "rationale": "CIP108:rationale" + } + }, + "authors": { + "@id": "CIP100:authors", + "@container": "@set", + "@context": { + "name": "http://xmlns.com/foaf/0.1/name", + "witness": { + "@id": "CIP100:witness", + "@context": { + "witnessAlgorithm": "CIP100:witnessAlgorithm", + "publicKey": "CIP100:publicKey", + "signature": "CIP100:signature" + } + } + } + } + }, + "hashAlgorithm": "blake2b-256", + "body": { + "title": "We must remove the ineffective Constitutional Committee", + "abstract": "The current constitutional committee have not voted for the last 100 epochs, causing an inability to pass any proposals. This is a waste of resources and must be removed.", + "motivation": "In order for governance to work an __active__ constitutional committee is required, without them the system grinds to a halt and important governance actions cannot be passed.", + "rationale": "By moving into a state of no confidence, **we** the DReps are able to vote in a new constitutional committee.", + "references": [ + { + "@type": "Other", + "label": "A governance action that has been unable to pass", + "uri": "https://raw.githubusercontent.com/cardano-foundation/CIPs/blob/master/CIP-0108/examples/treasury-withdrawal.jsonld", + "referenceHash": { + "hashDigest": "70e79c1f12ff3c8c955bc2178a542b5994a21be163dd7655af2c5308d2643323", + "hashAlgorithm": "blake2b-256" + } + } + ] + }, + "authors": [ + { + "witness": { + "witnessAlgorithm": "CIP-0008", + "publicKey": "7ea09a34aebb13c9841c71397b1cabfec5ddf950405293dee496cac2f437480a", + "signature": "84582aa201276761646472657373581d610fdc780023d8be7c9ff3a6bdc0d8d3b263bd0cc12448c40948efbf42a166686173686564f458204a7ecc544559df67ece3f7f90f76c4e3e7e329a274c79a06dcfbf28351db600e5840a5dc881ddabdec69e0e4dabdd43a922ef474f7be1029facdbb9106429e17ec61deda22f2778eda21005127f0c6d10f8a4b0210b8177d03d2ae4618d2423d0807" + } + } + ] +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json b/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json new file mode 100644 index 0000000000..fc6515b338 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json @@ -0,0 +1,73 @@ +{ + "@context": { + "@language": "en-us", + "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", + "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", + "hashAlgorithm": "CIP100:hashAlgorithm", + "body": { + "@id": "CIP108:body", + "@context": { + "references": { + "@id": "CIP108:references", + "@container": "@set", + "@context": { + "GovernanceMetadata": "CIP100:GovernanceMetadataReference", + "Other": "CIP100:OtherReference", + "label": "CIP100:reference-label", + "uri": "CIP100:reference-uri", + "referenceHash": { + "@id": "CIP108:referenceHash", + "@context": { + "hashDigest": "CIP108:hashDigest", + "hashAlgorithm": "CIP100:hashAlgorithm" + } + } + } + }, + "title": "CIP108:title", + "abstract": "CIP108:abstract", + "motivation": "CIP108:motivation", + "rationale": "CIP108:rationale" + } + }, + "authors": { + "@id": "CIP100:authors", + "@container": "@set", + "@context": { + "name": "http://xmlns.com/foaf/0.1/name", + "witness": { + "@id": "CIP100:witness", + "@context": { + "witnessAlgorithm": "CIP100:witnessAlgorithm", + "publicKey": "CIP100:publicKey", + "signature": "CIP100:signature" + } + } + } + } + }, + "hashAlgorithm": "blake2b-256", + "body": { + "title": "Buy Ryan a island", + "abstract": "Withdraw 200000000000 ADA from the treasury so Ryan can buy an island.", + "motivation": "The current problem is that Ryan does not have an island, but he would really like an island.", + "rationale": "With these funds from the treasury will be sold for **cold hard cash**, this cash can then be used to purchase an island for Ryan. An example of this island is provided in the references.", + "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" + } + ] + }, + "authors": [ + { + "name": "Ryan Williams", + "witness": { + "witnessAlgorithm": "ed25519", + "publicKey": "7ea09a34aebb13c9841c71397b1cabfec5ddf950405293dee496cac2f437480a", + "signature": "a476985b4cc0d457f247797611799a6f6a80fc8cb7ec9dcb5a8223888d0618e30de165f3d869c4a0d9107d8a5b612ad7c5e42441907f5b91796f0d7187d64a01" + } + } + ] +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs index dd1b2d90e5..3661fd42fe 100644 --- a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs +++ b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs @@ -15,6 +15,14 @@ module Test.Cardano.CLI.Hash , exampleDRepRegAnchorIpfsHash , exampleDRepRegAnchorPathTest , exampleDRepRegAnchorPathGolden + , exampleGovActionAnchorHash1 + , exampleGovActionAnchorHash2 + , exampleGovActionAnchorPathGolden1 + , exampleGovActionAnchorPathGolden2 + , exampleGovActionAnchorPathTest1 + , exampleGovActionAnchorPathTest2 + , exampleGovActionAnchorIpfsHash1 + , exampleGovActionAnchorIpfsHash2 ) where @@ -41,25 +49,58 @@ import Network.Wai.Handler.Warp (defaultSettings, openFreePort, runSet import Hedgehog as H import Hedgehog.Internal.Source (HasCallStack) -exampleAnchorDataHash, exampleAnchorDataHash2, exampleDRepRegAnchorHash :: String +-- ** Anchor hashes for the example files + +exampleAnchorDataHash, exampleAnchorDataHash2 :: String exampleAnchorDataHash = "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" exampleAnchorDataHash2 = "8b4fda934272320ec8d11ba5a7904ab74686a8ec97f2c1331b68d11e28bda26f" + +exampleDRepRegAnchorHash, exampleGovActionAnchorHash1, exampleGovActionAnchorHash2 :: String exampleDRepRegAnchorHash = "15a1c724bfbb8c0a0e84e2e359525017aefb8914ecc219bb9ad469368f14975d" +exampleGovActionAnchorHash1 = "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" +exampleGovActionAnchorHash2 = "21dd5a8219936e0d756f44f7f1a7179806b5afa45b6cbfb9e7d7efe3123c8e51" -exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2, exampleDRepRegAnchorPathGolden :: String +-- ** Paths to the example files for golden tests + +exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2 :: String exampleAnchorDataPathGolden = "test/cardano-cli-golden/files/input/example_anchor_data.txt" exampleAnchorDataPathGolden2 = "test/cardano-cli-golden/files/input/example_anchor_data2.txt" + +exampleDRepRegAnchorPathGolden + , exampleGovActionAnchorPathGolden1 + , exampleGovActionAnchorPathGolden2 + :: String exampleDRepRegAnchorPathGolden = "test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json" +exampleGovActionAnchorPathGolden1 = "test/cardano-cli-golden/files/input/example_gov_action_anchor1.json" +exampleGovActionAnchorPathGolden2 = "test/cardano-cli-golden/files/input/example_gov_action_anchor2.json" -exampleAnchorDataPathTest, exampleAnchorDataPathTest2, exampleDRepRegAnchorPathTest :: String +-- ** Paths to the example files for normal testes + +exampleAnchorDataPathTest, exampleAnchorDataPathTest2 :: String exampleAnchorDataPathTest = "test/cardano-cli-test/files/input/example_anchor_data.txt" exampleAnchorDataPathTest2 = "test/cardano-cli-test/files/input/example_anchor_data2.txt" + +exampleDRepRegAnchorPathTest + , exampleGovActionAnchorPathTest1 + , exampleGovActionAnchorPathTest2 + :: String exampleDRepRegAnchorPathTest = "test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json" +exampleGovActionAnchorPathTest1 = "test/cardano-cli-test/files/input/example_gov_action_anchor1.json" +exampleGovActionAnchorPathTest2 = "test/cardano-cli-test/files/input/example_gov_action_anchor2.json" -exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2, exampleDRepRegAnchorIpfsHash :: String +-- ** Ipfs hashes for the example files + +exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2 :: String exampleAnchorDataIpfsHash = "QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" exampleAnchorDataIpfsHash2 = "QmdTJ4PabgSabg8K1Z4MNXnSVM8bjJnAikC3rVWfPVExQj" + +exampleDRepRegAnchorIpfsHash + , exampleGovActionAnchorIpfsHash1 + , exampleGovActionAnchorIpfsHash2 + :: String exampleDRepRegAnchorIpfsHash = "Qmb6vATFuc2o9zeFEseTvKZiqGRvuYoZRT5SNZN6L88Les" +exampleGovActionAnchorIpfsHash1 = "QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA" +exampleGovActionAnchorIpfsHash2 = "QmfCgYdiMSTTJ4Uw93vqwDw2DL2xfr7QrNeRnsxZqaCcLx" -- | Tamper with the base16 hash by adding one to the first character tamperBase16Hash :: String -> Maybe String diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs index 4ec5934308..0c58302bd3 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs @@ -8,8 +8,9 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, + exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorPathTest1, + serveFilesWhile, tamperBase16Hash) import Test.Cardano.CLI.Util (execCardanoCLIWithEnvVars, expectFailure, noteInputFile, propertyOnce) @@ -23,7 +24,7 @@ hprop_governance_vote_create_wrong_hash_fails :: Property hprop_governance_vote_create_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the altered baseGovernanceVoteCreateHashCheck alteredHash @@ -34,7 +35,7 @@ hprop_governance_vote_create_wrong_hash_fails = hprop_governance_vote_create_right_hash_works :: Property hprop_governance_vote_create_right_hash_works = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - baseGovernanceVoteCreateHashCheck exampleAnchorDataHash tempDir + baseGovernanceVoteCreateHashCheck exampleGovActionAnchorHash1 tempDir baseGovernanceVoteCreateHashCheck :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -42,12 +43,12 @@ baseGovernanceVoteCreateHashCheck hash tempDir = do vkeyFile <- noteInputFile "test/cardano-cli-test/files/input/drep.vkey" voteFile <- H.noteTempFile tempDir "vote" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, exampleGovActionAnchorPathTest1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -66,7 +67,7 @@ baseGovernanceVoteCreateHashCheck hash tempDir = do , "--out-file" , voteFile , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data-hash" diff --git a/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json b/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json new file mode 100644 index 0000000000..46c70f22a2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json @@ -0,0 +1,76 @@ +{ + "@context": { + "@language": "en-us", + "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", + "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", + "hashAlgorithm": "CIP100:hashAlgorithm", + "body": { + "@id": "CIP108:body", + "@context": { + "references": { + "@id": "CIP108:references", + "@container": "@set", + "@context": { + "GovernanceMetadata": "CIP100:GovernanceMetadataReference", + "Other": "CIP100:OtherReference", + "label": "CIP100:reference-label", + "uri": "CIP100:reference-uri", + "referenceHash": { + "@id": "CIP108:referenceHash", + "@context": { + "hashDigest": "CIP108:hashDigest", + "hashAlgorithm": "CIP100:hashAlgorithm" + } + } + } + }, + "title": "CIP108:title", + "abstract": "CIP108:abstract", + "motivation": "CIP108:motivation", + "rationale": "CIP108:rationale" + } + }, + "authors": { + "@id": "CIP100:authors", + "@container": "@set", + "@context": { + "name": "http://xmlns.com/foaf/0.1/name", + "witness": { + "@id": "CIP100:witness", + "@context": { + "witnessAlgorithm": "CIP100:witnessAlgorithm", + "publicKey": "CIP100:publicKey", + "signature": "CIP100:signature" + } + } + } + } + }, + "hashAlgorithm": "blake2b-256", + "body": { + "title": "We must remove the ineffective Constitutional Committee", + "abstract": "The current constitutional committee have not voted for the last 100 epochs, causing an inability to pass any proposals. This is a waste of resources and must be removed.", + "motivation": "In order for governance to work an __active__ constitutional committee is required, without them the system grinds to a halt and important governance actions cannot be passed.", + "rationale": "By moving into a state of no confidence, **we** the DReps are able to vote in a new constitutional committee.", + "references": [ + { + "@type": "Other", + "label": "A governance action that has been unable to pass", + "uri": "https://raw.githubusercontent.com/cardano-foundation/CIPs/blob/master/CIP-0108/examples/treasury-withdrawal.jsonld", + "referenceHash": { + "hashDigest": "70e79c1f12ff3c8c955bc2178a542b5994a21be163dd7655af2c5308d2643323", + "hashAlgorithm": "blake2b-256" + } + } + ] + }, + "authors": [ + { + "witness": { + "witnessAlgorithm": "CIP-0008", + "publicKey": "7ea09a34aebb13c9841c71397b1cabfec5ddf950405293dee496cac2f437480a", + "signature": "84582aa201276761646472657373581d610fdc780023d8be7c9ff3a6bdc0d8d3b263bd0cc12448c40948efbf42a166686173686564f458204a7ecc544559df67ece3f7f90f76c4e3e7e329a274c79a06dcfbf28351db600e5840a5dc881ddabdec69e0e4dabdd43a922ef474f7be1029facdbb9106429e17ec61deda22f2778eda21005127f0c6d10f8a4b0210b8177d03d2ae4618d2423d0807" + } + } + ] +} \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor2.json b/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor2.json new file mode 100644 index 0000000000..fc6515b338 --- /dev/null +++ b/cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor2.json @@ -0,0 +1,73 @@ +{ + "@context": { + "@language": "en-us", + "CIP100": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#", + "CIP108": "https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#", + "hashAlgorithm": "CIP100:hashAlgorithm", + "body": { + "@id": "CIP108:body", + "@context": { + "references": { + "@id": "CIP108:references", + "@container": "@set", + "@context": { + "GovernanceMetadata": "CIP100:GovernanceMetadataReference", + "Other": "CIP100:OtherReference", + "label": "CIP100:reference-label", + "uri": "CIP100:reference-uri", + "referenceHash": { + "@id": "CIP108:referenceHash", + "@context": { + "hashDigest": "CIP108:hashDigest", + "hashAlgorithm": "CIP100:hashAlgorithm" + } + } + } + }, + "title": "CIP108:title", + "abstract": "CIP108:abstract", + "motivation": "CIP108:motivation", + "rationale": "CIP108:rationale" + } + }, + "authors": { + "@id": "CIP100:authors", + "@container": "@set", + "@context": { + "name": "http://xmlns.com/foaf/0.1/name", + "witness": { + "@id": "CIP100:witness", + "@context": { + "witnessAlgorithm": "CIP100:witnessAlgorithm", + "publicKey": "CIP100:publicKey", + "signature": "CIP100:signature" + } + } + } + } + }, + "hashAlgorithm": "blake2b-256", + "body": { + "title": "Buy Ryan a island", + "abstract": "Withdraw 200000000000 ADA from the treasury so Ryan can buy an island.", + "motivation": "The current problem is that Ryan does not have an island, but he would really like an island.", + "rationale": "With these funds from the treasury will be sold for **cold hard cash**, this cash can then be used to purchase an island for Ryan. An example of this island is provided in the references.", + "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" + } + ] + }, + "authors": [ + { + "name": "Ryan Williams", + "witness": { + "witnessAlgorithm": "ed25519", + "publicKey": "7ea09a34aebb13c9841c71397b1cabfec5ddf950405293dee496cac2f437480a", + "signature": "a476985b4cc0d457f247797611799a6f6a80fc8cb7ec9dcb5a8223888d0618e30de165f3d869c4a0d9107d8a5b612ad7c5e42441907f5b91796f0d7187d64a01" + } + } + ] +} \ No newline at end of file From 5d29072c16907471d156f75cd19e58e7471e83fa Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 19 Dec 2024 19:06:21 +0100 Subject: [PATCH 6/9] Fix `Governance.Action` tests --- .../Test/Golden/Governance/Action.hs | 86 ++++++++++--------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs index 5a80d97aa8..3147a550c9 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs @@ -10,10 +10,10 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataHash2, - exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2, - exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2, serveFilesWhile, - tamperBase16Hash) +import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, exampleGovActionAnchorHash2, + exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorIpfsHash2, + exampleGovActionAnchorPathGolden1, exampleGovActionAnchorPathGolden2, + serveFilesWhile, tamperBase16Hash) import qualified Test.Cardano.CLI.Util as H import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, noteInputFile, noteTempFile, propertyOnce) @@ -27,21 +27,21 @@ hprop_golden_governance_action_create_constitution_wrong_hash1_fails :: Property hprop_golden_governance_action_create_constitution_wrong_hash1_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_governance_action_create_constitution alteredHash - exampleAnchorDataHash2 + exampleGovActionAnchorHash2 tempDir hprop_golden_governance_action_create_constitution_wrong_hash2_fails :: Property hprop_golden_governance_action_create_constitution_wrong_hash2_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash2 + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash2 -- We run the test with the modified hash base_golden_governance_action_create_constitution - exampleAnchorDataHash + exampleGovActionAnchorHash1 alteredHash tempDir @@ -49,8 +49,8 @@ hprop_golden_governance_action_create_constitution :: Property hprop_golden_governance_action_create_constitution = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> base_golden_governance_action_create_constitution - exampleAnchorDataHash - exampleAnchorDataHash2 + exampleGovActionAnchorHash1 + exampleGovActionAnchorHash2 tempDir base_golden_governance_action_create_constitution @@ -77,14 +77,14 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do actionFile <- noteTempFile tempDir "create-constitution.action" redactedActionFile <- noteTempFile tempDir "create-constitution.action.redacted" - let relativeUrl1 = ["ipfs", exampleAnchorDataIpfsHash] - let relativeUrl2 = ["ipfs", exampleAnchorDataIpfsHash2] + let relativeUrl1 = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl2 = ["ipfs", exampleGovActionAnchorIpfsHash2] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [ (relativeUrl1, exampleAnchorDataPathGolden) - , (relativeUrl2, exampleAnchorDataPathGolden2) + [ (relativeUrl1, exampleGovActionAnchorPathGolden1) + , (relativeUrl2, exampleGovActionAnchorPathGolden2) ] ( \port -> do void $ @@ -98,7 +98,7 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do , "--anchor-data-hash" , hash1 , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--check-anchor-data" , "--governance-action-deposit" , "10" @@ -107,7 +107,7 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do , "--out-file" , actionFile , "--constitution-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash2 + , "ipfs://" ++ exampleGovActionAnchorIpfsHash2 , "--constitution-hash" , hash2 , "--check-constitution-hash" @@ -192,7 +192,7 @@ hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fail hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_conway_governance_action_view_update_committee_yaml alteredHash @@ -201,7 +201,7 @@ hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fail hprop_golden_conway_governance_action_view_update_committee_yaml :: Property hprop_golden_conway_governance_action_view_update_committee_yaml = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_view_update_committee_yaml exampleAnchorDataHash tempDir + base_golden_conway_governance_action_view_update_committee_yaml exampleGovActionAnchorHash1 tempDir base_golden_conway_governance_action_view_update_committee_yaml :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -210,12 +210,12 @@ base_golden_conway_governance_action_view_update_committee_yaml hash tempDir = d actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathGolden)] + [(relativeUrl, exampleGovActionAnchorPathGolden1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -230,7 +230,7 @@ base_golden_conway_governance_action_view_update_committee_yaml hash tempDir = d , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data" @@ -259,7 +259,7 @@ hprop_golden_conway_governance_action_view_create_info_json_outfile_wrong_hash_f hprop_golden_conway_governance_action_view_create_info_json_outfile_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_conway_governance_action_view_create_info_json_outfile alteredHash @@ -268,7 +268,9 @@ hprop_golden_conway_governance_action_view_create_info_json_outfile_wrong_hash_f hprop_golden_conway_governance_action_view_create_info_json_outfile :: Property hprop_golden_conway_governance_action_view_create_info_json_outfile = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_view_create_info_json_outfile exampleAnchorDataHash tempDir + base_golden_conway_governance_action_view_create_info_json_outfile + exampleGovActionAnchorHash1 + tempDir base_golden_conway_governance_action_view_create_info_json_outfile :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -277,12 +279,12 @@ base_golden_conway_governance_action_view_create_info_json_outfile hash tempDir actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathGolden)] + [(relativeUrl, exampleGovActionAnchorPathGolden1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -297,7 +299,7 @@ base_golden_conway_governance_action_view_create_info_json_outfile hash tempDir , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data" @@ -326,7 +328,7 @@ hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails :: Property hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_governanceActionCreateNoConfidence alteredHash @@ -335,7 +337,7 @@ hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails = hprop_golden_governanceActionCreateNoConfidence :: Property hprop_golden_governanceActionCreateNoConfidence = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governanceActionCreateNoConfidence exampleAnchorDataHash tempDir + base_golden_governanceActionCreateNoConfidence exampleGovActionAnchorHash1 tempDir base_golden_governanceActionCreateNoConfidence :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -345,12 +347,12 @@ base_golden_governanceActionCreateNoConfidence hash tempDir = do actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathGolden)] + [(relativeUrl, exampleGovActionAnchorPathGolden1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -365,7 +367,7 @@ base_golden_governanceActionCreateNoConfidence hash tempDir = do , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data" @@ -399,7 +401,7 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update_wrong_ha hprop_golden_conway_governance_action_create_protocol_parameters_update_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_conway_governance_action_create_protocol_parameters_update alteredHash @@ -408,7 +410,9 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update_wrong_ha hprop_golden_conway_governance_action_create_protocol_parameters_update :: Property hprop_golden_conway_governance_action_create_protocol_parameters_update = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_create_protocol_parameters_update exampleAnchorDataHash tempDir + base_golden_conway_governance_action_create_protocol_parameters_update + exampleGovActionAnchorHash1 + tempDir base_golden_conway_governance_action_create_protocol_parameters_update :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -420,12 +424,12 @@ base_golden_conway_governance_action_create_protocol_parameters_update hash temp actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathGolden)] + [(relativeUrl, exampleGovActionAnchorPathGolden1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -435,7 +439,7 @@ base_golden_conway_governance_action_create_protocol_parameters_update hash temp , "action" , "create-protocol-parameters-update" , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data" @@ -499,7 +503,7 @@ hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails :: Proper hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 -- We run the test with the modified hash base_golden_conway_governance_action_create_hardfork alteredHash @@ -508,7 +512,7 @@ hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails = hprop_golden_conway_governance_action_create_hardfork :: Property hprop_golden_conway_governance_action_create_hardfork = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_create_hardfork exampleAnchorDataHash tempDir + base_golden_conway_governance_action_create_hardfork exampleGovActionAnchorHash1 tempDir base_golden_conway_governance_action_create_hardfork :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () @@ -517,12 +521,12 @@ base_golden_conway_governance_action_create_hardfork hash tempDir = do actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathGolden)] + [(relativeUrl, exampleGovActionAnchorPathGolden1)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -532,7 +536,7 @@ base_golden_conway_governance_action_create_hardfork hash tempDir = do , "action" , "create-hardfork" , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , hash , "--check-anchor-data" From 631a21724f13ac4ee3117e27da93dbd15eaefdac Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 19 Dec 2024 19:10:01 +0100 Subject: [PATCH 7/9] Fix Vote golden tests --- .../Test/Golden/Governance/Vote.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs index e4120e9cfc..6eae4e120b 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs @@ -7,8 +7,9 @@ import Data.Monoid (Last (..)) import GHC.IO.Exception (ExitCode (..)) import qualified System.Environment as IO -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathGolden, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, + exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorPathGolden1, + serveFilesWhile, tamperBase16Hash) import Test.Cardano.CLI.Util (FileSem, bracketSem, execCardanoCLI, execDetailConfigCardanoCLI, newFileSem, noteInputFile, propertyOnce) @@ -192,8 +193,8 @@ hprop_golden_governance_vote_create_hash_fails :: Property hprop_golden_governance_vote_create_hash_fails = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] vkeyFile <- noteInputFile "test/cardano-cli-golden/files/input/drep.vkey" voteFile <- H.noteTempFile tempDir "vote" @@ -204,7 +205,7 @@ hprop_golden_governance_vote_create_hash_fails = env <- H.evalIO IO.getEnvironment (exitCode, _, result) <- serveFilesWhile - [ (relativeUrl, exampleAnchorDataPathGolden) + [ (relativeUrl, exampleGovActionAnchorPathGolden1) ] ( \port -> do execDetailConfigCardanoCLI @@ -226,7 +227,7 @@ hprop_golden_governance_vote_create_hash_fails = , "--out-file" , voteFile , "--anchor-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 , "--anchor-data-hash" , alteredHash , "--check-anchor-data-hash" From f779fe71188ad29591612846db38eb865ff9a773 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 19 Dec 2024 19:11:38 +0100 Subject: [PATCH 8/9] Recreate golden files --- .../action/conway-create-protocol-parameters-update.action | 2 +- .../governance/action/hardfork/conway-create-hardfork.action | 2 +- .../golden/governance/action/view/create-info.action.view | 4 ++-- .../governance/action/view/create-no-confidence.action.view | 4 ++-- .../governance/action/view/update-committee.action.view | 4 ++-- .../governance/vote/governance_vote_create_hash_fails.out | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update.action b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update.action index 99d344af9c..6a6919933c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update.action +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update.action @@ -1,5 +1,5 @@ { "type": "Governance proposal", "description": "Update protocol parameters proposal", - "cborHex": "84193039581de18f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058400f6a3031904d212a3009f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f707001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff019f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a009063b91903fd0a1a02515e841980b30a01010101010101010101ff029f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ff181e1a075bc371f6827835697066733a2f2f516d624c354542464a4c66384464506b5741736b47334575696e39744859386e617151324a446f486e574848584a5820de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" + "cborHex": "84193039581de18f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058400f6a3031904d212a3009f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f707001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff019f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a009063b91903fd0a1a02515e841980b30a01010101010101010101ff029f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ff181e1a075bc371f6827835697066733a2f2f516d6447483851613166356d4a4a78626a5975485571767771437155516d3636793745564e46454d677a5a4a65415820d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" } diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/hardfork/conway-create-hardfork.action b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/hardfork/conway-create-hardfork.action index 03730c6941..92eded75ce 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/hardfork/conway-create-hardfork.action +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/hardfork/conway-create-hardfork.action @@ -1,5 +1,5 @@ { "type": "Governance proposal", "description": "Hardfork initiation proposal", - "cborHex": "84193039581de18f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058301f6820a00827835697066733a2f2f516d624c354542464a4c66384464506b5741736b47334575696e39744859386e617151324a446f486e574848584a5820de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" + "cborHex": "84193039581de18f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058301f6820a00827835697066733a2f2f516d6447483851613166356d4a4a78626a5975485571767771437155516d3636793745564e46454d677a5a4a65415820d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" } diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view index 70fa003dba..cb9d94e482 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-info.action.view @@ -1,7 +1,7 @@ { "anchor": { - "dataHash": "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c", - "url": "ipfs://QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" + "dataHash": "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0", + "url": "ipfs://QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA" }, "deposit": 10, "governance action": { diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-no-confidence.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-no-confidence.action.view index aa61f9f484..a0f6777d3a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-no-confidence.action.view +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/create-no-confidence.action.view @@ -1,7 +1,7 @@ { "anchor": { - "dataHash": "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c", - "url": "ipfs://QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" + "dataHash": "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0", + "url": "ipfs://QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA" }, "deposit": 10, "governance action": { diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view index f83af62700..09f33d995b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/view/update-committee.action.view @@ -1,6 +1,6 @@ anchor: - dataHash: de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c - url: ipfs://QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ + dataHash: d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0 + url: ipfs://QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA deposit: 10 governance action: contents: diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/vote/governance_vote_create_hash_fails.out b/cardano-cli/test/cardano-cli-golden/files/golden/governance/vote/governance_vote_create_hash_fails.out index c8ce1e8809..f580ad71e6 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/vote/governance_vote_create_hash_fails.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/vote/governance_vote_create_hash_fails.out @@ -1,3 +1,3 @@ Command failed: governance vote create Error: Error while checking resignation certificate metadata hash: Hashes do not match! -Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" - Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" +Expected: "e0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" + Actual: "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" From 18fc533d9a035656fe6ea82e41b28cbbf40cb2d7 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Fri, 20 Dec 2024 15:45:54 +0100 Subject: [PATCH 9/9] Organise examples by grouping them in a datatype (refactoring) --- .gitattributes | 4 +- .../Test/Golden/Governance/Action.hs | 125 +++++++------- .../Test/Golden/Governance/Committee.hs | 14 +- .../Test/Golden/Governance/DRep.hs | 14 +- .../Test/Golden/Governance/Vote.hs | 15 +- ...chor_data.txt => example_anchor_data1.txt} | 0 .../Test/Cardano/CLI/Hash.hs | 154 ++++++++++-------- .../cardano-cli-test/Test/Cli/DRepMetadata.hs | 20 +-- .../Test/Cli/Governance/Committee.hs | 21 +-- .../Test/Cli/Governance/DRep.hs | 38 +++-- .../Test/Cli/Governance/Vote.hs | 22 +-- .../test/cardano-cli-test/Test/Cli/Hash.hs | 38 +++-- .../Cli/Shelley/Certificates/StakePool.hs | 91 +++-------- ...chor_data.txt => example_anchor_data1.txt} | 0 14 files changed, 267 insertions(+), 289 deletions(-) rename cardano-cli/test/cardano-cli-golden/files/input/{example_anchor_data.txt => example_anchor_data1.txt} (100%) rename cardano-cli/test/cardano-cli-test/files/input/{example_anchor_data.txt => example_anchor_data1.txt} (100%) diff --git a/.gitattributes b/.gitattributes index cc4488494f..0c04963ce7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,9 @@ -cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data.txt -text +cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data1.txt -text cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data2.txt -text cardano-cli/test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json -text cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor1.json -text cardano-cli/test/cardano-cli-golden/files/input/example_gov_action_anchor2.json -text -cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt -text +cardano-cli/test/cardano-cli-test/files/input/example_anchor_data1.txt -text cardano-cli/test/cardano-cli-test/files/input/example_anchor_data2.txt -text cardano-cli/test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json -text cardano-cli/test/cardano-cli-test/files/input/example_gov_action_anchor1.json -text diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs index 3147a550c9..70787a7396 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs @@ -10,10 +10,8 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, exampleGovActionAnchorHash2, - exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorIpfsHash2, - exampleGovActionAnchorPathGolden1, exampleGovActionAnchorPathGolden2, - serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), govActionAnchorDataExample1, + govActionAnchorDataExample2, serveFilesWhile, tamperAnchorDataExampleHash) import qualified Test.Cardano.CLI.Util as H import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, noteInputFile, noteTempFile, propertyOnce) @@ -27,21 +25,21 @@ hprop_golden_governance_action_create_constitution_wrong_hash1_fails :: Property hprop_golden_governance_action_create_constitution_wrong_hash1_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_governance_action_create_constitution alteredHash - exampleGovActionAnchorHash2 + govActionAnchorDataExample2 tempDir hprop_golden_governance_action_create_constitution_wrong_hash2_fails :: Property hprop_golden_governance_action_create_constitution_wrong_hash2_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash2 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample2 -- We run the test with the modified hash base_golden_governance_action_create_constitution - exampleGovActionAnchorHash1 + govActionAnchorDataExample1 alteredHash tempDir @@ -49,17 +47,17 @@ hprop_golden_governance_action_create_constitution :: Property hprop_golden_governance_action_create_constitution = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> base_golden_governance_action_create_constitution - exampleGovActionAnchorHash1 - exampleGovActionAnchorHash2 + govActionAnchorDataExample1 + govActionAnchorDataExample2 tempDir base_golden_governance_action_create_constitution :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) - => String - -> String + => AnchorDataExample + -> AnchorDataExample -> FilePath -> m () -base_golden_governance_action_create_constitution hash1 hash2 tempDir = do +base_golden_governance_action_create_constitution exampleAnchorData1 exampleAnchorData2 tempDir = do stakeAddressVKeyFile <- noteTempFile tempDir "stake-address.vkey" stakeAddressSKeyFile <- noteTempFile tempDir "stake-address.skey" @@ -77,14 +75,14 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do actionFile <- noteTempFile tempDir "create-constitution.action" redactedActionFile <- noteTempFile tempDir "create-constitution.action.redacted" - let relativeUrl1 = ["ipfs", exampleGovActionAnchorIpfsHash1] - let relativeUrl2 = ["ipfs", exampleGovActionAnchorIpfsHash2] + let relativeUrl1 = ["ipfs", anchorDataIpfsHash exampleAnchorData1] + let relativeUrl2 = ["ipfs", anchorDataIpfsHash exampleAnchorData2] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [ (relativeUrl1, exampleGovActionAnchorPathGolden1) - , (relativeUrl2, exampleGovActionAnchorPathGolden2) + [ (relativeUrl1, anchorDataPathGolden exampleAnchorData1) + , (relativeUrl2, anchorDataPathGolden exampleAnchorData2) ] ( \port -> do void $ @@ -96,9 +94,9 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do , "create-constitution" , "--mainnet" , "--anchor-data-hash" - , hash1 + , anchorDataHash exampleAnchorData1 , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData1 , "--check-anchor-data" , "--governance-action-deposit" , "10" @@ -107,9 +105,9 @@ base_golden_governance_action_create_constitution hash1 hash2 tempDir = do , "--out-file" , actionFile , "--constitution-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash2 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData2 , "--constitution-hash" - , hash2 + , anchorDataHash exampleAnchorData2 , "--check-constitution-hash" ] ) @@ -192,7 +190,7 @@ hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fail hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_conway_governance_action_view_update_committee_yaml alteredHash @@ -201,21 +199,22 @@ hprop_golden_conway_governance_action_view_update_committee_yaml_wrong_hash_fail hprop_golden_conway_governance_action_view_update_committee_yaml :: Property hprop_golden_conway_governance_action_view_update_committee_yaml = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_view_update_committee_yaml exampleGovActionAnchorHash1 tempDir + base_golden_conway_governance_action_view_update_committee_yaml govActionAnchorDataExample1 tempDir base_golden_conway_governance_action_view_update_committee_yaml - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_conway_governance_action_view_update_committee_yaml hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_conway_governance_action_view_update_committee_yaml exampleAnchorData tempDir = do stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathGolden1)] + [(relativeUrl, anchorDataPathGolden exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -230,9 +229,9 @@ base_golden_conway_governance_action_view_update_committee_yaml hash tempDir = d , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data" , "--threshold" , "0.61" @@ -259,7 +258,7 @@ hprop_golden_conway_governance_action_view_create_info_json_outfile_wrong_hash_f hprop_golden_conway_governance_action_view_create_info_json_outfile_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_conway_governance_action_view_create_info_json_outfile alteredHash @@ -269,22 +268,23 @@ hprop_golden_conway_governance_action_view_create_info_json_outfile :: Property hprop_golden_conway_governance_action_view_create_info_json_outfile = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> base_golden_conway_governance_action_view_create_info_json_outfile - exampleGovActionAnchorHash1 + govActionAnchorDataExample1 tempDir base_golden_conway_governance_action_view_create_info_json_outfile - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_conway_governance_action_view_create_info_json_outfile hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_conway_governance_action_view_create_info_json_outfile exampleAnchorData tempDir = do stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathGolden1)] + [(relativeUrl, anchorDataPathGolden exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -299,9 +299,9 @@ base_golden_conway_governance_action_view_create_info_json_outfile hash tempDir , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data" , "--out-file" , actionFile @@ -328,7 +328,7 @@ hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails :: Property hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_governanceActionCreateNoConfidence alteredHash @@ -337,22 +337,23 @@ hprop_golden_governanceActionCreateNoConfidence_wrong_hash_fails = hprop_golden_governanceActionCreateNoConfidence :: Property hprop_golden_governanceActionCreateNoConfidence = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governanceActionCreateNoConfidence exampleGovActionAnchorHash1 tempDir + base_golden_governanceActionCreateNoConfidence govActionAnchorDataExample1 tempDir base_golden_governanceActionCreateNoConfidence - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_governanceActionCreateNoConfidence hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_governanceActionCreateNoConfidence exampleAnchorData tempDir = do stakeAddressVKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/stake-address.vkey" actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathGolden1)] + [(relativeUrl, anchorDataPathGolden exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -367,9 +368,9 @@ base_golden_governanceActionCreateNoConfidence hash tempDir = do , "--deposit-return-stake-verification-key-file" , stakeAddressVKeyFile , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data" , "--prev-governance-action-index" , "5" @@ -401,7 +402,7 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update_wrong_ha hprop_golden_conway_governance_action_create_protocol_parameters_update_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_conway_governance_action_create_protocol_parameters_update alteredHash @@ -411,12 +412,13 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update :: Prope hprop_golden_conway_governance_action_create_protocol_parameters_update = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> base_golden_conway_governance_action_create_protocol_parameters_update - exampleGovActionAnchorHash1 + govActionAnchorDataExample1 tempDir base_golden_conway_governance_action_create_protocol_parameters_update - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_conway_governance_action_create_protocol_parameters_update hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_conway_governance_action_create_protocol_parameters_update exampleAnchorData tempDir = do stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" -- different versions of https://github.com/IntersectMBO/plutus/blob/master/plutus-core/cost-model/data/builtinCostModel.json -- transformed and compiled together @@ -424,12 +426,12 @@ base_golden_conway_governance_action_create_protocol_parameters_update hash temp actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathGolden1)] + [(relativeUrl, anchorDataPathGolden exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -439,9 +441,9 @@ base_golden_conway_governance_action_create_protocol_parameters_update hash temp , "action" , "create-protocol-parameters-update" , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data" , "--mainnet" , "--deposit-return-stake-verification-key-file" @@ -503,7 +505,7 @@ hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails :: Proper hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the modified hash base_golden_conway_governance_action_create_hardfork alteredHash @@ -512,21 +514,22 @@ hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails = hprop_golden_conway_governance_action_create_hardfork :: Property hprop_golden_conway_governance_action_create_hardfork = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_conway_governance_action_create_hardfork exampleGovActionAnchorHash1 tempDir + base_golden_conway_governance_action_create_hardfork govActionAnchorDataExample1 tempDir base_golden_conway_governance_action_create_hardfork - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_conway_governance_action_create_hardfork hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_conway_governance_action_create_hardfork exampleAnchorData tempDir = do stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey" actionFile <- noteTempFile tempDir "action" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathGolden1)] + [(relativeUrl, anchorDataPathGolden exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -536,9 +539,9 @@ base_golden_conway_governance_action_create_hardfork hash tempDir = do , "action" , "create-hardfork" , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data" , "--mainnet" , "--deposit-return-stake-verification-key-file" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs index fc463dbe0b..5db9b19a55 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs @@ -11,8 +11,8 @@ import System.Exit (ExitCode (..)) import System.FilePath (()) import Test.Cardano.CLI.Aeson (assertHasMappings) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathGolden, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import qualified Test.Cardano.CLI.Util as H hiding (noteTempFile) import Test.Cardano.CLI.Util @@ -335,8 +335,8 @@ hprop_golden_governance_committee_checks_wrong_hash_fails :: Property hprop_golden_governance_committee_checks_wrong_hash_fails = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + alteredHashAnchorData <- H.evalMaybe $ tamperAnchorDataExampleHash dummyAnchorDataExample1 + let relativeUrl = ["ipfs", anchorDataIpfsHash alteredHashAnchorData] ccColdVKey <- noteTempFile tempDir "cold.vkey" ccColdSKey <- noteTempFile tempDir "cold.skey" @@ -359,7 +359,7 @@ hprop_golden_governance_committee_checks_wrong_hash_fails = env <- H.evalIO IO.getEnvironment (exitCode, _, result) <- serveFilesWhile - [ (relativeUrl, exampleAnchorDataPathGolden) + [ (relativeUrl, anchorDataPathGolden alteredHashAnchorData) ] ( \port -> do execDetailConfigCardanoCLI @@ -374,9 +374,9 @@ hprop_golden_governance_committee_checks_wrong_hash_fails = , "--cold-verification-key-file" , ccColdVKey , "--resignation-metadata-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ anchorDataIpfsHash alteredHashAnchorData , "--resignation-metadata-hash" - , alteredHash + , anchorDataHash alteredHashAnchorData , "--check-resignation-metadata-hash" , "--out-file" , certFile diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs index 3e1dcd4736..6a85d82bf0 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -18,8 +18,8 @@ import System.Posix.Files (fileMode, getFileStatus) #endif import GHC.IO.Exception (ExitCode (ExitFailure)) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathGolden, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (FileSem, bracketSem, execCardanoCLI, execDetailCardanoCLI, newFileSem, noteInputFile, noteTempFile, propertyOnce) @@ -470,13 +470,13 @@ hprop_golden_drep_metadata_hash_url_wrong_hash_fails :: Property hprop_golden_drep_metadata_hash_url_wrong_hash_fails = propertyOnce $ do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash - let relativeUrl = [exampleAnchorDataIpfsHash] + alteredHashAnchorDataExample <- H.evalMaybe $ tamperAnchorDataExampleHash dummyAnchorDataExample1 + let relativeUrl = [anchorDataIpfsHash alteredHashAnchorDataExample] -- Create temporary HTTP server with files required by the call to `cardano-cli` (exitCode, _, result) <- serveFilesWhile - [ (relativeUrl, exampleAnchorDataPathGolden) + [ (relativeUrl, anchorDataPathGolden alteredHashAnchorDataExample) ] ( \port -> do execDetailCardanoCLI @@ -485,9 +485,9 @@ hprop_golden_drep_metadata_hash_url_wrong_hash_fails = , "drep" , "metadata-hash" , "--drep-metadata-url" - , "http://127.0.0.1:" ++ show port ++ "/" ++ exampleAnchorDataIpfsHash + , "http://127.0.0.1:" ++ show port ++ "/" ++ anchorDataIpfsHash alteredHashAnchorDataExample , "--expected-hash" - , alteredHash + , anchorDataHash alteredHashAnchorDataExample ] ) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs index 6eae4e120b..a5d4f96b47 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Vote.hs @@ -7,9 +7,8 @@ import Data.Monoid (Last (..)) import GHC.IO.Exception (ExitCode (..)) import qualified System.Environment as IO -import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, - exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorPathGolden1, - serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), govActionAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (FileSem, bracketSem, execCardanoCLI, execDetailConfigCardanoCLI, newFileSem, noteInputFile, propertyOnce) @@ -193,8 +192,8 @@ hprop_golden_governance_vote_create_hash_fails :: Property hprop_golden_governance_vote_create_hash_fails = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + tamperedExampleAnchorData <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 + let relativeUrl = ["ipfs", anchorDataIpfsHash tamperedExampleAnchorData] vkeyFile <- noteInputFile "test/cardano-cli-golden/files/input/drep.vkey" voteFile <- H.noteTempFile tempDir "vote" @@ -205,7 +204,7 @@ hprop_golden_governance_vote_create_hash_fails = env <- H.evalIO IO.getEnvironment (exitCode, _, result) <- serveFilesWhile - [ (relativeUrl, exampleGovActionAnchorPathGolden1) + [ (relativeUrl, anchorDataPathGolden tamperedExampleAnchorData) ] ( \port -> do execDetailConfigCardanoCLI @@ -227,9 +226,9 @@ hprop_golden_governance_vote_create_hash_fails = , "--out-file" , voteFile , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash tamperedExampleAnchorData , "--anchor-data-hash" - , alteredHash + , anchorDataHash tamperedExampleAnchorData , "--check-anchor-data-hash" ] ) diff --git a/cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data.txt b/cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data1.txt similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data.txt rename to cardano-cli/test/cardano-cli-golden/files/input/example_anchor_data1.txt diff --git a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs index 3661fd42fe..5285426ebe 100644 --- a/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs +++ b/cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Hash.hs @@ -1,28 +1,16 @@ {-# LANGUAGE FlexibleContexts #-} module Test.Cardano.CLI.Hash - ( exampleAnchorDataHash - , exampleAnchorDataHash2 + ( AnchorDataExample (..) , serveFilesWhile - , exampleAnchorDataPathTest - , exampleAnchorDataPathTest2 - , exampleAnchorDataPathGolden - , exampleAnchorDataPathGolden2 - , exampleAnchorDataIpfsHash - , exampleAnchorDataIpfsHash2 , tamperBase16Hash - , exampleDRepRegAnchorHash - , exampleDRepRegAnchorIpfsHash - , exampleDRepRegAnchorPathTest - , exampleDRepRegAnchorPathGolden - , exampleGovActionAnchorHash1 - , exampleGovActionAnchorHash2 - , exampleGovActionAnchorPathGolden1 - , exampleGovActionAnchorPathGolden2 - , exampleGovActionAnchorPathTest1 - , exampleGovActionAnchorPathTest2 - , exampleGovActionAnchorIpfsHash1 - , exampleGovActionAnchorIpfsHash2 + , dummyAnchorDataExample1 + , dummyAnchorDataExample2 + , drepRegAnchorDataExample + , govActionAnchorDataExample1 + , govActionAnchorDataExample2 + , tamperAnchorDataExampleHash + , stakePoolMetadataExample ) where @@ -49,58 +37,74 @@ import Network.Wai.Handler.Warp (defaultSettings, openFreePort, runSet import Hedgehog as H import Hedgehog.Internal.Source (HasCallStack) --- ** Anchor hashes for the example files - -exampleAnchorDataHash, exampleAnchorDataHash2 :: String -exampleAnchorDataHash = "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" -exampleAnchorDataHash2 = "8b4fda934272320ec8d11ba5a7904ab74686a8ec97f2c1331b68d11e28bda26f" - -exampleDRepRegAnchorHash, exampleGovActionAnchorHash1, exampleGovActionAnchorHash2 :: String -exampleDRepRegAnchorHash = "15a1c724bfbb8c0a0e84e2e359525017aefb8914ecc219bb9ad469368f14975d" -exampleGovActionAnchorHash1 = "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" -exampleGovActionAnchorHash2 = "21dd5a8219936e0d756f44f7f1a7179806b5afa45b6cbfb9e7d7efe3123c8e51" - --- ** Paths to the example files for golden tests - -exampleAnchorDataPathGolden, exampleAnchorDataPathGolden2 :: String -exampleAnchorDataPathGolden = "test/cardano-cli-golden/files/input/example_anchor_data.txt" -exampleAnchorDataPathGolden2 = "test/cardano-cli-golden/files/input/example_anchor_data2.txt" - -exampleDRepRegAnchorPathGolden - , exampleGovActionAnchorPathGolden1 - , exampleGovActionAnchorPathGolden2 - :: String -exampleDRepRegAnchorPathGolden = "test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json" -exampleGovActionAnchorPathGolden1 = "test/cardano-cli-golden/files/input/example_gov_action_anchor1.json" -exampleGovActionAnchorPathGolden2 = "test/cardano-cli-golden/files/input/example_gov_action_anchor2.json" - --- ** Paths to the example files for normal testes - -exampleAnchorDataPathTest, exampleAnchorDataPathTest2 :: String -exampleAnchorDataPathTest = "test/cardano-cli-test/files/input/example_anchor_data.txt" -exampleAnchorDataPathTest2 = "test/cardano-cli-test/files/input/example_anchor_data2.txt" - -exampleDRepRegAnchorPathTest - , exampleGovActionAnchorPathTest1 - , exampleGovActionAnchorPathTest2 - :: String -exampleDRepRegAnchorPathTest = "test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json" -exampleGovActionAnchorPathTest1 = "test/cardano-cli-test/files/input/example_gov_action_anchor1.json" -exampleGovActionAnchorPathTest2 = "test/cardano-cli-test/files/input/example_gov_action_anchor2.json" - --- ** Ipfs hashes for the example files - -exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2 :: String -exampleAnchorDataIpfsHash = "QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" -exampleAnchorDataIpfsHash2 = "QmdTJ4PabgSabg8K1Z4MNXnSVM8bjJnAikC3rVWfPVExQj" - -exampleDRepRegAnchorIpfsHash - , exampleGovActionAnchorIpfsHash1 - , exampleGovActionAnchorIpfsHash2 - :: String -exampleDRepRegAnchorIpfsHash = "Qmb6vATFuc2o9zeFEseTvKZiqGRvuYoZRT5SNZN6L88Les" -exampleGovActionAnchorIpfsHash1 = "QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA" -exampleGovActionAnchorIpfsHash2 = "QmfCgYdiMSTTJ4Uw93vqwDw2DL2xfr7QrNeRnsxZqaCcLx" +-- * Anchor data examples + +-- | Groups information about a given anchor data example +data AnchorDataExample = AnchorDataExample + { anchorDataHash :: String + , anchorDataPathGolden :: String + , anchorDataPathTest :: String + , anchorDataIpfsHash :: String + } + deriving (Eq, Show) + +-- ** Examples + +dummyAnchorDataExample1 :: AnchorDataExample +dummyAnchorDataExample1 = + AnchorDataExample + { anchorDataHash = "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_anchor_data1.txt" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_anchor_data1.txt" + , anchorDataIpfsHash = "QmbL5EBFJLf8DdPkWAskG3Euin9tHY8naqQ2JDoHnWHHXJ" + } + +dummyAnchorDataExample2 :: AnchorDataExample +dummyAnchorDataExample2 = + AnchorDataExample + { anchorDataHash = "8b4fda934272320ec8d11ba5a7904ab74686a8ec97f2c1331b68d11e28bda26f" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_anchor_data2.txt" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_anchor_data2.txt" + , anchorDataIpfsHash = "QmdTJ4PabgSabg8K1Z4MNXnSVM8bjJnAikC3rVWfPVExQj" + } + +drepRegAnchorDataExample :: AnchorDataExample +drepRegAnchorDataExample = + AnchorDataExample + { anchorDataHash = "15a1c724bfbb8c0a0e84e2e359525017aefb8914ecc219bb9ad469368f14975d" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_drep_reg_anchor_data.json" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_drep_reg_anchor_data.json" + , anchorDataIpfsHash = "Qmb6vATFuc2o9zeFEseTvKZiqGRvuYoZRT5SNZN6L88Les" + } + +govActionAnchorDataExample1 :: AnchorDataExample +govActionAnchorDataExample1 = + AnchorDataExample + { anchorDataHash = "d0c923d899917cd62cbf0e766cc2534a1f4739af69da0241a4992ad24d861ff0" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_gov_action_anchor1.json" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_gov_action_anchor1.json" + , anchorDataIpfsHash = "QmdGH8Qa1f5mJJxbjYuHUqvwqCqUQm66y7EVNFEMgzZJeA" + } + +govActionAnchorDataExample2 :: AnchorDataExample +govActionAnchorDataExample2 = + AnchorDataExample + { anchorDataHash = "21dd5a8219936e0d756f44f7f1a7179806b5afa45b6cbfb9e7d7efe3123c8e51" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_gov_action_anchor2.json" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_gov_action_anchor2.json" + , anchorDataIpfsHash = "QmfCgYdiMSTTJ4Uw93vqwDw2DL2xfr7QrNeRnsxZqaCcLx" + } + +stakePoolMetadataExample :: AnchorDataExample +stakePoolMetadataExample = + AnchorDataExample + { anchorDataHash = "8241de08075886a7d09c847c9bbd1719459dac0bd0a2f085e673611ebb9a5965" + , anchorDataPathGolden = "test/cardano-cli-golden/files/input/example_stake_pool_metadata.json" + , anchorDataPathTest = "test/cardano-cli-test/files/input/example_stake_pool_metadata.json" + , anchorDataIpfsHash = "QmR1HAT4Hb4HjjqcgoXwupYXMF6t8h7MoSP24HMfV8t38a" + } + +-- * Utility functions -- | Tamper with the base16 hash by adding one to the first character tamperBase16Hash :: String -> Maybe String @@ -114,6 +118,12 @@ tamperBase16Hash (headChar : tailStr) = lowerCaseRest = map toLower tailStr hexChars = ['0' .. '9'] ++ ['a' .. 'f'] +-- | Tamper with the base16 hash in an AnchorDataExample by adding one to the first character +tamperAnchorDataExampleHash :: AnchorDataExample -> Maybe AnchorDataExample +tamperAnchorDataExampleHash anchorDataExample@(AnchorDataExample{anchorDataHash = anchorDataHash'}) = do + tamperedAnchorDataHash <- tamperBase16Hash anchorDataHash' + return (anchorDataExample{anchorDataHash = tamperedAnchorDataHash}) + -- | Takes a relative url (as a list of segments), a file path, and an action, and it serves -- the file in the url provided in a random free port that is passed as a parameter to the -- action. After the action returns, it shuts down the server. It returns the result of the diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/DRepMetadata.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/DRepMetadata.hs index 99655ab383..982b2b696c 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/DRepMetadata.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/DRepMetadata.hs @@ -8,8 +8,8 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (execCardanoCLIWithEnvVars, expectFailure, propertyOnce) import Hedgehog (Property) @@ -22,7 +22,7 @@ hprop_drep_metadata_hash_url_wrong_hash_fails :: Property hprop_drep_metadata_hash_url_wrong_hash_fails = propertyOnce . expectFailure $ do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash dummyAnchorDataExample1 -- We run the test with the modified hash baseDrepMetadataHashUrl alteredHash @@ -30,22 +30,22 @@ hprop_drep_metadata_hash_url_wrong_hash_fails = -- @cabal test cardano-cli-test --test-options '-p "/drep metadata hash url correct hash/"'@ hprop_drep_metadata_hash_url_correct_hash :: Property hprop_drep_metadata_hash_url_correct_hash = - propertyOnce $ baseDrepMetadataHashUrl exampleAnchorDataHash + propertyOnce $ baseDrepMetadataHashUrl dummyAnchorDataExample1 baseDrepMetadataHashUrl :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) - => String + => AnchorDataExample -- ^ The hash to check against. Changing this value allows us to test the -- behavior of the command both when the hash is correct and when it is incorrect -- reusing the same code. -> m () -baseDrepMetadataHashUrl hash = do - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] +baseDrepMetadataHashUrl exampleAnchorData = do + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [ (relativeUrl, exampleAnchorDataPathTest) + [ (relativeUrl, anchorDataPathTest exampleAnchorData) ] ( \port -> do void $ @@ -56,8 +56,8 @@ baseDrepMetadataHashUrl hash = do , "drep" , "metadata-hash" , "--drep-metadata-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--expected-hash" - , hash + , anchorDataHash exampleAnchorData ] ) diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Committee.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Committee.hs index ad32847d6f..818d0b1776 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Committee.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Committee.hs @@ -8,8 +8,8 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, noteTempFile, propertyOnce) @@ -23,7 +23,7 @@ hprop_governance_committee_checks_wrong_hash_fails :: Property hprop_governance_committee_checks_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleAnchorDataHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash dummyAnchorDataExample1 -- We run the test with the altered baseGovernanceGovernanceCommitteeChecksHash alteredHash @@ -34,11 +34,12 @@ hprop_governance_committee_checks_wrong_hash_fails = hprop_governance_committee_checks_right_hash_works :: Property hprop_governance_committee_checks_right_hash_works = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - baseGovernanceGovernanceCommitteeChecksHash exampleAnchorDataHash tempDir + baseGovernanceGovernanceCommitteeChecksHash dummyAnchorDataExample1 tempDir baseGovernanceGovernanceCommitteeChecksHash - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -baseGovernanceGovernanceCommitteeChecksHash hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +baseGovernanceGovernanceCommitteeChecksHash exampleAnchorData tempDir = do ccColdVKey <- noteTempFile tempDir "cold.vkey" ccColdSKey <- noteTempFile tempDir "cold.skey" @@ -56,12 +57,12 @@ baseGovernanceGovernanceCommitteeChecksHash hash tempDir = do , ccColdSKey ] - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, anchorDataPathTest exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -73,9 +74,9 @@ baseGovernanceGovernanceCommitteeChecksHash hash tempDir = do , "--cold-verification-key-file" , ccColdVKey , "--resignation-metadata-url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--resignation-metadata-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-resignation-metadata-hash" , "--out-file" , certFile diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs index f5f6f354df..b80373dfe3 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/DRep.hs @@ -9,8 +9,8 @@ import Control.Monad import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleDRepRegAnchorHash, exampleDRepRegAnchorIpfsHash, - exampleDRepRegAnchorPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), drepRegAnchorDataExample, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, propertyOnce) @@ -96,7 +96,7 @@ hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleDRepRegAnchorHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash drepRegAnchorDataExample -- We run the test with the altered base_golden_governance_drep_registration_certificate_vkey_file alteredHash @@ -105,11 +105,12 @@ hprop_golden_governance_drep_registration_certificate_vkey_file_wrong_hash_fails hprop_golden_governance_drep_registration_certificate_vkey_file :: Property hprop_golden_governance_drep_registration_certificate_vkey_file = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governance_drep_registration_certificate_vkey_file exampleDRepRegAnchorHash tempDir + base_golden_governance_drep_registration_certificate_vkey_file drepRegAnchorDataExample tempDir base_golden_governance_drep_registration_certificate_vkey_file - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_governance_drep_registration_certificate_vkey_file hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_governance_drep_registration_certificate_vkey_file exampleAnchorData tempDir = do drepVKeyFile <- H.noteTempFile tempDir "drep.vkey" drepSKeyFile <- H.noteTempFile tempDir "drep.skey" @@ -127,12 +128,12 @@ base_golden_governance_drep_registration_certificate_vkey_file hash tempDir = do outFile <- H.noteTempFile tempDir "drep-reg-cert.txt" - let relativeUrl = ["ipfs", exampleDRepRegAnchorIpfsHash] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleDRepRegAnchorPathTest)] + [(relativeUrl, anchorDataPathTest exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -146,9 +147,9 @@ base_golden_governance_drep_registration_certificate_vkey_file hash tempDir = do , "--key-reg-deposit-amt" , "0" , "--drep-metadata-url" - , "ipfs://" ++ exampleDRepRegAnchorIpfsHash + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--drep-metadata-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-drep-metadata-hash" , "--out-file" , outFile @@ -159,7 +160,7 @@ hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails :: Pr hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleDRepRegAnchorHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash drepRegAnchorDataExample -- We run the test with the modified hash base_golden_governance_drep_update_certificate_vkey_file alteredHash @@ -168,11 +169,12 @@ hprop_golden_governance_drep_update_certificate_vkey_file_wrong_hash_fails = hprop_golden_governance_drep_update_certificate_vkey_file :: Property hprop_golden_governance_drep_update_certificate_vkey_file = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - base_golden_governance_drep_update_certificate_vkey_file exampleDRepRegAnchorHash tempDir + base_golden_governance_drep_update_certificate_vkey_file drepRegAnchorDataExample tempDir base_golden_governance_drep_update_certificate_vkey_file - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -base_golden_governance_drep_update_certificate_vkey_file hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +base_golden_governance_drep_update_certificate_vkey_file exampleAnchorData tempDir = do drepVKeyFile <- H.noteTempFile tempDir "drep.vkey" drepSKeyFile <- H.noteTempFile tempDir "drep.skey" @@ -190,12 +192,12 @@ base_golden_governance_drep_update_certificate_vkey_file hash tempDir = do outFile <- H.noteTempFile tempDir "drep-upd-cert.txt" - let relativeUrl = ["ipfs", exampleDRepRegAnchorIpfsHash] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleDRepRegAnchorPathTest)] + [(relativeUrl, anchorDataPathTest exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -207,9 +209,9 @@ base_golden_governance_drep_update_certificate_vkey_file hash tempDir = do , "--drep-verification-key-file" , drepVKeyFile , "--drep-metadata-url" - , "ipfs://" ++ exampleDRepRegAnchorIpfsHash + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--drep-metadata-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-drep-metadata-hash" , "--out-file" , outFile diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs index 0c58302bd3..79915145ca 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Vote.hs @@ -8,9 +8,8 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleGovActionAnchorHash1, - exampleGovActionAnchorIpfsHash1, exampleGovActionAnchorPathTest1, - serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), govActionAnchorDataExample1, + serveFilesWhile, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (execCardanoCLIWithEnvVars, expectFailure, noteInputFile, propertyOnce) @@ -24,7 +23,7 @@ hprop_governance_vote_create_wrong_hash_fails :: Property hprop_governance_vote_create_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleGovActionAnchorHash1 + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash govActionAnchorDataExample1 -- We run the test with the altered baseGovernanceVoteCreateHashCheck alteredHash @@ -35,20 +34,21 @@ hprop_governance_vote_create_wrong_hash_fails = hprop_governance_vote_create_right_hash_works :: Property hprop_governance_vote_create_right_hash_works = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - baseGovernanceVoteCreateHashCheck exampleGovActionAnchorHash1 tempDir + baseGovernanceVoteCreateHashCheck govActionAnchorDataExample1 tempDir baseGovernanceVoteCreateHashCheck - :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) => String -> FilePath -> m () -baseGovernanceVoteCreateHashCheck hash tempDir = do + :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) + => AnchorDataExample -> FilePath -> m () +baseGovernanceVoteCreateHashCheck exampleAnchorData tempDir = do vkeyFile <- noteInputFile "test/cardano-cli-test/files/input/drep.vkey" voteFile <- H.noteTempFile tempDir "vote" - let relativeUrl = ["ipfs", exampleGovActionAnchorIpfsHash1] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleAnchorData] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleGovActionAnchorPathTest1)] + [(relativeUrl, anchorDataPathTest exampleAnchorData)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -67,9 +67,9 @@ baseGovernanceVoteCreateHashCheck hash tempDir = do , "--out-file" , voteFile , "--anchor-url" - , "ipfs://" ++ exampleGovActionAnchorIpfsHash1 + , "ipfs://" ++ anchorDataIpfsHash exampleAnchorData , "--anchor-data-hash" - , hash + , anchorDataHash exampleAnchorData , "--check-anchor-data-hash" ] ) diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Hash.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Hash.hs index fd94022699..18ce85f29d 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Hash.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Hash.hs @@ -9,8 +9,8 @@ import System.Directory (getCurrentDirectory) import System.FilePath (dropTrailingPathSeparator) import System.FilePath.Posix (splitDirectories) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile) import Test.Cardano.CLI.Util import Hedgehog as H @@ -21,28 +21,30 @@ import qualified Hedgehog.Extras as H hprop_generate_anchor_data_hash_from_file :: Property hprop_generate_anchor_data_hash_from_file = propertyOnce $ do + let anchorDataExample = dummyAnchorDataExample1 result <- execCardanoCLI [ "hash" , "anchor-data" , "--file-binary" - , exampleAnchorDataPathTest + , anchorDataPathTest anchorDataExample ] - result === exampleAnchorDataHash + result === anchorDataHash anchorDataExample -- | Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/check anchor data hash from file/"'@ hprop_check_anchor_data_hash_from_file :: Property hprop_check_anchor_data_hash_from_file = propertyOnce $ do + let anchorDataExample = dummyAnchorDataExample1 void $ execCardanoCLI [ "hash" , "anchor-data" , "--file-binary" - , exampleAnchorDataPathTest + , anchorDataPathTest anchorDataExample , "--expected-hash" - , exampleAnchorDataHash + , anchorDataHash anchorDataExample ] -- | Execute me with: @@ -50,14 +52,15 @@ hprop_check_anchor_data_hash_from_file = hprop_check_anchor_data_hash_from_file_fails :: Property hprop_check_anchor_data_hash_from_file_fails = propertyOnce $ do + let anchorDataExample = dummyAnchorDataExample1 (ec, _, _) <- execDetailCardanoCLI [ "hash" , "anchor-data" , "--file-binary" - , exampleAnchorDataPathTest + , anchorDataPathTest anchorDataExample , "--expected-hash" - , 'c' : drop 1 exampleAnchorDataHash + , 'c' : drop 1 (anchorDataHash anchorDataExample) ] ec === ExitFailure 1 @@ -66,6 +69,7 @@ hprop_check_anchor_data_hash_from_file_fails = hprop_generate_anchor_data_hash_from_file_uri :: Property hprop_generate_anchor_data_hash_from_file_uri = propertyOnce $ do + let anchorDataExample = dummyAnchorDataExample1 cwd <- H.evalIO getCurrentDirectory posixCwd <- toPOSIX cwd result <- @@ -73,9 +77,9 @@ hprop_generate_anchor_data_hash_from_file_uri = [ "hash" , "anchor-data" , "--url" - , "file://" ++ posixCwd ++ "/" ++ exampleAnchorDataPathTest + , "file://" ++ posixCwd ++ "/" ++ anchorDataPathTest anchorDataExample ] - result === exampleAnchorDataHash + result === anchorDataHash anchorDataExample where toPOSIX :: FilePath -> PropertyT IO [Char] toPOSIX path = @@ -97,11 +101,12 @@ hprop_generate_anchor_data_hash_from_file_uri = hprop_check_anchor_data_hash_from_http_uri :: Property hprop_check_anchor_data_hash_from_http_uri = propertyOnce $ do + let anchorDataExample = dummyAnchorDataExample1 let relativeUrl = ["example", "url", "file.txt"] -- Create temporary HTTP server with files required by the call to `cardano-cli` serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, anchorDataPathTest anchorDataExample)] ( \port -> do void $ execCardanoCLI @@ -110,7 +115,7 @@ hprop_check_anchor_data_hash_from_http_uri = , "--url" , "http://localhost:" ++ show port ++ "/" ++ intercalate "/" relativeUrl , "--expected-hash" - , exampleAnchorDataHash + , anchorDataHash anchorDataExample ] ) @@ -119,12 +124,13 @@ hprop_check_anchor_data_hash_from_http_uri = hprop_check_anchor_data_hash_from_ipfs_uri :: Property hprop_check_anchor_data_hash_from_ipfs_uri = propertyOnce $ do - let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] + let anchorDataExample = dummyAnchorDataExample1 + let relativeUrl = ["ipfs", anchorDataIpfsHash anchorDataExample] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [(relativeUrl, exampleAnchorDataPathTest)] + [(relativeUrl, anchorDataPathTest anchorDataExample)] ( \port -> do void $ execCardanoCLIWithEnvVars @@ -132,8 +138,8 @@ hprop_check_anchor_data_hash_from_ipfs_uri = [ "hash" , "anchor-data" , "--url" - , "ipfs://" ++ exampleAnchorDataIpfsHash + , "ipfs://" ++ anchorDataIpfsHash anchorDataExample , "--expected-hash" - , exampleAnchorDataHash + , anchorDataHash anchorDataExample ] ) diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Certificates/StakePool.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Certificates/StakePool.hs index 94617d6dea..67ecc0fb39 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Certificates/StakePool.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Certificates/StakePool.hs @@ -8,8 +8,8 @@ import Control.Monad (void) import Control.Monad.Catch (MonadCatch) import Control.Monad.Trans.Control (MonadBaseControl) -import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, - exampleAnchorDataPathTest, serveFilesWhile, tamperBase16Hash) +import Test.Cardano.CLI.Hash (AnchorDataExample (..), dummyAnchorDataExample1, + serveFilesWhile, stakePoolMetadataExample, tamperAnchorDataExampleHash) import Test.Cardano.CLI.Util (execCardanoCLI, execCardanoCLIWithEnvVars, expectFailure, noteTempFile, propertyOnce) @@ -18,26 +18,13 @@ import qualified Hedgehog as H import qualified Hedgehog.Extras as H import Hedgehog.Internal.Property (Property) -exampleStakePoolMetadataHash :: String -exampleStakePoolMetadataHash = "8241de08075886a7d09c847c9bbd1719459dac0bd0a2f085e673611ebb9a5965" - -exampleStakePoolMetadataPathTest :: String -exampleStakePoolMetadataPathTest = "test/cardano-cli-test/files/input/example_stake_pool_metadata.json" - -exampleStakePoolMetadataIpfsHash :: String -exampleStakePoolMetadataIpfsHash = "QmR1HAT4Hb4HjjqcgoXwupYXMF6t8h7MoSP24HMfV8t38a" - -- Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/stake pool certificate hash check wrong metadata fails/"'@ hprop_stake_pool_certificate_hash_check_wrong_metadata_fails :: Property hprop_stake_pool_certificate_hash_check_wrong_metadata_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We run the test with the wrong metadata file - baseStakePoolCertificateHashCheck - exampleAnchorDataIpfsHash - exampleAnchorDataPathTest - exampleAnchorDataHash - tempDir + baseStakePoolCertificateHashCheck dummyAnchorDataExample1 tempDir -- Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/stake pool certificate hash check wrong hash fails/"'@ @@ -45,39 +32,25 @@ hprop_stake_pool_certificate_hash_check_wrong_hash_fails :: Property hprop_stake_pool_certificate_hash_check_wrong_hash_fails = propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleStakePoolMetadataHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash stakePoolMetadataExample -- We run the test with the modified hash - baseStakePoolCertificateHashCheck - exampleStakePoolMetadataIpfsHash - exampleStakePoolMetadataPathTest - alteredHash - tempDir + baseStakePoolCertificateHashCheck alteredHash tempDir -- Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/stake pool certificate hash check right hash works/"'@ hprop_stake_pool_certificate_hash_check_right_hash_works :: Property hprop_stake_pool_certificate_hash_check_right_hash_works = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> - baseStakePoolCertificateHashCheck - exampleStakePoolMetadataIpfsHash - exampleStakePoolMetadataPathTest - exampleStakePoolMetadataHash - tempDir + baseStakePoolCertificateHashCheck stakePoolMetadataExample tempDir baseStakePoolCertificateHashCheck :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) - => String - -- ^ The ipfs hash of the file for the URL name - -> FilePath - -- ^ File to use as the metadata file - -> String - -- ^ The hash to check against. Changing this value allows us to test the - -- behavior of the command both when the hash is correct and when it is incorrect - -- reusing the same code. + => AnchorDataExample + -- ^ Information about the example anchor data to use -> FilePath -- ^ Temporary directory for files generated during the test -> m () -baseStakePoolCertificateHashCheck ipfsHash metadataFile hash tempDir = do +baseStakePoolCertificateHashCheck exampleMetadata tempDir = do -- Key filepaths coldVerKey <- noteTempFile tempDir "cold-verification-key-file" coldSignKey <- noteTempFile tempDir "cold-signing-key-file" @@ -132,12 +105,12 @@ baseStakePoolCertificateHashCheck ipfsHash metadataFile hash tempDir = do H.assertFilesExist [vrfSignKey, vrfVerKey] - let relativeUrl = ["ipfs", ipfsHash] + let relativeUrl = ["ipfs", anchorDataIpfsHash exampleMetadata] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [ (relativeUrl, metadataFile) + [ (relativeUrl, anchorDataPathTest exampleMetadata) ] ( \port -> do -- Create stake pool registration certificate @@ -163,9 +136,9 @@ baseStakePoolCertificateHashCheck ipfsHash metadataFile hash tempDir = do , "--pool-owner-stake-verification-key-file" , poolRewardAccountAndOwnerVerKey , "--metadata-url" - , "ipfs://" ++ ipfsHash + , "ipfs://" ++ anchorDataIpfsHash exampleMetadata , "--metadata-hash" - , hash + , anchorDataHash exampleMetadata , "--check-metadata-hash" , "--out-file" , registrationCertificate @@ -178,10 +151,7 @@ hprop_stake_pool_metadata_hash_url_wrong_metadata_fails :: Property hprop_stake_pool_metadata_hash_url_wrong_metadata_fails = propertyOnce . expectFailure $ do -- We run the test with the wrong metadata file - baseStakePoolMetadataHashUrl - exampleAnchorDataIpfsHash - exampleAnchorDataPathTest - exampleAnchorDataHash + baseStakePoolMetadataHashUrl dummyAnchorDataExample1 -- Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/stake pool metadata hash url wrong hash fails/"'@ @@ -189,41 +159,28 @@ hprop_stake_pool_metadata_hash_url_wrong_hash_fails :: Property hprop_stake_pool_metadata_hash_url_wrong_hash_fails = propertyOnce . expectFailure $ do -- We modify the hash slightly so that the hash check fails - alteredHash <- H.evalMaybe $ tamperBase16Hash exampleStakePoolMetadataHash + alteredHash <- H.evalMaybe $ tamperAnchorDataExampleHash stakePoolMetadataExample -- We run the test with the modified hash - baseStakePoolMetadataHashUrl - exampleStakePoolMetadataIpfsHash - exampleStakePoolMetadataPathTest - alteredHash + baseStakePoolMetadataHashUrl alteredHash -- Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/stake pool metadata hash url correct hash/"'@ hprop_stake_pool_metadata_hash_url_correct_hash :: Property hprop_stake_pool_metadata_hash_url_correct_hash = - propertyOnce $ - baseStakePoolMetadataHashUrl - exampleStakePoolMetadataIpfsHash - exampleStakePoolMetadataPathTest - exampleStakePoolMetadataHash + propertyOnce $ baseStakePoolMetadataHashUrl stakePoolMetadataExample baseStakePoolMetadataHashUrl :: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) - => String - -- ^ The ipfs hash of the file for the URL name - -> FilePath - -- ^ File to use as the metadata file - -> String - -- ^ The hash to check against. Changing this value allows us to test the - -- behavior of the command both when the hash is correct and when it is incorrect - -- reusing the same code. + => AnchorDataExample + -- ^ Information about the example anchor data to use -> m () -baseStakePoolMetadataHashUrl ipfsHash metadataFile hash = do - let relativeUrl = ["ipfs", ipfsHash] +baseStakePoolMetadataHashUrl anchorDataExample = do + let relativeUrl = ["ipfs", anchorDataIpfsHash anchorDataExample] -- Create temporary HTTP server with files required by the call to `cardano-cli` -- In this case, the server emulates an IPFS gateway serveFilesWhile - [ (relativeUrl, metadataFile) + [ (relativeUrl, anchorDataPathTest anchorDataExample) ] ( \port -> do void $ @@ -233,8 +190,8 @@ baseStakePoolMetadataHashUrl ipfsHash metadataFile hash = do , "stake-pool" , "metadata-hash" , "--pool-metadata-url" - , "ipfs://" ++ ipfsHash + , "ipfs://" ++ anchorDataIpfsHash anchorDataExample , "--expected-hash" - , hash + , anchorDataHash anchorDataExample ] ) diff --git a/cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt b/cardano-cli/test/cardano-cli-test/files/input/example_anchor_data1.txt similarity index 100% rename from cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt rename to cardano-cli/test/cardano-cli-test/files/input/example_anchor_data1.txt