Skip to content

Commit

Permalink
Test for key non-extended-key command for StakeExtendedVerificationKe…
Browse files Browse the repository at this point in the history
…yShelley_ed25519_bip32 envelope
  • Loading branch information
newhoggy committed Feb 28, 2023
1 parent aa162eb commit d06b496
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
7 changes: 6 additions & 1 deletion cardano-cli/test/Test/Golden/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ keyTests :: IO Bool
keyTests =
H.checkSequential
$ H.Group "Key command group"
[ ("golden_KeyNonExtendedKey", Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey)
[ ( "golden_KeyNonExtendedKey_GenesisExtendedVerificationKey"
, Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey_GenesisExtendedVerificationKey
)
, ( "golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley"
, Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley
)
]
41 changes: 32 additions & 9 deletions cardano-cli/test/Test/Golden/Key/NonExtendedKey.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Key.NonExtendedKey
( golden_KeyNonExtendedKey
( golden_KeyNonExtendedKey_GenesisExtendedVerificationKey
, golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley
) where

import Control.Monad (void)
Expand All @@ -10,30 +11,52 @@ import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import System.FilePath ((</>))
import Test.OptParse (execCardanoCLI, propertyOnce)
import Test.Utilities (diffVsGoldenFile)
import Test.Utilities (diffFileVsGoldenFile)

{- HLINT ignore "Use camelCase" -}

-- | Test that converting a @cardano-address@ Byron signing key yields the
-- expected result.
golden_KeyNonExtendedKey :: Property
golden_KeyNonExtendedKey =
golden_KeyNonExtendedKey_GenesisExtendedVerificationKey :: Property
golden_KeyNonExtendedKey_GenesisExtendedVerificationKey =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
genesisVKeyFp <- H.note "test/data/golden/key/non-extended-keys/shelley.000.vkey"
nonExtendedGenesisVKeyFp <- H.note $ tempDir </> "non-extended-shelley.000.vkey"
nonExtendedFp <- H.note "test/data/golden/key/non-extended-keys/non-extended-shelley.000.vkey"
outFp <- H.note $ tempDir </> "non-extended-shelley.000.vkey"

H.assertFilesExist [genesisVKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "key", "non-extended-key"
, "--extended-verification-key-file", genesisVKeyFp
, "--verification-key-file", nonExtendedGenesisVKeyFp
, "--verification-key-file", outFp
]

-- Check for existence of the converted signing key file
H.assertFilesExist [nonExtendedGenesisVKeyFp]
H.assertFilesExist [outFp]

contents <- H.readFile nonExtendedGenesisVKeyFp
diffFileVsGoldenFile outFp nonExtendedFp

diffVsGoldenFile contents nonExtendedGenesisVKeyFp
-- | Test that converting a @cardano-address@ Byron signing key yields the
-- expected result.
golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley :: Property
golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
genesisVKeyFp <- H.note "test/data/golden/key/non-extended-keys/stake.000.vkey"
nonExtendedFp <- H.note "test/data/golden/key/non-extended-keys/non-extended-stake.000.vkey"
outFp <- H.note $ tempDir </> "non-extended-stake.000.vkey"

H.assertFilesExist [genesisVKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "key", "non-extended-key"
, "--extended-verification-key-file", genesisVKeyFp
, "--verification-key-file", outFp
]

-- Check for existence of the converted signing key file
H.assertFilesExist [outFp]

diffFileVsGoldenFile outFp nonExtendedFp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "GenesisVerificationKey_ed25519",
"description": "",
"cborHex": "58200834b58f4bdda9522bb202af1f546db4cbbd94b068ae72c9fd96d9b55279edf0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "StakeVerificationKeyShelley_ed25519",
"description": "",
"cborHex": "58200f205175c0a47cba409c328f066e31ea4e81ef211f539c12b64b4b14e1d87188"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "StakeExtendedVerificationKeyShelley_ed25519_bip32",
"description": "",
"cborHex": "58400f205175c0a47cba409c328f066e31ea4e81ef211f539c12b64b4b14e1d87188a54f03c3edad073428f37dbdad714b7c07371ca19fe66c72d41fda23a81d8309"
}

0 comments on commit d06b496

Please sign in to comment.