diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index f08e16551a..3133853714 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -334,6 +334,7 @@ test-suite cardano-cli-test Test.Cli.Pioneers.Exercise6 Test.Cli.Pipes Test.Cli.VerificationKey + Test.Cli.Shelley.Run.Hash Test.Cli.Shelley.Run.Query Test.Cli.Shelley.Transaction.Build @@ -394,9 +395,9 @@ test-suite cardano-cli-golden Test.Golden.Governance.Action Test.Golden.Governance.Committee Test.Golden.Governance.DRep - Test.Golden.Governance.Hash Test.Golden.Governance.StakeAddress Test.Golden.Governance.Vote + Test.Golden.Hash.Hash Test.Golden.Help Test.Golden.Key.NonExtendedKey Test.Golden.Shelley.Address.Build 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 abc00ac654..60ea9205e7 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 @@ -27,11 +27,11 @@ hprop_golden_governance_action_create_constitution = redactedActionFile <- noteTempFile tempDir "create-constitution.action.redacted" proposalHash <- execCardanoCLI - [ "conway", "hash", "anchor-data" + [ "hash", "anchor-data" , "--text", "whatever"] constitutionHash <- execCardanoCLI - [ "conway", "hash", "anchor-data" + [ "hash", "anchor-data" , "--text", "something else"] void $ execCardanoCLI @@ -63,7 +63,7 @@ hprop_golden_conway_governance_action_view_constitution_json = -- We go through a file for the hash, to test --out-file void $ execCardanoCLI - [ "conway", "hash", "anchor-data" + [ "hash", "anchor-data" , "--text", "whatever " , "--out-file", hashFile ] @@ -71,7 +71,7 @@ hprop_golden_conway_governance_action_view_constitution_json = proposalHash <- H.readFile hashFile constitutionHash <- execCardanoCLI - [ "conway", "hash", "anchor-data" + [ "hash", "anchor-data" , "--text", "nonAsciiInput: 你好 and some more: こんにちは" ] @@ -242,4 +242,4 @@ hprop_golden_conway_governance_action_create_hardfork = ] goldenActionFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/hardfork/conway-create-hardfork.action" - H.diffFileVsGoldenFile actionFile goldenActionFile \ No newline at end of file + H.diffFileVsGoldenFile actionFile goldenActionFile 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 86a3029910..7de4f401af 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 @@ -120,7 +120,7 @@ hprop_golden_governance_UpdateCommittee = outFile <- H.noteTempFile tempDir "answer-file.json" proposalHash <- execCardanoCLI - [ "conway", "hash", "anchor-data" + [ "hash", "anchor-data" , "--file-text", ccProposal ] H.note_ proposalHash diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Hash/Hash.hs similarity index 77% rename from cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs rename to cardano-cli/test/cardano-cli-golden/Test/Golden/Hash/Hash.hs index 78f80893e7..0ed7b04183 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Hash.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Hash/Hash.hs @@ -1,6 +1,6 @@ {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# HLINT ignore "Use camelCase" #-} -module Test.Golden.Governance.Hash where +module Test.Golden.Hash.Hash where import Control.Monad import Test.Cardano.CLI.Util @@ -13,12 +13,12 @@ import qualified Hedgehog.Extras.Test.Golden as H hprop_golden_governance_hash_script :: Property hprop_golden_governance_hash_script = H.propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do - scriptFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/hash/foo.script" + scriptFile <- noteInputFile "test/cardano-cli-golden/files/input/hash/foo.script" hashFile <- H.noteTempFile tempDir "foo.script.hash" - hashGold <- H.note "test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash" + hashGold <- H.note "test/cardano-cli-golden/files/golden/hash/foo.script.hash" void $ execCardanoCLI - [ "conway", "hash", "script" + [ "hash", "script" , "--script-file", scriptFile , "--out-file", hashFile ] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash b/cardano-cli/test/cardano-cli-golden/files/golden/hash/foo.script.hash similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/golden/governance/hash/foo.script.hash rename to cardano-cli/test/cardano-cli-golden/files/golden/hash/foo.script.hash diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script b/cardano-cli/test/cardano-cli-golden/files/input/hash/foo.script similarity index 100% rename from cardano-cli/test/cardano-cli-golden/files/input/governance/hash/foo.script rename to cardano-cli/test/cardano-cli-golden/files/input/hash/foo.script diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs index 31d4701e57..c887b17698 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs @@ -12,37 +12,6 @@ import Hedgehog (Property) import qualified Hedgehog as H import qualified Hedgehog.Extras as H -hprop_governance_hash_trip :: Property -hprop_governance_hash_trip = - propertyOnce $ do - governance_hash_trip_fun "foo" - governance_hash_trip_fun "longerText" - governance_hash_trip_fun "nonAscii: 你好" - governance_hash_trip_fun "nonAscii: à la mode de Cæn" - --- Test that @cardano-cli conway governance hash --text > file1@ and --- @cardano-cli conway governance hash --text --out-file file2@ yields --- similar @file1@ and @file2@ files. -governance_hash_trip_fun :: String -> H.PropertyT IO () -governance_hash_trip_fun input = - H.moduleWorkspace "tmp" $ \tempDir -> do - hashFile <- noteTempFile tempDir "hash.txt" - - hash <- execCardanoCLI - [ "conway", "hash", "anchor-data" - , "--text", input - ] - - void $ execCardanoCLI - [ "conway", "hash", "anchor-data" - , "--text", input - , "--out-file", hashFile - ] - - hashFromFile <- H.readFile hashFile - - H.diff hash (==) hashFromFile - -- | Execute me with: -- @cabal test cardano-cli-test --test-options '-p "/governance committee key hash/"'@ hprop_governance_committee_key_hash :: Property diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Run/Hash.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Run/Hash.hs new file mode 100644 index 0000000000..92fe34de83 --- /dev/null +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Run/Hash.hs @@ -0,0 +1,43 @@ +{- HLINT ignore "Use camelCase" -} +{-# LANGUAGE TypeApplications #-} + +module Test.Cli.Shelley.Run.Hash where + +import Control.Monad (void) + +import Test.Cardano.CLI.Util + +import Hedgehog (Property) +import qualified Hedgehog as H +import qualified Hedgehog.Extras as H + +hprop_hash_trip :: Property +hprop_hash_trip = + propertyOnce $ do + hash_trip_fun "foo" + hash_trip_fun "longerText" + hash_trip_fun "nonAscii: 你好" + hash_trip_fun "nonAscii: à la mode de Cæn" + +-- Test that @cardano-cli hash --text > file1@ and +-- @cardano-cli --text --out-file file2@ yields +-- similar @file1@ and @file2@ files. +hash_trip_fun :: String -> H.PropertyT IO () +hash_trip_fun input = + H.moduleWorkspace "tmp" $ \tempDir -> do + hashFile <- noteTempFile tempDir "hash.txt" + + hash <- execCardanoCLI + [ "hash", "anchor-data" + , "--text", input + ] + + void $ execCardanoCLI + [ "hash", "anchor-data" + , "--text", input + , "--out-file", hashFile + ] + + hashFromFile <- H.readFile hashFile + + H.diff hash (==) hashFromFile