Skip to content

Commit

Permalink
Adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jun 28, 2024
1 parent 60dad87 commit 2d0a701
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 42 deletions.
3 changes: 2 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,15 +63,15 @@ 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
]

proposalHash <- H.readFile hashFile

constitutionHash <- execCardanoCLI
[ "conway", "hash", "anchor-data"
[ "hash", "anchor-data"
, "--text", "nonAsciiInput: 你好 and some more: こんにちは"
]

Expand Down Expand Up @@ -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
H.diffFileVsGoldenFile actionFile goldenActionFile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
]
Expand Down
31 changes: 0 additions & 31 deletions cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Run/Hash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{- HLINT ignore "Use camelCase" -}
{-# LANGUAGE TypeApplications #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning test

cardano-cli/test/cardano-cli-test/Test/Cli/Shelley/Run/Hash.hs:2:1-33: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE TypeApplications #-}
  
Perhaps you should remove it.

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

0 comments on commit 2d0a701

Please sign in to comment.