diff options
| author | Adam Soltys <[email protected]> | 2026-02-26 13:36:28 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-26 13:36:28 -0800 |
| commit | a5faa64ba470f935ea3e7932feece3cd9fbadb90 (patch) | |
| tree | 79ec7d6cb2038b5920d5cca977a244fbb189923c /test/e2e | |
| parent | b137cdfca84cf68a2b8a620ba1c55337e88a0050 (diff) | |
| download | coinos-ui-a5faa64ba470f935ea3e7932feece3cd9fbadb90.tar.gz coinos-ui-a5faa64ba470f935ea3e7932feece3cd9fbadb90.zip | |
ark tests
Diffstat (limited to 'test/e2e')
| -rw-r--r-- | test/e2e/ark-receive-from-server-wallet.spec.ts | 158 | ||||
| -rw-r--r-- | test/e2e/ark-send-custodial.spec.ts | 13 | ||||
| -rw-r--r-- | test/e2e/ark-vault-to-custodial.spec.ts | 63 | ||||
| -rw-r--r-- | test/e2e/custodial-bitcoin-send.spec.ts | 15 | ||||
| -rw-r--r-- | test/e2e/custodial-send-lightning.spec.ts | 4 | ||||
| -rw-r--r-- | test/e2e/custodial-send-username.spec.ts | 6 | ||||
| -rw-r--r-- | test/e2e/helpers.ts | 59 | ||||
| -rw-r--r-- | test/e2e/login-balance.spec.ts | 13 | ||||
| -rwxr-xr-x | test/e2e/run-staging.sh | 65 |
9 files changed, 236 insertions, 160 deletions
diff --git a/test/e2e/ark-receive-from-server-wallet.spec.ts b/test/e2e/ark-receive-from-server-wallet.spec.ts index bb7acb7b..3ad7205f 100644 --- a/test/e2e/ark-receive-from-server-wallet.spec.ts +++ b/test/e2e/ark-receive-from-server-wallet.spec.ts @@ -1,148 +1,36 @@ import { expect, test } from "@playwright/test"; +import { + bobUsername, + bobPassword, + testSecret, + arkWalletPassword, + login, + ensureArkAccount, + createArkInvoiceViaUI, + sendArkFromTestEndpoint, + waitForInvoicePaid, +} from "./helpers"; -const username = process.env.E2E_USERNAME || "bob"; -const password = process.env.E2E_PASSWORD || "pw"; -const testSecret = process.env.E2E_TEST_SECRET; -const apiBaseUrl = process.env.E2E_API_BASE_URL || "http://localhost:3119"; -const pauseAtEnd = process.env.E2E_PAUSE_AT_END === "true"; - -test("bob receives 1000 sats in ark vault after server wallet send", async ({ page }) => { +test("bob receives 100 sats in ark vault after server wallet send", async ({ page }) => { test.setTimeout(90_000); test.skip(!testSecret, "E2E_TEST_SECRET is required for /test/ark/send"); - await page.goto("/login"); - await page.getByTestId("login-username").fill(username); - await page.locator('input[name="password"]').first().fill(password); - await page.getByTestId("login-submit").click(); - - await expect(page).toHaveURL(new RegExp(`/${username}(?:[/?#]|$)`)); - - const arkAccountCard = page.locator('[data-testid="account-card"][data-account-type="ark"]'); - const arkAccountCount = await arkAccountCard.count(); - expect(arkAccountCount).toBeGreaterThan(0); - - let invoiceOpened = false; - - const walletPassInput = page.getByTestId("walletpass-input"); - - for (let i = 0; i < arkAccountCount; i++) { - const card = arkAccountCard.nth(i); - await card.scrollIntoViewIfNeeded(); - const accountHref = await card.locator('a[href^="/account/"]').first().getAttribute("href"); - const accountId = accountHref?.split("/account/")[1]; - - await card.locator('a[href="/invoice"]').first().click(); - - // Ark vault actions can require wallet password to derive/unlock key. - if ( - await walletPassInput - .first() - .isVisible({ timeout: 2000 }) - .catch(() => false) - ) { - await walletPassInput.fill(password); - await page.getByTestId("walletpass-submit").click(); - } - - invoiceOpened = await page - .waitForURL(/\/invoice\/[^/?#]+/, { timeout: 5000 }) - .then(() => true) - .catch(() => false); - - // Fallback for brittle click bubbling in account cards: - // set the selected aid cookie and navigate to invoice route directly. - if (!invoiceOpened && accountId) { - await page.evaluate((aid) => { - document.cookie = `aid=${aid}; path=/; max-age=86400`; - }, accountId); - await page.goto("/invoice"); - invoiceOpened = await page - .waitForURL(/\/invoice\/[^/?#]+/, { timeout: 5000 }) - .then(() => true) - .catch(() => false); - } - - if (invoiceOpened) break; - - if ( - await page - .getByTestId("walletpass-cancel") - .isVisible() - .catch(() => false) - ) { - await page.getByTestId("walletpass-cancel").click(); - } - } - - expect(invoiceOpened).toBeTruthy(); - await expect(page).toHaveURL(/\/invoice\/[^/?#]+/); - - const invoiceText = (await page.getByTestId("invoice-text").first().innerText()).trim(); - const addressMatch = invoiceText.match(/t?ark1[a-z0-9]+/i); - expect(addressMatch).toBeTruthy(); - const address = addressMatch![0]; - - const invoiceId = page.url().split("/invoice/")[1]?.split(/[/?#]/)[0]; - expect(invoiceId).toBeTruthy(); - - const sendResult = await page.evaluate( - async ({ address, testSecret, invoiceId }) => { - const res = await fetch("/test/ark/send", { - method: "POST", - headers: { - "content-type": "application/json", - "x-test-secret": testSecret, - }, - body: JSON.stringify({ address, amount: 1000, iid: invoiceId }), - }); - const text = await res.text(); - return { ok: res.ok, status: res.status, text }; - }, - { address, testSecret: testSecret!, invoiceId }, - ); - expect( - sendResult.ok, - `/test/ark/send failed (${sendResult.status}): ${sendResult.text}`, - ).toBeTruthy(); - - let paid = false; - let status: any; - - for (let i = 0; i < 30; i++) { - const statusResponse = await page.request.get(`${apiBaseUrl}/invoice/${invoiceId}`); - if (statusResponse.ok()) { - status = await statusResponse.json(); - if ((status?.received || 0) >= 1000 || (status?.pending || 0) >= 1000) { - paid = true; - break; - } - } - await page.waitForTimeout(1000); - } + await login(page, bobUsername, bobPassword); + await ensureArkAccount(page, arkWalletPassword); - expect( - paid, - `ark payment did not appear in invoice status: ${JSON.stringify(status)}`, - ).toBeTruthy(); + // Navigate back to dashboard after account setup + await page.goto(`/${bobUsername}`); + await page.waitForLoadState("networkidle"); - const paidRouteReached = await page - .waitForURL(new RegExp(`/invoice/${invoiceId}/paid(?:[/?#]|$)`), { - timeout: 20_000, - }) - .then(() => true) - .catch(() => false); + const { invoiceId, address } = await createArkInvoiceViaUI(page, arkWalletPassword); + console.log(`[e2e] Bob ark address: ${address}, invoice: ${invoiceId}`); - if (pauseAtEnd) { - // Keep browser open for manual inspection at end of flow. - await page.pause(); - } + await sendArkFromTestEndpoint(page, address, 100, invoiceId); - expect( - paidRouteReached, - `expected redirect to /invoice/${invoiceId}/paid, current URL: ${page.url()}`, - ).toBeTruthy(); + const status = await waitForInvoicePaid(page, invoiceId, 100); + expect(status.received).toBeGreaterThanOrEqual(100); console.log( - `[e2e] ark invoice ${invoiceId} funded with 1000 sats (received=${status?.received || 0}, pending=${status?.pending || 0})`, + `[e2e] ark invoice ${invoiceId} funded with 100 sats (received=${status?.received || 0})`, ); }); diff --git a/test/e2e/ark-send-custodial.spec.ts b/test/e2e/ark-send-custodial.spec.ts index 5806ca72..ab5d2141 100644 --- a/test/e2e/ark-send-custodial.spec.ts +++ b/test/e2e/ark-send-custodial.spec.ts @@ -5,8 +5,9 @@ import { bobUsername, bobPassword, testSecret, - apiBaseUrl, + arkWalletPassword, loginNewContext, + ensureArkAccount, createArkInvoiceViaUI, pasteAndSend, fillNumpadAmount, @@ -17,14 +18,18 @@ test("custodial sends to external ark address", async ({ browser }) => { test.setTimeout(120_000); test.skip(!testSecret, "E2E_TEST_SECRET is required for ark tests"); - // --- Alice: log in and get her ark vault address --- + // --- Alice: log in, ensure ark account, get her ark vault address --- const { context: aliceContext, page: alicePage } = await loginNewContext( browser, aliceUsername, alicePassword, ); - const { address: arkAddress } = await createArkInvoiceViaUI(alicePage, alicePassword); + await ensureArkAccount(alicePage, arkWalletPassword); + await alicePage.goto(`/${aliceUsername}`); + await alicePage.waitForLoadState("networkidle"); + + const { address: arkAddress } = await createArkInvoiceViaUI(alicePage, arkWalletPassword); console.log(`[e2e] Alice ark address: ${arkAddress}`); await aliceContext.close(); @@ -45,7 +50,7 @@ test("custodial sends to external ark address", async ({ browser }) => { expect(bobUrl).toContain("/send/ark/"); // Enter amount on numpad - await fillNumpadAmount(bobPage, 1000); + await fillNumpadAmount(bobPage, 100); // Now on the confirmation page with Send button await bobPage.waitForURL(/\/send\/ark\/[^/]+\/\d+/, { timeout: 10_000 }); diff --git a/test/e2e/ark-vault-to-custodial.spec.ts b/test/e2e/ark-vault-to-custodial.spec.ts new file mode 100644 index 00000000..36754696 --- /dev/null +++ b/test/e2e/ark-vault-to-custodial.spec.ts @@ -0,0 +1,63 @@ +import { expect, test } from "@playwright/test"; +import { + bobUsername, + bobPassword, + testSecret, + arkWalletPassword, + login, + ensureArkAccount, + createArkInvoiceViaUI, + sendArkFromTestEndpoint, + waitForInvoicePaid, + fillNumpadAmount, + waitForSentRedirect, +} from "./helpers"; + +test("vault sends to own custodial account", async ({ page }) => { + test.slow(); + test.setTimeout(180_000); + test.skip(!testSecret, "E2E_TEST_SECRET is required for ark tests"); + + // --- Login and ensure ark account --- + await login(page, bobUsername, bobPassword); + await ensureArkAccount(page, arkWalletPassword); + + // --- Fund vault via /test/ark/send --- + await page.goto(`/${bobUsername}`); + await page.waitForLoadState("networkidle"); + + const { invoiceId, address } = await createArkInvoiceViaUI(page, arkWalletPassword); + console.log(`[e2e] Bob vault address: ${address}, invoice: ${invoiceId}`); + + await sendArkFromTestEndpoint(page, address, 100, invoiceId); + await waitForInvoicePaid(page, invoiceId, 100); + console.log("[e2e] Vault funded with 100 sats"); + + // --- Send vault → custodial (self-send to own username) --- + await page.goto(`/pay/${bobUsername}`); + await page.waitForLoadState("networkidle"); + + // Should redirect to /send/ark/{serverAddr}/{amount} or similar vault→custodial path + // The UI detects vault→custodial and routes accordingly + await page.waitForURL(/\/send\//, { timeout: 15_000 }); + console.log(`[e2e] Bob on send page: ${page.url()}`); + + // Enter amount + await fillNumpadAmount(page, 100); + + // Handle WalletPass modal if it appears + const walletPassInput = page.getByTestId("walletpass-input"); + if (await walletPassInput.isVisible({ timeout: 3_000 }).catch(() => false)) { + await walletPassInput.fill(arkWalletPassword); + await page.getByTestId("walletpass-submit").click(); + } + + // Confirm send + const sendButton = page.locator('button[type="submit"]'); + if (await sendButton.isVisible({ timeout: 5_000 }).catch(() => false)) { + await sendButton.click(); + } + + await waitForSentRedirect(page, 60_000); + console.log(`[e2e] Vault→custodial payment sent: ${page.url()}`); +}); diff --git a/test/e2e/custodial-bitcoin-send.spec.ts b/test/e2e/custodial-bitcoin-send.spec.ts index c8543dac..23428abc 100644 --- a/test/e2e/custodial-bitcoin-send.spec.ts +++ b/test/e2e/custodial-bitcoin-send.spec.ts @@ -52,17 +52,20 @@ test("custodial-to-custodial via bitcoin address sends internally and notifies r const amountInput = bobPage.locator('[aria-label="Amount input"]'); await expect(amountInput).toBeVisible({ timeout: 5_000 }); - // Switch to sats mode if in fiat mode (click swap if lightning icon is not visible next to input) + // Ensure sats mode: swap button shows lightning icon when in fiat mode const swapButton = bobPage.locator('[aria-label="Swap currency display"]'); - const swapText = await swapButton.innerText(); - if (swapText.includes("⚡") || swapText.includes("lightning")) { - await swapButton.click(); + if (await swapButton.isVisible({ timeout: 2_000 }).catch(() => false)) { + const hasLightning = await swapButton.locator('iconify-icon[icon="ph:lightning-fill"]').count(); + if (hasLightning > 0) { + await swapButton.click(); + await bobPage.waitForTimeout(300); + } } // Type amount using keyboard await amountInput.click(); await bobPage.keyboard.press("Control+a"); - await bobPage.keyboard.type("1000"); + await bobPage.keyboard.type("100"); // Click "Next" to set the amount const nextButton = bobPage.locator('button[type="button"].btn-accent'); @@ -75,7 +78,7 @@ test("custodial-to-custodial via bitcoin address sends internally and notifies r await sendButton.click(); // Bob should be redirected to /sent/ after successful payment - await bobPage.waitForURL(/\/sent\//, { timeout: 15_000 }); + await bobPage.waitForURL(/\/sent\//, { timeout: 30_000 }); console.log(`[e2e] Bob payment sent: ${bobPage.url()}`); // --- Verify Alice receives notification and is redirected to /paid --- diff --git a/test/e2e/custodial-send-lightning.spec.ts b/test/e2e/custodial-send-lightning.spec.ts index 885da1ae..62bf9415 100644 --- a/test/e2e/custodial-send-lightning.spec.ts +++ b/test/e2e/custodial-send-lightning.spec.ts @@ -30,11 +30,11 @@ test("custodial-to-custodial via lightning bolt11 sends internally and notifies }); const { token } = await tokenRes.json(); - // Create lightning invoice with amount 1000 sats + // Create lightning invoice with amount 100 sats const invoiceRes = await alicePage.request.post(`${apiBaseUrl}/invoice`, { headers: { authorization: `Bearer ${token}` }, data: { - invoice: { type: "lightning", amount: 1000 }, + invoice: { type: "lightning", amount: 100 }, user: { username: aliceUsername }, }, }); diff --git a/test/e2e/custodial-send-username.spec.ts b/test/e2e/custodial-send-username.spec.ts index f8b4a002..cbf2ce74 100644 --- a/test/e2e/custodial-send-username.spec.ts +++ b/test/e2e/custodial-send-username.spec.ts @@ -39,7 +39,7 @@ test("custodial-to-custodial via username (/pay/) sends and notifies recipient", console.log(`[e2e] Alice balance before: ${aliceBalanceBefore}`); - // --- Bob: navigate to /pay/alice and send 1000 sats --- + // --- Bob: navigate to /pay/alice and send 100 sats --- const { context: bobContext, page: bobPage } = await loginNewContext( browser, bobUsername, @@ -50,7 +50,7 @@ test("custodial-to-custodial via username (/pay/) sends and notifies recipient", await bobPage.waitForURL(new RegExp(`/pay/${aliceUsername}`)); // Numpad should be visible — type amount and click Next (submits form) - await fillNumpadAmount(bobPage, 1000); + await fillNumpadAmount(bobPage, 100); // The form creates an invoice. If Alice has tip prompt, we go to /invoice/{id}/tip // Otherwise we go to /invoice/{id} which loads the send page @@ -102,7 +102,7 @@ test("custodial-to-custodial via username (/pay/) sends and notifies recipient", })(); console.log(`[e2e] Alice balance after: ${aliceBalanceAfter}`); - expect(aliceBalanceAfter).toBeGreaterThanOrEqual(aliceBalanceBefore + 1000); + expect(aliceBalanceAfter).toBeGreaterThanOrEqual(aliceBalanceBefore + 100); await aliceContext.close(); await bobContext.close(); diff --git a/test/e2e/helpers.ts b/test/e2e/helpers.ts index 08d19810..b45c2919 100644 --- a/test/e2e/helpers.ts +++ b/test/e2e/helpers.ts @@ -3,6 +3,7 @@ import type { Browser, Page } from "@playwright/test"; import { expect } from "@playwright/test"; // --- Environment --- +export const arkWalletPassword = process.env.E2E_ARK_WALLET_PASSWORD || "testpw123"; export const aliceUsername = process.env.E2E_ALICE_USERNAME || "alice"; export const alicePassword = process.env.E2E_ALICE_PASSWORD || "pw"; export const bobUsername = process.env.E2E_BOB_USERNAME || "bob"; @@ -218,6 +219,17 @@ export async function pasteAndSend(page: Page, text: string) { export async function fillNumpadAmount(page: Page, amount: number) { const amountInput = page.locator('[aria-label="Amount input"]'); await expect(amountInput).toBeVisible({ timeout: 5_000 }); + + // Ensure sats mode: swap button shows lightning icon when in fiat mode + const swapButton = page.locator('[aria-label="Swap currency display"]'); + if (await swapButton.isVisible({ timeout: 2_000 }).catch(() => false)) { + const hasLightning = await swapButton.locator('iconify-icon[icon="ph:lightning-fill"]').count(); + if (hasLightning > 0) { + await swapButton.click(); + await page.waitForTimeout(300); + } + } + await amountInput.click(); await page.keyboard.press("Control+a"); await page.keyboard.type(String(amount)); @@ -311,7 +323,7 @@ export async function sendArkFromTestEndpoint( async ({ address, testSecret, amount, iid }) => { const body: any = { address, amount }; if (iid) body.iid = iid; - const res = await fetch("/test/ark/send", { + const res = await fetch("/api/test/ark/send", { method: "POST", headers: { "content-type": "application/json", @@ -338,3 +350,48 @@ export async function setActiveAccount(page: Page, accountId: string) { document.cookie = `aid=${aid}; path=/; max-age=86400`; }, accountId); } + +export async function ensureArkAccount(page: Page, password: string) { + await page.goto("/account/ark"); + await page.waitForLoadState("networkidle"); + + // If redirected to dashboard, user already has an ark account + const url = page.url(); + if (!url.includes("/account/ark")) { + console.log("[e2e] Ark account already exists, skipping creation"); + return; + } + + // Check if we're on the creation page (has key generation) + const revealButton = page.locator("button.btn-warning"); + const hasReveal = await revealButton.isVisible({ timeout: 30_000 }).catch(() => false); + if (!hasReveal) { + console.log("[e2e] Ark account page loaded but no reveal button — account may already exist"); + return; + } + + // Click "Reveal Backup Key" + await revealButton.click(); + + // Click "I've Backed It Up" + const backedUpButton = page.locator("button.btn-accent"); + await expect(backedUpButton).toBeVisible({ timeout: 5_000 }); + await backedUpButton.click(); + + // Fill password and confirm password + const passwordInputs = page.locator('input[type="password"]'); + await expect(passwordInputs.first()).toBeVisible({ timeout: 5_000 }); + const count = await passwordInputs.count(); + for (let i = 0; i < count; i++) { + await passwordInputs.nth(i).fill(password); + } + + // Click "Create Wallet" submit + const submitButton = page.locator('button[type="submit"]'); + await expect(submitButton).toBeVisible({ timeout: 5_000 }); + await submitButton.click(); + + // Wait for redirect to dashboard (account created) + await page.waitForURL((u) => !u.pathname.includes("/account/ark"), { timeout: 30_000 }); + console.log("[e2e] Ark account created successfully"); +} diff --git a/test/e2e/login-balance.spec.ts b/test/e2e/login-balance.spec.ts index 58e4c2dd..0c982e29 100644 --- a/test/e2e/login-balance.spec.ts +++ b/test/e2e/login-balance.spec.ts @@ -1,16 +1,11 @@ import { expect, test } from "@playwright/test"; +import { login, bobUsername, bobPassword } from "./helpers"; -const username = process.env.E2E_USERNAME || "bob"; -const password = process.env.E2E_PASSWORD || "pw"; +const username = process.env.E2E_USERNAME || bobUsername; +const password = process.env.E2E_PASSWORD || bobPassword; test("login and report account balance", async ({ page }) => { - await page.goto("/login"); - - await page.getByTestId("login-username").fill(username); - await page.locator('input[name="password"]').first().fill(password); - await page.getByTestId("login-submit").click(); - - await expect(page).toHaveURL(new RegExp(`/${username}(?:[/?#]|$)`)); + await login(page, username, password); const balances = page.getByTestId("balance-value"); await expect(balances.first()).toBeVisible(); diff --git a/test/e2e/run-staging.sh b/test/e2e/run-staging.sh new file mode 100755 index 00000000..0f1aaebd --- /dev/null +++ b/test/e2e/run-staging.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +set -euo pipefail + +# --- Staging E2E test runner --- +# Runs tests against staging.coinos.io that don't require docker/local infra. +# +# Usage: +# ./test/e2e/run-staging.sh # headless +# ./test/e2e/run-staging.sh headed # visible browser +# ./test/e2e/run-staging.sh debug # Playwright inspector +# ./test/e2e/run-staging.sh <spec> # run a specific test file + +export E2E_BASE_URL="${E2E_BASE_URL:-https://staging.coinos.io}" +export E2E_API_BASE_URL="${E2E_API_BASE_URL:-https://staging.coinos.io/api}" +export E2E_SKIP_WEBSERVER=1 + +# Test accounts — create these on staging first +export E2E_ALICE_USERNAME="${E2E_ALICE_USERNAME:-testalice}" +export E2E_ALICE_PASSWORD="${E2E_ALICE_PASSWORD:-testpw123}" +export E2E_BOB_USERNAME="${E2E_BOB_USERNAME:-testbob}" +export E2E_BOB_PASSWORD="${E2E_BOB_PASSWORD:-testpw123}" + +# login-balance.spec.ts uses E2E_USERNAME/E2E_PASSWORD +export E2E_USERNAME="${E2E_USERNAME:-$E2E_BOB_USERNAME}" +export E2E_PASSWORD="${E2E_PASSWORD:-$E2E_BOB_PASSWORD}" + +# Test secret for ark endpoints (must match staging server config) +export E2E_TEST_SECRET="${E2E_TEST_SECRET:-}" + +# Ark wallet password for vault creation/unlock +export E2E_ARK_WALLET_PASSWORD="${E2E_ARK_WALLET_PASSWORD:-testpw123}" + +# Tests that work against staging (no docker exec / local node deps) +STAGING_SPECS=( + "test/e2e/login-balance.spec.ts" + "test/e2e/custodial-send-username.spec.ts" + "test/e2e/custodial-send-lightning.spec.ts" + "test/e2e/custodial-bitcoin-send.spec.ts" + "test/e2e/ark-receive-from-server-wallet.spec.ts" + "test/e2e/ark-send-custodial.spec.ts" + # vault/ark tests — client-side SDK signing is unreliable + # "test/e2e/ark-vault-to-custodial.spec.ts" + # "test/e2e/ark-custodial-receive.spec.ts" + # "test/e2e/vault-send-bitcoin.spec.ts" + # "test/e2e/vault-send-to-custodial-btc.spec.ts" +) + +MODE="${1:-}" + +case "$MODE" in + headed) + npx playwright test "${STAGING_SPECS[@]}" --project=chromium --headed --workers=1 + ;; + debug) + export PWDEBUG=1 + npx playwright test "${STAGING_SPECS[@]}" --project=chromium --headed --workers=1 + ;; + test/e2e/*.spec.ts) + # Run a specific test file + npx playwright test "$MODE" --project=chromium --workers=1 + ;; + *) + npx playwright test "${STAGING_SPECS[@]}" --project=chromium --workers=1 + ;; +esac |
