Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository cardano-haskell-packages
-- See CONTRIBUTING for information about these, including some Nix commands
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-06-12T10:10:17Z
, hackage.haskell.org 2024-06-18T11:54:44Z
, cardano-haskell-packages 2024-06-12T10:10:17Z

packages:
Expand Down Expand Up @@ -45,3 +45,5 @@ write-ghc-environment-files: always
-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

-- Add upper bound to io-classes-mtl:
30 changes: 28 additions & 2 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ library
Cardano.CLI.Orphans
Cardano.CLI.OS.Posix
Cardano.CLI.Parser
Cardano.CLI.Polysemy
Cardano.CLI.Pretty
Cardano.CLI.Read
Cardano.CLI.Render
Expand Down Expand Up @@ -228,6 +229,7 @@ library
, directory
, filepath
, formatting
, hw-polysemy:core ^>= 0.2.8.0
, io-classes
, iproute
, mtl
Expand All @@ -241,6 +243,8 @@ library
, ouroboros-network-api
, ouroboros-network-protocols ^>=0.8
, parsec
, polysemy
, polysemy-plugin
, prettyprinter
, prettyprinter-ansi-terminal
, random
Expand All @@ -254,6 +258,7 @@ library
, utf8-string
, vector
, yaml
ghc-options: -fplugin=Polysemy.Plugin

executable cardano-cli
import: project-config
Expand All @@ -270,18 +275,27 @@ library cardano-cli-test-lib
import: project-config
visibility: public
hs-source-dirs: test/cardano-cli-test-lib
exposed-modules: Test.Cardano.CLI.Aeson
exposed-modules: Test.Cardano.Api.Polysemy
Test.Cardano.CLI.Aeson
Test.Cardano.CLI.Polysemy
Test.Cardano.CLI.Util
ghc-options: -fplugin=Polysemy.Plugin
build-depends: aeson
, aeson-pretty
, bytestring
, cardano-api
, cardano-api:internal
, cardano-cli
, directory
, exceptions
, filepath
, hedgehog
, hedgehog-extras ^>= 0.6.1.0
, hw-polysemy:core ^>= 0.2.8.0
, hw-polysemy:hedgehog ^>= 0.2.8.0
, mtl
, polysemy
, polysemy-plugin
, lifted-base
, monad-control
, process
Expand All @@ -305,17 +319,23 @@ test-suite cardano-cli-test
, cardano-ledger-alonzo
, cardano-slotting
, containers
, exceptions
, filepath
, hedgehog
, hedgehog-extras ^>= 0.6.1.0
, exceptions
, hw-polysemy:core ^>= 0.2.8.0
, hw-polysemy:hedgehog ^>= 0.2.8.0
, polysemy
, polysemy-plugin
, regex-tdfa
, tasty
, tasty-hedgehog
, text
, time
, transformers

ghc-options: -fplugin=Polysemy.Plugin

build-tool-depends: tasty-discover:tasty-discover

other-modules: Test.Cli.AddCostModels
Expand Down Expand Up @@ -366,6 +386,10 @@ test-suite cardano-cli-golden
, filepath
, hedgehog ^>= 1.4
, hedgehog-extras ^>= 0.6.1.0
, hw-polysemy:core ^>= 0.2.8.0
, hw-polysemy:hedgehog ^>= 0.2.8.0
, polysemy
, polysemy-plugin
, regex-compat
, regex-tdfa
, tasty
Expand All @@ -377,6 +401,8 @@ test-suite cardano-cli-golden
build-tool-depends: cardano-cli:cardano-cli
, tasty-discover:tasty-discover

ghc-options: -fplugin=Polysemy.Plugin

other-modules: Test.Golden.Babbage.Transaction.CalculateMinFee
Test.Golden.Byron.SigningKeys
Test.Golden.Byron.Tx
Expand Down
36 changes: 36 additions & 0 deletions cardano-cli/src/Cardano/CLI/Polysemy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma

