Skip to content

Commit

Permalink
Local configuration of the E2E test suite uses local-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Unisay committed Oct 23, 2023
1 parent 5b84767 commit 47de832
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 208 deletions.
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ e2e-preprod:

# run wallet-e2e suite against the local test cluster
e2e-local:
nix run '.#cardano-wallet-e2e' -- local \
-s lib/wallet-e2e/test-state \
-c lib/wallet-e2e/config/cardano-node/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

# run wallet-e2e suite against the manually started node/wallet
e2e-manual:
Expand Down
4 changes: 2 additions & 2 deletions lib/local-cluster/exe/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import qualified Service
import qualified Cardano.Wallet.LocalCluster as LocalCluster

import Prelude

main :: IO ()
main = Service.main
main = LocalCluster.main
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}

module Service where
module Cardano.Wallet.LocalCluster where

import Prelude

Expand Down Expand Up @@ -42,6 +42,10 @@ import Cardano.Wallet.Launch.Cluster
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Control.Applicative
( optional
, (<**>)
)
import Control.Monad.Trans.Resource
( allocate
, runResourceT
Expand Down Expand Up @@ -78,6 +82,7 @@ import qualified Cardano.Node.Cli.Launcher as NC
import qualified Cardano.Wallet.Cli.Launcher as WC
import qualified Cardano.Wallet.Faucet.Mnemonics as Mnemonics
import qualified Cardano.Wallet.Launch.Cluster as Cluster
import qualified Options.Applicative as O
import qualified Path
import qualified Path.IO as PathIO

Expand Down Expand Up @@ -213,7 +218,9 @@ main = withUtf8 $ do
cfgNodeLogging <-
Cluster.logFileConfigFromEnv
(Just (Cluster.clusterEraToString clusterEra))
cfgClusterConfigs <- getClusterConfigsPath
cfgClusterConfigs <- parseCommandLineOptions >>= \case
CommandLineOptions Nothing -> getClusterConfigsPathFromEnv
CommandLineOptions (Just path) -> pure path
let clusterCfg = Cluster.Config
{ cfgStakePools = Cluster.defaultPoolConfigs
, cfgLastHardFork = clusterEra
Expand Down Expand Up @@ -270,8 +277,25 @@ main = withUtf8 $ do
-- | Returns a path to the local cluster configuration, which is usually relative to the
-- package sources, but can be overridden by the @LOCAL_CLUSTER_CONFIGS@ environment
-- variable.
getClusterConfigsPath :: IO (Tagged "cluster-configs" FilePath)
getClusterConfigsPath =
getClusterConfigsPathFromEnv :: IO (Tagged "cluster-configs" FilePath)
getClusterConfigsPathFromEnv =
lookupEnvNonEmpty "LOCAL_CLUSTER_CONFIGS" <&> Tagged . \case
Nothing -> $(getTestData) </> "cluster-configs"
Just fp -> fp


newtype CommandLineOptions = CommandLineOptions
{ clusterConfigsDir :: Maybe (Tagged "cluster-configs" FilePath)
}

parseCommandLineOptions :: IO CommandLineOptions
parseCommandLineOptions = O.execParser $
O.info (parser <**> O.helper) (O.progDesc "Local Cluster for testing")
where
parser = CommandLineOptions <$> optional (
Tagged <$> O.strOption
( O.long "cluster-configs"
<> O.metavar "LOCAL_CLUSTER_CONFIGS"
<> O.help "Path to the local cluster configuration directory"
)
)
3 changes: 2 additions & 1 deletion lib/local-cluster/local-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ library
Cardano.Wallet.Faucet.Mnemonics
Cardano.Wallet.Faucet.Shelley
Cardano.Wallet.Launch.Cluster
Service
Cardano.Wallet.LocalCluster

hs-source-dirs: lib
build-depends:
Expand Down Expand Up @@ -91,6 +91,7 @@ library
, memory ^>=0.18
, network-uri ^>=2.6.4.2
, OddWord ^>=1.0.1
, optparse-applicative
, ouroboros-network ^>=0.8.1
, ouroboros-network-api ^>=0.5
, path ^>=0.9.2
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet-e2e/cardano-wallet-e2e.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ library
Cardano.Wallet.Spec.Effect.Trace
Cardano.Wallet.Spec.Interpreters.Effectfully
Cardano.Wallet.Spec.Interpreters.Pure
Cardano.Wallet.Spec.Network.Config
Cardano.Wallet.Spec.Network.Configured
Cardano.Wallet.Spec.Network.Local
Cardano.Wallet.Spec.Network.Manual
Cardano.Wallet.Spec.Network.Node.Cli
Cardano.Wallet.Spec.Network.Preprod
Cardano.Wallet.Spec.Network.Wait
Cardano.Wallet.Spec.Network.Wallet.Cli
Cardano.Wallet.Spec.Stories.Language
Cardano.Wallet.Spec.Stories.Wallet
Expand Down
9 changes: 5 additions & 4 deletions lib/wallet-e2e/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ testNetworkOptionsToConfig = \case
TestNetworkOptionManual ->
pure TestNetworkManual
TestNetworkOptionLocal stateDir nodeConfigsDir -> do
absStateDir <- makeDirAbsolute (untag stateDir)
pure (TestNetworkLocal absStateDir)
absStateDir <- traverse makeDirAbsolute stateDir
absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir
pure (TestNetworkLocal absStateDir absNodeConfigsDir)
TestNetworkOptionPreprod stateDir nodeConfigsDir -> do
absStateDir <- makeDirAbsolute (untag stateDir)
absNodeConfigsDir <- makeDirAbsolute (untag nodeConfigsDir)
absStateDir <- traverse makeDirAbsolute stateDir
absNodeConfigsDir <- traverse makeDirAbsolute nodeConfigsDir
pure (TestNetworkPreprod absStateDir absNodeConfigsDir)
where
makeDirAbsolute = \case
Expand Down
47 changes: 29 additions & 18 deletions lib/wallet-e2e/src/Cardano/Wallet/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import qualified Cardano.Wallet.Spec.Network.Preprod as Preprod
import Cardano.Wallet.Spec.Interpreters.Effectfully
( story
)
import Cardano.Wallet.Spec.Network.Config
( NetworkConfig
import Cardano.Wallet.Spec.Network.Configured
( ConfiguredNetwork
)
import Cardano.Wallet.Spec.Stories.Wallet
( createdWalletHasZeroAda
Expand All @@ -22,6 +22,12 @@ import Cardano.Wallet.Spec.Stories.Wallet
import Cardano.Wallet.Spec.TimeoutSpec
( timeoutSpec
)
import Control.Monad.Trans.Resource
( runResourceT
)
import Data.Tagged
( Tagged
)
import Path
( Abs
, Dir
Expand All @@ -35,12 +41,11 @@ import Test.Syd
)

walletSpec :: TestNetworkConfig -> Spec
walletSpec networkConfig =
aroundAll (setupForNetwork networkConfig) 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 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

effectsSpec :: Spec
effectsSpec = describe "Effect interpreters" do
Expand All @@ -51,14 +56,20 @@ effectsSpec = describe "Effect interpreters" do

data TestNetworkConfig
= TestNetworkManual
| TestNetworkLocal !(Path Abs Dir)
| TestNetworkPreprod !(Path Abs Dir) !(Path Abs Dir)
| TestNetworkLocal
(Tagged "state" (Path Abs Dir))
(Tagged "config" (Path Abs Dir))
| TestNetworkPreprod
(Tagged "state" (Path Abs Dir))
(Tagged "config" (Path Abs Dir))

setupForNetwork :: TestNetworkConfig -> (NetworkConfig -> IO ()) -> IO ()
setupForNetwork = \case
TestNetworkManual ->
Manual.nodeWalletSetup
TestNetworkLocal stateDir ->
Local.nodeWalletSetup stateDir
TestNetworkPreprod stateDir nodeConfigDir ->
Preprod.nodeWalletSetup stateDir nodeConfigDir
configureTestNet :: TestNetworkConfig -> (ConfiguredNetwork -> IO ()) -> IO ()
configureTestNet testNetworkConfig withConfiguredNetwork = runResourceT $ do
config <- case testNetworkConfig of
TestNetworkManual ->
pure Manual.configuredNetwork
TestNetworkLocal stateDir nodeConfigDir ->
Local.configuredNetwork stateDir nodeConfigDir
TestNetworkPreprod stateDir nodeConfigDir ->
Preprod.configuredNetwork stateDir nodeConfigDir
liftIO $ withConfiguredNetwork config
54 changes: 27 additions & 27 deletions lib/wallet-e2e/src/Cardano/Wallet/Spec/Effect/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ import Cardano.Wallet.Spec.Effect.Trace
( FxTrace
, trace
)
import Cardano.Wallet.Spec.Network.Config
( NetworkConfig (..)
import Cardano.Wallet.Spec.Network.Configured
( ConfiguredNetwork (..)
)
import Effectful
( (:>)
Expand Down Expand Up @@ -158,10 +158,10 @@ runQuery
, FxAssert :> es
, FxTrace :> es
)
=> NetworkConfig
=> ConfiguredNetwork
-> Eff (FxQuery : es) a
-> Eff es a
runQuery networkConfig = interpret \_ -> \case
runQuery configuredNetwork = interpret \_ -> \case
ListKnownWallets -> do
resp <- runClient LW.listWallets
assert "ListKnownWallets response status"
Expand Down Expand Up @@ -321,28 +321,28 @@ runQuery networkConfig = interpret \_ -> \case
>>= \case
Left (e :: SomeException) ->
environmentException
$ WalletNetworkInfoException networkConfig e
$ WalletNetworkInfoException configuredNetwork e
Right resp | status <- responseStatus resp -> do
unless (status == ok200) do
environmentException
$ WalletNetworkInfoStatus networkConfig status
$ WalletNetworkInfoStatus configuredNetwork status
case responseBody resp of
W.GetNetworkInformationResponseError err ->
environmentException
$ WalletNetworkInfoError networkConfig (toText err)
$ WalletNetworkInfoError configuredNetwork (toText err)
W.GetNetworkInformationResponse406
W.GetNetworkInformationResponseBody406{..} ->
environmentException
$ WalletNetworkInfoError
networkConfig
configuredNetwork
getNetworkInformationResponseBody406Message
W.GetNetworkInformationResponse200
W.GetNetworkInformationResponseBody200{..} -> do
nodeStatus <-
NodeStatus.fromClientResponse getNetworkInformationResponseBody200Sync_progress
& maybe
( environmentException
$ WalletNetworkInfoUnknownNodeStatus networkConfig
$ WalletNetworkInfoUnknownNodeStatus configuredNetwork
)
pure
pure NetworkInfo{nodeStatus}
Expand All @@ -352,7 +352,7 @@ runQuery networkConfig = interpret \_ -> \case
WC.runWithConfiguration
WC.Configuration
{ WC.configBaseURL =
walletInstanceApiUrl (networkConfigWallet networkConfig)
walletInstanceApiUrl (configuredNetworkWallet configuredNetwork)
, WC.configSecurityScheme = WC.anonymousSecurityScheme
, WC.configIncludeUserAgent = False
, WC.configApplicationName = ""
Expand All @@ -362,33 +362,33 @@ environmentException :: (Fail :> es) => ExecutionEnvironmentException -> Eff es
environmentException = fail . displayException

data ExecutionEnvironmentException
= WalletNetworkInfoException NetworkConfig SomeException
| WalletNetworkInfoStatus NetworkConfig Http.Status
| WalletNetworkInfoError NetworkConfig Text
| NodeIsNotReady NetworkConfig
| WalletNetworkInfoUnknownNodeStatus NetworkConfig
= WalletNetworkInfoException ConfiguredNetwork SomeException
| WalletNetworkInfoStatus ConfiguredNetwork Http.Status
| WalletNetworkInfoError ConfiguredNetwork Text
| NodeIsNotReady ConfiguredNetwork
| WalletNetworkInfoUnknownNodeStatus ConfiguredNetwork
deriving anyclass (Exception)

instance Show ExecutionEnvironmentException where
show = \case
WalletNetworkInfoException networkConfig se ->
requirement networkConfig
WalletNetworkInfoException configuredNetwork se ->
requirement configuredNetwork
<> "However, an exception happened when trying to retrieve \n\
\network information from the wallet backend: \n\n"
<> displayException se
WalletNetworkInfoUnknownNodeStatus networkConfig ->
requirement networkConfig
WalletNetworkInfoStatus networkConfig _ ->
requirement networkConfig
WalletNetworkInfoError networkConfig _ ->
requirement networkConfig
NodeIsNotReady networkConfig ->
requirement networkConfig
WalletNetworkInfoUnknownNodeStatus configuredNetwork ->
requirement configuredNetwork
WalletNetworkInfoStatus configuredNetwork _ ->
requirement configuredNetwork
WalletNetworkInfoError configuredNetwork _ ->
requirement configuredNetwork
NodeIsNotReady configuredNetwork ->
requirement configuredNetwork
where
requirement :: NetworkConfig -> String
requirement :: ConfiguredNetwork -> String
requirement configuration =
"E2E test suite requires a running cardano-wallet instance \n\
\connected to a running cardano-node and listenting on "
<> show
(walletInstanceApiUrl (networkConfigWallet configuration))
(walletInstanceApiUrl (configuredNetworkWallet configuration))
<> "\n\n"
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import Cardano.Wallet.Spec.Effect.Trace
, recordTraceLog
, runTracePure
)
import Cardano.Wallet.Spec.Network.Config
( NetworkConfig
import Cardano.Wallet.Spec.Network.Configured
( ConfiguredNetwork
)
import Effectful
( Eff
Expand Down Expand Up @@ -73,7 +73,7 @@ type Story a =
]
a

story :: String -> Story () -> TestDefM '[NetworkConfig] () ()
story :: String -> Story () -> TestDefM '[ConfiguredNetwork] () ()
story label story' =
itWithOuter label \network -> do
interpretStory network story' >>= \(result, log) -> do
Expand All @@ -83,18 +83,18 @@ story label story' =
Right () -> pass

interpretStory
:: NetworkConfig
:: ConfiguredNetwork
-> Story a
-> IO (Either String a, Seq Text)
interpretStory networkConfig story' = do
interpretStory configuredNetwork story' = do
connectionManager <-
Http.newManager
Http.defaultManagerSettings
{ managerResponseTimeout = Http.responseTimeoutNone
}
stdGen <- initStdGen
story'
& runQuery networkConfig
& runQuery configuredNetwork
& runHttpClient connectionManager
& runRandom stdGen
& runTimeout
Expand Down
9 changes: 9 additions & 0 deletions lib/wallet-e2e/src/Cardano/Wallet/Spec/Network/Configured.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Cardano.Wallet.Spec.Network.Configured where

import Cardano.Wallet.Cli.Launcher
( WalletApi
)

newtype ConfiguredNetwork = ConfiguredNetwork
{ configuredNetworkWallet :: WalletApi
}
Loading

0 comments on commit 47de832

Please sign in to comment.