Skip to content

Commit

Permalink
[ADP-3252] Add logs directory option to wallet e2e executable (#4381)
Browse files Browse the repository at this point in the history
- [x] add an option to control where test trace logs are written
- [x] update justfile to use the new option
- [x] refactor code for less duplication

ADP-3252
  • Loading branch information
paolino authored Jan 2, 2024
2 parents 25d66cd + 38bb032 commit f28e540
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 182 deletions.
17 changes: 11 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -36,14 +36,19 @@ integration:
# run wallet-e2e suite against the preprod network
e2e-preprod:
nix run '.#cardano-wallet-e2e' -- preprod \
-s lib/wallet-e2e/test-state \
-c lib/wallet-e2e/config/cardano-node/preprod
-s lib/wallet-e2e/test-state/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:
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 \
-t lib/wallet-e2e/test-output/local

# run wallet-e2e suite against the manually started node/wallet
e2e-manual:
Expand Down
3 changes: 3 additions & 0 deletions lib/wallet-e2e/cardano-wallet-e2e.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ 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.Lib.Paths
Cardano.Wallet.Spec.Network.Configured
Cardano.Wallet.Spec.Network.Local
Cardano.Wallet.Spec.Network.Manual
Expand All @@ -116,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
Expand Down
124 changes: 5 additions & 119 deletions lib/wallet-e2e/exe/Main.hs
Original file line number Diff line number Diff line change
@@ -1,137 +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 Data.Tagged
( Tagged (..)
)
import Main.Utf8
( withUtf8
)
import Options.Applicative
( Parser
, eitherReader
, execParser
, fullDesc
, help
, helper
, info
, long
, metavar
, option
, progDesc
, short
)
import Path
( Dir
, SomeBase (..)
, parseSomeDir
)
import Path.IO
( AnyPath (makeAbsolute)
import Options
( withTestOptions
)
import Test.Syd
( sydTestWith
)

main :: IO ()
main = withUtf8 do
testNetworkOptions <-
execParser
$ info
(parser <**> helper)
(fullDesc <> progDesc "E2E Wallet test suite")
testNetwork <- testNetworkOptionsToConfig testNetworkOptions
main = withUtf8 $ withTestOptions $ \testNetwork traceConfiguration ->
sydTestWith SydTest.defaultSettings{SydTest.settingRetries = 1} do
effectsSpec
walletSpec testNetwork

--------------------------------------------------------------------------------
-- Command line options --------------------------------------------------------

data TestNetworkOptions
= TestNetworkOptionManual
| TestNetworkOptionLocal
(Tagged "state" (SomeBase Dir))
(Tagged "config" (SomeBase Dir))
| TestNetworkOptionPreprod
(Tagged "state" (SomeBase Dir))
(Tagged "config" (SomeBase Dir))

testNetworkOptionsToConfig :: TestNetworkOptions -> IO TestNetworkConfig
testNetworkOptionsToConfig = \case
TestNetworkOptionManual ->
pure TestNetworkManual
TestNetworkOptionLocal stateDir nodeConfigsDir -> do
absStateDir <- traverse makeDirAbsolute stateDir
absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir
pure (TestNetworkLocal absStateDir absNodeConfigsDir)
TestNetworkOptionPreprod stateDir nodeConfigsDir -> do
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
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 (Tagged "state" (SomeBase Dir)) =
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 (Tagged "config" (SomeBase Dir)) =
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"
)
walletSpec traceConfiguration testNetwork
142 changes: 142 additions & 0 deletions lib/wallet-e2e/exe/Options.hs
Original file line number Diff line number Diff line change
@@ -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"
)
Loading

0 comments on commit f28e540

Please sign in to comment.