Skip to content

Commit

Permalink
Rebase on master and update Byron signing key serialisation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jan 11, 2021
1 parent deb5038 commit ad9f835
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
8 changes: 6 additions & 2 deletions cardano-cli/src/Cardano/CLI/Byron/Run.hs
Expand Up @@ -21,7 +21,8 @@ import qualified Cardano.Crypto.Hashing as Crypto
import qualified Cardano.Crypto.Signing as Crypto

import Cardano.Api hiding (UpdateProposal)
import Cardano.Api.Byron (Tx (..), VerificationKey (..))
import Cardano.Api.Byron (ByronWitness (..), SigningKey (..), Tx (..),
VerificationKey (..))

import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)
Expand Down Expand Up @@ -130,7 +131,10 @@ runMigrateDelegateKeyFrom
-> ExceptT ByronClientCmdError IO ()
runMigrateDelegateKeyFrom oldKeyformat oldKey (NewSigningKeyFile newKey) = do
sk <- firstExceptT ByronCmdKeyFailure $ readByronSigningKey oldKeyformat oldKey
firstExceptT ByronCmdHelpersError . ensureNewFileLBS newKey $ serialiseByronWitness sk
migratedWitness <- case sk of
LegacyWitness (ByronSigningKeyLegacy sKey) -> return . NonLegacyWitness $ ByronSigningKey sKey
NonLegacyWitness _ -> panic "TODO: Can only migrate from legacy witness"
firstExceptT ByronCmdHelpersError . ensureNewFileLBS newKey $ serialiseByronWitness migratedWitness

runPrintGenesisHash :: GenesisFile -> ExceptT ByronClientCmdError IO ()
runPrintGenesisHash genFp = do
Expand Down
33 changes: 21 additions & 12 deletions cardano-cli/test/Test/Golden/Byron/SigningKeys.hs
Expand Up @@ -12,13 +12,14 @@ 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.Api.Byron

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

import Hedgehog (Property, checkParallel, discover, property, success)
import Hedgehog (Group (..), Property, checkSequential, property, success)
import qualified Hedgehog.Extras.Test.Base as H
import Hedgehog.Internal.Property (failWith)
import Test.OptParse
Expand Down Expand Up @@ -71,12 +72,10 @@ prop_print_nonLegacy_signing_key_address = propertyOnce $ do

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
byronSkey <- liftIO keygen
case deserialiseFromRawBytes (AsSigningKey AsByronKey) (serialiseToRawBytes byronSkey ) of
Nothing -> failWith Nothing $ "Failed to deserialise non-legacy Byron signing key."
Just _ -> success

prop_migrate_legacy_to_nonlegacy_signingkeys :: Property
prop_migrate_legacy_to_nonlegacy_signingkeys =
Expand All @@ -88,11 +87,10 @@ prop_migrate_legacy_to_nonlegacy_signingkeys =
[ "migrate-delegate-key-from"
, "--byron-legacy-formats"
, "--from", legKeyFp
, "--byron-formats"
, "--to", nonLegacyKeyFp
]

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

case eSignKey of
Expand All @@ -117,4 +115,15 @@ prop_deserialiseLegacy_Signing_Key_API = propertyOnce $ do

tests :: IO Bool
tests =
checkParallel $$discover
checkSequential
$ Group "Byron Signing Key Serialisation"
[ ("prop_deserialise_legacy_signing_Key", prop_deserialise_legacy_signing_Key)
, ("prop_print_legacy_signing_key_address", prop_print_legacy_signing_key_address)
, ("prop_deserialise_nonLegacy_signing_Key", prop_deserialise_nonLegacy_signing_Key)
, ("prop_print_nonLegacy_signing_key_address", prop_print_nonLegacy_signing_key_address)
, ("prop_generate_and_read_nonlegacy_signingkeys", prop_generate_and_read_nonlegacy_signingkeys)
, ("prop_migrate_legacy_to_nonlegacy_signingkeys", prop_migrate_legacy_to_nonlegacy_signingkeys)
, ("prop_deserialise_NonLegacy_Signing_Key_API", prop_deserialise_NonLegacy_Signing_Key_API)
, ("prop_deserialiseLegacy_Signing_Key_API", prop_deserialiseLegacy_Signing_Key_API)
]

0 comments on commit ad9f835

Please sign in to comment.