From 1cca3a649f75fbb9908645cdc28f67bff56257a0 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 15 Oct 2024 13:48:39 +0200 Subject: [PATCH] Add golden test for failed hash check in `governance committee create-cold-key-resignation-certificate` --- .../Test/Golden/Governance/Committee.hs | 68 ++++++++++++++++++- ...ance_committee_checks_wrong_hash_fails.out | 3 + 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out 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 5131cfddea..fc463dbe0b 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 @@ -5,16 +5,22 @@ module Test.Golden.Governance.Committee where import Control.Monad (forM_, void) +import Data.Monoid (Last (..)) +import qualified System.Environment as IO +import System.Exit (ExitCode (..)) import System.FilePath (()) import Test.Cardano.CLI.Aeson (assertHasMappings) +import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataIpfsHash, + exampleAnchorDataPathGolden, serveFilesWhile, tamperBase16Hash) import qualified Test.Cardano.CLI.Util as H hiding (noteTempFile) import Test.Cardano.CLI.Util import Hedgehog (Property) import qualified Hedgehog as H -import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras as H import qualified Hedgehog.Extras.Test.Golden as H +import Hedgehog.Internal.Property ((===)) goldenDir, inputDir :: FilePath goldenDir = "test/cardano-cli-golden/files/golden" @@ -322,3 +328,63 @@ hprop_golden_governance_extended_committee_key_hash = ] result H.=== expected + +-- Execute me with: +-- @cabal test cardano-cli-test --test-options '-p "/golden governance committee checks wrong hash fails/"'@ +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] + + ccColdVKey <- noteTempFile tempDir "cold.vkey" + ccColdSKey <- noteTempFile tempDir "cold.skey" + + certFile <- noteTempFile tempDir "hot-auth.cert" + + void $ + execCardanoCLI + [ "conway" + , "governance" + , "committee" + , "key-gen-cold" + , "--verification-key-file" + , ccColdVKey + , "--signing-key-file" + , ccColdSKey + ] + + -- Create temporary HTTP server with files required by the call to `cardano-cli` + env <- H.evalIO IO.getEnvironment + (exitCode, _, result) <- + serveFilesWhile + [ (relativeUrl, exampleAnchorDataPathGolden) + ] + ( \port -> do + execDetailConfigCardanoCLI + ( H.defaultExecConfig + { H.execConfigEnv = Last $ Just (("IPFS_GATEWAY_URI", "http://localhost:" ++ show port ++ "/") : env) + } + ) + [ "conway" + , "governance" + , "committee" + , "create-cold-key-resignation-certificate" + , "--cold-verification-key-file" + , ccColdVKey + , "--resignation-metadata-url" + , "ipfs://" ++ exampleAnchorDataIpfsHash + , "--resignation-metadata-hash" + , alteredHash + , "--check-resignation-metadata-hash" + , "--out-file" + , certFile + ] + ) + + exitCode === ExitFailure 1 + + H.diffVsGoldenFile + result + "test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out" diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out new file mode 100644 index 0000000000..901e798c65 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/governance_committee_checks_wrong_hash_fails.out @@ -0,0 +1,3 @@ +Command failed: governance committee create-cold-key-resignation-certificate Error: Error while checking metadata hash: Hashes do not match! +Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" + Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c"