Skip to content

Commit

Permalink
Use Haskell to configure mithril in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Feb 6, 2025
1 parent 3de379e commit a81c239
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 63 deletions.
5 changes: 0 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,6 @@ steps:
agents:
system: ${windows}
env:
NODE_DB_DIR: "test\\e2e\\state\\node\\db"
NODE_DIR: "test\\e2e\\state\\node"
WALLET_DB_DIR: "test\\e2e\\state\\wallet"
AGGREGATOR_ENDPOINT: "${PREPROD_AGGREGATOR_ENDPOINT}"
GENESIS_VERIFICATION_KEY: "${PREPROD_GENESIS_VERIFICATION_KEY}"
concurrency: 1
concurrency_group: 'windows-tests'

Expand Down
82 changes: 52 additions & 30 deletions lib/integration/exe/e2e.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Test.Integration.Scenario.Preprod as Preprod

import Cardano.Launcher.Mithril
( downloadLatestSnapshot
, downloadMithril
)
import Cardano.Launcher.Node
( CardanoNodeConfig (..)
, isWindows
Expand Down Expand Up @@ -71,11 +75,15 @@ import Network.URI
( parseURI
)
import System.Directory
( createDirectoryIfMissing
( copyFile
, createDirectoryIfMissing
, doesDirectoryExist
, getCurrentDirectory
, listDirectory
)
import System.Environment
( lookupEnv
, setEnv
)
import System.FilePath
( takeDirectory
Expand Down Expand Up @@ -105,28 +113,15 @@ import Test.Utils.Paths

-- ENV configuration -----------------------------------------------------------

data E2EConfig = E2EConfig
{ walletDbDir :: FilePath
, nodeDir :: FilePath
, nodeDbDir :: FilePath
, preprodMnemonics :: [SomeMnemonic]
newtype E2EConfig = E2EConfig
{ preprodMnemonics :: [SomeMnemonic]
}

getConfig :: IO E2EConfig
getConfig = do
walletDbDir <- fromMaybe defaultWalletDbDir <$> lookupEnv "WALLET_DB_DIR"
nodeDbDir <- fromMaybe defaultNodeDbDir <$> lookupEnv "NODE_DB_DIR"
nodeDir <- fromMaybe defaultNodeDir <$> lookupEnv "NODE_DIR"
preprodMnemonics <- getPreprodMnemonics
pure $ E2EConfig {..}
where
-- Probably too fine grained control with all these settings, but works for now
defaultNodeDbDir = repoRoot </> "test" </> "e2e" </> "state" </> "node" </> "db"
defaultNodeDir = repoRoot </> "test" </> "e2e" </> "state" </> "node"
defaultWalletDbDir = repoRoot </> "test" </> "e2e" </> "state" </> "wallet"

repoRoot = ".." </> ".." -- works when run with 'cabal test'

getPreprodMnemonics :: IO [SomeMnemonic]
getPreprodMnemonics
= map (SomeMnemonic . unsafeMkMnemonic @15 . T.words)
Expand Down Expand Up @@ -160,19 +155,46 @@ main = withUtf8 $ do

-- setup -----------------------------------------------------------------------



-- | Recursively copy a directory from 'src' to 'dst'
copyDir :: FilePath -> FilePath -> IO ()
copyDir src dst = do
-- Create the destination directory (and parents) if needed.
createDirectoryIfMissing True dst
-- List all items in the source directory.
entries <- listDirectory src
-- Process each entry.
forM_ entries $ \entry -> do
let srcPath = src </> entry
dstPath = dst </> entry
isDir <- doesDirectoryExist srcPath
if isDir
then copyDir srcPath dstPath -- recursively copy subdirectories
else copyFile srcPath dstPath -- copy individual files

-- Usage:
--

configureContext :: E2EConfig -> (Context -> IO ()) -> IO ()
configureContext E2EConfig{walletDbDir,nodeDbDir,nodeDir,preprodMnemonics} action = do
cwd <- getCurrentDirectory
let nodeSocket = if isWindows
then "\\\\.\\pipe\\socket"
else cwd </> nodeDbDir </> "node.socket"
configureContext E2EConfig{preprodMnemonics} action = do
-- TODO only set if unset
setEnv "GENESIS_VERIFICATION_KEY" "5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d"
setEnv "AGGREGATOR_ENDPOINT" "https://aggregator.release-preprod.api.mithril.network/aggregator"

withConfigDir $ \configDir -> do
downloadLatestSnapshot configDir =<< downloadMithril
--copyDir ("db" </> "db") (configDir </> "db")

let nodeSocket = if isWindows
then "\\\\.\\pipe\\socket"
else "node.socket"
let nodeConfig =
CardanoNodeConfig
{ nodeDir = cwd </> nodeDir
, nodeConfigFile = cwd </> configDir </> "config.json"
, nodeTopologyFile = cwd </> configDir </> "topology.json"
, nodeDatabaseDir = cwd </> nodeDbDir
{ nodeDir = configDir
, nodeConfigFile = configDir </> "config.json"
, nodeTopologyFile = configDir </> "topology.json"
, nodeDatabaseDir = configDir </> "db"
, nodeDlgCertFile = Nothing
, nodeSignKeyFile = Nothing
, nodeOpCertFile = Nothing
Expand All @@ -185,15 +207,15 @@ configureContext E2EConfig{walletDbDir,nodeDbDir,nodeDir,preprodMnemonics} actio
, nodeSocketPathFile = JustK nodeSocket
}


withCardanoNode nullTracer nodeConfig $ \(JustK node) -> do
let walletConfig =
CardanoWalletConfig
{ walletPort = 8090
, walletDatabaseDir = walletDbDir
, walletNetwork = Launcher.Testnet $
configDir </> "byron-genesis.json"
, walletDatabaseDir = "wallet-db"
, walletNetwork = Launcher.Testnet "byron-genesis.json"
, executable = Nothing
, workingDir = Nothing
, workingDir = Just configDir
, extraArgs = []
}
withCardanoWallet nullTracer node walletConfig $ \wallet -> do
Expand Down Expand Up @@ -247,7 +269,7 @@ configureContext E2EConfig{walletDbDir,nodeDbDir,nodeDir,preprodMnemonics} actio
-- compile-time, and tweaked for less verbose logs.
withConfigDir :: (FilePath -> IO a) -> IO a
withConfigDir action = liftIO $
withSystemTempDirectory "e2e-node-configs" $ \tmpDir -> do
withSystemTempDirectory "e2e" $ \tmpDir -> do
-- Write the embedded config dir to the temporary dir
forM_ embeddedConfigs $ \(relPath, content) -> do
let dest = tmpDir </> relPath
Expand Down
3 changes: 3 additions & 0 deletions lib/launcher/cardano-wallet-launcher.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ library
base
, bytestring
, contra-tracer
, directory
, either
, extra
, filepath
, fmt
, http-conduit
, iohk-monitoring
, network
, process
Expand All @@ -49,6 +51,7 @@ library
Cardano.Launcher
Cardano.Launcher.Node
Cardano.Launcher.Wallet
Cardano.Launcher.Mithril
Cardano.Startup
Data.MaybeK
if os(windows)
Expand Down
29 changes: 1 addition & 28 deletions scripts/buildkite/main/windows-e2e.bat
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
set PATH=%PATH%;C:\Users\hal\AppData\Local\Microsoft\WinGet\Links

REM ------------- mithril -------------

SET mithril-tar=mithril-2450.0-windows-x64.tar
echo %mithril-tar%
SET mithril-package=%mithril-tar%.gz
echo %mithril-package%
wget https://github.com/input-output-hk/mithril/releases/download/2450.0/%mithril-package%
7z x .\%mithril-package%
tar xf .\%mithril-tar%
.\mithril-client.exe --version
for /f "delims=" %%i in ('.\mithril-client.exe cdb snapshot list --json ^| jq -r .[0].digest') do set digest=%%i
echo %digest%
.\mithril-client.exe cdb download --download-dir . %digest%
REM delete the old db folder
REM this is stupid but will do for now
mkdir %NODE_DB_DIR%
rd /q /s %NODE_DB_DIR%
REM move the new db folder entirely into the old db folder
move .\db %NODE_DB_DIR%
ls %NODE_DB_DIR%

REM ------------- ruby tests -------------

cd test\e2e
call bundle install
call bundle exec rake get_latest_windows_tests[%BUILDKITE_BRANCH%,bins,any,latest]
cd ..\..

echo %NODE_DB_DIR%
echo %WALLET_DB_DIR%
test\e2e\bins\cardano-wallet-integration-test-e2e.exe
bins\cardano-wallet-integration-test-e2e.exe
exit /b %ERRORLEVEL%

0 comments on commit a81c239

Please sign in to comment.