From c9fe1ab17840c3c10835a387969f05231dbe86e7 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 2 Mar 2026 22:34:44 +0000 Subject: [PATCH] fix: tests/setup/stack.ts: contract addresses have no env var override path (#391) Co-Authored-By: Claude Sonnet 4.6 --- docs/ENVIRONMENT.md | 16 ++++++++++++ tests/setup/health-checks.ts | 49 ++++++++++++++++++++++-------------- tests/setup/stack.ts | 4 ++- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 7d70df8..06a1fe3 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -95,6 +95,22 @@ For testing login: `lobsterDao`, `test123`, `lobster-x010syqe?412!` After bootstrap, addresses are in `/home/debian/harb/tmp/containers/contracts.env`. Landing sources this file on startup for `VITE_KRAIKEN_ADDRESS` and `VITE_STAKE_ADDRESS`. +## E2E Test Environment Variables + +The Playwright test setup (`tests/setup/stack.ts`) reads stack coordinates from env vars, falling back to `onchain/deployments-local.json` when they are absent. + +| Variable | Purpose | +|---|---| +| `STACK_RPC_URL` | RPC endpoint (default: `http://localhost:8081/api/rpc`) | +| `STACK_WEBAPP_URL` | Web app base URL (default: `http://localhost:8081`) | +| `STACK_GRAPHQL_URL` | GraphQL endpoint (default: `http://localhost:8081/api/graphql`) | +| `STACK_KRAIKEN_ADDRESS` | Kraiken contract address (overrides deployments-local.json) | +| `STACK_STAKE_ADDRESS` | Stake contract address (overrides deployments-local.json) | +| `STACK_LM_ADDRESS` | LiquidityManager contract address (overrides deployments-local.json) | +| `STACK_OPTIMIZER_PROXY_ADDRESS` | OptimizerProxy address (optional; enables optimizer integration tests) | + +When all three of `STACK_KRAIKEN_ADDRESS`, `STACK_STAKE_ADDRESS`, and `STACK_LM_ADDRESS` are set, the deployments file is not read at all, which allows tests to run in containerised environments that have no local checkout. + ## Playwright Testing ```bash diff --git a/tests/setup/health-checks.ts b/tests/setup/health-checks.ts index 38cb980..3f1febb 100644 --- a/tests/setup/health-checks.ts +++ b/tests/setup/health-checks.ts @@ -18,8 +18,12 @@ export interface HealthCheckResult { * 1. Checking eth_chainId returns the expected chain * 2. Making an eth_call to verify contract accessibility * 3. Confirming deployed contracts are accessible + * + * @param kraikenAddress - Optional Kraiken contract address. When provided the + * deployments-local.json file is not read, which allows the check to succeed + * in containerised environments that supply addresses via env vars. */ -export async function checkRpcFunctional(rpcUrl: string): Promise { +export async function checkRpcFunctional(rpcUrl: string, kraikenAddress?: string): Promise { const service = 'RPC Proxy'; try { @@ -54,24 +58,27 @@ export async function checkRpcFunctional(rpcUrl: string): Promise { // Skip GraphQL check temporarily - Ponder crashed but staking still works const results = await Promise.all([ - checkRpcFunctional(options.rpcUrl), + checkRpcFunctional(options.rpcUrl, options.contracts?.Kraiken), checkWebAppAccessible(options.webAppUrl), // checkGraphqlIndexed(options.graphqlUrl), ]); diff --git a/tests/setup/stack.ts b/tests/setup/stack.ts index 359879b..f8bac03 100644 --- a/tests/setup/stack.ts +++ b/tests/setup/stack.ts @@ -34,14 +34,16 @@ function loadContractAddresses(): ContractAddresses { const envLm = process.env.STACK_LM_ADDRESS; if (envKraiken && envStake && envLm) { + const envOptimizerProxy = process.env.STACK_OPTIMIZER_PROXY_ADDRESS; return { Kraiken: envKraiken, Stake: envStake, LiquidityManager: envLm, + ...(envOptimizerProxy !== undefined ? { OptimizerProxy: envOptimizerProxy } : {}), }; } - let fileContracts: ContractAddresses; + let fileContracts!: ContractAddresses; try { const deploymentsPath = join(process.cwd(), 'onchain', 'deployments-local.json'); const deploymentsJson = readFileSync(deploymentsPath, 'utf-8');