From 04a3e03d66832a4f6fa83caf5429fd8f2f7bc224 Mon Sep 17 00:00:00 2001 From: Bogdan Crisan Date: Wed, 16 Oct 2024 22:34:40 +0200 Subject: [PATCH] [ECO-2262] Fix playwright tests (#294) Co-authored-by: Matt <90358481+xbtmatt@users.noreply.github.com> --- .../{playwright.yaml => frontend-e2e.yaml} | 23 +++++--- cfg/cspell-frontend-dictionary.txt | 1 + src/docker/compose.yaml | 8 ++- src/docker/example.local.env | 3 - src/docker/frontend/Dockerfile | 10 ++-- src/typescript/ci.env | 1 + src/typescript/frontend/.eslintignore | 1 + src/typescript/frontend/package.json | 5 +- src/typescript/frontend/playwright.config.ts | 56 +++++++------------ .../frontend/src/app/pools/api/route.ts | 10 +++- src/typescript/frontend/src/app/test/route.ts | 8 +-- src/typescript/frontend/src/lib/env.ts | 2 +- .../frontend/src/lib/utils/aptos-client.ts | 15 ++++- .../frontend/tests/e2e/global.setup.ts | 11 ++++ .../frontend/tests/e2e/global.teardown.ts | 6 ++ src/typescript/package.json | 5 +- .../utils/test}/docker/docker-test-harness.ts | 54 +++++++++--------- .../utils => src/utils/test}/docker/logs.ts | 8 +-- .../utils => src/utils/test}/docker/utils.ts | 11 ++-- .../utils/test}/ensure-write-file-sync.ts | 0 .../test}/get-publish-txn-from-indexer.ts | 4 +- .../test}/get-txn-batch-highest-version.ts | 2 +- .../utils => src/utils/test}/helpers.ts | 10 ++-- .../{tests/utils => src/utils/test}/index.ts | 2 +- .../utils => src/utils/test}/load-priv-key.ts | 2 +- .../utils => src/utils/test}/print-divider.ts | 0 .../utils => src/utils/test}/publish.ts | 4 +- .../utils => src/utils/test}/sample-data.ts | 4 +- .../utils => src/utils/test}/test-accounts.ts | 2 +- .../sdk/tests/e2e/broker/websockets.test.ts | 4 +- src/typescript/sdk/tests/e2e/chat.test.ts | 4 +- .../sdk/tests/e2e/emoji-data.test.ts | 4 +- src/typescript/sdk/tests/e2e/fund.test.ts | 2 +- src/typescript/sdk/tests/e2e/publish.test.ts | 4 +- .../sdk/tests/e2e/queries/address.test.ts | 6 +- .../tests/e2e/queries/liquidity-pools.test.ts | 6 +- .../tests/e2e/queries/market-state.test.ts | 6 +- .../sdk/tests/e2e/queries/num-markets.test.ts | 4 +- .../tests/e2e/queries/search-emojis.test.ts | 4 +- .../sdk/tests/e2e/queries/simple.test.ts | 6 +- .../e2e/queries/sorted/sort-queries.test.ts | 6 +- .../sdk/tests/e2e/queries/volume.test.ts | 8 +-- src/typescript/sdk/tests/e2e/register.test.ts | 4 +- src/typescript/sdk/tests/e2e/swap.test.ts | 4 +- src/typescript/sdk/tests/e2e/views.test.ts | 2 +- src/typescript/sdk/tests/post-test.ts | 6 +- src/typescript/sdk/tests/pre-test.ts | 10 ++-- .../sdk/tests/unit/emoji-regex.test.ts | 2 +- .../sdk/tests/unit/git-root.test.ts | 2 +- .../sdk/tests/unit/period-boundaries.test.ts | 2 +- src/typescript/turbo.json | 16 ++++-- 51 files changed, 208 insertions(+), 172 deletions(-) rename .github/workflows/{playwright.yaml => frontend-e2e.yaml} (58%) create mode 100644 src/typescript/frontend/tests/e2e/global.setup.ts create mode 100644 src/typescript/frontend/tests/e2e/global.teardown.ts rename src/typescript/sdk/{tests/utils => src/utils/test}/docker/docker-test-harness.ts (81%) rename src/typescript/sdk/{tests/utils => src/utils/test}/docker/logs.ts (91%) rename src/typescript/sdk/{tests/utils => src/utils/test}/docker/utils.ts (92%) rename src/typescript/sdk/{tests/utils => src/utils/test}/ensure-write-file-sync.ts (100%) rename src/typescript/sdk/{tests/utils => src/utils/test}/get-publish-txn-from-indexer.ts (91%) rename src/typescript/sdk/{tests/utils => src/utils/test}/get-txn-batch-highest-version.ts (84%) rename src/typescript/sdk/{tests/utils => src/utils/test}/helpers.ts (95%) rename src/typescript/sdk/{tests/utils => src/utils/test}/index.ts (65%) rename src/typescript/sdk/{tests/utils => src/utils/test}/load-priv-key.ts (96%) rename src/typescript/sdk/{tests/utils => src/utils/test}/print-divider.ts (100%) rename src/typescript/sdk/{tests/utils => src/utils/test}/publish.ts (98%) rename src/typescript/sdk/{tests/utils => src/utils/test}/sample-data.ts (94%) rename src/typescript/sdk/{tests/utils => src/utils/test}/test-accounts.ts (96%) diff --git a/.github/workflows/playwright.yaml b/.github/workflows/frontend-e2e.yaml similarity index 58% rename from .github/workflows/playwright.yaml rename to .github/workflows/frontend-e2e.yaml index 3a5676901..820131ca1 100644 --- a/.github/workflows/playwright.yaml +++ b/.github/workflows/frontend-e2e.yaml @@ -3,7 +3,7 @@ jobs: test: defaults: run: - working-directory: 'src/typescript/frontend' + working-directory: 'src/typescript' runs-on: 'ubuntu-latest' steps: - uses: 'actions/checkout@v4' @@ -15,14 +15,23 @@ jobs: - env: GITHUB_ACCESS_TOKEN: '${{ secrets.TRADING_VIEW_REPO_ACCESS_TOKEN }}' TRADING_VIEW_REPO_OWNER: '${{ secrets.TRADING_VIEW_REPO_OWNER }}' - name: 'Prepare CI env' - run: 'pnpm run playwright-preps' + name: 'Test' + run: 'echo -n $TRADING_VIEW_REPO_OWNER | wc -c' + - env: + GITHUB_ACCESS_TOKEN: '${{ secrets.TRADING_VIEW_REPO_ACCESS_TOKEN }}' + TRADING_VIEW_REPO_OWNER: '${{ secrets.TRADING_VIEW_REPO_OWNER }}' + name: 'Clone submodule' + run: 'pnpm run submodule' + - name: 'Run pnpm i' + run: 'pnpm i' - name: 'Install Playwright Browsers' - run: 'pnpm exec playwright install --with-deps' + run: 'pnpm run playwright:install' - name: 'Copy env file' - run: 'cp ../env.ci .env' + run: 'cp ci.env .env' + - name: 'Copy docker env file' + run: 'cp ../docker/example.local.env ../docker/.env' - name: 'Run Playwright tests' - run: 'pnpm exec playwright test' + run: 'pnpm run e2e:frontend' - if: 'always()' uses: 'actions/upload-artifact@v4' with: @@ -30,7 +39,7 @@ jobs: path: 'playwright-report/' retention-days: 30 timeout-minutes: 60 -name: 'Playwright Tests' +name: 'Run the Playwright E2E tests' "on": pull_request: branches: diff --git a/cfg/cspell-frontend-dictionary.txt b/cfg/cspell-frontend-dictionary.txt index 8021d7194..c814a2cc8 100644 --- a/cfg/cspell-frontend-dictionary.txt +++ b/cfg/cspell-frontend-dictionary.txt @@ -49,3 +49,4 @@ ipinfo localstorage vpnapi ctrls +dockerenv diff --git a/src/docker/compose.yaml b/src/docker/compose.yaml index c34ac2690..fa7e7fe6d 100644 --- a/src/docker/compose.yaml +++ b/src/docker/compose.yaml @@ -93,17 +93,20 @@ services: - '${PROCESSOR_WS_PORT}:${PROCESSOR_WS_PORT}' frontend: + extra_hosts: + - 'host.docker.internal:host-gateway' build: context: '../..' dockerfile: 'src/docker/frontend/Dockerfile' args: HASH_SEED: '${HASH_SEED}' + EMOJICOIN_INDEXER_URL: 'http://localhost:3000' NEXT_PUBLIC_APTOS_NETWORK: '${APTOS_NETWORK}' NEXT_PUBLIC_INTEGRATOR_ADDRESS: '${EMOJICOIN_INTEGRATOR_ADDRESS}' NEXT_PUBLIC_INTEGRATOR_FEE_RATE_BPS: '${FEE_RATE_BPS}' NEXT_PUBLIC_IS_ALLOWLIST_ENABLED: 'false' NEXT_PUBLIC_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}' - NEXT_PUBLIC_MQTT_URL: 'ws://localhost:${BROKER_PORT}' + NEXT_PUBLIC_BROKER_URL: 'ws://localhost:${BROKER_PORT}' NEXT_PUBLIC_REWARDS_MODULE_ADDRESS: >- ${EMOJICOIN_REWARDS_MODULE_ADDRESS} REVALIDATION_TIME: '${REVALIDATION_TIME}' @@ -113,12 +116,13 @@ services: - 'frontend' environment: HASH_SEED: '${HASH_SEED}' + EMOJICOIN_INDEXER_URL: 'http://localhost:3000' NEXT_PUBLIC_APTOS_NETWORK: '${APTOS_NETWORK}' NEXT_PUBLIC_INTEGRATOR_ADDRESS: '${EMOJICOIN_INTEGRATOR_ADDRESS}' NEXT_PUBLIC_INTEGRATOR_FEE_RATE_BPS: '${FEE_RATE_BPS}' NEXT_PUBLIC_IS_ALLOWLIST_ENABLED: 'false' NEXT_PUBLIC_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}' - NEXT_PUBLIC_MQTT_URL: 'ws://localhost:${BROKER_PORT}' + NEXT_PUBLIC_BROKER_URL: 'ws://localhost:${BROKER_PORT}' NEXT_PUBLIC_REWARDS_MODULE_ADDRESS: '${EMOJICOIN_REWARDS_MODULE_ADDRESS}' REVALIDATION_TIME: '${REVALIDATION_TIME}' healthcheck: diff --git a/src/docker/example.local.env b/src/docker/example.local.env index 9ccd03f76..268f5a1f2 100644 --- a/src/docker/example.local.env +++ b/src/docker/example.local.env @@ -77,6 +77,3 @@ FEE_RATE_BPS="100" # Secret hash seed. HASH_SEED="some random string that is not public" - -# The URL for the indexer's `postgrest` REST API. -EMOJICOIN_INDEXER_URL="http://localhost:3000" diff --git a/src/docker/frontend/Dockerfile b/src/docker/frontend/Dockerfile index 87907c6f7..091d2b9cd 100644 --- a/src/docker/frontend/Dockerfile +++ b/src/docker/frontend/Dockerfile @@ -8,7 +8,7 @@ RUN ["mv", "/root/.local/share/pnpm/pnpm", "/usr/local/bin"] COPY . / -WORKDIR /src/typescript/frontend +WORKDIR /src/typescript ARG HASH_SEED \ NEXT_PUBLIC_APTOS_NETWORK \ @@ -19,8 +19,7 @@ ARG HASH_SEED \ NEXT_PUBLIC_REWARDS_MODULE_ADDRESS \ NEXT_PUBLIC_BROKER_URL \ REVALIDATION_TIME \ - EMOJICOIN_INDEXER_URL \ - EMOJICOIN_INDEXER_API_KEY + EMOJICOIN_INDEXER_URL ENV HASH_SEED=$HASH_SEED \ NEXT_PUBLIC_APTOS_NETWORK=$NEXT_PUBLIC_APTOS_NETWORK \ NEXT_PUBLIC_INTEGRATOR_ADDRESS=$NEXT_PUBLIC_INTEGRATOR_ADDRESS \ @@ -30,9 +29,8 @@ ENV HASH_SEED=$HASH_SEED \ NEXT_PUBLIC_REWARDS_MODULE_ADDRESS=$NEXT_PUBLIC_REWARDS_MODULE_ADDRESS \ NEXT_PUBLIC_BROKER_URL=$NEXT_PUBLIC_BROKER_URL \ REVALIDATION_TIME=$REVALIDATION_TIME \ - EMOJICOIN_INDEXER_URL=$EMOJICOIN_INDEXER_URL \ - EMOJICOIN_INDEXER_API_KEY=${EMOJICOIN_INDEXER_API_KEY} + EMOJICOIN_INDEXER_URL=$EMOJICOIN_INDEXER_URL RUN ["bash", "-c", "pnpm install && pnpm run build"] -CMD ["pnpm", "run", "start", "-H", "0.0.0.0"] +CMD ["bash", "-c", "pnpm run start -- -H 0.0.0.0"] diff --git a/src/typescript/ci.env b/src/typescript/ci.env index f0095dc30..6fc7c9a20 100644 --- a/src/typescript/ci.env +++ b/src/typescript/ci.env @@ -1,3 +1,4 @@ +APTOS_NETWORK="local" NEXT_PUBLIC_APTOS_NETWORK="local" NEXT_PUBLIC_BROKER_URL="ws://localhost:3009" NEXT_PUBLIC_MODULE_ADDRESS="0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d" diff --git a/src/typescript/frontend/.eslintignore b/src/typescript/frontend/.eslintignore index d737c4ec3..429512ba7 100644 --- a/src/typescript/frontend/.eslintignore +++ b/src/typescript/frontend/.eslintignore @@ -2,3 +2,4 @@ build/ dist/ .next/ public/static/ +tests/e2e/global.*.ts diff --git a/src/typescript/frontend/package.json b/src/typescript/frontend/package.json index 800ac216b..6bfb399d0 100644 --- a/src/typescript/frontend/package.json +++ b/src/typescript/frontend/package.json @@ -90,19 +90,20 @@ "build:debug": "BUILD_DEBUG=true next build --no-lint --no-mangling --debug", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next", "dev": "NODE_OPTIONS='--inspect' next dev --turbo --port 3001", - "e2e": "playwright test", "e2e-chromium": "playwright test --project=chromium", "e2e-firefox": "playwright test --project=firefox", "e2e-webkit": "playwright test --project=webkit", + "e2e:frontend": "playwright test --project=firefox", "format": "pnpm _format --write", "format:check": "pnpm _format --check", "lint": "eslint -c .eslintrc.js --ext .js,.jsx,.ts,.tsx .", "lint:fix": "pnpm run lint --fix", - "playwright-preps": "./submodule.sh && pnpm i && pnpm exec playwright install", + "playwright:install": "playwright install --with-deps", "pre-commit": "pnpm run pre-commit:install && pnpm run pre-commit:run", "pre-commit:install": "pre-commit install -c ../../../cfg/pre-commit-config.yaml", "pre-commit:run": "pre-commit run --all-files -c ../../../cfg/pre-commit-config.yaml", "start": "next start --port 3001", + "submodule": "./submodule.sh", "vercel-install": "./submodule.sh && pnpm i" }, "version": "0.0.1-alpha" diff --git a/src/typescript/frontend/playwright.config.ts b/src/typescript/frontend/playwright.config.ts index 9b1116d3d..ccfcab617 100644 --- a/src/typescript/frontend/playwright.config.ts +++ b/src/typescript/frontend/playwright.config.ts @@ -1,12 +1,5 @@ import { defineConfig, devices } from "@playwright/test"; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// import dotenv from 'dotenv'; -// dotenv.config({ path: path.resolve(__dirname, '.env') }); - /** * See https://playwright.dev/docs/test-configuration. */ @@ -21,7 +14,7 @@ export default defineConfig({ /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", + reporter: process.env.GITHUB_ACTIONS ? "github" : "list", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ @@ -29,51 +22,42 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", + + launchOptions: { + env: { + ...process.env, + NODE_OPTIONS: `${process.env.NODE_OPTIONS || ""} --conditions=react-server`, + }, + }, }, /* Configure projects for major browsers */ projects: [ + { + name: "setup", + testMatch: /global\.setup\.ts/, + teardown: "teardown", + }, + { + name: "teardown", + testMatch: /global\.teardown\.ts/, + }, { name: "chromium", use: { ...devices["Desktop Chrome"] }, + dependencies: ["setup"], }, { name: "firefox", use: { ...devices["Desktop Firefox"] }, + dependencies: ["setup"], }, { name: "webkit", use: { ...devices["Desktop Safari"] }, + dependencies: ["setup"], }, - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { ...devices['Pixel 5'] }, - // }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, ], - - /* Run your local dev server before starting the tests */ - webServer: { - command: "pnpm run build && pnpm run start", - url: "http://127.0.0.1:3001/", - reuseExistingServer: false, - timeout: 120 * 1000, - }, }); diff --git a/src/typescript/frontend/src/app/pools/api/route.ts b/src/typescript/frontend/src/app/pools/api/route.ts index e6ab2af2c..8a640addf 100644 --- a/src/typescript/frontend/src/app/pools/api/route.ts +++ b/src/typescript/frontend/src/app/pools/api/route.ts @@ -23,6 +23,12 @@ export async function GET(request: Request) { // The liquidity `provider`, aka the account to search for in the user liquidity pools. const provider = searchParams.get("account"); - const data = await getPoolData(page, sortBy, orderBy, searchEmojis, provider ?? undefined); - return new Response(stringifyJSON(data)); + let res: Awaited> = []; + + try { + res = await getPoolData(page, sortBy, orderBy, searchEmojis, provider ?? undefined); + } catch (e) { + console.error(e); + } + return new Response(stringifyJSON(res)); } diff --git a/src/typescript/frontend/src/app/test/route.ts b/src/typescript/frontend/src/app/test/route.ts index d36c92079..afee2db37 100644 --- a/src/typescript/frontend/src/app/test/route.ts +++ b/src/typescript/frontend/src/app/test/route.ts @@ -1,15 +1,15 @@ -import { REVALIDATE_TEST } from "const"; import { getAptos } from "lib/utils/aptos-client"; import { NextResponse } from "next/server"; -export const revalidate = REVALIDATE_TEST; +export const revalidate = 2; +export const fetchCache = "default-cache"; export async function GET() { const aptos = getAptos(); try { const version = await aptos.getLedgerInfo().then((res) => res.ledger_version); return new NextResponse(version.toString()); - } catch { - return new NextResponse("", { status: 500 }); + } catch (e) { + return new NextResponse(JSON.stringify(e), { status: 500 }); } } diff --git a/src/typescript/frontend/src/lib/env.ts b/src/typescript/frontend/src/lib/env.ts index 945ab3d06..8c69f0d56 100644 --- a/src/typescript/frontend/src/lib/env.ts +++ b/src/typescript/frontend/src/lib/env.ts @@ -25,7 +25,7 @@ const IS_ALLOWLIST_ENABLED: boolean = process.env.NEXT_PUBLIC_IS_ALLOWLIST_ENABL if (process.env.NEXT_PUBLIC_APTOS_NETWORK) { const network = process.env.NEXT_PUBLIC_APTOS_NETWORK; - if (["mainnet", "testnet", "devnet", "local", "custom"].includes(network)) { + if (["mainnet", "testnet", "devnet", "local", "custom", "docker"].includes(network)) { APTOS_NETWORK = network as Network; } else { throw new Error(`Invalid network: ${network}`); diff --git a/src/typescript/frontend/src/lib/utils/aptos-client.ts b/src/typescript/frontend/src/lib/utils/aptos-client.ts index d966815d0..b6f2bb710 100644 --- a/src/typescript/frontend/src/lib/utils/aptos-client.ts +++ b/src/typescript/frontend/src/lib/utils/aptos-client.ts @@ -1,12 +1,25 @@ /* eslint-disable import/no-unused-modules */ // Used in the frontend repo. +/* eslint-disable @typescript-eslint/no-var-requires */ import { NetworkToFaucetAPI, NetworkToIndexerAPI, NetworkToNodeAPI } from "@aptos-labs/ts-sdk"; import { Aptos, AptosConfig, NetworkToNetworkName } from "@aptos-labs/ts-sdk"; import { APTOS_NETWORK } from "lib/env"; +const toDockerUrl = (url: string) => url.replace("127.0.0.1", "host.docker.internal"); + // Get an Aptos config based off of the network environment variables. export const getAptosConfig = (): AptosConfig => { - // Check if it's a valid network. const networkString = APTOS_NETWORK; + if (networkString === "local" && typeof window === "undefined") { + const fs = require("node:fs"); + if (fs.existsSync("/.dockerenv")) { + return new AptosConfig({ + network: NetworkToNetworkName["local"], + fullnode: toDockerUrl(NetworkToNodeAPI["local"]), + indexer: toDockerUrl(NetworkToIndexerAPI["local"]), + faucet: toDockerUrl(NetworkToFaucetAPI["local"]), + }); + } + } const network = NetworkToNetworkName[networkString ?? APTOS_NETWORK]; const fullnode = NetworkToNodeAPI[network]; const indexer = NetworkToIndexerAPI[network]; diff --git a/src/typescript/frontend/tests/e2e/global.setup.ts b/src/typescript/frontend/tests/e2e/global.setup.ts new file mode 100644 index 000000000..e4782ba2f --- /dev/null +++ b/src/typescript/frontend/tests/e2e/global.setup.ts @@ -0,0 +1,11 @@ +import { test as setup } from "@playwright/test"; +import { DockerTestHarness } from "../../../sdk/src/utils/test/docker/docker-test-harness"; + +setup("setup the Docker containers", async ({}) => { + // Five minute timeout. + setup.setTimeout(300_000); + const startDockerServices = process.env.APTOS_NETWORK === "local"; + if (startDockerServices) { + await DockerTestHarness.run(true); + } +}); diff --git a/src/typescript/frontend/tests/e2e/global.teardown.ts b/src/typescript/frontend/tests/e2e/global.teardown.ts new file mode 100644 index 000000000..f22043bd2 --- /dev/null +++ b/src/typescript/frontend/tests/e2e/global.teardown.ts @@ -0,0 +1,6 @@ +/* eslint-disable no-underscore-dangle */ +import { DockerTestHarness } from "../../../sdk/src/utils/test/docker/docker-test-harness"; + +export default async function postTest() { + await DockerTestHarness.stop(); +} diff --git a/src/typescript/package.json b/src/typescript/package.json index 9d41ac7c4..479dd6244 100644 --- a/src/typescript/package.json +++ b/src/typescript/package.json @@ -24,20 +24,23 @@ "dev:debug": "pnpm dotenv -v FETCH_DEBUG=true -- pnpm run dev", "dev:debug-verbose": "pnpm dotenv -v FETCH_DEBUG_VERBOSE=true -- pnpm run dev", "down": "pnpm run prune", - "e2e:testnet": "turbo run e2e:testnet", + "e2e:frontend": "pnpm run load-env:e2e-frontend -- turbo run e2e:frontend", "format": "turbo run format -- --write", "format:check": "turbo run format -- --check", "full-clean": "pnpm run clean && rm -rf node_modules && rm -rf sdk/node_modules && rm -rf frontend/node_modules", "lint": "turbo run lint", "lint:fix": "turbo run lint -- --fix", "load-env": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env", + "load-env:e2e-frontend": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env -e ci.env -v NODE_ENV=test", "load-env:test": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env -e ci.env", "load-env:test-debug": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env -e ci.env -v FETCH_DEBUG=true", "load-env:test-verbose": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env -e ci.env -v FETCH_DEBUG=true VERBOSE_TEST_LOGS=true", "load-env:unit-test": "dotenv -e .env.local -e .env -e .env.example -e ../docker/example.local.env -e ../docker/.env -e ci.env -v NO_TEST_SETUP=true", + "playwright:install": "turbo run playwright:install", "prune": "../docker/utils/prune.sh --reset-localnet --yes", "restart": "pnpm run down && pnpm run up", "start": "dotenv -e .env.local -e .env -- turbo run start", + "submodule": "turbo run submodule", "test": "pnpm run load-env:test -- turbo run test --force", "test:debug": "pnpm run load-env:test-debug -- turbo run test --force", "test:frontend": "pnpm run load-env:test -- turbo run test --filter @econia-labs/emojicoin-frontend --log-prefix none", diff --git a/src/typescript/sdk/tests/utils/docker/docker-test-harness.ts b/src/typescript/sdk/src/utils/test/docker/docker-test-harness.ts similarity index 81% rename from src/typescript/sdk/tests/utils/docker/docker-test-harness.ts rename to src/typescript/sdk/src/utils/test/docker/docker-test-harness.ts index 8a579e8fb..1233bce6f 100644 --- a/src/typescript/sdk/tests/utils/docker/docker-test-harness.ts +++ b/src/typescript/sdk/src/utils/test/docker/docker-test-harness.ts @@ -1,9 +1,10 @@ // eslint-disable no-await-in-loop // cspell:word localnet -import { type ChildProcessWithoutNullStreams } from "child_process"; -import path from "path"; -import { waitFor } from "../../../src/utils"; +import path from "node:path"; +import os from "node:os"; +import { kill } from "node:process"; +import { waitFor } from "../.."; import { getGitRoot } from "../helpers"; import { type ContainerName } from "./logs"; import { @@ -13,10 +14,12 @@ import { execPromise, spawnWrapper, } from "./utils"; -import { EMOJICOIN_INDEXER_URL } from "../../../src/server/env"; -import { TableName } from "../../../src/indexer-v2/types/json-types"; +import { EMOJICOIN_INDEXER_URL } from "../../../server/env"; +import { TableName } from "../../../indexer-v2/types/json-types"; +import { readFileSync, writeFileSync } from "node:fs"; const LOCAL_COMPOSE_PATH = path.join(getGitRoot(), "src/docker", "compose.local.yaml"); +const LOCAL_ENV_PATH = path.join(getGitRoot(), "src/docker", "example.local.env"); const PRUNE_SCRIPT = path.join(getGitRoot(), "src/docker/utils", "prune.sh"); const PING_STATE_INTERVAL = 200; @@ -55,16 +58,11 @@ const isDataNotCorrupted = (state?: ContainerState): boolean | undefined => { return true; }; -const MAX_WAIT_TIME_SECONDS = 120; +const MAX_WAIT_TIME_SECONDS = 240; +const TMP_PID_FILE_PATH = path.join(os.tmpdir(), "emojicoin-e2e-process-id"); export class DockerTestHarness { - public includeFrontend: boolean; - - public processes: ChildProcessWithoutNullStreams[] = []; - - constructor({ includeFrontend }: { includeFrontend: boolean }) { - this.includeFrontend = includeFrontend; - } + constructor() {} /** * Removes all related processes. @@ -76,23 +74,21 @@ export class DockerTestHarness { /** * Stops the Docker containers. */ - async stop() { + static async stop() { await execPromise(`docker compose -f ${LOCAL_COMPOSE_PATH} stop`); - while (this.processes.length) { - const process = this.processes.pop(); - if (process) { - process.kill(); - } + const process = Number(readFileSync(TMP_PID_FILE_PATH, { encoding: "utf-8" })); + if (process) { + kill(process); } } /** * Calls the Docker helper script to start the containers. */ - async run() { - await this.start(); + static async run(frontend: boolean, filterLogsFrom: ContainerName[] = []) { + await DockerTestHarness.start(frontend, filterLogsFrom); const promises = [ - this.waitForPrimaryService(), + DockerTestHarness.waitForPrimaryService(frontend), DockerTestHarness.waitForDeployer(), DockerTestHarness.waitForMigrationsToComplete(), ]; @@ -102,7 +98,7 @@ export class DockerTestHarness { /** * Starts a completely new Docker environment for the test harness. */ - async start() { + static async start(frontend: boolean, filterLogsFrom: ContainerName[]) { // Ensure that we have a fresh Docker environment before starting the test harness. await DockerTestHarness.remove(); @@ -111,12 +107,14 @@ export class DockerTestHarness { "compose", "-f", LOCAL_COMPOSE_PATH, + "--env-file", + LOCAL_ENV_PATH, + ...(frontend ? ["--profile", "frontend"] : []), "up", - this.includeFrontend ? "--profile frontend" : "", ].filter((arg) => arg !== ""); - const child = spawnWrapper(command, args); - this.processes.push(child); + const process = spawnWrapper(command, args, false, filterLogsFrom); + writeFileSync(TMP_PID_FILE_PATH, process.pid?.toString() ?? ""); } /** @@ -124,10 +122,10 @@ export class DockerTestHarness { * * @returns Promise */ - async waitForPrimaryService(): Promise { + static async waitForPrimaryService(frontend: boolean): Promise { // The broker will be the last container up, unless we're running the frontend. // In that case, the frontend will be last. - const container: ContainerName = this.includeFrontend ? "frontend" : "broker"; + const container: ContainerName = frontend ? "frontend" : "broker"; const ready = await waitFor({ condition: async () => await isPrimaryContainerReady(container), interval: PING_STATE_INTERVAL, diff --git a/src/typescript/sdk/tests/utils/docker/logs.ts b/src/typescript/sdk/src/utils/test/docker/logs.ts similarity index 91% rename from src/typescript/sdk/tests/utils/docker/logs.ts rename to src/typescript/sdk/src/utils/test/docker/logs.ts index de8e915a0..b569f773a 100644 --- a/src/typescript/sdk/tests/utils/docker/logs.ts +++ b/src/typescript/sdk/src/utils/test/docker/logs.ts @@ -59,9 +59,7 @@ containerNames.forEach((containerName, index) => { coloredNames.set(containerName, colorText(r, g, b)(containerName)); }); -const shouldPrint = (containerName: ContainerName) => { - // @ts-expect-error Using `globalThis` as any. - const filterLogsFrom = globalThis.__DOCKER_LOGS_FILTER__ as Array; +const shouldPrint = (containerName: ContainerName, filterLogsFrom: ContainerName[]) => { return !filterLogsFrom.includes(containerName); }; @@ -90,13 +88,13 @@ const colorContainerName = (originalText: string) => { return originalText.replace(logPrefix, newLogPrefix); }; -const printLogs = (log: string | Buffer) => { +const printLogs = (log: string | Buffer, filterLogsFrom: ContainerName[]) => { if (typeof log === "undefined" || log === null) { return; } const { containerName } = matchContainerLogs(log); // Filter out logs from containers that we shouldn't print. - if (containerName && !shouldPrint(containerName)) { + if (containerName && !shouldPrint(containerName, filterLogsFrom)) { return; } let res = log.toString(); diff --git a/src/typescript/sdk/tests/utils/docker/utils.ts b/src/typescript/sdk/src/utils/test/docker/utils.ts similarity index 92% rename from src/typescript/sdk/tests/utils/docker/utils.ts rename to src/typescript/sdk/src/utils/test/docker/utils.ts index 839f67391..df65a684c 100644 --- a/src/typescript/sdk/tests/utils/docker/utils.ts +++ b/src/typescript/sdk/src/utils/test/docker/utils.ts @@ -51,8 +51,8 @@ type ExecCallback = ( ) => void; const logger: ExecCallback = (error, stdout, stderr) => { - printLogs(stdout); - printLogs(stderr); + printLogs(stdout, []); + printLogs(stderr, []); if (error) { console.error(error); } @@ -96,15 +96,16 @@ export async function getContainerState(name: ContainerName): Promise { const childProcess = spawn(command, args); if (!quiet) { childProcess.stdout.on("data", (data) => { - printLogs(data.toString().trim()); + printLogs(data.toString().trim(), filterLogsFrom); }); childProcess.stderr.on("data", (data) => { - printLogs(data.toString().trim()); + printLogs(data.toString().trim(), filterLogsFrom); }); childProcess.on("error", (error) => { console.error(error); diff --git a/src/typescript/sdk/tests/utils/ensure-write-file-sync.ts b/src/typescript/sdk/src/utils/test/ensure-write-file-sync.ts similarity index 100% rename from src/typescript/sdk/tests/utils/ensure-write-file-sync.ts rename to src/typescript/sdk/src/utils/test/ensure-write-file-sync.ts diff --git a/src/typescript/sdk/tests/utils/get-publish-txn-from-indexer.ts b/src/typescript/sdk/src/utils/test/get-publish-txn-from-indexer.ts similarity index 91% rename from src/typescript/sdk/tests/utils/get-publish-txn-from-indexer.ts rename to src/typescript/sdk/src/utils/test/get-publish-txn-from-indexer.ts index 08a6533e0..635c6eb6c 100644 --- a/src/typescript/sdk/tests/utils/get-publish-txn-from-indexer.ts +++ b/src/typescript/sdk/src/utils/test/get-publish-txn-from-indexer.ts @@ -4,8 +4,8 @@ import { isUserTransactionResponse, type TransactionResponse, } from "@aptos-labs/ts-sdk"; -import { getEvents, Trigger } from "../../src"; -import { getAptosClient } from "../../src/utils/aptos-client"; +import { getEvents, Trigger } from "../.."; +import { getAptosClient } from "../aptos-client"; import { getPublisherPrivateKey } from "./helpers"; export const getPublishTransactionFromIndexer = async () => { diff --git a/src/typescript/sdk/tests/utils/get-txn-batch-highest-version.ts b/src/typescript/sdk/src/utils/test/get-txn-batch-highest-version.ts similarity index 84% rename from src/typescript/sdk/tests/utils/get-txn-batch-highest-version.ts rename to src/typescript/sdk/src/utils/test/get-txn-batch-highest-version.ts index 8a4501739..74cedb48a 100644 --- a/src/typescript/sdk/tests/utils/get-txn-batch-highest-version.ts +++ b/src/typescript/sdk/src/utils/test/get-txn-batch-highest-version.ts @@ -1,5 +1,5 @@ import { type UserTransactionResponse } from "@aptos-labs/ts-sdk"; -import { compareBigInt } from "../../src/utils/compare-bigint"; +import { compareBigInt } from "../compare-bigint"; export const getTxnBatchHighestVersion = (responses: Array) => { const response = responses.sort((a, b) => compareBigInt(a.version, b.version)).at(-1); diff --git a/src/typescript/sdk/tests/utils/helpers.ts b/src/typescript/sdk/src/utils/test/helpers.ts similarity index 95% rename from src/typescript/sdk/tests/utils/helpers.ts rename to src/typescript/sdk/src/utils/test/helpers.ts index 2c4e317c8..82ace3397 100644 --- a/src/typescript/sdk/tests/utils/helpers.ts +++ b/src/typescript/sdk/src/utils/test/helpers.ts @@ -7,9 +7,9 @@ import { } from "@aptos-labs/ts-sdk"; import path from "path"; import findGitRoot from "find-git-root"; -import { getAptosClient } from "../../src/utils/aptos-client"; -import { getEmojicoinMarketAddressAndTypeTags } from "../../src/markets/utils"; -import { EmojicoinDotFun, getEvents } from "../../src/emojicoin_dot_fun"; +import { getAptosClient } from "../aptos-client"; +import { getEmojicoinMarketAddressAndTypeTags } from "../../markets/utils"; +import { EmojicoinDotFun, getEvents } from "../../emojicoin_dot_fun"; import { type EmojiName, generateRandomSymbol, @@ -20,8 +20,8 @@ import { type SymbolEmoji, toMarketEmojiData, type Types, -} from "../../src"; -import { type Events } from "../../src/emojicoin_dot_fun/events"; +} from "../.."; +import { type Events } from "../../emojicoin_dot_fun/events"; // The exact amount of APT to trigger a transition out of the bonding curve. Note that the // fee integrator rate BPs must be set to 0 for this to work. diff --git a/src/typescript/sdk/tests/utils/index.ts b/src/typescript/sdk/src/utils/test/index.ts similarity index 65% rename from src/typescript/sdk/tests/utils/index.ts rename to src/typescript/sdk/src/utils/test/index.ts index fc7a3084e..9541e4c8b 100644 --- a/src/typescript/sdk/tests/utils/index.ts +++ b/src/typescript/sdk/src/utils/test/index.ts @@ -1,4 +1,4 @@ -export * from "../../src/utils/aptos-client"; +export * from "../aptos-client"; export * from "./helpers"; export * from "./publish"; export * from "./load-priv-key"; diff --git a/src/typescript/sdk/tests/utils/load-priv-key.ts b/src/typescript/sdk/src/utils/test/load-priv-key.ts similarity index 96% rename from src/typescript/sdk/tests/utils/load-priv-key.ts rename to src/typescript/sdk/src/utils/test/load-priv-key.ts index de2fd54fa..341044bed 100644 --- a/src/typescript/sdk/tests/utils/load-priv-key.ts +++ b/src/typescript/sdk/src/utils/test/load-priv-key.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import { Account, AccountAddress, Ed25519PrivateKey } from "@aptos-labs/ts-sdk"; -import { VERCEL } from "../../src/const"; +import { VERCEL } from "../../const"; export const getTestPublisherPrivateKey = () => { if (VERCEL) { diff --git a/src/typescript/sdk/tests/utils/print-divider.ts b/src/typescript/sdk/src/utils/test/print-divider.ts similarity index 100% rename from src/typescript/sdk/tests/utils/print-divider.ts rename to src/typescript/sdk/src/utils/test/print-divider.ts diff --git a/src/typescript/sdk/tests/utils/publish.ts b/src/typescript/sdk/src/utils/test/publish.ts similarity index 98% rename from src/typescript/sdk/tests/utils/publish.ts rename to src/typescript/sdk/src/utils/test/publish.ts index 871d6acf2..d7a628d54 100644 --- a/src/typescript/sdk/tests/utils/publish.ts +++ b/src/typescript/sdk/src/utils/test/publish.ts @@ -9,8 +9,8 @@ import { Ed25519PrivateKey, } from "@aptos-labs/ts-sdk"; import path from "path"; -import { getAptosClient } from "../../src/utils/aptos-client"; -import { MAX_GAS_FOR_PUBLISH, ONE_APT, EMOJICOIN_DOT_FUN_MODULE_NAME } from "../../src"; +import { getAptosClient } from "../aptos-client"; +import { MAX_GAS_FOR_PUBLISH, ONE_APT, EMOJICOIN_DOT_FUN_MODULE_NAME } from "../.."; import { getGitRoot } from "./helpers"; type ResultJSON = { diff --git a/src/typescript/sdk/tests/utils/sample-data.ts b/src/typescript/sdk/src/utils/test/sample-data.ts similarity index 94% rename from src/typescript/sdk/tests/utils/sample-data.ts rename to src/typescript/sdk/src/utils/test/sample-data.ts index 56bede1fc..279e95f96 100644 --- a/src/typescript/sdk/tests/utils/sample-data.ts +++ b/src/typescript/sdk/src/utils/test/sample-data.ts @@ -1,5 +1,5 @@ -import { Trigger } from "../../src"; -import { type Types } from "../../src/types/types"; +import { Trigger } from "../.."; +import { type Types } from "../../types/types"; export const SAMPLE_SWAP_EVENT: Types["SwapEvent"] = { marketID: 1n, diff --git a/src/typescript/sdk/tests/utils/test-accounts.ts b/src/typescript/sdk/src/utils/test/test-accounts.ts similarity index 96% rename from src/typescript/sdk/tests/utils/test-accounts.ts rename to src/typescript/sdk/src/utils/test/test-accounts.ts index a4c8cc51b..29c588041 100644 --- a/src/typescript/sdk/tests/utils/test-accounts.ts +++ b/src/typescript/sdk/src/utils/test/test-accounts.ts @@ -1,5 +1,5 @@ import { Account, type Ed25519Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk"; -import testAccountData from "../../../../docker/deployer/json/test-accounts.json"; +import testAccountData from "../../../../../docker/deployer/json/test-accounts.json"; export type FundedAddress = keyof typeof testAccountData; type D = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; diff --git a/src/typescript/sdk/tests/e2e/broker/websockets.test.ts b/src/typescript/sdk/tests/e2e/broker/websockets.test.ts index fd670a033..b7fd8acb7 100644 --- a/src/typescript/sdk/tests/e2e/broker/websockets.test.ts +++ b/src/typescript/sdk/tests/e2e/broker/websockets.test.ts @@ -22,8 +22,8 @@ import { Swap, SwapWithRewards, } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { EXACT_TRANSITION_INPUT_AMOUNT, getAptosClient } from "../../utils"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import { EXACT_TRANSITION_INPUT_AMOUNT, getAptosClient } from "../../../src/utils/test"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; import { type BrokerEvent } from "../../../src/broker-v2/types"; import { isChatEventModel, diff --git a/src/typescript/sdk/tests/e2e/chat.test.ts b/src/typescript/sdk/tests/e2e/chat.test.ts index d80064c42..d1fb8ee3f 100644 --- a/src/typescript/sdk/tests/e2e/chat.test.ts +++ b/src/typescript/sdk/tests/e2e/chat.test.ts @@ -2,10 +2,10 @@ import { Ed25519Account } from "@aptos-labs/ts-sdk"; import { ONE_APT } from "../../src/const"; import { getRegistryAddress, toChatEvent } from "../../src"; import { EmojicoinDotFun } from "../../src/emojicoin_dot_fun"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; import { getEmojicoinMarketAddressAndTypeTags } from "../../src/markets/utils"; import { STRUCT_STRINGS } from "../../src/utils/type-tags"; -import { getFundedAccount } from "../utils/test-accounts"; +import { getFundedAccount } from "../../src/utils/test/test-accounts"; jest.setTimeout(20000); diff --git a/src/typescript/sdk/tests/e2e/emoji-data.test.ts b/src/typescript/sdk/tests/e2e/emoji-data.test.ts index d0b0a9efa..11022caf5 100644 --- a/src/typescript/sdk/tests/e2e/emoji-data.test.ts +++ b/src/typescript/sdk/tests/e2e/emoji-data.test.ts @@ -6,10 +6,10 @@ import { type WriteSetChangeWriteResource, type WriteSetChangeWriteTableItem, } from "@aptos-labs/ts-sdk"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; import { STRUCT_STRINGS, SYMBOL_DATA, normalizeHex } from "../../src"; import EmojiJSONData from "../../src/emoji_data/symbol-emojis.json"; -import { getPublishTransactionFromIndexer } from "../utils/get-publish-txn-from-indexer"; +import { getPublishTransactionFromIndexer } from "../../src/utils/test/get-publish-txn-from-indexer"; jest.setTimeout(10000); diff --git a/src/typescript/sdk/tests/e2e/fund.test.ts b/src/typescript/sdk/tests/e2e/fund.test.ts index c173cf956..0f874acf5 100644 --- a/src/typescript/sdk/tests/e2e/fund.test.ts +++ b/src/typescript/sdk/tests/e2e/fund.test.ts @@ -1,6 +1,6 @@ import { Ed25519Account, isUserTransactionResponse } from "@aptos-labs/ts-sdk"; import { ONE_APT } from "../../src"; -import { getAptosClient } from "../utils"; +import { getAptosClient } from "../../src/utils/test"; jest.setTimeout(10000); diff --git a/src/typescript/sdk/tests/e2e/publish.test.ts b/src/typescript/sdk/tests/e2e/publish.test.ts index 7d2df7b93..74e507dd8 100644 --- a/src/typescript/sdk/tests/e2e/publish.test.ts +++ b/src/typescript/sdk/tests/e2e/publish.test.ts @@ -1,7 +1,7 @@ import { AccountAddress, Network, isUserTransactionResponse } from "@aptos-labs/ts-sdk"; -import { getModuleExists, publishPackage } from "../utils/publish"; +import { getModuleExists, publishPackage } from "../../src/utils/test/publish"; import { EMOJICOIN_DOT_FUN_MODULE_NAME, MODULE_ADDRESS, ONE_APT } from "../../src"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; jest.setTimeout(60000); jest.retryTimes(3); diff --git a/src/typescript/sdk/tests/e2e/queries/address.test.ts b/src/typescript/sdk/tests/e2e/queries/address.test.ts index 704792e65..787befb85 100644 --- a/src/typescript/sdk/tests/e2e/queries/address.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/address.test.ts @@ -1,10 +1,10 @@ import { getEvents } from "../../../src"; import { Chat } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; import { fetchChatEvents } from "../../../src/indexer-v2/queries"; -import { getAptosClient } from "../../utils"; +import { getAptosClient } from "../../../src/utils/test"; import RowEqualityChecks from "./equality-checks"; -import { getFundedAccount } from "../../utils/test-accounts"; -import TestHelpers from "../../utils/helpers"; +import { getFundedAccount } from "../../../src/utils/test/test-accounts"; +import TestHelpers from "../../../src/utils/test/helpers"; jest.setTimeout(20000); diff --git a/src/typescript/sdk/tests/e2e/queries/liquidity-pools.test.ts b/src/typescript/sdk/tests/e2e/queries/liquidity-pools.test.ts index 741177f74..1f8f5379c 100644 --- a/src/typescript/sdk/tests/e2e/queries/liquidity-pools.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/liquidity-pools.test.ts @@ -2,12 +2,12 @@ import { type TypeTag, type UserTransactionResponse } from "@aptos-labs/ts-sdk"; import { maxBigInt, type MarketSymbolEmojis } from "../../../src"; -import TestHelpers, { EXACT_TRANSITION_INPUT_AMOUNT } from "../../utils/helpers"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import TestHelpers, { EXACT_TRANSITION_INPUT_AMOUNT } from "../../../src/utils/test/helpers"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; import { waitForEmojicoinIndexer } from "../../../src/indexer-v2/queries/utils"; import { ProvideLiquidity, Swap } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { getAptosClient } from "../../utils"; +import { getAptosClient } from "../../../src/utils/test"; import { fetchMarkets, fetchUserLiquidityPools } from "../../../src/indexer-v2/queries"; import { LIMIT } from "../../../src/queries"; diff --git a/src/typescript/sdk/tests/e2e/queries/market-state.test.ts b/src/typescript/sdk/tests/e2e/queries/market-state.test.ts index 9fcceaa96..cbdbd85f4 100644 --- a/src/typescript/sdk/tests/e2e/queries/market-state.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/market-state.test.ts @@ -1,10 +1,10 @@ import { getEventsAsProcessorModelsFromResponse, type MarketSymbolEmojis } from "../../../src"; -import TestHelpers from "../../utils/helpers"; -import { getFundedAccount } from "../../utils/test-accounts"; +import TestHelpers from "../../../src/utils/test/helpers"; +import { getFundedAccount } from "../../../src/utils/test/test-accounts"; import { waitForEmojicoinIndexer } from "../../../src/indexer-v2/queries/utils"; import { SwapWithRewards } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { getAptosClient } from "../../utils"; +import { getAptosClient } from "../../../src/utils/test"; import { fetchMarketState } from "../../../src/indexer-v2/queries"; import { type MarketStateModel } from "../../../src/indexer-v2/types"; import { type JsonValue } from "../../../src/types/json-types"; diff --git a/src/typescript/sdk/tests/e2e/queries/num-markets.test.ts b/src/typescript/sdk/tests/e2e/queries/num-markets.test.ts index 76d47b230..e642292d2 100644 --- a/src/typescript/sdk/tests/e2e/queries/num-markets.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/num-markets.test.ts @@ -2,8 +2,8 @@ import { getRegistryResourceFromWriteSet, toRegistryView } from "../../../src"; import { type EmojiName } from "../../../src/emoji_data/types"; import { RegistryView } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; import { getAptosClient } from "../../../src/utils/aptos-client"; -import TestHelpers from "../../utils/helpers"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import TestHelpers from "../../../src/utils/test/helpers"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; jest.setTimeout(20000); diff --git a/src/typescript/sdk/tests/e2e/queries/search-emojis.test.ts b/src/typescript/sdk/tests/e2e/queries/search-emojis.test.ts index beaa8ecde..299e802f3 100644 --- a/src/typescript/sdk/tests/e2e/queries/search-emojis.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/search-emojis.test.ts @@ -1,6 +1,6 @@ import { type EmojiName, namesToEmojis } from "../../../src"; -import TestHelpers from "../../utils/helpers"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import TestHelpers from "../../../src/utils/test/helpers"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; import { fetchMarkets } from "../../../src/indexer-v2/queries/app/home"; import { waitForEmojicoinIndexer } from "../../../src/indexer-v2/queries/utils"; diff --git a/src/typescript/sdk/tests/e2e/queries/simple.test.ts b/src/typescript/sdk/tests/e2e/queries/simple.test.ts index 2022f4774..b5c2db050 100644 --- a/src/typescript/sdk/tests/e2e/queries/simple.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/simple.test.ts @@ -1,16 +1,16 @@ import { type EmojiName, getEvents, ONE_APT } from "../../../src"; -import TestHelpers, { EXACT_TRANSITION_INPUT_AMOUNT } from "../../utils/helpers"; +import TestHelpers, { EXACT_TRANSITION_INPUT_AMOUNT } from "../../../src/utils/test/helpers"; import { Chat, ProvideLiquidity, Swap } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; import { fetchChatEvents, fetchSwapEvents, fetchUserLiquidityPools, } from "../../../src/indexer-v2/queries"; -import { getAptosClient } from "../../utils"; +import { getAptosClient } from "../../../src/utils/test"; import RowEqualityChecks from "./equality-checks"; import { queryHelper } from "../../../src/indexer-v2/queries/utils"; import { TableName } from "../../../src/indexer-v2/types/json-types"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; import { postgrest } from "../../../src/indexer-v2/queries/client"; import { fetchLatestStateEventForMarket, fetchLiquidityEvents } from "."; diff --git a/src/typescript/sdk/tests/e2e/queries/sorted/sort-queries.test.ts b/src/typescript/sdk/tests/e2e/queries/sorted/sort-queries.test.ts index 0ace0758d..8cc2f2677 100644 --- a/src/typescript/sdk/tests/e2e/queries/sorted/sort-queries.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/sorted/sort-queries.test.ts @@ -9,11 +9,11 @@ import { SYMBOL_DATA, UnitOfTime, } from "../../../../src"; -import TestHelpers from "../../../utils/helpers"; -import { getFundedAccounts } from "../../../utils/test-accounts"; +import TestHelpers from "../../../../src/utils/test/helpers"; +import { getFundedAccounts } from "../../../../src/utils/test/test-accounts"; import { waitForEmojicoinIndexer } from "../../../../src/indexer-v2/queries/utils"; import { Swap } from "../../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { getAptosClient } from "../../../utils"; +import { getAptosClient } from "../../../../src/utils/test"; import { fetchMarkets } from "../../../../src/indexer-v2/queries/app/home"; import { SortMarketsBy } from "../../../../src/indexer-v2/types/common"; import { diff --git a/src/typescript/sdk/tests/e2e/queries/volume.test.ts b/src/typescript/sdk/tests/e2e/queries/volume.test.ts index 9ea8d4d2e..dae2a9ba2 100644 --- a/src/typescript/sdk/tests/e2e/queries/volume.test.ts +++ b/src/typescript/sdk/tests/e2e/queries/volume.test.ts @@ -15,11 +15,11 @@ import { sumByKey, } from "../../../src"; import { Swap } from "../../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { getAptosClient } from "../../utils"; -import { getFundedAccounts } from "../../utils/test-accounts"; +import { getAptosClient } from "../../../src/utils/test"; +import { getFundedAccounts } from "../../../src/utils/test/test-accounts"; import { type Events } from "../../../src/emojicoin_dot_fun/events"; -import { getTxnBatchHighestVersion } from "../../utils/get-txn-batch-highest-version"; -import TestHelpers from "../../utils/helpers"; +import { getTxnBatchHighestVersion } from "../../../src/utils/test/get-txn-batch-highest-version"; +import TestHelpers from "../../../src/utils/test/helpers"; import { getOneMinutePeriodicStateEvents, getPeriodExpiryDate, diff --git a/src/typescript/sdk/tests/e2e/register.test.ts b/src/typescript/sdk/tests/e2e/register.test.ts index d2ab13f7e..c5acb6c62 100644 --- a/src/typescript/sdk/tests/e2e/register.test.ts +++ b/src/typescript/sdk/tests/e2e/register.test.ts @@ -8,9 +8,9 @@ import { getRegistryAddress, } from "../../src"; import { EmojicoinDotFun } from "../../src/emojicoin_dot_fun"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; import { standardizeAddress } from "../../src/utils/account-address"; -import { getFundedAccount } from "../utils/test-accounts"; +import { getFundedAccount } from "../../src/utils/test/test-accounts"; jest.setTimeout(20000); diff --git a/src/typescript/sdk/tests/e2e/swap.test.ts b/src/typescript/sdk/tests/e2e/swap.test.ts index a43a0ac26..652c64c18 100644 --- a/src/typescript/sdk/tests/e2e/swap.test.ts +++ b/src/typescript/sdk/tests/e2e/swap.test.ts @@ -7,7 +7,7 @@ import { import { ONE_APT } from "../../src/const"; import { SYMBOL_DATA } from "../../src"; import { EmojicoinDotFun } from "../../src/emojicoin_dot_fun"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; import { getEmojicoinMarketAddressAndTypeTags, getRegistrationGracePeriodFlag, @@ -18,7 +18,7 @@ import { getCoinBalanceFromChanges, getFeeStatement, } from "../../src/utils/parse-changes-for-balances"; -import { getFundedAccount } from "../utils/test-accounts"; +import { getFundedAccount } from "../../src/utils/test/test-accounts"; jest.setTimeout(90000); diff --git a/src/typescript/sdk/tests/e2e/views.test.ts b/src/typescript/sdk/tests/e2e/views.test.ts index 9415a4bd7..6e83384fc 100644 --- a/src/typescript/sdk/tests/e2e/views.test.ts +++ b/src/typescript/sdk/tests/e2e/views.test.ts @@ -1,6 +1,6 @@ import { Hex, type HexInput } from "@aptos-labs/ts-sdk"; import * as EmojicoinDotFun from "../../src/emojicoin_dot_fun/emojicoin-dot-fun"; -import { getPublishHelpers } from "../utils"; +import { getPublishHelpers } from "../../src/utils/test"; jest.setTimeout(15000); diff --git a/src/typescript/sdk/tests/post-test.ts b/src/typescript/sdk/tests/post-test.ts index 45d46aa75..4e6c8ed73 100644 --- a/src/typescript/sdk/tests/post-test.ts +++ b/src/typescript/sdk/tests/post-test.ts @@ -1,8 +1,6 @@ /* eslint-disable no-underscore-dangle */ -import { type DockerTestHarness } from "./utils/docker/docker-test-harness"; +import { DockerTestHarness } from "../src/utils/test/docker/docker-test-harness"; export default async function postTest() { - // @ts-expect-error Using `globalThis` as any. - const testHarness: DockerTestHarness | undefined = globalThis.__TEST_HARNESS__; - if (testHarness) await testHarness.stop(); + await DockerTestHarness.stop(); } diff --git a/src/typescript/sdk/tests/pre-test.ts b/src/typescript/sdk/tests/pre-test.ts index f3ae35006..c5aae8c6b 100644 --- a/src/typescript/sdk/tests/pre-test.ts +++ b/src/typescript/sdk/tests/pre-test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-underscore-dangle */ import WebSocket from "ws"; -import { DockerTestHarness } from "./utils/docker/docker-test-harness"; -import { type ContainerName } from "./utils/docker/logs"; +import { DockerTestHarness } from "../src/utils/test/docker/docker-test-harness"; +import { type ContainerName } from "../src/utils/test/docker/logs"; export default async function preTest() { // @ts-expect-error Using `globalThis` as any for a polyfill for `WebSocket` in node.js. @@ -19,13 +19,11 @@ export default async function preTest() { } // @ts-expect-error Using `globalThis` as any. globalThis.__DOCKER_LOGS_FILTER__ = noLogs; - const testHarness = new DockerTestHarness({ includeFrontend: false }); // -------------------------------------------------------------------------------------- // Start the docker containers. // -------------------------------------------------------------------------------------- - await testHarness.run(); - // @ts-expect-error Using `globalThis` as any. - globalThis.__TEST_HARNESS__ = testHarness; + // Start the Docker test harness without the frontend container. + await DockerTestHarness.run(false); // The docker container start-up script publishes the package on-chain. } diff --git a/src/typescript/sdk/tests/unit/emoji-regex.test.ts b/src/typescript/sdk/tests/unit/emoji-regex.test.ts index 8cae450df..03ec3b330 100644 --- a/src/typescript/sdk/tests/unit/emoji-regex.test.ts +++ b/src/typescript/sdk/tests/unit/emoji-regex.test.ts @@ -8,7 +8,7 @@ import { symbolToEmojis, } from "../../src/emoji_data/utils"; import SymbolEmojiData from "../../src/emoji_data/symbol-emojis.json"; -import { getGitRoot } from "../utils"; +import { getGitRoot } from "../../src/utils/test"; describe("tests emojis against the emoji regex to ensure they're properly validated", () => { it("tests a few single emojis", () => { diff --git a/src/typescript/sdk/tests/unit/git-root.test.ts b/src/typescript/sdk/tests/unit/git-root.test.ts index f85321336..ead2aa978 100644 --- a/src/typescript/sdk/tests/unit/git-root.test.ts +++ b/src/typescript/sdk/tests/unit/git-root.test.ts @@ -1,5 +1,5 @@ import path from "path"; -import { getGitRoot } from "../utils/helpers"; +import { getGitRoot } from "../../src/utils/test/helpers"; describe("ensures find git root works as expected", () => { it("should find the correct git root", () => { diff --git a/src/typescript/sdk/tests/unit/period-boundaries.test.ts b/src/typescript/sdk/tests/unit/period-boundaries.test.ts index a82569a6a..ce2b66689 100644 --- a/src/typescript/sdk/tests/unit/period-boundaries.test.ts +++ b/src/typescript/sdk/tests/unit/period-boundaries.test.ts @@ -1,5 +1,5 @@ import { PeriodDuration, getPeriodStartTime } from "../../src"; -import { SAMPLE_STATE_EVENT, SAMPLE_SWAP_EVENT } from "../utils/sample-data"; +import { SAMPLE_STATE_EVENT, SAMPLE_SWAP_EVENT } from "../../src/utils/test/sample-data"; const swap = SAMPLE_SWAP_EVENT; const state = SAMPLE_STATE_EVENT; diff --git a/src/typescript/turbo.json b/src/typescript/turbo.json index 06d9188cb..aff1c6312 100644 --- a/src/typescript/turbo.json +++ b/src/typescript/turbo.json @@ -10,9 +10,6 @@ "globalEnv": [], "tasks": { "build": { - "dependsOn": [ - "^build" - ], "outputs": [ "dist/**", ".next/**" @@ -31,7 +28,8 @@ "cache": false, "persistent": true }, - "e2e:testnet": { + "e2e:frontend": { + "cache": false, "outputs": [] }, "format": { @@ -46,6 +44,9 @@ "lint:fix": { "outputs": [] }, + "playwright:install": { + "outputs": [] + }, "start": { "dependsOn": [ "build" @@ -53,16 +54,23 @@ "outputs": [], "persistent": true }, + "submodule": { + "outputs": [] + }, "test": { + "cache": false, "outputs": [] }, "test:parallel": { + "cache": false, "outputs": [] }, "test:sequential": { + "cache": false, "outputs": [] }, "unit-test": { + "cache": false, "outputs": [] } }