cardano-cli/src/Cardano/CLI/Polysemy.hs:3:1-34: Warning: Unused LANGUAGE pragma    Found:   {-# LANGUAGE OverloadedStrings #-}    Perhaps you should remove it.
{-# LANGUAGE TypeApplications #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma

cardano-cli/src/Cardano/CLI/Polysemy.hs:4:1-33: Warning: Unused LANGUAGE pragma    Found:   {-# LANGUAGE TypeApplications #-}    Perhaps you should remove it.
{-# LANGUAGE TypeOperators #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma

cardano-cli/src/Cardano/CLI/Polysemy.hs:5:1-30: Warning: Unused LANGUAGE pragma    Found:   {-# LANGUAGE TypeOperators #-}    Perhaps you should remove it.    Note: may require `{-# LANGUAGE ExplicitNamespaces #-}` adding to the top of the file

module Cardano.CLI.Polysemy
( ByronKeyFailure(..),
ByronKeyFormat(..),
SigningKeyFile,
File(..),
FileDirection(..),
readByronSigningKey
) where

import Cardano.Api.Byron (SomeByronSigningKey (..))

import Cardano.CLI.Byron.Key (ByronKeyFailure (..))
import qualified Cardano.CLI.Byron.Key as Cli
import Cardano.CLI.Types.Common

import Control.Monad.Except (runExceptT)

import HaskellWorks.Polysemy
import HaskellWorks.Polysemy.Prelude
import Polysemy ()

readByronSigningKey :: ()
=> Member (Error ByronKeyFailure) r
=> Member (Embed IO) r
=> ByronKeyFormat
-> SigningKeyFile In
-> Sem r SomeByronSigningKey
readByronSigningKey bKeyFormat fp =
(embed $ runExceptT $ Cli.readByronSigningKey bKeyFormat fp)
& onLeftM throw
Comment on lines +35 to +36

Check notice

Code scanning / HLint

Move brackets to avoid $

cardano-cli/src/Cardano/CLI/Polysemy.hs:(35,3)-(36,19): Suggestion: Move brackets to avoid $    Found:   (embed $ runExceptT $ Cli.readByronSigningKey bKeyFormat fp)     & onLeftM throw    Perhaps:   embed (runExceptT $ Cli.readByronSigningKey bKeyFormat fp)     & onLeftM throw
149 changes: 73 additions & 76 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Byron/SigningKeys.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

module Test.Golden.Byron.SigningKeys
( hprop_deserialise_legacy_signing_Key
Expand All @@ -11,106 +12,102 @@ module Test.Golden.Byron.SigningKeys
, hprop_print_nonLegacy_signing_key_address
) where

import Cardano.Api.Byron

import Cardano.CLI.Byron.Key (readByronSigningKey)
import Cardano.CLI.Byron.Legacy (decodeLegacyDelegateKey)
import Cardano.CLI.Types.Common
import Cardano.CLI.Polysemy
import qualified Cardano.Crypto.Signing as Crypto

import Codec.CBOR.Read (deserialiseFromBytes)
import Control.Monad (void)
import qualified Data.ByteString.Lazy as LB
import Codec.CBOR.Read (DeserialiseFailure, deserialiseFromBytes)

import Test.Cardano.CLI.Util
import Test.Cardano.Api.Polysemy
import Test.Cardano.CLI.Polysemy

import Hedgehog (Property, property, success)
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Test.Base as H
import Hedgehog.Internal.Property (failWith)
import HaskellWorks.Polysemy
import qualified HaskellWorks.Polysemy.Data.ByteString.Lazy as LBS
import HaskellWorks.Polysemy.Hedgehog
import HaskellWorks.Prelude

hprop_deserialise_legacy_signing_Key :: Property
hprop_deserialise_legacy_signing_Key = propertyOnce $ do
legSkeyBs <- H.evalIO $ LB.readFile "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
case deserialiseFromBytes decodeLegacyDelegateKey legSkeyBs of
Left deSerFail -> failWith Nothing $ show deSerFail
Right _ -> success
hprop_deserialise_legacy_signing_Key = propertyOnce $ localWorkspace $ do
legSkeyBs <- LBS.readFile "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
& trapFail @IOException

fromEither (deserialiseFromBytes decodeLegacyDelegateKey legSkeyBs)
& trapFail @DeserialiseFailure
& void

hprop_deserialise_nonLegacy_signing_Key :: Property
hprop_deserialise_nonLegacy_signing_Key = propertyOnce $ do
skeyBs <- H.evalIO $ LB.readFile "test/cardano-cli-golden/files/input/byron/keys/byron.skey"
case deserialiseFromBytes Crypto.fromCBORXPrv skeyBs of
Left deSerFail -> failWith Nothing $ show deSerFail
Right _ -> success
hprop_deserialise_nonLegacy_signing_Key = propertyOnce $ localWorkspace $ do
skeyBs <- LBS.readFile "test/cardano-cli-golden/files/input/byron/keys/byron.skey"
& trapFail @IOException

fromEither (deserialiseFromBytes Crypto.fromCBORXPrv skeyBs)
& trapFail @DeserialiseFailure
& void

hprop_print_legacy_signing_key_address :: Property
hprop_print_legacy_signing_key_address = propertyOnce $ do
let legKeyFp = "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
hprop_print_legacy_signing_key_address = propertyOnce $ localWorkspace $ do
legKeyFp <- jotPkgInputFile "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"

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

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

hprop_print_nonLegacy_signing_key_address :: Property
hprop_print_nonLegacy_signing_key_address = propertyOnce $ do
let nonLegKeyFp = "test/cardano-cli-golden/files/input/byron/keys/byron.skey"
hprop_print_nonLegacy_signing_key_address = propertyOnce $ localWorkspace $ do
nonLegKeyFp <- jotPkgInputFile "test/cardano-cli-golden/files/input/byron/keys/byron.skey"

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

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

hprop_generate_and_read_nonlegacy_signingkeys :: Property
hprop_generate_and_read_nonlegacy_signingkeys = property $ do
byronSkey <- H.evalIO $ generateSigningKey AsByronKey
case deserialiseFromRawBytes (AsSigningKey AsByronKey) (serialiseToRawBytes byronSkey) of
Left _ -> failWith Nothing "Failed to deserialise non-legacy Byron signing key. "
Right _ -> success
hprop_generate_and_read_nonlegacy_signingkeys = propertyOnce $ localWorkspace $ do
byronSkey <- generateSigningKey AsByronKey

hprop_migrate_legacy_to_nonlegacy_signingkeys :: Property
hprop_migrate_legacy_to_nonlegacy_signingkeys =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
let legKeyFp = "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
nonLegacyKeyFp <- noteTempFile tempDir "nonlegacy.skey"
fromEither (deserialiseFromRawBytes (AsSigningKey AsByronKey) (serialiseToRawBytes byronSkey))
-- Failed to deserialise non-legacy Byron signing key
& trapFail @SerialiseAsRawBytesError
& void

void $ execCardanoCLI
[ "migrate-delegate-key-from"
, "--from", legKeyFp
, "--to", nonLegacyKeyFp
]
hprop_migrate_legacy_to_nonlegacy_signingkeys :: Property
hprop_migrate_legacy_to_nonlegacy_signingkeys = propertyOnce $ localWorkspace $ do
legKeyFp <- jotPkgInputFile "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
nonLegacyKeyFp <- jotTempFile "nonlegacy.skey"

eSignKey <- H.evalIO . runExceptT . readByronSigningKey NonLegacyByronKeyFormat
$ File nonLegacyKeyFp
execCardanoCli_
[ "migrate-delegate-key-from"
, "--from", legKeyFp
, "--to", nonLegacyKeyFp
]

case eSignKey of
Left err -> failWith Nothing $ show err
Right _ -> success
readByronSigningKey NonLegacyByronKeyFormat (File nonLegacyKeyFp)
& trapFail @ByronKeyFailure
& void

hprop_deserialise_NonLegacy_Signing_Key_API :: Property
hprop_deserialise_NonLegacy_Signing_Key_API = propertyOnce $ do
eFailOrWit <- H.evalIO . runExceptT $ readByronSigningKey NonLegacyByronKeyFormat "test/cardano-cli-golden/files/input/byron/keys/byron.skey"
case eFailOrWit of
Left keyFailure -> failWith Nothing $ show keyFailure
Right _ -> success
hprop_deserialise_NonLegacy_Signing_Key_API = propertyOnce $ localWorkspace $ do
readByronSigningKey NonLegacyByronKeyFormat "test/cardano-cli-golden/files/input/byron/keys/byron.skey"
& trapFail @ByronKeyFailure
& void

hprop_deserialiseLegacy_Signing_Key_API :: Property
hprop_deserialiseLegacy_Signing_Key_API = propertyOnce $ do
eFailOrWit <- H.evalIO . runExceptT $ readByronSigningKey LegacyByronKeyFormat "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
case eFailOrWit of
Left keyFailure -> failWith Nothing $ show keyFailure
Right _ -> success
hprop_deserialiseLegacy_Signing_Key_API = propertyOnce $ localWorkspace $ do
readByronSigningKey LegacyByronKeyFormat "test/cardano-cli-golden/files/input/byron/keys/legacy.skey"
& trapFail @ByronKeyFailure
& void
Loading