-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for local file hashing in
hash anchor-data
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module Test.Cli.Hash where | ||
|
||
import Control.Monad (void) | ||
import Data.List (intercalate) | ||
import GHC.IO.Exception (ExitCode (ExitFailure)) | ||
import System.Directory (getCurrentDirectory) | ||
import System.FilePath (dropTrailingPathSeparator) | ||
import System.FilePath.Posix (splitDirectories) | ||
|
||
import Test.Cardano.CLI.Util | ||
|
||
import Hedgehog as H | ||
import qualified Hedgehog.Extras as H | ||
|
||
exampleAnchorDataHash :: String | ||
exampleAnchorDataHash = "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" | ||
|
||
exampleAnchorDataPath :: String | ||
exampleAnchorDataPath = "test/cardano-cli-test/files/input/example_anchor_data.txt" | ||
|
||
-- | Execute me with: | ||
-- @cabal test cardano-cli-test --test-options '-p "/generate anchor data hash from file/"'@ | ||
hprop_generate_anchor_data_hash_from_file :: Property | ||
hprop_generate_anchor_data_hash_from_file = | ||
propertyOnce $ do | ||
result <- | ||
execCardanoCLI | ||
[ "hash" | ||
, "anchor-data" | ||
, "--file-binary" | ||
, exampleAnchorDataPath | ||
] | ||
result === exampleAnchorDataHash | ||
|
||
-- | 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 | ||
void $ | ||
execCardanoCLI | ||
[ "hash" | ||
, "anchor-data" | ||
, "--file-binary" | ||
, exampleAnchorDataPath | ||
, "--expected-hash" | ||
, exampleAnchorDataHash | ||
] | ||
|
||
-- | Execute me with: | ||
-- @cabal test cardano-cli-test --test-options '-p "/check anchor data hash from file fails/"'@ | ||
hprop_check_anchor_data_hash_from_file_fails :: Property | ||
hprop_check_anchor_data_hash_from_file_fails = | ||
propertyOnce $ do | ||
(ec, _, _) <- | ||
execDetailCardanoCLI | ||
[ "hash" | ||
, "anchor-data" | ||
, "--file-binary" | ||
, exampleAnchorDataPath | ||
, "--expected-hash" | ||
, 'c' : drop 1 exampleAnchorDataHash | ||
] | ||
ec === ExitFailure 1 | ||
|
||
-- | Execute me with: | ||
-- @cabal test cardano-cli-test --test-options '-p "/generate anchor data hash from file uri/"'@ | ||
hprop_generate_anchor_data_hash_from_file_uri :: Property | ||
hprop_generate_anchor_data_hash_from_file_uri = | ||
propertyOnce $ do | ||
cwd <- H.evalIO getCurrentDirectory | ||
posixCwd <- toPOSIX cwd | ||
result <- | ||
execCardanoCLI | ||
[ "hash" | ||
, "anchor-data" | ||
, "--url" | ||
, "file://" ++ posixCwd ++ "/" ++ exampleAnchorDataPath | ||
] | ||
result === exampleAnchorDataHash | ||
where | ||
toPOSIX :: FilePath -> PropertyT IO [Char] | ||
toPOSIX path = | ||
case map dropTrailingPathSeparator (splitDirectories path) of | ||
letter : restOfPath -> do | ||
fixedLetter <- case letter of | ||
'/' : _ -> return "" | ||
l : ':' : _ -> return $ l : ":/" | ||
wrongLetter -> do | ||
H.note_ ("Unexpected letter: " ++ wrongLetter) | ||
H.failure | ||
return $ fixedLetter ++ intercalate "/" (fixedLetter : restOfPath) | ||
[] -> do | ||
H.note_ ("Path doesn't split:" ++ path) | ||
H.failure |
2 changes: 2 additions & 0 deletions
2
cardano-cli/test/cardano-cli-test/files/input/example_anchor_data.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This is just a random file with content that is used for | ||
testing the hashing of anchor data files. |