-
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.
Test URL functionality for
governance drep metadata-hash
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 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
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
3 changes: 3 additions & 0 deletions
3
...rdano-cli-golden/files/golden/governance/drep/drep_metadata_hash_url_wrong_hash_fails.out
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,3 @@ | ||
Command failed: governance drep metadata-hash Error: Hashes do not match! | ||
Expected: "ee38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" | ||
Actual: "de38a4f5b8b9d8372386cc923bad19d1a0662298cf355bbe947e5eedf127fa9c" |
60 changes: 60 additions & 0 deletions
60
cardano-cli/test/cardano-cli-test/Test/Cli/DRepMetadata.hs
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,60 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
|
||
module Test.Cli.DRepMetadata where | ||
|
||
import Cardano.Api (MonadIO) | ||
|
||
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.Util (execCardanoCLIWithEnvVars, expectFailure, propertyOnce) | ||
|
||
import Hedgehog (Property) | ||
import qualified Hedgehog as H | ||
import Hedgehog.Internal.Property (MonadTest) | ||
|
||
-- Execute me with: | ||
-- @cabal test cardano-cli-test --test-options '-p "/drep metadata hash url wrong hash fails/"'@ | ||
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 | ||
-- We run the test with the modified hash | ||
baseDrepMetadataHashUrl alteredHash | ||
|
||
-- Execute me with: | ||
-- @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 | ||
|
||
baseDrepMetadataHashUrl | ||
:: (MonadBaseControl IO m, MonadTest m, MonadIO m, MonadCatch m) | ||
=> String | ||
-> m () | ||
baseDrepMetadataHashUrl hash = do | ||
let relativeUrl = ["ipfs", exampleAnchorDataIpfsHash] | ||
|
||
-- 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) | ||
] | ||
( \port -> do | ||
void $ | ||
execCardanoCLIWithEnvVars | ||
[("IPFS_GATEWAY_URI", "http://localhost:" ++ show port ++ "/")] | ||
[ "conway" | ||
, "governance" | ||
, "drep" | ||
, "metadata-hash" | ||
, "--drep-metadata-url" | ||
, "ipfs://" ++ exampleAnchorDataIpfsHash | ||
, "--expected-hash" | ||
, hash | ||
] | ||
) |