Skip to content

Commit

Permalink
Add CLI golden tests for new cardano-address key conversion command
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Sep 14, 2020
1 parent ce78c11 commit a7ab18a
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -235,6 +235,7 @@ test-suite cardano-cli-golden
Test.Golden.Shelley.Genesis.KeyGenGenesis
Test.Golden.Shelley.Genesis.KeyGenUtxo
Test.Golden.Shelley.Genesis.KeyHash
Test.Golden.Shelley.Key.ConvertCardanoAddressKey
Test.Golden.Shelley.Node.IssueOpCert
Test.Golden.Shelley.Node.KeyGen
Test.Golden.Shelley.Node.KeyGenKes
Expand Down
16 changes: 16 additions & 0 deletions cardano-cli/test/Test/Golden/Shelley.hs
Expand Up @@ -3,6 +3,7 @@
module Test.Golden.Shelley
( keyTests
, certificateTests
, keyConversionTests
, metaDatatests
, multiSigTests
, txTests
Expand All @@ -19,6 +20,11 @@ import Test.Golden.Shelley.Genesis.KeyGenDelegate (golden_shelleyGenes
import Test.Golden.Shelley.Genesis.KeyGenGenesis (golden_shelleyGenesisKeyGenGenesis)
import Test.Golden.Shelley.Genesis.KeyGenUtxo (golden_shelleyGenesisKeyGenUtxo)
import Test.Golden.Shelley.Genesis.KeyHash (golden_shelleyGenesisKeyHash)
import Test.Golden.Shelley.Key.ConvertCardanoAddressKey
(golden_convertCardanoAddressByronSigningKey,
golden_convertCardanoAddressIcarusSigningKey,
golden_convertCardanoAddressShelleyPaymentSigningKey,
golden_convertCardanoAddressShelleyStakeSigningKey)
import Test.Golden.Shelley.Node.IssueOpCert (golden_shelleyNodeIssueOpCert)
import Test.Golden.Shelley.Node.KeyGen (golden_shelleyNodeKeyGen)
import Test.Golden.Shelley.Node.KeyGenKes (golden_shelleyNodeKeyGenKes)
Expand Down Expand Up @@ -126,6 +132,16 @@ certificateTests =
, ("golden_shelleyGenesisKeyDelegationCertificate", golden_shelleyGenesisKeyDelegationCertificate)
]

keyConversionTests :: IO Bool
keyConversionTests =
H.checkSequential
$ H.Group "Key Conversion Goldens"
[ ("golden_convertCardanoAddressByronSigningKey", golden_convertCardanoAddressByronSigningKey)
, ("golden_convertCardanoAddressIcarusSigningKey", golden_convertCardanoAddressIcarusSigningKey)
, ("golden_convertCardanoAddressShelleyPaymentSigningKey", golden_convertCardanoAddressShelleyPaymentSigningKey)
, ("golden_convertCardanoAddressShelleyStakeSigningKey", golden_convertCardanoAddressShelleyStakeSigningKey)
]

metaDatatests :: IO Bool
metaDatatests =
H.checkSequential
Expand Down
190 changes: 190 additions & 0 deletions cardano-cli/test/Test/Golden/Shelley/Key/ConvertCardanoAddressKey.hs
@@ -0,0 +1,190 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Shelley.Key.ConvertCardanoAddressKey
( golden_convertCardanoAddressByronSigningKey
, golden_convertCardanoAddressIcarusSigningKey
, golden_convertCardanoAddressShelleyPaymentSigningKey
, golden_convertCardanoAddressShelleyStakeSigningKey
) where

import Cardano.Prelude hiding (readFile)

import Hedgehog (Property, (===))

import Test.OptParse

{- HLINT ignore "Reduce duplication" -}

-- | An example signing key generated by @cardano-address@ using the
-- deprecated Byron style.
exampleByronSigningKey :: Text
exampleByronSigningKey =
"xprv1pp72a64en2vf568jywe9azlgrqe3p2jjf9gxxeejn2fex8g889x54w6emg2egkaz2rxyc"
<> "560fp0hrv8y0hzpuzu27zhhhgwc8t5tvrczz2jnhhjwdnd6cdjx4dxehrsr2pr406rchw"
<> "ctfwrgpc9r7nmakvaegyz9"

-- | An example signing key generated by @cardano-address@ using the Icarus
-- style.
exampleIcarusSigningKey :: Text
exampleIcarusSigningKey =
"xprv1yq7c6nlmxncg7txy0z6lqf3fww4vm20m60lrxttx5lr4qmkvh395m3p59v8fn4ku9mzyc"
<> "g2rkxatgwm86uc3pvrt06e43afya6rm0s2azlpnc9yrhygl2heckeyhhtgad08c0zljpn"
<> "c6fse2ldzyx9c86yvddxjw"

-- | An example signing key generated by @cardano-address@ using the Shelley
-- style.
exampleShelleySigningKey :: Text
exampleShelleySigningKey =
"xprv1yq7c6nlmxncg7txy0z6lqf3fww4vm20m60lrxttx5lr4qmkvh395m3p59v8fn4ku9mzyc"
<> "g2rkxatgwm86uc3pvrt06e43afya6rm0s2azlpnc9yrhygl2heckeyhhtgad08c0zljpn"
<> "c6fse2ldzyx9c86yvddxjw"

-- | Test that converting a @cardano-address@ Byron signing key yields the
-- expected result.
golden_convertCardanoAddressByronSigningKey :: Property
golden_convertCardanoAddressByronSigningKey =
propertyOnce . moduleWorkspace "tmp" $ \tempDir -> do

-- `cardano-address` signing key filepath
signingKeyFp <- noteTempFile tempDir "cardano-address-byron.skey"

-- Converted signing key filepath
convertedSigningKeyFp <-
noteTempFile tempDir "converted-cardano-address-byron.skey"

-- Write `cardano-address` signing key to disk
liftIO $ writeFile signingKeyFp exampleByronSigningKey
assertFilesExist [signingKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "shelley","key","convert-cardano-address-key"
, "--byron-payment-key"
, "--signing-key-file", signingKeyFp
, "--out-file", convertedSigningKeyFp
]

-- Check for existence of the converted signing key file
assertFilesExist [convertedSigningKeyFp]

-- Check that the contents of the converted signing key file match that of
-- the golden file.
actualConvertedSigningKey <- readFile convertedSigningKeyFp
expectedConvertedSigningKey <-
readFile $
"test/data/golden/shelley/keys/converted_cardano-address_keys/"
<> "byron_signing_key"
expectedConvertedSigningKey === actualConvertedSigningKey

-- | Test that converting a @cardano-address@ Icarus signing key yields the
-- expected result.
golden_convertCardanoAddressIcarusSigningKey :: Property
golden_convertCardanoAddressIcarusSigningKey =
propertyOnce . moduleWorkspace "tmp" $ \tempDir -> do

-- `cardano-address` signing key filepath
signingKeyFp <- noteTempFile tempDir "cardano-address-icarus.skey"

-- Converted signing key filepath
convertedSigningKeyFp <-
noteTempFile tempDir "converted-cardano-address-icarus.skey"

-- Write `cardano-address` signing key to disk
liftIO $ writeFile signingKeyFp exampleIcarusSigningKey
assertFilesExist [signingKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "shelley","key","convert-cardano-address-key"
, "--icarus-payment-key"
, "--signing-key-file", signingKeyFp
, "--out-file", convertedSigningKeyFp
]

-- Check for existence of the converted signing key file
assertFilesExist [convertedSigningKeyFp]

-- Check that the contents of the converted signing key file match that of
-- the golden file.
actualConvertedSigningKey <- readFile convertedSigningKeyFp
expectedConvertedSigningKey <-
readFile $
"test/data/golden/shelley/keys/converted_cardano-address_keys/"
<> "icarus_signing_key"
expectedConvertedSigningKey === actualConvertedSigningKey

-- | Test that converting a @cardano-address@ Shelley payment signing key
-- yields the expected result.
golden_convertCardanoAddressShelleyPaymentSigningKey :: Property
golden_convertCardanoAddressShelleyPaymentSigningKey =
propertyOnce . moduleWorkspace "tmp" $ \tempDir -> do

-- `cardano-address` signing key filepath
signingKeyFp <-
noteTempFile tempDir "cardano-address-shelley-payment.skey"

-- Converted signing key filepath
convertedSigningKeyFp <-
noteTempFile tempDir "converted-cardano-address-shelley-payment.skey"

-- Write `cardano-address` signing key to disk
liftIO $ writeFile signingKeyFp exampleShelleySigningKey
assertFilesExist [signingKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "shelley","key","convert-cardano-address-key"
, "--shelley-payment-key"
, "--signing-key-file", signingKeyFp
, "--out-file", convertedSigningKeyFp
]

-- Check for existence of the converted signing key file
assertFilesExist [convertedSigningKeyFp]

-- Check that the contents of the converted signing key file match that of
-- the golden file.
actualConvertedSigningKey <- readFile convertedSigningKeyFp
expectedConvertedSigningKey <-
readFile $
"test/data/golden/shelley/keys/converted_cardano-address_keys/"
<> "shelley_payment_signing_key"
expectedConvertedSigningKey === actualConvertedSigningKey

-- | Test that converting a @cardano-address@ Shelley stake signing key yields
-- the expected result.
golden_convertCardanoAddressShelleyStakeSigningKey :: Property
golden_convertCardanoAddressShelleyStakeSigningKey =
propertyOnce . moduleWorkspace "tmp" $ \tempDir -> do

-- `cardano-address` signing key filepath
signingKeyFp <-
noteTempFile tempDir "cardano-address-shelley-stake.skey"

-- Converted signing key filepath
convertedSigningKeyFp <-
noteTempFile tempDir "converted-cardano-address-shelley-stake.skey"

-- Write `cardano-address` signing key to disk
liftIO $ writeFile signingKeyFp exampleShelleySigningKey
assertFilesExist [signingKeyFp]

-- Convert the `cardano-address` signing key
void $ execCardanoCLI
[ "shelley","key","convert-cardano-address-key"
, "--shelley-stake-key"
, "--signing-key-file", signingKeyFp
, "--out-file", convertedSigningKeyFp
]

-- Check for existence of the converted signing key file
assertFilesExist [convertedSigningKeyFp]

-- Check that the contents of the converted signing key file match that of
-- the golden file.
actualConvertedSigningKey <- readFile convertedSigningKeyFp
expectedConvertedSigningKey <-
readFile $
"test/data/golden/shelley/keys/converted_cardano-address_keys/"
<> "shelley_stake_signing_key"
expectedConvertedSigningKey === actualConvertedSigningKey
1 change: 1 addition & 0 deletions cardano-cli/test/cardano-cli-golden.hs
Expand Up @@ -9,6 +9,7 @@ main =
defaultMain
[ Test.Golden.Shelley.keyTests
, Test.Golden.Shelley.certificateTests
, Test.Golden.Shelley.keyConversionTests
, Test.Golden.Shelley.metaDatatests
, Test.Golden.Shelley.multiSigTests
, Test.Golden.Shelley.txTests
Expand Down
@@ -0,0 +1,5 @@
{
"type": "PaymentSigningKeyByron_ed25519_bip32",
"description": "",
"cborHex": "5880087caeeab99a989a68f223b25e8be8183310aa5249506367329a93931d07394d4abb59da15945ba250cc4c534f485f71b0e47dc41e0b8af0af7ba1d83ae8b60f975e5b024cda7923bacc4c25cca498b9e67380dfe588764b614d8e7a37656dfd0212a53bde4e6cdbac3646ab4d9b8e03504757e878bbb0b4b8680e0a3f4f7db3"
}
@@ -0,0 +1,5 @@
{
"type": "PaymentSigningKeyByron_ed25519_bip32",
"description": "",
"cborHex": "5880203d8d4ffb34f08f2cc478b5f0262973aacda9fbd3fe332d66a7c7506eccbc4b4dc4342b0e99d6dc2ec44c2143b1bab43b67d73110b06b7eb358f524ee87b7c13ceae36bc0e1fbaacbcb259f9342c322459015ea351bc0f644d93de7d0099a735d17c33c1483b911f55f38b6497bad1d6bcf878bf20cf1a4c32afb44431707d1"
}
@@ -0,0 +1,5 @@
{
"type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
"description": "",
"cborHex": "5880203d8d4ffb34f08f2cc478b5f0262973aacda9fbd3fe332d66a7c7506eccbc4b4dc4342b0e99d6dc2ec44c2143b1bab43b67d73110b06b7eb358f524ee87b7c13ceae36bc0e1fbaacbcb259f9342c322459015ea351bc0f644d93de7d0099a735d17c33c1483b911f55f38b6497bad1d6bcf878bf20cf1a4c32afb44431707d1"
}
@@ -0,0 +1,5 @@
{
"type": "StakeExtendedSigningKeyShelley_ed25519_bip32",
"description": "",
"cborHex": "5880203d8d4ffb34f08f2cc478b5f0262973aacda9fbd3fe332d66a7c7506eccbc4b4dc4342b0e99d6dc2ec44c2143b1bab43b67d73110b06b7eb358f524ee87b7c13ceae36bc0e1fbaacbcb259f9342c322459015ea351bc0f644d93de7d0099a735d17c33c1483b911f55f38b6497bad1d6bcf878bf20cf1a4c32afb44431707d1"
}

0 comments on commit a7ab18a

Please sign in to comment.