From 7ceec38659a66e81f3559e8fd9eb0ed71deb8e56 Mon Sep 17 00:00:00 2001 From: paolino Date: Fri, 29 Dec 2023 11:34:24 +0000 Subject: [PATCH 1/5] Split state dirs between local-cluster and preprod --- lib/wallet-e2e/test-state/local/.gitignore | 4 ++++ lib/wallet-e2e/test-state/preprod/.gitignore | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 lib/wallet-e2e/test-state/local/.gitignore create mode 100644 lib/wallet-e2e/test-state/preprod/.gitignore diff --git a/lib/wallet-e2e/test-state/local/.gitignore b/lib/wallet-e2e/test-state/local/.gitignore new file mode 100644 index 00000000000..5e7d2734cfc --- /dev/null +++ b/lib/wallet-e2e/test-state/local/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/lib/wallet-e2e/test-state/preprod/.gitignore b/lib/wallet-e2e/test-state/preprod/.gitignore new file mode 100644 index 00000000000..5e7d2734cfc --- /dev/null +++ b/lib/wallet-e2e/test-state/preprod/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore From da94be9a0c712afc9e50da0ada7d72531c94f66a Mon Sep 17 00:00:00 2001 From: paolino Date: Fri, 29 Dec 2023 11:32:58 +0000 Subject: [PATCH 2/5] Fix justfile stylish command --- justfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/justfile b/justfile index cd351351324..66d9aaef7b7 100644 --- a/justfile +++ b/justfile @@ -2,8 +2,8 @@ default: @just --list # check that the code is formatted with stylish-haskell -check target="stylish": - ./.buildkite/check-{{target}}.sh +check: + ./.buildkite/check-code-format.sh # build wallet-e2e suite with cabal build: @@ -36,15 +36,16 @@ integration: # run wallet-e2e suite against the preprod network e2e-preprod: nix run '.#cardano-wallet-e2e' -- preprod \ - -s lib/wallet-e2e/test-state \ + -s lib/wallet-e2e/test-state/preprod \ -c lib/wallet-e2e/config/cardano-node/preprod # run wallet-e2e suite against the local test cluster e2e-local: nix shell \ - '.#local-cluster' '.#cardano-node' '.#cardano-wallet' '.#cardano-wallet-e2e' '.#local-cluster' \ - -c wallet-e2e local -s lib/wallet-e2e/test-state -c lib/local-cluster/test/data/cluster-configs - + '.#local-cluster' '.#cardano-node' '.#cardano-wallet' '.#cardano-wallet-e2e' \ + -c wallet-e2e local \ + -s lib/wallet-e2e/test-state/local \ + -c lib/local-cluster/test/data/cluster-configs # run wallet-e2e suite against the manually started node/wallet e2e-manual: nix run '.#cardano-wallet-e2e' -- manual From 33722002be24902cc352df2c8eb368f0ab09a7c4 Mon Sep 17 00:00:00 2001 From: paolino Date: Fri, 29 Dec 2023 11:23:16 +0000 Subject: [PATCH 3/5] Add tracing dir option to new E2E executable --- justfile | 8 ++- lib/wallet-e2e/cardano-wallet-e2e.cabal | 1 + lib/wallet-e2e/exe/Main.hs | 56 +++++++++++++++---- lib/wallet-e2e/src/Cardano/Wallet/Spec.hs | 27 +++++++-- .../src/Cardano/Wallet/Spec/Effect/Trace.hs | 16 +++--- .../Wallet/Spec/Interpreters/Config.hs | 14 +++++ .../Wallet/Spec/Interpreters/Effectfully.hs | 31 ++++++++-- .../Cardano/Wallet/Spec/Interpreters/Pure.hs | 29 +++++++++- lib/wallet-e2e/test-state/.gitignore | 4 -- 9 files changed, 150 insertions(+), 36 deletions(-) create mode 100644 lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs delete mode 100644 lib/wallet-e2e/test-state/.gitignore diff --git a/justfile b/justfile index 66d9aaef7b7..4c50a89bd21 100644 --- a/justfile +++ b/justfile @@ -37,7 +37,9 @@ integration: e2e-preprod: nix run '.#cardano-wallet-e2e' -- preprod \ -s lib/wallet-e2e/test-state/preprod \ - -c lib/wallet-e2e/config/cardano-node/preprod + -c lib/wallet-e2e/config/cardano-node/preprod \ + -t lib/wallet-e2e/test-output/preprod + # run wallet-e2e suite against the local test cluster e2e-local: @@ -45,7 +47,9 @@ e2e-local: '.#local-cluster' '.#cardano-node' '.#cardano-wallet' '.#cardano-wallet-e2e' \ -c wallet-e2e local \ -s lib/wallet-e2e/test-state/local \ - -c lib/local-cluster/test/data/cluster-configs + -c lib/local-cluster/test/data/cluster-configs \ + -t lib/wallet-e2e/test-output/local + # run wallet-e2e suite against the manually started node/wallet e2e-manual: nix run '.#cardano-wallet-e2e' -- manual diff --git a/lib/wallet-e2e/cardano-wallet-e2e.cabal b/lib/wallet-e2e/cardano-wallet-e2e.cabal index b83390c4410..8deafcd35aa 100644 --- a/lib/wallet-e2e/cardano-wallet-e2e.cabal +++ b/lib/wallet-e2e/cardano-wallet-e2e.cabal @@ -98,6 +98,7 @@ library Cardano.Wallet.Spec.Effect.Random Cardano.Wallet.Spec.Effect.Timeout Cardano.Wallet.Spec.Effect.Trace + Cardano.Wallet.Spec.Interpreters.Config Cardano.Wallet.Spec.Interpreters.Effectfully Cardano.Wallet.Spec.Interpreters.Pure Cardano.Wallet.Spec.Network.Configured diff --git a/lib/wallet-e2e/exe/Main.hs b/lib/wallet-e2e/exe/Main.hs index 243127d9d3a..d0ad6753ba5 100644 --- a/lib/wallet-e2e/exe/Main.hs +++ b/lib/wallet-e2e/exe/Main.hs @@ -8,6 +8,9 @@ import Cardano.Wallet.Spec , effectsSpec , walletSpec ) +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration (..) + ) import Data.Tagged ( Tagged (..) ) @@ -29,7 +32,9 @@ import Options.Applicative , short ) import Path - ( Dir + ( Abs + , Dir + , Path , SomeBase (..) , parseSomeDir ) @@ -42,19 +47,49 @@ import Test.Syd main :: IO () main = withUtf8 do - testNetworkOptions <- + TestOptions{..} :: TestOptions <- execParser $ info - (parser <**> helper) + (parserTestOptions <**> helper) (fullDesc <> progDesc "E2E Wallet test suite") testNetwork <- testNetworkOptionsToConfig testNetworkOptions + traceConfiguration <- do + absTraceDir <- + traverse makeDirAbsolute + $ testGlobalOptionsTraceOutput testGlobalOptions + pure $ TraceConfiguration absTraceDir sydTestWith SydTest.defaultSettings{SydTest.settingRetries = 1} do effectsSpec - walletSpec testNetwork + walletSpec traceConfiguration testNetwork + +parserTestOptions :: Parser TestOptions +parserTestOptions = TestOptions <$> parserNetworkOptions <*> parserGlobalOptions -------------------------------------------------------------------------------- -- Command line options -------------------------------------------------------- +data TestOptions = TestOptions + { testNetworkOptions :: TestNetworkOptions + , testGlobalOptions :: TestGlobalOptions + } + +newtype TestGlobalOptions = TestGlobalOptions + { testGlobalOptionsTraceOutput :: Tagged "tracing-dir" (SomeBase Dir) + } + +parserGlobalOptions :: Parser TestGlobalOptions +parserGlobalOptions = TestGlobalOptions <$> traceOutputOption + where + traceOutputOption :: Parser (Tagged "tracing-dir" (SomeBase Dir)) = + option + (eitherReader (bimap show Tagged . parseSomeDir)) + ( long "tracing-dir" + <> short 't' + <> metavar "TRACE_OUTPUT_DIR" + <> help + "Absolute or relative directory path to save trace output" + ) + data TestNetworkOptions = TestNetworkOptionManual | TestNetworkOptionLocal @@ -76,13 +111,14 @@ testNetworkOptionsToConfig = \case absStateDir <- traverse makeDirAbsolute stateDir absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir pure (TestNetworkPreprod absStateDir absNodeConfigsDir) - where - makeDirAbsolute = \case - Abs absDir -> pure absDir - Rel relDir -> makeAbsolute relDir -parser :: Parser TestNetworkOptions -parser = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod +makeDirAbsolute :: SomeBase Dir -> IO (Path Abs Dir) +makeDirAbsolute = \case + Abs absDir -> pure absDir + Rel relDir -> makeAbsolute relDir + +parserNetworkOptions :: Parser TestNetworkOptions +parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod where cmdManual = OptParse.command diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs index 4552bcbf2d2..55737309f9f 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs @@ -8,6 +8,9 @@ import qualified Cardano.Wallet.Spec.Network.Local as Local import qualified Cardano.Wallet.Spec.Network.Manual as Manual import qualified Cardano.Wallet.Spec.Network.Preprod as Preprod +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration + ) import Cardano.Wallet.Spec.Interpreters.Effectfully ( story ) @@ -40,12 +43,24 @@ import Test.Syd , sequential ) -walletSpec :: TestNetworkConfig -> Spec -walletSpec config = aroundAll (configureTestNet config) do - describe "Wallet Backend API" $ sequential do - story "Created wallet is listed" createdWalletListed - story "Created wallet can be retrieved by id" createdWalletRetrievable - story "Created wallet has zero ADA balance" createdWalletHasZeroAda +walletSpec :: TraceConfiguration -> TestNetworkConfig -> Spec +walletSpec tracingConfig config = + aroundAll (configureTracing tracingConfig) + $ aroundAll (configureTestNet config) + $ do + describe "Wallet Backend API" $ sequential do + story + "Created wallet is listed" + createdWalletListed + story + "Created wallet can be retrieved by id" + createdWalletRetrievable + story + "Created wallet has zero ADA balance" + createdWalletHasZeroAda + +configureTracing :: TraceConfiguration -> (TraceConfiguration -> IO ()) -> IO () +configureTracing config f = f config effectsSpec :: Spec effectsSpec = describe "Effect interpreters" do diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Effect/Trace.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Effect/Trace.hs index c5dc6022b9c..12e35834048 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Effect/Trace.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Effect/Trace.hs @@ -5,9 +5,15 @@ module Cardano.Wallet.Spec.Effect.Trace where import qualified Data.Sequence as Seq +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration (..) + ) import Data.Sequence ( (|>) ) +import Data.Tagged + ( Tagged (..) + ) import Effectful ( Eff , Effect @@ -24,13 +30,11 @@ import Effectful.TH ) import Path ( parseRelFile - , reldir , toFilePath , () ) import Path.IO ( ensureDir - , getCurrentDir ) import Prelude hiding ( modify @@ -47,13 +51,11 @@ runTracePure :: Eff (FxTrace : es) a -> Eff es (a, Seq Text) runTracePure = reinterpret (runState Seq.empty) \_ (Trace msg) -> modify (|> msg) -recordTraceLog :: String -> Seq Text -> IO () -recordTraceLog storyLabel log = do - cwd <- getCurrentDir - let outDir = cwd [reldir|test-output|] +recordTraceLog :: TraceConfiguration -> String -> Seq Text -> IO () +recordTraceLog (TraceConfiguration (Tagged outDir)) storyLabel log = do ensureDir outDir fileName <- parseRelFile - ([if c == ' ' then '_' else c | c <- storyLabel] <> ".log") + $ [if c == ' ' then '_' else c | c <- storyLabel] <> ".log" let outFile = outDir fileName writeFile (toFilePath outFile) $ toString $ unlines $ toList log diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs new file mode 100644 index 00000000000..4acb0b70781 --- /dev/null +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs @@ -0,0 +1,14 @@ +module Cardano.Wallet.Spec.Interpreters.Config where + +import Data.Tagged + ( Tagged + ) +import Path + ( Abs + , Dir + , Path + ) + +newtype TraceConfiguration = TraceConfiguration + { traceConfigurationDir :: Tagged "tracing-dir" (Path Abs Dir) + } diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Effectfully.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Effectfully.hs index 966115c3a31..ca8d7ab9bec 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Effectfully.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Effectfully.hs @@ -30,6 +30,9 @@ import Cardano.Wallet.Spec.Effect.Trace , recordTraceLog , runTracePure ) +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration + ) import Cardano.Wallet.Spec.Network.Configured ( ConfiguredNetwork ) @@ -55,9 +58,10 @@ import System.Random ( initStdGen ) import Test.Syd - ( TestDefM + ( HList (..) + , TestDefM , expectationFailure - , itWithOuter + , itWithAll ) type Story a = @@ -73,11 +77,26 @@ type Story a = ] a -story :: String -> Story () -> TestDefM '[ConfiguredNetwork] () () +type StoryConfig = + '[ ConfiguredNetwork + , TraceConfiguration + ] + +onStoryConfig + :: HList StoryConfig + -> (ConfiguredNetwork -> TraceConfiguration -> a) + -> a +onStoryConfig (HCons network (HCons traceOutput HNil)) f = f network traceOutput + +story + :: String + -> Story () + -> TestDefM StoryConfig () () story label story' = - itWithOuter label \network -> do - interpretStory network story' >>= \(result, log) -> do - recordTraceLog label log + itWithAll label \config () -> onStoryConfig config + $ \network traceOutput -> do + (result, log) <- interpretStory network story' + recordTraceLog traceOutput label log case result of Left err -> expectationFailure err Right () -> pass diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Pure.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Pure.hs index 5d8bb1c8815..884545cd0e3 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Pure.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Pure.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE QuasiQuotes #-} + module Cardano.Wallet.Spec.Interpreters.Pure ( pureStory , PureStory @@ -24,6 +26,12 @@ import Cardano.Wallet.Spec.Effect.Trace , recordTraceLog , runTracePure ) +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration (..) + ) +import Data.Tagged + ( Tagged (..) + ) import Effectful ( Eff , runPureEff @@ -32,6 +40,15 @@ import Effectful.Fail ( Fail , runFail ) +import GHC.IO + ( unsafePerformIO + ) +import Path.IO + ( makeAbsolute + ) +import Path.Posix + ( reldir + ) import Test.Syd ( TestDefM , expectationFailure @@ -49,13 +66,23 @@ type PureStory a = ] a +defaultTraceConfiguration :: TraceConfiguration +defaultTraceConfiguration = + TraceConfiguration + { traceConfigurationDir = + Tagged @"tracing-dir" + $ unsafePerformIO + $ makeAbsolute [reldir|lib/wallet-e2e/test-output|] + } + pureStory :: String -> PureStory a -> TestDefM outers () () pureStory label story = it label do interpretStoryPure story & \case Left err -> expectationFailure (show err) Right (Left err) -> expectationFailure err - Right (Right (_unit :: a, log)) -> recordTraceLog label log + Right (Right (_unit :: a, log)) -> + recordTraceLog defaultTraceConfiguration label log interpretStoryPure :: PureStory a diff --git a/lib/wallet-e2e/test-state/.gitignore b/lib/wallet-e2e/test-state/.gitignore deleted file mode 100644 index 5e7d2734cfc..00000000000 --- a/lib/wallet-e2e/test-state/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore From 8bfebe2012f63ac99f3808d332da9cad68d5fc10 Mon Sep 17 00:00:00 2001 From: paolino Date: Fri, 29 Dec 2023 19:01:57 +0000 Subject: [PATCH 4/5] Factor out dir related types --- lib/wallet-e2e/cardano-wallet-e2e.cabal | 1 + lib/wallet-e2e/exe/Main.hs | 44 +++++++------------ lib/wallet-e2e/src/Cardano/Wallet/Spec.hs | 19 +++----- .../Wallet/Spec/Interpreters/Config.hs | 11 ++--- .../src/Cardano/Wallet/Spec/Lib/Paths.hs | 26 +++++++++++ .../src/Cardano/Wallet/Spec/Network/Config.hs | 7 --- .../src/Cardano/Wallet/Spec/Network/Local.hs | 15 +++---- .../Cardano/Wallet/Spec/Network/Preprod.hs | 15 +++---- 8 files changed, 65 insertions(+), 73 deletions(-) create mode 100644 lib/wallet-e2e/src/Cardano/Wallet/Spec/Lib/Paths.hs delete mode 100644 lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Config.hs diff --git a/lib/wallet-e2e/cardano-wallet-e2e.cabal b/lib/wallet-e2e/cardano-wallet-e2e.cabal index 8deafcd35aa..696236cb38d 100644 --- a/lib/wallet-e2e/cardano-wallet-e2e.cabal +++ b/lib/wallet-e2e/cardano-wallet-e2e.cabal @@ -101,6 +101,7 @@ library Cardano.Wallet.Spec.Interpreters.Config Cardano.Wallet.Spec.Interpreters.Effectfully Cardano.Wallet.Spec.Interpreters.Pure + Cardano.Wallet.Spec.Lib.Paths Cardano.Wallet.Spec.Network.Configured Cardano.Wallet.Spec.Network.Local Cardano.Wallet.Spec.Network.Manual diff --git a/lib/wallet-e2e/exe/Main.hs b/lib/wallet-e2e/exe/Main.hs index d0ad6753ba5..84ae79f5a7e 100644 --- a/lib/wallet-e2e/exe/Main.hs +++ b/lib/wallet-e2e/exe/Main.hs @@ -11,6 +11,10 @@ import Cardano.Wallet.Spec import Cardano.Wallet.Spec.Interpreters.Config ( TraceConfiguration (..) ) +import Cardano.Wallet.Spec.Lib.Paths + ( SomeDirOf + , makeDirAbsolute + ) import Data.Tagged ( Tagged (..) ) @@ -32,14 +36,7 @@ import Options.Applicative , short ) import Path - ( Abs - , Dir - , Path - , SomeBase (..) - , parseSomeDir - ) -import Path.IO - ( AnyPath (makeAbsolute) + ( parseSomeDir ) import Test.Syd ( sydTestWith @@ -55,7 +52,7 @@ main = withUtf8 do testNetwork <- testNetworkOptionsToConfig testNetworkOptions traceConfiguration <- do absTraceDir <- - traverse makeDirAbsolute + makeDirAbsolute $ testGlobalOptionsTraceOutput testGlobalOptions pure $ TraceConfiguration absTraceDir sydTestWith SydTest.defaultSettings{SydTest.settingRetries = 1} do @@ -74,13 +71,13 @@ data TestOptions = TestOptions } newtype TestGlobalOptions = TestGlobalOptions - { testGlobalOptionsTraceOutput :: Tagged "tracing-dir" (SomeBase Dir) + { testGlobalOptionsTraceOutput :: SomeDirOf "tracing-dir" } parserGlobalOptions :: Parser TestGlobalOptions parserGlobalOptions = TestGlobalOptions <$> traceOutputOption where - traceOutputOption :: Parser (Tagged "tracing-dir" (SomeBase Dir)) = + traceOutputOption :: Parser (SomeDirOf "tracing-dir") = option (eitherReader (bimap show Tagged . parseSomeDir)) ( long "tracing-dir" @@ -92,31 +89,22 @@ parserGlobalOptions = TestGlobalOptions <$> traceOutputOption data TestNetworkOptions = TestNetworkOptionManual - | TestNetworkOptionLocal - (Tagged "state" (SomeBase Dir)) - (Tagged "config" (SomeBase Dir)) - | TestNetworkOptionPreprod - (Tagged "state" (SomeBase Dir)) - (Tagged "config" (SomeBase Dir)) + | TestNetworkOptionLocal (SomeDirOf "state") (SomeDirOf "config") + | TestNetworkOptionPreprod (SomeDirOf "state") (SomeDirOf "config") testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig testNetworkOptionsToConfig = \case TestNetworkOptionManual -> pure TestNetworkManual TestNetworkOptionLocal stateDir nodeConfigsDir -> do - absStateDir <- traverse makeDirAbsolute stateDir - absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir + absStateDir <- makeDirAbsolute stateDir + absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir pure (TestNetworkLocal absStateDir absNodeConfigsDir) TestNetworkOptionPreprod stateDir nodeConfigsDir -> do - absStateDir <- traverse makeDirAbsolute stateDir - absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir + absStateDir <- makeDirAbsolute stateDir + absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir pure (TestNetworkPreprod absStateDir absNodeConfigsDir) -makeDirAbsolute :: SomeBase Dir -> IO (Path Abs Dir) -makeDirAbsolute = \case - Abs absDir -> pure absDir - Rel relDir -> makeAbsolute relDir - parserNetworkOptions :: Parser TestNetworkOptions parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod where @@ -151,7 +139,7 @@ parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod "Automatically starts a preprod node and wallet." ) ) - stateDirOption :: Parser (Tagged "state" (SomeBase Dir)) = + stateDirOption :: Parser (SomeDirOf "state") = option (eitherReader (bimap show Tagged . parseSomeDir)) ( long "state-dir" @@ -161,7 +149,7 @@ parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod "Absolute or relative directory path \ \ to save node and wallet state" ) - nodeConfigsDirOption :: Parser (Tagged "config" (SomeBase Dir)) = + nodeConfigsDirOption :: Parser (SomeDirOf "config") = option (eitherReader (bimap show Tagged . parseSomeDir)) ( long "node-configs-dir" diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs index 55737309f9f..68c1b2a9c9f 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec.hs @@ -14,6 +14,9 @@ import Cardano.Wallet.Spec.Interpreters.Config import Cardano.Wallet.Spec.Interpreters.Effectfully ( story ) +import Cardano.Wallet.Spec.Lib.Paths + ( DirOf + ) import Cardano.Wallet.Spec.Network.Configured ( ConfiguredNetwork ) @@ -28,14 +31,6 @@ import Cardano.Wallet.Spec.TimeoutSpec import Control.Monad.Trans.Resource ( runResourceT ) -import Data.Tagged - ( Tagged - ) -import Path - ( Abs - , Dir - , Path - ) import Test.Syd ( Spec , aroundAll @@ -71,12 +66,8 @@ effectsSpec = describe "Effect interpreters" do data TestNetworkConfig = TestNetworkManual - | TestNetworkLocal - (Tagged "state" (Path Abs Dir)) - (Tagged "config" (Path Abs Dir)) - | TestNetworkPreprod - (Tagged "state" (Path Abs Dir)) - (Tagged "config" (Path Abs Dir)) + | TestNetworkLocal (DirOf "state") (DirOf "config") + | TestNetworkPreprod (DirOf "state") (DirOf "config") configureTestNet :: TestNetworkConfig -> (ConfiguredNetwork -> IO ()) -> IO () configureTestNet testNetworkConfig withConfiguredNetwork = runResourceT $ do diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs index 4acb0b70781..146e012573c 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Interpreters/Config.hs @@ -1,14 +1,9 @@ module Cardano.Wallet.Spec.Interpreters.Config where -import Data.Tagged - ( Tagged - ) -import Path - ( Abs - , Dir - , Path +import Cardano.Wallet.Spec.Lib.Paths + ( DirOf ) newtype TraceConfiguration = TraceConfiguration - { traceConfigurationDir :: Tagged "tracing-dir" (Path Abs Dir) + { traceConfigurationDir :: DirOf "tracing-dir" } diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Lib/Paths.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Lib/Paths.hs new file mode 100644 index 00000000000..cb587498d42 --- /dev/null +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Lib/Paths.hs @@ -0,0 +1,26 @@ +module Cardano.Wallet.Spec.Lib.Paths where + +import Data.Tagged + ( Tagged (..) + , untag + ) +import Path + ( Abs + , Dir + , Path + , SomeBase (..) + ) +import Path.IO + ( AnyPath (..) + ) + +type DirOf x = Tagged x (Path Abs Dir) +type SomeDirOf x = Tagged x (SomeBase Dir) + +makeDirAbsolute :: SomeDirOf x -> IO (DirOf x) +makeDirAbsolute = fmap Tagged . makeAbsolute' . untag + +makeAbsolute' :: SomeBase Dir -> IO (Path Abs Dir) +makeAbsolute' = \case + Abs absDir -> pure absDir + Rel relDir -> makeAbsolute relDir diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Config.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Config.hs deleted file mode 100644 index f536328af41..00000000000 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Config.hs +++ /dev/null @@ -1,7 +0,0 @@ -module Cardano.Wallet.Spec.Network.Config where - -import Cardano.Wallet.Cli.Launcher - ( WalletApi - ) - -newtype NetworkConfig = NetworkConfig {networkConfigWallet :: WalletApi} diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Local.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Local.hs index 5c9fe8bf8b0..73b8a96be22 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Local.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Local.hs @@ -9,6 +9,9 @@ import qualified Cardano.Wallet.Spec.Network.Wait as Wait import Cardano.Wallet.Cli.Launcher ( WalletApi (..) ) +import Cardano.Wallet.Spec.Lib.Paths + ( DirOf + ) import Cardano.Wallet.Spec.Network.Configured ( ConfiguredNetwork (..) ) @@ -17,14 +20,10 @@ import Control.Monad.Trans.Resource , allocate ) import Data.Tagged - ( Tagged - , untag + ( untag ) import Path - ( Abs - , Dir - , Path - , relfile + ( relfile , toFilePath , () ) @@ -42,8 +41,8 @@ import System.Process.Typed ) configuredNetwork - :: Tagged "state" (Path Abs Dir) - -> Tagged "config" (Path Abs Dir) + :: DirOf "state" + -> DirOf "config" -> ResourceT IO ConfiguredNetwork configuredNetwork stateDir clusterConfigsDir = do walletApi <- startCluster diff --git a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Preprod.hs b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Preprod.hs index 8289b5832a2..58376ab2a10 100644 --- a/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Preprod.hs +++ b/lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Preprod.hs @@ -14,6 +14,9 @@ import Cardano.Node.Cli.Launcher import Cardano.Wallet.Cli.Launcher ( WalletProcessConfig (..) ) +import Cardano.Wallet.Spec.Lib.Paths + ( DirOf + ) import Cardano.Wallet.Spec.Network.Configured ( ConfiguredNetwork (..) ) @@ -22,21 +25,17 @@ import Control.Monad.Trans.Resource , allocate ) import Data.Tagged - ( Tagged - , untag + ( untag ) import Path - ( Abs - , Dir - , Path - , reldir + ( reldir , relfile , () ) configuredNetwork - :: Tagged "state" (Path Abs Dir) - -> Tagged "config" (Path Abs Dir) + :: DirOf "state" + -> DirOf "config" -> ResourceT IO ConfiguredNetwork configuredNetwork stateDir nodeConfigDir = do nodeApi <- startNode From 38bb032e46d269012e631a59207d6cf4696c1593 Mon Sep 17 00:00:00 2001 From: paolino Date: Fri, 29 Dec 2023 19:07:35 +0000 Subject: [PATCH 5/5] Factor out Options --- lib/wallet-e2e/cardano-wallet-e2e.cabal | 1 + lib/wallet-e2e/exe/Main.hs | 146 +----------------------- lib/wallet-e2e/exe/Options.hs | 142 +++++++++++++++++++++++ 3 files changed, 147 insertions(+), 142 deletions(-) create mode 100644 lib/wallet-e2e/exe/Options.hs diff --git a/lib/wallet-e2e/cardano-wallet-e2e.cabal b/lib/wallet-e2e/cardano-wallet-e2e.cabal index 696236cb38d..e30522176e9 100644 --- a/lib/wallet-e2e/cardano-wallet-e2e.cabal +++ b/lib/wallet-e2e/cardano-wallet-e2e.cabal @@ -118,6 +118,7 @@ executable wallet-e2e hs-source-dirs: exe main-is: Main.hs ghc-options: -threaded -rtsopts -with-rtsopts=-N + other-modules: Options build-depends: , base ^>=4.14.3.0 , cardano-wallet-e2e diff --git a/lib/wallet-e2e/exe/Main.hs b/lib/wallet-e2e/exe/Main.hs index 84ae79f5a7e..e866dfdf06f 100644 --- a/lib/wallet-e2e/exe/Main.hs +++ b/lib/wallet-e2e/exe/Main.hs @@ -1,161 +1,23 @@ module Main where -import qualified Options.Applicative as OptParse import qualified Test.Syd.OptParse as SydTest import Cardano.Wallet.Spec - ( TestNetworkConfig (..) - , effectsSpec + ( effectsSpec , walletSpec ) -import Cardano.Wallet.Spec.Interpreters.Config - ( TraceConfiguration (..) - ) -import Cardano.Wallet.Spec.Lib.Paths - ( SomeDirOf - , makeDirAbsolute - ) -import Data.Tagged - ( Tagged (..) - ) import Main.Utf8 ( withUtf8 ) -import Options.Applicative - ( Parser - , eitherReader - , execParser - , fullDesc - , help - , helper - , info - , long - , metavar - , option - , progDesc - , short - ) -import Path - ( parseSomeDir +import Options + ( withTestOptions ) import Test.Syd ( sydTestWith ) main :: IO () -main = withUtf8 do - TestOptions{..} :: TestOptions <- - execParser - $ info - (parserTestOptions <**> helper) - (fullDesc <> progDesc "E2E Wallet test suite") - testNetwork <- testNetworkOptionsToConfig testNetworkOptions - traceConfiguration <- do - absTraceDir <- - makeDirAbsolute - $ testGlobalOptionsTraceOutput testGlobalOptions - pure $ TraceConfiguration absTraceDir +main = withUtf8 $ withTestOptions $ \testNetwork traceConfiguration -> sydTestWith SydTest.defaultSettings{SydTest.settingRetries = 1} do effectsSpec walletSpec traceConfiguration testNetwork - -parserTestOptions :: Parser TestOptions -parserTestOptions = TestOptions <$> parserNetworkOptions <*> parserGlobalOptions - --------------------------------------------------------------------------------- --- Command line options -------------------------------------------------------- - -data TestOptions = TestOptions - { testNetworkOptions :: TestNetworkOptions - , testGlobalOptions :: TestGlobalOptions - } - -newtype TestGlobalOptions = TestGlobalOptions - { testGlobalOptionsTraceOutput :: SomeDirOf "tracing-dir" - } - -parserGlobalOptions :: Parser TestGlobalOptions -parserGlobalOptions = TestGlobalOptions <$> traceOutputOption - where - traceOutputOption :: Parser (SomeDirOf "tracing-dir") = - option - (eitherReader (bimap show Tagged . parseSomeDir)) - ( long "tracing-dir" - <> short 't' - <> metavar "TRACE_OUTPUT_DIR" - <> help - "Absolute or relative directory path to save trace output" - ) - -data TestNetworkOptions - = TestNetworkOptionManual - | TestNetworkOptionLocal (SomeDirOf "state") (SomeDirOf "config") - | TestNetworkOptionPreprod (SomeDirOf "state") (SomeDirOf "config") - -testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig -testNetworkOptionsToConfig = \case - TestNetworkOptionManual -> - pure TestNetworkManual - TestNetworkOptionLocal stateDir nodeConfigsDir -> do - absStateDir <- makeDirAbsolute stateDir - absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir - pure (TestNetworkLocal absStateDir absNodeConfigsDir) - TestNetworkOptionPreprod stateDir nodeConfigsDir -> do - absStateDir <- makeDirAbsolute stateDir - absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir - pure (TestNetworkPreprod absStateDir absNodeConfigsDir) - -parserNetworkOptions :: Parser TestNetworkOptions -parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod - where - cmdManual = - OptParse.command - "manual" - ( OptParse.info - (pure TestNetworkOptionManual) - ( OptParse.progDesc - "Relies on a node and wallet started manually." - ) - ) - cmdLocal = - OptParse.command - "local" - ( OptParse.info - ( TestNetworkOptionLocal - <$> stateDirOption - <*> nodeConfigsDirOption - ) - (OptParse.progDesc "Automatically starts a local test cluster.") - ) - cmdPreprod = - OptParse.command - "preprod" - ( OptParse.info - ( TestNetworkOptionPreprod - <$> stateDirOption - <*> nodeConfigsDirOption - ) - ( OptParse.progDesc - "Automatically starts a preprod node and wallet." - ) - ) - stateDirOption :: Parser (SomeDirOf "state") = - option - (eitherReader (bimap show Tagged . parseSomeDir)) - ( long "state-dir" - <> short 's' - <> metavar "STATE_DIR" - <> help - "Absolute or relative directory path \ - \ to save node and wallet state" - ) - nodeConfigsDirOption :: Parser (SomeDirOf "config") = - option - (eitherReader (bimap show Tagged . parseSomeDir)) - ( long "node-configs-dir" - <> short 'c' - <> metavar "NODE_CONFIGS_DIR" - <> help - "Absolute or relative directory path \ - \ to a directory with node configs" - ) diff --git a/lib/wallet-e2e/exe/Options.hs b/lib/wallet-e2e/exe/Options.hs new file mode 100644 index 00000000000..d1967ff1959 --- /dev/null +++ b/lib/wallet-e2e/exe/Options.hs @@ -0,0 +1,142 @@ +module Options where + +import qualified Options.Applicative as OptParse + +import Cardano.Wallet.Spec + ( TestNetworkConfig (..) + ) +import Cardano.Wallet.Spec.Interpreters.Config + ( TraceConfiguration (..) + ) +import Cardano.Wallet.Spec.Lib.Paths + ( SomeDirOf + , makeDirAbsolute + ) +import Data.Tagged + ( Tagged (..) + ) +import Options.Applicative + ( Parser + , eitherReader + , help + , long + , metavar + , option + , short + ) +import Path + ( parseSomeDir + ) + +withTestOptions :: (TestNetworkConfig -> TraceConfiguration -> IO b) -> IO b +withTestOptions action = do + TestOptions{..} :: TestOptions <- + OptParse.execParser + $ OptParse.info + (parserTestOptions OptParse.<**> OptParse.helper) + (OptParse.fullDesc <> OptParse.progDesc "E2E Wallet test suite") + testNetwork <- testNetworkOptionsToConfig testNetworkOptions + traceConfiguration <- do + absTraceDir <- + makeDirAbsolute + $ testGlobalOptionsTraceOutput testGlobalOptions + pure $ TraceConfiguration absTraceDir + action testNetwork traceConfiguration + +parserTestOptions :: Parser TestOptions +parserTestOptions = TestOptions <$> parserNetworkOptions <*> parserGlobalOptions + +data TestOptions = TestOptions + { testNetworkOptions :: TestNetworkOptions + , testGlobalOptions :: TestGlobalOptions + } + +newtype TestGlobalOptions = TestGlobalOptions + { testGlobalOptionsTraceOutput :: SomeDirOf "tracing-dir" + } + +parserGlobalOptions :: Parser TestGlobalOptions +parserGlobalOptions = TestGlobalOptions <$> traceOutputOption + where + traceOutputOption :: Parser (SomeDirOf "tracing-dir") = + option + (eitherReader (bimap show Tagged . parseSomeDir)) + ( long "tracing-dir" + <> short 't' + <> metavar "TRACE_OUTPUT_DIR" + <> help + "Absolute or relative directory path to save trace output" + ) + +data TestNetworkOptions + = TestNetworkOptionManual + | TestNetworkOptionLocal (SomeDirOf "state") (SomeDirOf "config") + | TestNetworkOptionPreprod (SomeDirOf "state") (SomeDirOf "config") + +testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig +testNetworkOptionsToConfig = \case + TestNetworkOptionManual -> + pure TestNetworkManual + TestNetworkOptionLocal stateDir nodeConfigsDir -> do + absStateDir <- makeDirAbsolute stateDir + absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir + pure (TestNetworkLocal absStateDir absNodeConfigsDir) + TestNetworkOptionPreprod stateDir nodeConfigsDir -> do + absStateDir <- makeDirAbsolute stateDir + absNodeConfigsDir <- makeDirAbsolute nodeConfigsDir + pure (TestNetworkPreprod absStateDir absNodeConfigsDir) + +parserNetworkOptions :: Parser TestNetworkOptions +parserNetworkOptions = OptParse.subparser $ cmdManual <> cmdLocal <> cmdPreprod + where + cmdManual = + OptParse.command + "manual" + ( OptParse.info + (pure TestNetworkOptionManual) + ( OptParse.progDesc + "Relies on a node and wallet started manually." + ) + ) + cmdLocal = + OptParse.command + "local" + ( OptParse.info + ( TestNetworkOptionLocal + <$> stateDirOption + <*> nodeConfigsDirOption + ) + (OptParse.progDesc "Automatically starts a local test cluster.") + ) + cmdPreprod = + OptParse.command + "preprod" + ( OptParse.info + ( TestNetworkOptionPreprod + <$> stateDirOption + <*> nodeConfigsDirOption + ) + ( OptParse.progDesc + "Automatically starts a preprod node and wallet." + ) + ) + stateDirOption :: Parser (SomeDirOf "state") = + option + (eitherReader (bimap show Tagged . parseSomeDir)) + ( long "state-dir" + <> short 's' + <> metavar "STATE_DIR" + <> help + "Absolute or relative directory path \ + \ to save node and wallet state" + ) + nodeConfigsDirOption :: Parser (SomeDirOf "config") = + option + (eitherReader (bimap show Tagged . parseSomeDir)) + ( long "node-configs-dir" + <> short 'c' + <> metavar "NODE_CONFIGS_DIR" + <> help + "Absolute or relative directory path \ + \ to a directory with node configs" + )