taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 46e64180a75d2ab3de079db00cbddcd3a9f63e44
parent b5b9cc3fcc6c9882b842640f567370fb5fb5ec6c
Author: Florian Dold <dold@taler.net>
Date:   Fri, 27 Nov 2026 02:20:31 +0100

harness: cover withdrawal and peer payment recovery after reconnect

Wait for the withdrawal task to pause before closing the popup so an
ordinary HTTP retry cannot mask a missed network change. For peer
payments, require the share QR code to appear after connectivity
returns, including when the extension page loses its wallet port.

Issue: https://bugs.taler.net/n/9691

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-upgrade.ts | 40+---------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-deposit.ts | 12++++++++++++
Mpackages/taler-harness/src/integrationtests/wallet-web-ui-checkout-test-support.ts | 14+++++++++-----
Mpackages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts | 41+++++++++++++++++++++++++++++++++++++++++
5 files changed, 201 insertions(+), 44 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts @@ -11,6 +11,7 @@ import assert from "node:assert/strict"; import http from "node:http"; import path from "node:path"; import * as nodeUrl from "node:url"; +import type { WalletNotification } from "@gnu-taler/taler-util"; import type { BrowserContext, Page } from "playwright-core"; import { loadPlaywright, @@ -23,6 +24,7 @@ import { findBrowserBinary } from "../stagefright/stage.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + walletWebUiChromeCall, reserveTcpPort, waitForWalletWebUi, } from "./wallet-web-ui-test-support.js"; @@ -30,6 +32,8 @@ import { const SETTINGS_KEY = "gnu-taler-wallet-browser-integration-v1"; const EXTENSION_ID = "wallet@taler.net"; const EXTENSION_UUID = "5e0d7cc0-49c7-4d18-8433-7b3c3e39de4d"; +// Allow one 30-second worker network poll plus time to process the wallet task. +const NETWORK_CHANGE_TIMEOUT_MS = 45_000; const TALER_URI = "taler://withdraw/bank.example/operation-123"; const FOUNTAIN_URI = `taler://fountain/merchant.example/campus/${"0".repeat(52)}`; type FirefoxDriver = import("selenium-webdriver/firefox.js").Driver; @@ -269,6 +273,66 @@ async function exerciseChromeWalletReconnect( await page.close(); } +/** Confirm at the bank while offline, then wait for the background withdrawal. */ +async function confirmWithdrawalWithPopupClosed( + page: Page, + extensionId: string, + confirm: () => Promise<void>, +) { + const context = page.context(); + await page + .getByRole("heading", { name: "Waiting for bank confirmation" }) + .waitFor(); + await page.goto("about:blank"); + const popup = await context.newPage(); + await popup.goto(`chrome-extension://${extensionId}/popup.html`); + // Wait until wallet-core has actually parked the withdrawal. A failed HTTP + // request could otherwise retry successfully even if the host sent no hints. + const withdrawal = await popup.evaluateHandle(() => { + const state = { waitingForNetwork: false }; + const port = (globalThis as any).chrome.runtime.connect({ + name: "wallet-ui-v1", + }); + port.onMessage.addListener( + ({ notification }: { notification?: WalletNotification }) => { + if ( + notification?.type === "task-observability-event" && + notification.taskId.startsWith("withdraw:") && + notification.event.type === "shepherd-task-result" && + notification.event.resultType === "network-required" + ) { + state.waitingForNetwork = true; + } + }, + ); + return state; + }); + await walletWebUiChromeCall( + popup, + "setWalletRunConfig", + { config: { testing: { emitObservabilityEvents: true } } }, + true, + ); + await context.setOffline(true); + await popup.getByText("No internet connection.", { exact: true }).waitFor(); + await popup.waitForFunction((state) => state.waitingForNetwork, withdrawal, { + timeout: NETWORK_CHANGE_TIMEOUT_MS, + }); + await popup.close(); + await confirm(); + await Promise.all([ + context.waitForEvent("response", { + predicate: (response) => + response.request().serviceWorker() !== null && + response.request().method() === "POST" && + new nodeUrl.URL(response.url()).pathname.endsWith("/withdraw") && + response.ok(), + timeout: NETWORK_CHANGE_TIMEOUT_MS, + }), + context.setOffline(false), + ]); +} + async function exerciseOfflineBalanceList(page: Page, extensionId: string) { await page.setViewportSize({ width: 390, height: 600 }); await page.goto(`chrome-extension://${extensionId}/wallet.html`); @@ -340,6 +404,77 @@ async function exerciseOfflineConfirmation(page: Page, extensionId: string) { await cancel.click(); } +/** Restore Internet access while the share page is disconnected from the host. */ +async function exerciseOfflinePeerReconnect(page: Page, extensionId: string) { + const context = page.context(); + const worker = context + .serviceWorkers() + .find((w) => new nodeUrl.URL(w.url()).hostname === extensionId); + assert.ok(worker); + const disconnectPort = await worker.evaluateHandle(() => { + const onConnect = (globalThis as any).chrome.runtime.onConnect; + type Port = { name: string; disconnect(): void }; + let walletPort: Port; + const capture = (port: Port) => { + if (port.name !== "wallet-ui-v1") return; + walletPort = port; + onConnect.removeListener(capture); + }; + onConnect.addListener(capture); + return () => walletPort.disconnect(); + }); + const viewport = { width: 390, height: 600 }; + await page.setViewportSize(viewport); + await page.goto( + `chrome-extension://${extensionId}/wallet.html#/peer/send?currency=TESTKUDOS`, + ); + await page.getByLabel("Amount").fill("1"); + await page.getByLabel("Payment description").fill("Offline transfer"); + await page.getByRole("button", { name: "Review" }).click(); + await page.getByText("Wallet spends", { exact: true }).waitFor(); + await page.evaluate("window.scrollTo(0, document.body.scrollHeight)"); + assert.ok( + await page.evaluate("window.scrollY > 0"), + "payment review should be scrolled", + ); + await context.setOffline(true); + const notice = page.getByText("No internet connection.", { exact: true }); + await notice.waitFor(); + const box = await notice.boundingBox(); + assert.ok( + box && box.y >= 0 && box.y + box.height <= viewport.height, + "the offline warning should be visible in the scrolled payment review", + ); + await page.getByRole("button", { name: "Create link" }).click(); + await page.getByRole("heading", { name: "Share payment link" }).waitFor(); + await page + .getByText( + /Preparing a secure share link|Waiting for a response from the exchange/, + ) + .waitFor(); + + const allowReconnect = await page.evaluateHandle(() => { + const runtime = (globalThis as any).chrome.runtime; + const connect = runtime.connect; + runtime.connect = () => { + throw new Error("Wallet port temporarily unavailable"); + }; + return () => { + runtime.connect = connect; + }; + }); + await disconnectPort.evaluate((disconnect) => disconnect()); + await page + .getByText("Wallet host: Disconnected", { exact: true }) + .waitFor({ state: "attached" }); + await context.setOffline(false); + await notice.waitFor({ state: "hidden" }); + await allowReconnect.evaluate((restore) => restore()); + await page + .getByRole("img", { name: "QR code for the peer payment link" }) + .waitFor({ timeout: NETWORK_CHANGE_TIMEOUT_MS }); +} + async function exerciseChromeIntegration( context: BrowserContext, extensionId: string, @@ -605,6 +740,8 @@ export async function runWalletWebUiChromeExtensionIntegrationTest( const extensionId = new nodeUrl.URL(worker.url()).hostname; await exerciseBrowserCheckout(t, { walletUrl: `chrome-extension://${extensionId}/wallet.html`, + confirmWithdrawal: (confirm) => + confirmWithdrawalWithPopupClosed(checkout, extensionId, confirm), goto: (url) => checkout.goto(url), click: (name) => checkout.getByRole("button", { name, exact: true }).click(), @@ -624,6 +761,7 @@ export async function runWalletWebUiChromeExtensionIntegrationTest( hijackLinks: true, }), }); + await exerciseOfflinePeerReconnect(checkout, extensionId); await exerciseOfflineBalanceList(checkout, extensionId); await exerciseOfflineConfirmation(checkout, extensionId); } finally { diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-upgrade.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-upgrade.ts @@ -24,6 +24,7 @@ import { findBrowserBinary } from "../stagefright/stage.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + walletWebUiChromeCall, } from "./wallet-web-ui-test-support.js"; const FIREFOX_EXTENSION_ID = "wallet@taler.net"; @@ -177,45 +178,6 @@ async function legacyChromeCall( return response.result; } -async function walletWebUiChromeCall( - page: Page, - operation: string, - args: unknown, -): Promise<any> { - const response = await page.evaluate( - async ({ operation, args }) => - new Promise<any>((resolve, reject) => { - const runtime = (globalThis as any).chrome.runtime; - const port = runtime.connect({ name: "wallet-ui-v1" }); - const id = `upgrade-${Date.now()}-${Math.random()}`; - const timeout = setTimeout(() => { - port.disconnect(); - reject(Error(`wallet-webui call ${operation} timed out`)); - }, 30_000); - port.onMessage.addListener((message: any) => { - if (message?.kind !== "response" || message.response?.id !== id) - return; - clearTimeout(timeout); - port.disconnect(); - resolve(message.response); - }); - port.postMessage({ - version: 1, - kind: "request", - mutation: false, - request: { id, operation, args }, - }); - }), - { operation, args }, - ); - if (response?.type !== "response") { - throw Error( - `wallet-webui call ${operation} failed: ${JSON.stringify(response)}`, - ); - } - return response.result; -} - async function seedLegacyChromeWallet( page: Page, talerWithdrawUri: string, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-deposit.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-deposit.ts @@ -177,11 +177,23 @@ export async function runWalletWebUiPwaPeerDepositTest(t: GlobalTestState) { await page .getByText("Browser push transfer", { exact: true }) .waitFor(); + await page.context().setOffline(true); + const offlineNotice = page + .getByRole("status") + .getByText("No internet connection.", { exact: true }); + await offlineNotice.waitFor(); await page.getByRole("button", { name: "Create link" }).click(); await page .getByRole("heading", { name: "Share payment link" }) .waitFor(); await page + .getByText( + /Preparing a secure share link|Waiting for a response from the exchange/, + ) + .waitFor(); + await page.context().setOffline(false); + await offlineNotice.waitFor({ state: "hidden" }); + await page .getByRole("img", { name: "QR code for the peer payment link" }) .waitFor(); pushUri = await readShareUri(page); diff --git a/packages/taler-harness/src/integrationtests/wallet-web-ui-checkout-test-support.ts b/packages/taler-harness/src/integrationtests/wallet-web-ui-checkout-test-support.ts @@ -41,6 +41,7 @@ export interface CheckoutBrowser { waitUrl(url: string): Promise<unknown>; tabCount(): Promise<number>; balance(): Promise<string | null>; + confirmWithdrawal?: (confirm: () => Promise<void>) => Promise<void>; setAutomaticOpening(): Promise<void>; } @@ -64,11 +65,14 @@ export async function exerciseBrowserCheckout( await browser.click("Withdraw"); await browser.waitHeading("Review withdrawal"); await browser.click("Withdraw"); - await confirmWithdrawalWhenReady(() => - bankClient.confirmWithdrawalOperation(user.username, { - withdrawalOperationId: withdrawal.withdrawal_id, - }), - ); + const confirm = () => + confirmWithdrawalWhenReady(() => + bankClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: withdrawal.withdrawal_id, + }), + ); + if (browser.confirmWithdrawal) await browser.confirmWithdrawal(confirm); + else await confirm(); await browser.goto(browser.walletUrl); const deadline = Date.now() + 60_000; while (true) { diff --git a/packages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts b/packages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts @@ -12,6 +12,7 @@ import fs from "node:fs"; import http from "node:http"; import net from "node:net"; import path from "node:path"; +import type { Page } from "playwright-core"; import { delayMs } from "../harness/harness.js"; declare const __INSTALL_PREFIX__: string; @@ -25,6 +26,46 @@ export function acknowledgeBestEffortStorageForTest(): void { ).sessionStorage.setItem("gnu-taler-wallet-best-effort-acknowledged", "yes"); } +export async function walletWebUiChromeCall( + page: Page, + operation: string, + args: unknown, + mutation = false, +): Promise<any> { + const response = await page.evaluate( + async ({ operation, args, mutation }) => + new Promise<any>((resolve, reject) => { + const runtime = (globalThis as any).chrome.runtime; + const port = runtime.connect({ name: "wallet-ui-v1" }); + const id = crypto.randomUUID(); + const timeout = setTimeout(() => { + port.disconnect(); + reject(Error(`wallet-webui call ${operation} timed out`)); + }, 30_000); + port.onMessage.addListener((message: any) => { + if (message?.kind !== "response" || message.response?.id !== id) + return; + clearTimeout(timeout); + port.disconnect(); + resolve(message.response); + }); + port.postMessage({ + version: 1, + kind: "request", + mutation, + request: { id, operation, args }, + }); + }), + { operation, args, mutation }, + ); + if (response?.type !== "response") { + throw Error( + `wallet-webui call ${operation} failed: ${JSON.stringify(response)}`, + ); + } + return response.result; +} + export function findWalletWebUiDirectory(): string { const candidates = [ process.env.TALER_WALLET_WEBUI_DIR,