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