-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
POC for polysemy
Showing
8 changed files
with
240 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
cardano-cli/test/cardano-cli-test-lib/Test/Cardano/API/Polysemy.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
|
||
module Test.Cardano.API.Polysemy | ||
( File(..), | ||
FileDirection(..), | ||
VRFPrivateKeyFilePermissionError(..), | ||
checkVrfFilePermissions, | ||
) where | ||
|
||
import Cardano.Api (File (..), FileDirection (..)) | ||
import qualified Cardano.Api.IO as Api | ||
import Cardano.Api.IO.Base (VRFPrivateKeyFilePermissionError (..)) | ||
|
||
import Control.Monad.Except (runExceptT) | ||
|
||
import HaskellWorks.Polysemy | ||
import HaskellWorks.Prelude | ||
import Polysemy () | ||
|
||
checkVrfFilePermissions :: () | ||
=> Member (Error VRFPrivateKeyFilePermissionError) r | ||
=> Member (Embed IO) r | ||
=> File () In | ||
-> Sem r () | ||
checkVrfFilePermissions vrfSignKey = | ||
embed (runExceptT (Api.checkVrfFilePermissions vrfSignKey)) | ||
& onLeftM throw |
89 changes: 89 additions & 0 deletions
89
cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Polysemy.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Test.Cardano.CLI.Polysemy | ||
( cardanoCliPath, | ||
execCardanoCli, | ||
execCardanoCli_, | ||
execDetailCardanoCli, | ||
localWorkspace, | ||
) where | ||
|
||
import Polysemy () | ||
import HaskellWorks.Polysemy | ||
import HaskellWorks.Polysemy.Error.Types | ||
import HaskellWorks.Polysemy.Hedgehog | ||
import HaskellWorks.Polysemy.Hedgehog.Process | ||
import HaskellWorks.Polysemy.Prelude | ||
import HaskellWorks.Polysemy.System.Process | ||
|
||
cardanoCliPath :: FilePath | ||
cardanoCliPath = "cardano-cli" | ||
|
||
-- | Execute cardano-cli via the command line. | ||
-- | ||
-- Waits for the process to finish and returns the stdout. | ||
execCardanoCli :: () | ||
=> HasCallStack | ||
=> Member (Embed IO) r | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> [String] | ||
-- ^ Arguments to the CLI command | ||
-> Sem r String | ||
-- ^ Captured stdout | ||
execCardanoCli args = withFrozenCallStack $ | ||
execFlexOk "cardano-cli" "CARDANO_CLI" args | ||
& trapFail @GenericError | ||
& trapFail @IOException | ||
|
||
execCardanoCli_ :: () | ||
=> HasCallStack | ||
=> Member (Embed IO) r | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> [String] | ||
-- ^ Arguments to the CLI command | ||
-> Sem r () | ||
execCardanoCli_ args = withFrozenCallStack $ | ||
void $ execCardanoCli args | ||
|
||
-- | Execute cardano-cli via the command line, expecting it to fail. | ||
-- | ||
-- Waits for the process to finish and returns the exit code, stdout and stderr. | ||
execDetailCardanoCli :: () | ||
=> HasCallStack | ||
=> Member (Embed IO) r | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> [String] | ||
-- ^ Arguments to the CLI command | ||
-> Sem r (ExitCode, String, String) | ||
-- ^ Captured stdout | ||
execDetailCardanoCli arguments = withFrozenCallStack $ | ||
execDetailFlex defaultExecConfig "cardano-cli" "CARDANO_CLI" arguments | ||
& trapFail @GenericError | ||
& trapFail @IOException | ||
|
||
localWorkspace :: () | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> Member (Embed IO) r | ||
=> Sem | ||
( Reader Workspace | ||
: Reader ProjectRoot | ||
: Reader PackagePath | ||
: Resource | ||
: r) | ||
() | ||
-> Sem r () | ||
localWorkspace f = do | ||
cabalProjectDir <- findCabalProjectDir "." | ||
|
||
f & moduleWorkspace "cardano-cli" | ||
& runReader (ProjectRoot cabalProjectDir) | ||
& runReader (PackagePath "cardano-cli") | ||
& runResource |
Oops, something went wrong.