Skip to content

Commit

Permalink
Merge #2271
Browse files Browse the repository at this point in the history
2271: Add various property tests for legacy and non-legacy byron era signing keys r=Jimbo4350 a=Jimbo4350



Co-authored-by: Jordan Millar <[email protected]>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 authored Jan 8, 2021
2 parents e699e87 + e581d84 commit 8e0501f
Showing 1 changed file with 73 additions and 5 deletions.
78 changes: 73 additions & 5 deletions cardano-cli/test/Test/Golden/Byron/SigningKeys.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,94 @@ import qualified Data.ByteString.Lazy as LB

import qualified Cardano.Crypto.Signing as Crypto

import Cardano.CLI.Byron.Key (deserialiseSigningKey, keygen, readEraSigningKey,
serialiseSigningKey)
import Cardano.CLI.Byron.Legacy (decodeLegacyDelegateKey)
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Types (SigningKeyFile (..))

import Hedgehog (Property, checkParallel, discover, success)
import Hedgehog (Property, checkParallel, discover, property, success)
import qualified Hedgehog.Extras.Test.Base as H
import Hedgehog.Internal.Property (failWith)
import Test.OptParse

prop_deserialise_Legacy_Signing_Key :: Property
prop_deserialise_Legacy_Signing_Key = propertyOnce $ do
prop_deserialise_legacy_signing_Key :: Property
prop_deserialise_legacy_signing_Key = propertyOnce $ do
legSkeyBs <- liftIO $ LB.readFile "test/data/golden/byron/keys/legacy.skey"
case deserialiseFromBytes decodeLegacyDelegateKey legSkeyBs of
Left deSerFail -> failWith Nothing $ show deSerFail
Right _ -> success

prop_deserialise_NonLegacy_Signing_Key :: Property
prop_deserialise_NonLegacy_Signing_Key = propertyOnce $ do
prop_deserialise_nonLegacy_signing_Key :: Property
prop_deserialise_nonLegacy_signing_Key = propertyOnce $ do
skeyBs <- liftIO $ LB.readFile "test/data/golden/byron/keys/byron.skey"
case deserialiseFromBytes Crypto.fromCBORXPrv skeyBs of
Left deSerFail -> failWith Nothing $ show deSerFail
Right _ -> success

prop_print_legacy_signing_key_address :: Property
prop_print_legacy_signing_key_address = propertyOnce $ do
let legKeyFp = "test/data/golden/byron/keys/legacy.skey"

void $ execCardanoCLI
[ "signing-key-address", "--byron-legacy-formats"
, "--testnet-magic", "42"
, "--secret", legKeyFp
]

void $ execCardanoCLI
[ "signing-key-address", "--byron-legacy-formats"
, "--mainnet"
, "--secret", legKeyFp
]

prop_print_nonLegacy_signing_key_address :: Property
prop_print_nonLegacy_signing_key_address = propertyOnce $ do
let nonLegKeyFp = "test/data/golden/byron/keys/byron.skey"

void $ execCardanoCLI
[ "signing-key-address", "--byron-formats"
, "--testnet-magic", "42"
, "--secret", nonLegKeyFp
]

void $ execCardanoCLI
[ "signing-key-address", "--byron-formats"
, "--mainnet"
, "--secret", nonLegKeyFp
]

prop_generate_and_read_nonlegacy_signingkeys :: Property
prop_generate_and_read_nonlegacy_signingkeys = property $ do
byronSkey <- liftIO $ keygen Crypto.emptyPassphrase
case serialiseSigningKey NonLegacyByronKeyFormat byronSkey of
Left err -> failWith Nothing $ show err
Right sKeyBS -> case deserialiseSigningKey NonLegacyByronKeyFormat "" sKeyBS of
Left err -> failWith Nothing $ show err
Right _ -> success

prop_migrate_legacy_to_nonlegacy_signingkeys :: Property
prop_migrate_legacy_to_nonlegacy_signingkeys =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
let legKeyFp = "test/data/golden/byron/keys/legacy.skey"
nonLegacyKeyFp <- noteTempFile tempDir "nonlegacy.skey"

void $ execCardanoCLI
[ "migrate-delegate-key-from"
, "--byron-legacy-formats"
, "--from", legKeyFp
, "--byron-formats"
, "--to", nonLegacyKeyFp
]

eSignKey <- liftIO . runExceptT . readEraSigningKey NonLegacyByronKeyFormat
$ SigningKeyFile nonLegacyKeyFp

case eSignKey of
Left err -> failWith Nothing $ show err
Right _ -> success


-- -----------------------------------------------------------------------------

tests :: IO Bool
Expand Down

0 comments on commit 8e0501f

Please sign in to comment.