Skip to content

Commit

Permalink
conway governance hash: add test that stdout and --out-file yield the…
Browse files Browse the repository at this point in the history
… same result
  • Loading branch information
smelc committed Nov 16, 2023
1 parent f216caa commit 6915ec0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ test-suite cardano-cli-test

other-modules: Test.Cli.CliIntermediateFormat
Test.Cli.FilePermissions
Test.Cli.Governance.Hash
Test.Cli.ITN
Test.Cli.JSON
Test.Cli.Pioneers.Exercise1
Expand Down
42 changes: 42 additions & 0 deletions cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{- HLINT ignore "Use camelCase" -}

module Test.Cli.Governance.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_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", "governance", "hash"
, "--text", input
]

void $ execCardanoCLI
[ "conway", "governance", "hash"
, "--text", input
, "--out-file", hashFile
]

hashFromFile <- H.readFile hashFile

H.diff hash (==) hashFromFile

0 comments on commit 6915ec0

Please sign in to comment.