taler-typescript-core

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

commit 9a732caca330d4c509a18d189b34bf0aa4e19113
parent a9da1aa70c09e818ddd205544bee8da4e739364a
Author: Florian Dold <dold@taler.net>
Date:   Mon,  9 Nov 2026 15:30:32 +0100

clients: share explicit HTTP transports and long-poll queues

Route protocol long polls through fetchLongpoll. Pass transports and
queues from wallets, applications and fixtures, using named client
options.

Diffstat:
Mpackages/libeufin-bank-webui/src/pages/BankFrame.tsx | 6+++++-
Mpackages/taler-harness/src/bench2.ts | 18++++++++++++++++--
Mpackages/taler-harness/src/harness/environments.ts | 11+++++++++--
Mpackages/taler-harness/src/harness/harness-donau.ts | 10+++++++++-
Mpackages/taler-harness/src/harness/harness.ts | 11++++++++++-
Mpackages/taler-harness/src/harness/tops.ts | 6+++++-
Mpackages/taler-harness/src/index.ts | 68++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mpackages/taler-harness/src/integrationtests/merchant-kyc-auth-helper.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-bank-wop.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-claim-loop.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-claim-retry-backoff.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-currency-scope-separation.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-denom-unoffered.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-deposit-too-large.ts | 24++++++++++++++++++++----
Mpackages/taler-harness/src/integrationtests/test-donau-idempotency.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-donau-keychange.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-donau-minus-t.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-donau-multi.ts | 4++++
Mpackages/taler-harness/src/integrationtests/test-donau.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-exchange-deposit.ts | 20+++++++++++++++++---
Mpackages/taler-harness/src/integrationtests/test-exchange-purse.ts | 21++++++++++++++++++---
Mpackages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts | 9+++++++--
Mpackages/taler-harness/src/integrationtests/test-merchant-acctsel.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts | 2++
Mpackages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts | 6++++++
Mpackages/taler-harness/src/integrationtests/test-merchant-instances.ts | 2++
Mpackages/taler-harness/src/integrationtests/test-merchant-kyc-auth-multi.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-merchant-longpolling.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-order-listing.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-payto-reuse.ts | 4++++
Mpackages/taler-harness/src/integrationtests/test-merchant-refund-api.ts | 2++
Mpackages/taler-harness/src/integrationtests/test-merchant-refund-fees.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-reports.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-self-provision-activation.ts | 5++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-self-provision-inactive-account-permissions.ts | 9+++++++--
Mpackages/taler-harness/src/integrationtests/test-merchant-sessions.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-settlement.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts | 2++
Mpackages/taler-harness/src/integrationtests/test-merchant-templates.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-tokenfamilies.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-tokenfamily-keys.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-webui-kyc-swap.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-merchant-webui-mfa.ts | 13+++++++++++--
Mpackages/taler-harness/src/integrationtests/test-merchant-webui-simple.ts | 12++++++++++--
Mpackages/taler-harness/src/integrationtests/test-merchant-wire.ts | 14++++++++++++--
Mpackages/taler-harness/src/integrationtests/test-multiexchange.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-otp.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-paivana-repurchase.ts | 12+++++++-----
Mpackages/taler-harness/src/integrationtests/test-pay-paid.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-abort.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-claim-cleanup.ts | 9++++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-claim.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-deleted.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-expired.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-multiple.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-payment-order-gone.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-template.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-transient.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment-unclaim.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-payment.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-paywall-flow.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-refund-auto.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-refund-gone.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-refund-incremental.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-refund.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-repurchase.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-tops-aml-basic.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-challenger-failure.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-expired-successor.ts | 9++++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-kyx-natural.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-merchant-simple-kycauth.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-tops-merchant-swt-kycauth.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-tops-peer.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-util-merchant-client.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-android-transactions.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-android.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-balance.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-wallet-coin-recovery.ts | 12++++++++++--
Mpackages/taler-harness/src/integrationtests/test-wallet-dbless.ts | 28+++++++++++++++++++++++++---
Mpackages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-wallet-progress-token.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-tokens.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-donau.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts | 8+++++++-
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts | 3+++
Mpackages/taler-harness/src/integrationtests/test-wallet-wirefees.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/test-wire-metadata.ts | 5+++++
Mpackages/taler-harness/src/integrationtests/test-withdrawal-bank-outage.ts | 11+++++++++--
Mpackages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts | 25+++++++++++++++++++++----
Mpackages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts | 7++++++-
Mpackages/taler-harness/src/integrationtests/wallet-android-test-support.ts | 11+++++++++--
Mpackages/taler-harness/src/integrationtests/wallet-web-ui-checkout-test-support.ts | 7++++++-
Mpackages/taler-harness/src/lint.ts | 11+++++++++--
Mpackages/taler-harness/src/playground.ts | 16+++++++++++++---
Mpackages/taler-harness/src/stagefright/merchant.ts | 9++++++++-
Mpackages/taler-merchant-webui/src/api/client.test.ts | 49++++++++++++++++++++++++++++++++++++++++++++++++-
Mpackages/taler-merchant-webui/src/api/client.ts | 47++++++++++++++++++++++++++---------------------
Mpackages/taler-merchant-webui/src/api/templateCreation.test.ts | 7+++++--
Mpackages/taler-merchant-webui/src/utils/inventoryTemplates.test.ts | 10++++++----
Mpackages/taler-util/src/http-client/aml-accounts.test.ts | 9+++++++++
Mpackages/taler-util/src/http-client/aml-wallet-credit.test.ts | 3+++
Mpackages/taler-util/src/http-client/bank-integration.ts | 42++++++++++++++++++++++++++++++------------
Apackages/taler-util/src/http-client/client-construction.test.ts | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-util/src/http-client/exchange-batch-deposit.test.ts | 3+++
Mpackages/taler-util/src/http-client/exchange-client.ts | 76+++++++++++++++++++++++++++++++++++++++-------------------------------------
Mpackages/taler-util/src/http-client/exchange-keys.test.ts | 7+++++++
Apackages/taler-util/src/http-client/exchange-longpoll.test.ts | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-util/src/http-client/exchange-refund.test.ts | 3+++
Mpackages/taler-util/src/http-client/exchange-reserve-close.test.ts | 3+++
Mpackages/taler-util/src/http-client/exchange-reserve-history.test.ts | 7+++++++
Mpackages/taler-util/src/http-client/exchange-track-deposit.test.ts | 5+++++
Mpackages/taler-util/src/http-client/merchant-abort.test.ts | 4+++-
Mpackages/taler-util/src/http-client/merchant-inventory.test.ts | 22+++++++++++++++-------
Mpackages/taler-util/src/http-client/merchant-management.test.ts | 49+++++++++++++++++++++++++++++++++++++++++--------
Mpackages/taler-util/src/http-client/merchant-refund.test.ts | 4+++-
Mpackages/taler-util/src/http-client/merchant.ts | 71++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mpackages/taler-util/src/http-client/path-escaping.test.ts | 13+++++++++----
Mpackages/taler-util/src/http-client/status-handling.test.ts | 7+++++++
Mpackages/taler-util/src/longpoll-http.test.ts | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-util/src/longpoll-queue.test.ts | 58++++++++++++++++------------------------------------------
Mpackages/taler-util/src/longpoll-queue.ts | 18------------------
Mpackages/taler-wallet-cli/src/wallet-http.test.ts | 27++++++++++++++++++++-------
Mpackages/taler-wallet-core/src/dbless.ts | 22+++++++++++++++++++---
Mpackages/taler-wallet-core/src/exchanges.ts | 35+++++++++++------------------------
Mpackages/taler-wallet-core/src/http-injection.test.ts | 5+++++
Mpackages/taler-wallet-core/src/kyc.test.ts | 26++++++++++++++++++++++++--
Mpackages/taler-wallet-core/src/pay-merchant.test.ts | 3++-
Mpackages/taler-wallet-core/src/pay-merchant.ts | 8+++-----
Mpackages/taler-wallet-core/src/pay-paivana.ts | 10++--------
Mpackages/taler-wallet-core/src/pay-peer-common.test.ts | 3++-
Mpackages/taler-wallet-core/src/pay-repurchase.test.ts | 4+++-
Mpackages/taler-wallet-core/src/pay-template.test.ts | 22++++++++++++++++++----
Mpackages/taler-wallet-core/src/pay-template.ts | 17+++--------------
Mpackages/taler-wallet-core/src/purse-deposit-reconciliation.test.ts | 3++-
Mpackages/taler-wallet-core/src/refresh.ts | 16++++++----------
Mpackages/taler-wallet-core/src/testing-check-coins.test.ts | 3++-
Mpackages/taler-wallet-core/src/testing.ts | 44+++++++++++++++-----------------------------
Mpackages/taler-wallet-core/src/transaction-reasons.test.ts | 2++
Apackages/taler-wallet-core/src/wallet-http-clients.test.ts | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/wallet.ts | 45+++++++++++++++++++++++++++++----------------
Mpackages/taler-wallet-core/src/withdraw.ts | 28+++++++++++++++-------------
Mpackages/taler-wallet-core/src/withdrawal-kyc.test.ts | 3++-
Mpackages/taler-wallet-core/src/withdrawal-kyc.ts | 8+++-----
Mpackages/web-util/src/context/exchange-api.ts | 5+++++
155 files changed, 1653 insertions(+), 460 deletions(-)

diff --git a/packages/libeufin-bank-webui/src/pages/BankFrame.tsx b/packages/libeufin-bank-webui/src/pages/BankFrame.tsx @@ -15,6 +15,7 @@ */ import { + LongpollQueue, AbsoluteTime, HttpStatusCode, ObservabilityEventType, @@ -56,6 +57,9 @@ import { COREBANK_API_BASE_URL_OVERRIDE_KEY } from "../developer-settings.js"; const TALER_SCREEN_ID = 103; +const integrationHttp = new BrowserFetchHttpLib(); +const longpollQueue = new LongpollQueue(); + const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined; const REVOCATION_WARNING_KEY = "bank-logout-revocation-unconfirmed"; @@ -335,7 +339,7 @@ function BankSettingsDialog({ try { const integration = new TalerBankIntegrationHttpClient( new URL("taler-integration/", active.backendBaseUrl).href, - { httpClient: new BrowserFetchHttpLib() }, + { httpClient: integrationHttp, longpollQueue }, ); const aborted = await integration.abortWithdrawalOperationById( active.operationId, diff --git a/packages/taler-harness/src/bench2.ts b/packages/taler-harness/src/bench2.ts @@ -18,6 +18,7 @@ * Imports. */ import { + LongpollQueue, AmountString, buildCodecForObject, codecForNumber, @@ -57,6 +58,7 @@ export async function runBench2(configJson: any): Promise<void> { const http = createPlatformHttpLib({ enableThrottling: false, }); + const longpollQueue = new LongpollQueue(); const numIter = benchConf.iterations ?? 1; const numDeposits = benchConf.deposits ?? 5; @@ -67,7 +69,11 @@ export async function runBench2(configJson: any): Promise<void> { const merchantPriv = merchantPair.priv; for (let i = 0; i < numIter; i++) { - const exchangeInfo = await downloadExchangeInfo(benchConf.exchange, http); + const exchangeInfo = await downloadExchangeInfo( + benchConf.exchange, + http, + longpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); @@ -83,7 +89,12 @@ export async function runBench2(configJson: any): Promise<void> { console.log("waiting for reserve"); - await checkReserve(http, benchConf.exchange, reserveKeyPair.pub); + await checkReserve( + http, + longpollQueue, + benchConf.exchange, + reserveKeyPair.pub, + ); console.log("reserve found"); @@ -92,6 +103,7 @@ export async function runBench2(configJson: any): Promise<void> { for (let j = 0; j < numDeposits; j++) { console.log("withdrawing coin"); const coin = await withdrawCoin({ + longpollQueue, http, cryptoApi, reserveKeyPair: { @@ -105,6 +117,7 @@ export async function runBench2(configJson: any): Promise<void> { console.log("depositing coin"); await depositCoin({ + longpollQueue, amount: `${curr}:4` as AmountString, coin: coin, cryptoApi, @@ -122,6 +135,7 @@ export async function runBench2(configJson: any): Promise<void> { console.log("refreshing coin"); await refreshCoin({ + longpollQueue, oldCoin: coin, cryptoApi, http, diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts @@ -73,6 +73,7 @@ import { FaultInjectedMerchantService, } from "./faultInjection.js"; import { + harnessLongpollQueue, BankService, BankServiceHandle, BrowserService, @@ -502,7 +503,10 @@ export async function createSimpleTestkudosEnvironmentV3( if (opts.paivanaWebsite) { const instanceUrl = merchant.makeInstanceBaseUrl("admin"); - const api = new TalerMerchantInstanceHttpClient(instanceUrl); + const api = new TalerMerchantInstanceHttpClient(instanceUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); await api.addTemplate(merchantAdminAccessToken, { template_id: "paivana", template_description: "test paivana", @@ -769,6 +773,7 @@ export async function makeTestPaymentV2( const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( @@ -1108,11 +1113,12 @@ export async function createKycTestkudosEnvironmentFull( const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), - harnessHttpLib, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeApi = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); return { @@ -1230,6 +1236,7 @@ export async function createKycTestkudosEnvironment( const exchangeApi = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); return { diff --git a/packages/taler-harness/src/harness/harness-donau.ts b/packages/taler-harness/src/harness/harness-donau.ts @@ -24,7 +24,14 @@ import { } from "@gnu-taler/taler-util"; import * as fs from "node:fs"; import { CoinConfig, defaultCoinConfig } from "./denomStructures.js"; -import { GlobalTestState, pingProc, ProcessWrapper, sh } from "./harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + pingProc, + ProcessWrapper, + sh, +} from "./harness.js"; /** * Test harness for various DONAU, the @@ -369,6 +376,7 @@ export async function registerDonauMerchantCharity(args: { }) { const merchantClient = new TalerMerchantInstanceHttpClient( args.merchantInstanceUrl, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const inst = succeedOrThrow( await merchantClient.getCurrentInstanceDetails(args.merchantAccessToken), diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -38,6 +38,7 @@ import { InstanceAuthConfigurationMessage, InstanceConfigurationMessage, Logger, + LongpollQueue, LoginTokenRequest, LoginTokenScope, MerchantAccountKycRedirectsResponse, @@ -2617,7 +2618,10 @@ export class ExchangeService implements ExchangeServiceInterface { await this.pingUntilAvailable(); { - const exchangeClient = new TalerExchangeHttpClient(this.baseUrl, {}); + const exchangeClient = new TalerExchangeHttpClient(this.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); // Would throw on incompatible version. const configResp = await exchangeClient.getConfig(); this.globalState.assertTrue(configResp.type === "ok"); @@ -2682,6 +2686,9 @@ export const harnessHttpLib = createPlatformHttpLib({ enableThrottling: false, }); +/** One concurrency budget for protocol requests made by this harness process. */ +export const harnessLongpollQueue = new LongpollQueue(); + export interface PartialMerchantInstanceConfig { auth?: InstanceAuthConfigurationMessage; id: string; @@ -3065,6 +3072,7 @@ export class MerchantService implements MerchantServiceInterface { if (!opts.skipConfigValidation) { const merchantClient = new TalerMerchantManagementHttpClient( this.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const configResp = await merchantClient.getConfig(); this.globalState.assertTrue(configResp.type === "ok"); @@ -3186,6 +3194,7 @@ export class MerchantService implements MerchantServiceInterface { await expectSuccessResponseOrThrow(resp); const merchantApi = new TalerMerchantInstanceHttpClient( this.makeInstanceBaseUrl(instanceConfig.id), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const { access_token } = succeedOrThrow( diff --git a/packages/taler-harness/src/harness/tops.ts b/packages/taler-harness/src/harness/tops.ts @@ -55,6 +55,7 @@ import { TestfakeChallengerService, } from "./fake-challenger.js"; import { + harnessLongpollQueue, BankService, BankServiceHandle, DbInfo, @@ -765,11 +766,12 @@ export async function createTopsEnvironment( const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), - harnessHttpLib, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeApi = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); const officerAcc: OfficerSession = { @@ -1025,9 +1027,11 @@ export async function setupMeasuresTestEnvironment( const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Do KYC auth transfer diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts @@ -102,6 +102,8 @@ import { createSimpleTestkudosEnvironmentV3, } from "./harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, GlobalTestState, WalletClient, @@ -290,7 +292,10 @@ testingCli }) .action(async (args) => { const merchantBaseUrl = "https://backend.test.taler.net/instances/sandbox/"; - const merchantApi = new TalerMerchantInstanceHttpClient(merchantBaseUrl); + const merchantApi = new TalerMerchantInstanceHttpClient(merchantBaseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const tokResp = succeedOrThrow( await merchantApi.createAccessToken("sandbox", "sandbox", { scope: LoginTokenScope.All, @@ -936,8 +941,13 @@ deploymentCli const cryptoApi = cryptiDisp.cryptoApi; const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); const exchangeBaseUrl = "https://exchange.demo.taler.net/"; - const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchangeBaseUrl, + http, + harnessLongpollQueue, + ); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "KUDOS:10" as AmountString, corebankApiBaseUrl: "https://bank.demo.taler.net/", exchangeInfo, @@ -964,8 +974,13 @@ deploymentCli const cryptoApi = cryptiDisp.cryptoApi; const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); const exchangeBaseUrl = "https://exchange.test.taler.net/"; - const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchangeBaseUrl, + http, + harnessLongpollQueue, + ); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: "https://bank.test.taler.net/", exchangeInfo, @@ -993,8 +1008,13 @@ deploymentCli const cryptoApi = cryptiDisp.cryptoApi; const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); const exchangeBaseUrl = "http://localhost:8081/"; - const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchangeBaseUrl, + http, + harnessLongpollQueue, + ); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: "http://localhost:8082/taler-bank-access/", exchangeInfo, @@ -1205,17 +1225,17 @@ deploymentCli const httpLib = createPlatformHttpLib({}); const merchantManager = new TalerMerchantManagementHttpClient( args.provisionBankMerchant.merchantApiBaseUrl, - httpLib, + { httpClient: httpLib, longpollQueue: harnessLongpollQueue }, ); const bank = new TalerCoreBankHttpClient( args.provisionBankMerchant.corebankApiBaseUrl, httpLib, ); const instanceURL = merchantManager.getSubInstanceAPI(id) as HostPortPath; - const merchantInstance = new TalerMerchantInstanceHttpClient( - instanceURL, - httpLib, - ); + const merchantInstance = new TalerMerchantInstanceHttpClient(instanceURL, { + httpClient: httpLib, + longpollQueue: harnessLongpollQueue, + }); const conv = new TalerBankConversionHttpClient( bank.getConversionInfoAPI().href, httpLib, @@ -1592,10 +1612,10 @@ deploymentCli .action(async (args) => { const httpLib = createPlatformHttpLib({}); const baseUrl = args.provisionMerchantInstance.merchantApiBaseUrl; - const managementApi = new TalerMerchantManagementHttpClient( - baseUrl, - httpLib, - ); + const managementApi = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: httpLib, + longpollQueue: harnessLongpollQueue, + }); const managementToken = createRFC8959AccessTokenEncoded( args.provisionMerchantInstance.managementToken, ); @@ -1654,10 +1674,10 @@ deploymentCli const instanceUrl = managementApi.getSubInstanceAPI(instanceId); - const instanceApi = new TalerMerchantInstanceHttpClient( - instanceUrl, - httpLib, - ); + const instanceApi = new TalerMerchantInstanceHttpClient(instanceUrl, { + httpClient: httpLib, + longpollQueue: harnessLongpollQueue, + }); const { access_token } = succeedOrThrow( await instanceApi.createAccessToken(instanceId, instancePassword, { @@ -1709,10 +1729,10 @@ deploymentCli const httpLib = createPlatformHttpLib({}); const donauBaseUrl = args.provisionMerchantDonau.donauBaseUrl; const merchantUrl = args.provisionMerchantDonau.merchantBaseUrl; - const merchantClient = new TalerMerchantInstanceHttpClient( - merchantUrl, - httpLib, - ); + const merchantClient = new TalerMerchantInstanceHttpClient(merchantUrl, { + httpClient: httpLib, + longpollQueue: harnessLongpollQueue, + }); const currency = args.provisionMerchantDonau.currency; const merchantToken = args.provisionMerchantDonau .merchantAuthToken as AccessToken; @@ -2408,6 +2428,7 @@ merchantCli .action(async (args) => { const merchantApi = new TalerMerchantInstanceHttpClient( args.token.merchantBaseUrl, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const instance = args.token.instance; const password = args.token.password; @@ -2454,7 +2475,10 @@ merchantCli const info = await Promise.all( allAccounts.map(async ({ exchange_url, payto_uri }) => { - const exchangeApi = new TalerExchangeHttpClient(exchange_url, {}); + const exchangeApi = new TalerExchangeHttpClient(exchange_url, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const kyc_status = await exchangeApi.checkKycStatus({ accountPub: encodeCrock(merchantPub), accountSig: accountOwnerSig, diff --git a/packages/taler-harness/src/integrationtests/merchant-kyc-auth-helper.ts b/packages/taler-harness/src/integrationtests/merchant-kyc-auth-helper.ts @@ -19,6 +19,8 @@ import { } from "@gnu-taler/taler-util"; import { configureCommonKyc } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, GlobalTestState, @@ -121,6 +123,7 @@ export async function doAccountKycAuth( ): Promise<void> { const merchantClient = new TalerMerchantInstanceHttpClient( args.merchant.makeInstanceBaseUrl(args.merchantInstId), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const initialStatus = succeedOrThrow( await merchantClient.getCurrentInstanceKycStatus( diff --git a/packages/taler-harness/src/integrationtests/test-bank-wop.ts b/packages/taler-harness/src/integrationtests/test-bank-wop.ts @@ -29,7 +29,11 @@ import { createSimpleTestkudosEnvironmentV3, registerHarnessBankTestUser, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test handing over a withdrawal to another wallet. @@ -52,6 +56,7 @@ export async function runBankWopTest(t: GlobalTestState) { const biClient = new TalerBankIntegrationHttpClient( `${bank.corebankApiBaseUrl}taler-integration/`, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const wopid = withdrawalRes.withdrawal_id; diff --git a/packages/taler-harness/src/integrationtests/test-claim-loop.ts b/packages/taler-harness/src/integrationtests/test-claim-loop.ts @@ -32,7 +32,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Run test for the merchant's order lifecycle and for the responses of @@ -58,6 +62,7 @@ export async function runClaimLoopTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Set up order. diff --git a/packages/taler-harness/src/integrationtests/test-claim-retry-backoff.ts b/packages/taler-harness/src/integrationtests/test-claim-retry-backoff.ts @@ -29,7 +29,12 @@ import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, } from "../harness/environments.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; /** * Check that the backoff of a failing claim survives being woken up. @@ -71,6 +76,7 @@ export async function runClaimRetryBackoffTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-currency-scope-separation.ts b/packages/taler-harness/src/integrationtests/test-currency-scope-separation.ts @@ -32,6 +32,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, GlobalTestState, MerchantService, getTestHarnessPaytoForLabel, @@ -109,6 +111,7 @@ export async function runCurrencyScopeSeparationTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const refundResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts b/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts @@ -31,7 +31,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; const logger = new Logger("test-denom-unoffered"); @@ -80,6 +84,7 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Make the exchange forget the denomination. diff --git a/packages/taler-harness/src/integrationtests/test-deposit-too-large.ts b/packages/taler-harness/src/integrationtests/test-deposit-too-large.ts @@ -35,7 +35,11 @@ import { withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Test deposit with a large number of coins. @@ -73,7 +77,11 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { // Withdraw digital cash without using the wallet database. - const exchangeInfo = await downloadExchangeInfo(exchange.baseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchange.baseUrl, + http, + harnessLongpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); @@ -84,6 +92,7 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { }); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:20" as AmountString, http, reservePub: reserveKeyPair.pub, @@ -98,7 +107,12 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { console.log(exchangeInfo); - await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); + await checkReserve( + http, + harnessLongpollQueue, + exchange.baseUrl, + reserveKeyPair.pub, + ); const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:0.1" as AmountString); @@ -107,6 +121,7 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { for (let i = 0; i < 100; i++) { const coin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { @@ -125,6 +140,7 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { const oversizedError = await t.assertThrowsTalerErrorAsync(() => depositCoinBatch({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, @@ -155,7 +171,7 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { { // Try downloading exchange info again to make // sure that exchange is still running and didn't crash! - await downloadExchangeInfo(exchange.baseUrl, http); + await downloadExchangeInfo(exchange.baseUrl, http, harnessLongpollQueue); } } diff --git a/packages/taler-harness/src/integrationtests/test-donau-idempotency.ts b/packages/taler-harness/src/integrationtests/test-donau-idempotency.ts @@ -39,7 +39,12 @@ import { createTestkudosDonau, registerDonauMerchantCharity, } from "../harness/harness-donau.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; export async function runDonauIdempotencyTest(t: GlobalTestState) { // Set up test environment @@ -73,6 +78,7 @@ export async function runDonauIdempotencyTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const donauClient = new DonauHttpClient(donau.baseUrl); diff --git a/packages/taler-harness/src/integrationtests/test-donau-keychange.ts b/packages/taler-harness/src/integrationtests/test-donau-keychange.ts @@ -39,7 +39,12 @@ import { createTestkudosDonau, registerDonauMerchantCharity, } from "../harness/harness-donau.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; export async function runDonauKeychangeTest(t: GlobalTestState) { // Set up test environment @@ -70,6 +75,7 @@ export async function runDonauKeychangeTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const donauClient = new DonauHttpClient(donau.baseUrl); diff --git a/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts b/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts @@ -38,7 +38,11 @@ import { createTestkudosDonau, registerDonauMerchantCharity, } from "../harness/harness-donau.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; export async function runDonauMinusTTest(t: GlobalTestState) { // Set up test environment @@ -68,6 +72,7 @@ export async function runDonauMinusTTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const donauClient = new DonauHttpClient(donau.baseUrl); diff --git a/packages/taler-harness/src/integrationtests/test-donau-multi.ts b/packages/taler-harness/src/integrationtests/test-donau-multi.ts @@ -40,6 +40,8 @@ import { registerDonauMerchantCharity, } from "../harness/harness-donau.js"; import { + harnessLongpollQueue, + harnessHttpLib, delayMs, getTestHarnessPaytoForLabel, GlobalTestState, @@ -74,6 +76,7 @@ export async function runDonauMultiTest(t: GlobalTestState) { const merchantClient1 = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const donauClient = new DonauHttpClient(donau.baseUrl); @@ -113,6 +116,7 @@ export async function runDonauMultiTest(t: GlobalTestState) { const merchantClient2 = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl("minst2"), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const { charityId: charityId2, merchantPub: merchantPub2 } = diff --git a/packages/taler-harness/src/integrationtests/test-donau.ts b/packages/taler-harness/src/integrationtests/test-donau.ts @@ -39,7 +39,12 @@ import { createTestkudosDonau, registerDonauMerchantCharity, } from "../harness/harness-donau.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; export async function runDonauTest(t: GlobalTestState) { // Set up test environment @@ -70,6 +75,7 @@ export async function runDonauTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const donauClient = new DonauHttpClient(donau.baseUrl); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts @@ -40,7 +40,7 @@ import { withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { harnessLongpollQueue, GlobalTestState } from "../harness/harness.js"; const logger = new Logger("test-exchange-deposit.ts"); @@ -63,11 +63,16 @@ export async function runExchangeDepositTest(t: GlobalTestState) { try { // Withdraw digital cash into the wallet. - const exchangeInfo = await downloadExchangeInfo(exchange.baseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchange.baseUrl, + http, + harnessLongpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, http, amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, @@ -77,7 +82,12 @@ export async function runExchangeDepositTest(t: GlobalTestState) { await exchange.runWirewatchOnce(); - await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); + await checkReserve( + http, + harnessLongpollQueue, + exchange.baseUrl, + reserveKeyPair.pub, + ); const d1 = findDenomOrThrow( exchangeInfo, @@ -88,6 +98,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { logger.info(`found denomination: ${j2s(d1)}`); const coin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { @@ -104,6 +115,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { const timestamp = TalerProtocolTimestamp.now(); await depositCoin({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, @@ -117,6 +129,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { // Idempotency await depositCoin({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, @@ -131,6 +144,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { try { // Non-idempotent request with different amount await depositCoin({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-purse.ts b/packages/taler-harness/src/integrationtests/test-exchange-purse.ts @@ -43,7 +43,11 @@ import { withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Test the exchange's purse API. @@ -62,7 +66,11 @@ export async function runExchangePurseTest(t: GlobalTestState) { try { // Withdraw digital cash into the wallet. - const exchangeInfo = await downloadExchangeInfo(exchange.baseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchange.baseUrl, + http, + harnessLongpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); @@ -76,6 +84,7 @@ export async function runExchangePurseTest(t: GlobalTestState) { }); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:10" as AmountString, http, reservePub: reserveKeyPair.pub, @@ -89,7 +98,12 @@ export async function runExchangePurseTest(t: GlobalTestState) { console.log(exchangeInfo); - await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); + await checkReserve( + http, + harnessLongpollQueue, + exchange.baseUrl, + reserveKeyPair.pub, + ); const d1 = findDenomOrThrow( exchangeInfo, @@ -98,6 +112,7 @@ export async function runExchangePurseTest(t: GlobalTestState) { ); const coin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts @@ -26,7 +26,12 @@ import { } from "@gnu-taler/taler-util"; import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, + waitMs, +} from "../harness/harness.js"; import { createTopsEnvironment } from "../harness/tops.js"; const logger = new Logger(`test-kyc-merchant-deposit.ts`); @@ -77,7 +82,7 @@ export async function runKycMerchantWalletReuseTest(t: GlobalTestState) { const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl("mt1"), - harnessHttpLib, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); while (true) { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-acctsel.ts b/packages/taler-harness/src/integrationtests/test-merchant-acctsel.ts @@ -34,6 +34,8 @@ import { makeHarnessExchangeBankAccount, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, GlobalTestState, @@ -163,6 +165,7 @@ export async function runMerchantAcctselTest(t: GlobalTestState) { const merchApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); for (const scenario of [ diff --git a/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts b/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts @@ -34,7 +34,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + waitMs, +} from "../harness/harness.js"; /** * Test deposit with a large number of coins. @@ -82,6 +87,7 @@ export async function runMerchantDepositLargeTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts @@ -43,6 +43,7 @@ import { FaultInjectedMerchantService, } from "../harness/faultInjection.js"; import { + harnessLongpollQueue, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -219,6 +220,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); let orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts @@ -35,6 +35,8 @@ import { makeHarnessExchangeBankAccount, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, GlobalTestState, @@ -138,7 +140,10 @@ export async function runMerchantExchangeDuplicateTest(t: GlobalTestState) { // Sanity check: the exchange really does advertise two accounts that // share one wire method, otherwise this test would pass vacuously. { - const exchangeClient = new TalerExchangeHttpClient(exchange1.baseUrl); + const exchangeClient = new TalerExchangeHttpClient(exchange1.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const keys = succeedOrThrow(await exchangeClient.getKeys()); console.log(`exchange advertises accounts: ${j2s(keys.accounts)}`); @@ -162,6 +167,7 @@ export async function runMerchantExchangeDuplicateTest(t: GlobalTestState) { const merchApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const ordResp1 = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts b/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts @@ -36,6 +36,7 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, getTestHarnessPaytoForLabel, GlobalTestState, harnessHttpLib, @@ -109,6 +110,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { const managementClient = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const instancesBefore = succeedOrThrow( @@ -221,6 +223,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { for (const spelling of [CANONICAL_ID, MIXED_ID, UPPER_ID]) { const client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(CANONICAL_ID), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( await client.createAccessToken( @@ -237,6 +240,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { const { access_token: instanceToken } = succeedOrThrow( await new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(UPPER_ID), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ).createAccessToken( CANONICAL_ID, INSTANCE_PASSWORD, @@ -250,6 +254,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { for (const spelling of [CANONICAL_ID, MIXED_ID, UPPER_ID]) { const client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(spelling), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const cfg = succeedOrThrow(await client.getConfig()); t.assertDeepEqual(cfg.currency, "TESTKUDOS"); @@ -276,6 +281,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { // configured with a capitalised instance name would. const orderClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(MIXED_ID), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances.ts @@ -28,6 +28,7 @@ import { URL, } from "@gnu-taler/taler-util"; import { + harnessLongpollQueue, ExchangeService, getTestHarnessPaytoForLabel, GlobalTestState, @@ -260,6 +261,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { let merchantClient = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-kyc-auth-multi.ts b/packages/taler-harness/src/integrationtests/test-merchant-kyc-auth-multi.ts @@ -32,6 +32,8 @@ import { } from "@gnu-taler/taler-util"; import { createKycTestkudosEnvironmentFull } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -119,6 +121,7 @@ export async function runMerchantKycAuthMultiTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(merchantInstId), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const accounts1 = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts @@ -33,7 +33,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Verify public order-status long polling times out while unpaid and wakes @@ -57,6 +61,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); /* diff --git a/packages/taler-harness/src/integrationtests/test-merchant-order-listing.ts b/packages/taler-harness/src/integrationtests/test-merchant-order-listing.ts @@ -56,7 +56,11 @@ import { URL, } from "@gnu-taler/taler-util"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Summaries of the orders we create, in creation order. The orders get @@ -73,6 +77,7 @@ export async function runMerchantOrderListingTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); for (const summary of orderSummaries) { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-payto-reuse.ts b/packages/taler-harness/src/integrationtests/test-merchant-payto-reuse.ts @@ -36,6 +36,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -175,6 +177,7 @@ export async function runMerchantPaytoReuseTest(t: GlobalTestState) { { const m1Client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(merchantInstId1), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( @@ -228,6 +231,7 @@ export async function runMerchantPaytoReuseTest(t: GlobalTestState) { { const m2Client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(merchantInstId2), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts @@ -23,6 +23,7 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, GlobalTestState, harnessHttpLib, MerchantServiceInterface, @@ -41,6 +42,7 @@ async function testRefundApi( const { walletClient, merchant, merchantAdminAccessToken } = env; const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( await merchantClient.createOrder(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-fees.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-fees.ts @@ -31,7 +31,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test for refunds with deposits. @@ -67,6 +71,7 @@ export async function runMerchantRefundFeesTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-reports.ts b/packages/taler-harness/src/integrationtests/test-merchant-reports.ts @@ -31,7 +31,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, sh } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + sh, +} from "../harness/harness.js"; export async function runMerchantReportsTest(t: GlobalTestState) { // Set up test environment @@ -59,6 +64,7 @@ export async function runMerchantReportsTest(t: GlobalTestState) { const instanceMgmtApi = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); function assertPdf(reportBytes: Uint8Array) { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-self-provision-activation.ts b/packages/taler-harness/src/integrationtests/test-merchant-self-provision-activation.ts @@ -20,6 +20,8 @@ import { } from "@gnu-taler/taler-util"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, getTestHarnessPaytoForLabel, GlobalTestState, } from "../harness/harness.js"; @@ -81,6 +83,7 @@ export async function runMerchantSelfProvisionActivationTest( }); const merchantClient = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const initialInstances = succeedOrThrow( await merchantClient.listInstances(merchantAdminAccessToken), @@ -132,7 +135,7 @@ export async function runMerchantSelfProvisionActivationTest( const instanceApi = new TalerMerchantInstanceHttpClient( merchantClient.getSubInstanceAPI(instanceInfo.id), - merchantClient.httpLib, + { httpClient: merchantClient.httpLib, longpollQueue: harnessLongpollQueue }, ); const completedInstances = succeedOrThrow( await merchantClient.listInstances(merchantAdminAccessToken), diff --git a/packages/taler-harness/src/integrationtests/test-merchant-self-provision-inactive-account-permissions.ts b/packages/taler-harness/src/integrationtests/test-merchant-self-provision-inactive-account-permissions.ts @@ -34,7 +34,11 @@ import { solveMFA, wait2FaCode, } from "../harness/tan-helper.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test activation-time permissions and password recovery for a @@ -100,6 +104,7 @@ export async function runMerchantSelfProvisionInactiveAccountPermissionsTest( const merchantClient = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); { @@ -130,7 +135,7 @@ export async function runMerchantSelfProvisionInactiveAccountPermissionsTest( const instanceApi = new TalerMerchantInstanceHttpClient( merchantClient.getSubInstanceAPI(instanceInfo.id), - merchantClient.httpLib, + { httpClient: merchantClient.httpLib, longpollQueue: harnessLongpollQueue }, ); const inactiveLogin = await instanceApi.createAccessToken( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts b/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts @@ -25,7 +25,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Verify the public session-status endpoint used by Paivana, including its @@ -57,6 +61,7 @@ export async function runMerchantSessionsTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Paivana session IDs contain an expiration and an unpadded base64url hash. const expiration = Math.floor(Date.now() / 1000) + 3600; diff --git a/packages/taler-harness/src/integrationtests/test-merchant-settlement.ts b/packages/taler-harness/src/integrationtests/test-merchant-settlement.ts @@ -27,7 +27,12 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, runCommand } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + runCommand, +} from "../harness/harness.js"; /** * An aggregated payout must settle every order even if reconciliation runs @@ -39,6 +44,7 @@ export async function runMerchantSettlementTest(t: GlobalTestState) { env; const client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const sql = (label: string, query: string) => runCommand(t, label, "psql", [ diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -26,6 +26,7 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, ExchangeService, GlobalTestState, harnessHttpLib, @@ -72,6 +73,7 @@ async function testPublicOrderScenario( const sessionId = `session-${suffix}`; const merchantClient = new TalerMerchantInstanceHttpClient( c.merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const createOrder = () => merchantClient.createOrder(c.merchantAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-templates.ts b/packages/taler-harness/src/integrationtests/test-merchant-templates.ts @@ -29,7 +29,11 @@ import { succeedOrThrow, } from "@gnu-taler/taler-util"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; export async function runMerchantTemplatesTest(t: GlobalTestState) { t.allowLogs({ @@ -51,6 +55,7 @@ export async function runMerchantTemplatesTest(t: GlobalTestState) { const client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-merchant-tokenfamilies.ts b/packages/taler-harness/src/integrationtests/test-merchant-tokenfamilies.ts @@ -42,7 +42,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + waitMs, +} from "../harness/harness.js"; export async function runMerchantTokenfamiliesTest(t: GlobalTestState) { t.allowLog({ @@ -76,6 +81,7 @@ export async function runMerchantTokenfamiliesTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const tokenFamilyJson = { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-tokenfamily-keys.ts b/packages/taler-harness/src/integrationtests/test-merchant-tokenfamily-keys.ts @@ -34,7 +34,11 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test that a token family gets exactly one signing key per validity @@ -59,6 +63,7 @@ export async function runMerchantTokenfamilyKeysTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const slugDiscount1 = "slugdiscount1"; diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-kyc-swap.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-kyc-swap.ts @@ -24,6 +24,8 @@ import { import fs from "node:fs"; import path from "node:path"; import { + harnessLongpollQueue, + harnessHttpLib, GlobalTestState, MERCHANT_DEFAULT_AUTH, waitMs, @@ -72,7 +74,10 @@ export async function runMerchantWebuiKycSwapTest(t: GlobalTestState) { const instanceId = "admin"; const password = "secretpassword123"; const baseUrl = env.merchant.makeInstanceBaseUrl(instanceId); - const managementClient = new TalerMerchantManagementHttpClient(baseUrl); + const managementClient = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); await managementClient.updateCurrentInstanceAuthentication( env.merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-mfa.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-mfa.ts @@ -23,7 +23,12 @@ import { } from "@gnu-taler/taler-util"; import fs from "node:fs"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, MERCHANT_DEFAULT_AUTH } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + MERCHANT_DEFAULT_AUTH, +} from "../harness/harness.js"; import { launchMerchantWebuiBrowser } from "../harness/merchant-webui-browser.js"; import { configureTestMerchantMfa, @@ -146,7 +151,10 @@ async function runMerchantWebuiMfaTestImpl( await createSimpleTestkudosEnvironmentV3(t); const instanceUrl = merchant.makeInstanceBaseUrl(account); - const instanceApi = new TalerMerchantInstanceHttpClient(instanceUrl); + const instanceApi = new TalerMerchantInstanceHttpClient(instanceUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const { accessToken: resetAccessToken } = await merchant.addInstanceWithWireAccount( { @@ -162,6 +170,7 @@ async function runMerchantWebuiMfaTestImpl( ); const resetInstanceApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(resetAccount), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // The standard fixture deliberately has no contact address. Add one before diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-simple.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-simple.ts @@ -37,6 +37,8 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, GlobalTestState, LibeufinNexusService, @@ -1375,7 +1377,10 @@ export async function runMerchantWebuiSimpleTest(t: GlobalTestState) { auth: MERCHANT_DEFAULT_AUTH, }); - const merchantClient = new TalerMerchantManagementHttpClient(baseUrl); + const merchantClient = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); // Configure instance authentication method to token with password await merchantClient.updateCurrentInstanceAuthentication(adminAccessToken, { @@ -1384,7 +1389,10 @@ export async function runMerchantWebuiSimpleTest(t: GlobalTestState) { old_password: MERCHANT_DEFAULT_AUTH.password, }); - const merchantInstanceClient = new TalerMerchantInstanceHttpClient(baseUrl); + const merchantInstanceClient = new TalerMerchantInstanceHttpClient(baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); // Create wallet with test money const { walletClient } = await createWalletDaemonWithClient(t, { diff --git a/packages/taler-harness/src/integrationtests/test-merchant-wire.ts b/packages/taler-harness/src/integrationtests/test-merchant-wire.ts @@ -35,7 +35,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + waitMs, +} from "../harness/harness.js"; /** * Test APIs related to merchant wire transfers. @@ -61,12 +66,16 @@ export async function runMerchantWireTest(t: GlobalTestState) { { adminAccessToken: merchantAdminAccessToken }, ); - const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl); + const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const keys = succeedOrThrow(await exchangeClient.getKeys()); t.assertTrue(!keys.kyc_enabled); const unsupportedAccountClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl("unsupported-wire-account"), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); while (true) { @@ -124,6 +133,7 @@ export async function runMerchantWireTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-multiexchange.ts b/packages/taler-harness/src/integrationtests/test-multiexchange.ts @@ -47,6 +47,8 @@ import { FaultInjectionRequestContext, } from "../harness/faultInjection.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, GlobalTestState, @@ -362,6 +364,7 @@ export async function runMultiExchangeTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( faultyMerchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const abortOrder = succeedOrThrow( await merchantClient.createOrder(adminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-otp.ts b/packages/taler-harness/src/integrationtests/test-otp.ts @@ -34,7 +34,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Verify merchant OTP device and template setup and an OTP-confirmed payment. @@ -47,6 +51,7 @@ export async function runOtpTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( await merchantClient.addOtpDevice(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-paivana-repurchase.ts b/packages/taler-harness/src/integrationtests/test-paivana-repurchase.ts @@ -26,17 +26,18 @@ import { TransactionMinorState, TransactionType, } from "@gnu-taler/taler-util"; -import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + waitMs, +} from "../harness/harness.js"; -const harnessHttpLib = createPlatformHttpLib({ - enableThrottling: false, -}); export const logger = new Logger("test-paivana.ts"); /** @@ -68,6 +69,7 @@ export async function runPaivanaRepurchaseTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( await merchantClient.updateTemplate(merchantAdminAccessToken, "paivana", { diff --git a/packages/taler-harness/src/integrationtests/test-pay-paid.ts b/packages/taler-harness/src/integrationtests/test-pay-paid.ts @@ -34,7 +34,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionRequestContext } from "../harness/faultInjection.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Run test for the wallets repurchase detection mechanism @@ -86,6 +90,7 @@ export async function runPayPaidTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); let orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-payment-abort.ts b/packages/taler-harness/src/integrationtests/test-payment-abort.ts @@ -37,7 +37,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionRequestContext } from "../harness/faultInjection.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; export async function runPaymentAbortTest(t: GlobalTestState) { // Set up test environment @@ -71,6 +75,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( faultyMerchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); let orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim-cleanup.ts b/packages/taler-harness/src/integrationtests/test-payment-claim-cleanup.ts @@ -30,7 +30,13 @@ import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, } from "../harness/environments.js"; -import { GlobalTestState, WalletClient, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + WalletClient, + waitMs, +} from "../harness/harness.js"; /** * A payment that is still claiming has never been shown to the user, so it @@ -44,6 +50,7 @@ export async function runPaymentClaimCleanupTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); async function makeOrder(summary: string): Promise<string> { diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts @@ -33,7 +33,12 @@ import { createWalletDaemonWithClient, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, WalletClient } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + WalletClient, +} from "../harness/harness.js"; /** * Run test where a wallet tries to claim an already claimed order. @@ -46,6 +51,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); let w2 = await createWalletDaemonWithClient(t, { diff --git a/packages/taler-harness/src/integrationtests/test-payment-deleted.ts b/packages/taler-harness/src/integrationtests/test-payment-deleted.ts @@ -30,7 +30,11 @@ import { prepareTestPayment, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test behavior when an order is deleted while the wallet is paying for it. @@ -65,6 +69,7 @@ export async function runPaymentDeletedTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-payment-expired.ts b/packages/taler-harness/src/integrationtests/test-payment-expired.ts @@ -33,7 +33,11 @@ import { prepareTestPayment, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Run a test for the following scenario: @@ -75,6 +79,7 @@ export async function runPaymentExpiredTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); { diff --git a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts @@ -34,6 +34,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -148,6 +150,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts b/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts @@ -30,7 +30,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Once the merchant has deleted an order, it answers every request about it @@ -53,6 +57,7 @@ export async function runPaymentOrderGoneTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); await withdrawViaBankV4(t, { diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts @@ -37,7 +37,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test for taler://payment-template/ URIs @@ -50,6 +54,7 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const mySummary = "hello, I'm a summary"; @@ -242,6 +247,7 @@ export async function runTemplatePickupTimeTest(t: GlobalTestState) { await createSimpleTestkudosEnvironmentV3(t); const api = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( // "Piece" is a builtin unit slug. The backend resolves a product's unit diff --git a/packages/taler-harness/src/integrationtests/test-payment-transient.ts b/packages/taler-harness/src/integrationtests/test-payment-transient.ts @@ -35,7 +35,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionResponseContext } from "../harness/faultInjection.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Run test for a payment where the merchant has a transient @@ -61,6 +65,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( faultyMerchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts b/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts @@ -23,7 +23,11 @@ import { createWalletDaemonWithClient, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; export async function runPaymentUnclaimTest(t: GlobalTestState) { t.allowLog({ @@ -56,6 +60,7 @@ export async function runPaymentUnclaimTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const created = succeedOrThrow( await merchantClient.createOrder(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-payment.ts b/packages/taler-harness/src/integrationtests/test-payment.ts @@ -32,7 +32,11 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -97,6 +101,7 @@ export async function runPaymentTest(t: GlobalTestState) { await t.runSpanAsync("idempotent-payment", async () => { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( await merchantClient.createOrder(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts @@ -33,7 +33,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal. @@ -46,6 +50,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts @@ -30,7 +30,11 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal. @@ -43,6 +47,7 @@ export async function runRefundAutoTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-refund-gone.ts b/packages/taler-harness/src/integrationtests/test-refund-gone.ts @@ -32,7 +32,11 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test wallet behavior when a refund expires before the wallet @@ -57,6 +61,7 @@ export async function runRefundGoneTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts @@ -30,7 +30,12 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal. @@ -43,6 +48,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-refund.ts b/packages/taler-harness/src/integrationtests/test-refund.ts @@ -37,7 +37,11 @@ import { makeTestPaymentV2, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; export async function runRefundTest(t: GlobalTestState) { // Set up test environment @@ -58,6 +62,7 @@ export async function runRefundTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-repurchase.ts b/packages/taler-harness/src/integrationtests/test-repurchase.ts @@ -32,7 +32,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, + waitMs, +} from "../harness/harness.js"; /** * Check repurchase detection for legacy and version 1 contracts. @@ -51,6 +56,7 @@ export async function runRepurchaseTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); function makeOrder( diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -40,6 +40,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, GlobalTestState, @@ -147,6 +149,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); t.logStep("exchangeUpdated1Cond"); diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-basic.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-basic.ts @@ -32,7 +32,11 @@ import { } from "@gnu-taler/taler-util"; import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doTopsAcceptTos } from "../harness/tops.js"; const logger = new Logger("test-tops-aml.ts"); @@ -57,6 +61,7 @@ export async function runTopsAmlBasicTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Withdrawal below threshold succeeds! @@ -71,6 +76,7 @@ export async function runTopsAmlBasicTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer { diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-challenger-failure.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-challenger-failure.ts @@ -30,6 +30,7 @@ import { } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { + harnessLongpollQueue, GlobalTestState, harnessHttpLib, runCommand, @@ -73,9 +74,11 @@ export async function runTopsAmlChallengerFailureTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); const { accessToken, merchantPaytoHash } = await doTopsKycAuth(t, { diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts @@ -31,7 +31,11 @@ import { TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -62,6 +66,7 @@ export async function runTopsAmlCustomAddrPostalTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer { @@ -129,6 +134,7 @@ export async function runTopsAmlCustomAddrPostalTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Accept ToS diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts @@ -34,7 +34,11 @@ import { TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doTopsAcceptTos } from "../harness/tops.js"; const logger = new Logger("test-tops-aml.ts"); @@ -61,6 +65,7 @@ export async function runTopsAmlCustomAddrSmsTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer { @@ -129,6 +134,7 @@ export async function runTopsAmlCustomAddrSmsTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Accept ToS diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-expired-successor.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-expired-successor.ts @@ -69,7 +69,12 @@ import { TalerExchangeHttpClient, TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; -import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, + waitMs, +} from "../harness/harness.js"; import { createTopsEnvironment, doTopsKycAuth, @@ -117,9 +122,11 @@ export async function runTopsAmlExpiredSuccessorTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Gets the account to "kyc-required". No AML officer involved: the pending diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-kyx-natural.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-kyx-natural.ts @@ -26,7 +26,11 @@ import { TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -55,6 +59,7 @@ export async function runTopsAmlKyxNaturalTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer @@ -68,6 +73,7 @@ export async function runTopsAmlKyxNaturalTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Accept ToS diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts @@ -69,7 +69,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -96,6 +100,7 @@ export async function runTopsAmlP2pFreshWalletTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Sending wallet. diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts @@ -72,7 +72,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -149,6 +153,7 @@ export async function runTopsAmlSanctionPreservesRulesTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); const smsRequirement = async (): Promise<string | undefined> => { diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts @@ -75,7 +75,11 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -103,6 +107,7 @@ export async function runTopsAmlStaleValidationTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); const w0 = await createWalletDaemonWithClient(t, { name: "w0" }); diff --git a/packages/taler-harness/src/integrationtests/test-tops-merchant-simple-kycauth.ts b/packages/taler-harness/src/integrationtests/test-tops-merchant-simple-kycauth.ts @@ -28,6 +28,8 @@ import { } from "@gnu-taler/taler-util"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, GlobalTestState, LibeufinNexusService, @@ -136,6 +138,7 @@ export async function runTopsMerchantSimpleKycauthTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer diff --git a/packages/taler-harness/src/integrationtests/test-tops-merchant-swt-kycauth.ts b/packages/taler-harness/src/integrationtests/test-tops-merchant-swt-kycauth.ts @@ -29,6 +29,8 @@ import { import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, GlobalTestState, LibeufinNexusService, @@ -147,6 +149,7 @@ export async function runTopsMerchantSwtKycauthTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Do KYC auth transfer diff --git a/packages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts b/packages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts @@ -25,7 +25,11 @@ import { TalerExchangeHttpClient, TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment, doTopsKycAuth, @@ -53,9 +57,11 @@ export async function runTopsMerchantTosTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); // Do KYC auth transfer diff --git a/packages/taler-harness/src/integrationtests/test-tops-peer.ts b/packages/taler-harness/src/integrationtests/test-tops-peer.ts @@ -32,7 +32,11 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; import { createTopsEnvironment } from "../harness/tops.js"; export async function runTopsPeerTest(t: GlobalTestState) { @@ -48,6 +52,7 @@ export async function runTopsPeerTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); t.logStep("starting withdrawal"); diff --git a/packages/taler-harness/src/integrationtests/test-util-merchant-client.ts b/packages/taler-harness/src/integrationtests/test-util-merchant-client.ts @@ -18,7 +18,11 @@ * Imports. */ import { TalerMerchantInstanceHttpClient } from "@gnu-taler/taler-util"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; import { HarnessHttpServer, SimpleServerRequest, @@ -89,6 +93,7 @@ export async function runUtilMerchantClientTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( "http://localhost:8081", + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = await merchantClient.claimOrder({ diff --git a/packages/taler-harness/src/integrationtests/test-wallet-android-transactions.ts b/packages/taler-harness/src/integrationtests/test-wallet-android-transactions.ts @@ -19,7 +19,11 @@ import { TalerBankIntegrationHttpClient, TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; import { approveAndroidKyc, confirmAndroidWithdrawal, @@ -44,6 +48,7 @@ export async function runWalletAndroidWithdrawalAbortTest(t: GlobalTestState) { await wallet.flow("transaction-state", { STATE: aborted }); const bank = new TalerBankIntegrationHttpClient( `${env.bank.corebankApiBaseUrl}taler-integration/`, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const state = succeedOrThrow( await bank.getWithdrawalOperationById( @@ -165,6 +170,7 @@ export async function runWalletAndroidPaymentAbortTest(t: GlobalTestState) { await withAndroidWallet(t, { funded: true }, async (wallet, env) => { const client = new TalerMerchantInstanceHttpClient( env.merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const order = succeedOrThrow( await client.createOrder(env.merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-wallet-android.ts b/packages/taler-harness/src/integrationtests/test-wallet-android.ts @@ -23,7 +23,11 @@ import { TalerMerchantInstanceHttpClient, TemplateType, } from "@gnu-taler/taler-util"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; import { withAndroidWallet, settleAndroidDeposit, @@ -39,6 +43,7 @@ export async function runWalletAndroidPaymentTest(t: GlobalTestState) { await withAndroidWallet(t, { funded: true }, async (wallet, env) => { const client = new TalerMerchantInstanceHttpClient( env.merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const order = succeedOrThrow( await client.createOrder(env.merchantAdminAccessToken, { @@ -81,6 +86,7 @@ async function templateTest( await withAndroidWallet(t, { funded: true }, async (wallet, env) => { const client = new TalerMerchantInstanceHttpClient( env.merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const summary = editableSummary ? "Android chosen summary" diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts @@ -40,6 +40,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, DbInfo, ExchangeService, @@ -206,6 +208,7 @@ export async function runWalletBalanceTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // Withdraw digital cash into the wallet. diff --git a/packages/taler-harness/src/integrationtests/test-wallet-coin-recovery.ts b/packages/taler-harness/src/integrationtests/test-wallet-coin-recovery.ts @@ -38,7 +38,12 @@ import { createWalletDaemonWithClient, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, runCommand } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + runCommand, +} from "../harness/harness.js"; function coinConfig(cs: boolean): CoinConfig[] { return [1, 2, 6].map((value) => ({ @@ -203,7 +208,10 @@ async function recoverV27(t: GlobalTestState, cs: boolean) { d.stampExpireWithdraw > Date.now() * 1000, )!, ); - const client = new TalerExchangeHttpClient(exchange.baseUrl); + const client = new TalerExchangeHttpClient(exchange.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const seed = encodeCrock(getRandomBytes(64)); const blindingSeed = cs ? encodeCrock(getRandomBytes(32)) : undefined; const values = cs diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts @@ -38,7 +38,11 @@ import { withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -60,7 +64,11 @@ export async function runWalletDblessTest(t: GlobalTestState) { try { // Withdraw digital cash into the wallet. - const exchangeInfo = await downloadExchangeInfo(exchange.baseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchange.baseUrl, + http, + harnessLongpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); @@ -74,6 +82,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { }); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:12" as AmountString, http, reservePub: reserveKeyPair.pub, @@ -87,11 +96,17 @@ export async function runWalletDblessTest(t: GlobalTestState) { console.log(exchangeInfo); - await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); + await checkReserve( + http, + harnessLongpollQueue, + exchange.baseUrl, + reserveKeyPair.pub, + ); const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8" as AmountString); const coin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { @@ -106,6 +121,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { const contractTermsHash = encodeCrock(getRandomBytes(64)); await depositCoin({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, @@ -118,6 +134,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { // Idempotency await depositCoin({ + longpollQueue: harnessLongpollQueue, contractTermsHash, merchantPriv, wireSalt, @@ -134,6 +151,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { ]; await refreshCoin({ + longpollQueue: harnessLongpollQueue, oldCoin: coin, cryptoApi, http, @@ -143,6 +161,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { // The exchange must still accept the previous refresh protocol, since // wallets can have refresh groups that melted with it before upgrading. const legacyCoin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { @@ -154,6 +173,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { }); await refreshCoin({ + longpollQueue: harnessLongpollQueue, oldCoin: legacyCoin, cryptoApi, http, @@ -168,6 +188,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { // keys; the exchange must still accept the commitment without them from // wallets that melt with the v32 protocol (#11862). const v32Coin = await withdrawCoin({ + longpollQueue: harnessLongpollQueue, http, cryptoApi, reserveKeyPair: { @@ -179,6 +200,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { }); await refreshCoin({ + longpollQueue: harnessLongpollQueue, oldCoin: v32Coin, cryptoApi, http, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts b/packages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts @@ -29,7 +29,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; const logger = new Logger("test-wallet-devexp-fakeprotover.ts"); @@ -39,6 +43,7 @@ export async function runWalletDevexpFakeprotoverTest(t: GlobalTestState) { const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, }); const exchangeConfRes = succeedOrThrow(await exchangeClient.getConfig()); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -39,6 +39,8 @@ import { withdrawViaBankV4, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, getTestHarnessPaytoForLabel, GlobalTestState, @@ -292,6 +294,7 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-wallet-progress-token.ts b/packages/taler-harness/src/integrationtests/test-wallet-progress-token.ts @@ -37,7 +37,12 @@ import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, } from "../harness/environments.js"; -import { GlobalTestState, waitMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + waitMs, +} from "../harness/harness.js"; /** * Exercise the progressToken machinery of requests that talk to the network @@ -439,6 +444,7 @@ export async function runWalletProgressTokenTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( await merchantClient.addTemplate(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts @@ -40,7 +40,12 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, WalletClient } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, + WalletClient, +} from "../harness/harness.js"; const logger = new Logger("test-wallet-tokens-discount.ts"); @@ -58,6 +63,7 @@ export async function runWalletTokensDiscountTest(t: GlobalTestState) { const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // withdraw some test money diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts @@ -42,7 +42,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; const logger = new Logger("test-wallet-tokens.ts"); @@ -69,6 +73,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); // withdraw some test money diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-donau.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-donau.ts @@ -19,7 +19,12 @@ import { import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { DonauService } from "../harness/harness-donau.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; import { Stage } from "../stagefright/stage.js"; import { acknowledgeBestEffortStorageForTest, @@ -67,6 +72,7 @@ export async function runWalletWebUiPwaDonauTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const merchantDetails = succeedOrThrow( await merchantClient.getCurrentInstanceDetails(merchantAdminAccessToken), diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts @@ -25,7 +25,12 @@ import { succeedOrThrow, } from "@gnu-taler/taler-util"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { delayMs, GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, + GlobalTestState, +} from "../harness/harness.js"; import { Stage } from "../stagefright/stage.js"; import { acknowledgeBestEffortStorageForTest, @@ -167,6 +172,7 @@ async function withFundedWallet( merchantAdminAccessToken, merchantClient: new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ), }); }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts @@ -33,6 +33,8 @@ import path from "node:path"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, ExchangeService, GlobalTestState, setupDb, @@ -108,6 +110,7 @@ async function runPwaWithdrawalTest( ); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); succeedOrThrow( await merchantClient.addOtpDevice(merchantAdminAccessToken, { diff --git a/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts b/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts @@ -30,7 +30,11 @@ import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * Test payment where the exchange charges wire fees. @@ -64,6 +68,7 @@ export async function runWalletWirefeesTest(t: GlobalTestState) { const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const orderResp = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-wire-metadata.ts b/packages/taler-harness/src/integrationtests/test-wire-metadata.ts @@ -41,6 +41,8 @@ import { makeHarnessExchangeBankAccount, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -121,6 +123,7 @@ export async function runWireMetadataTest(t: GlobalTestState) { }); const merchantMgmtClient = new TalerMerchantManagementHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); merchant.addExchange(exchange); @@ -143,6 +146,7 @@ export async function runWireMetadataTest(t: GlobalTestState) { const merchantAdminClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const merchantAdminTok = succeedOrThrow( @@ -169,6 +173,7 @@ export async function runWireMetadataTest(t: GlobalTestState) { const merchantMinst1Client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl("minst1"), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const merchantMinst1Tok = succeedOrThrow( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-outage.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-outage.ts @@ -23,7 +23,11 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; /** * The exchange's funded reserve must let a withdrawal finish even when the @@ -82,7 +86,10 @@ export async function runWithdrawalBankOutageTest(t: GlobalTestState) { }); await exchange.runWirewatchOnce(); - const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl); + const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const reserveStatus = await exchangeClient.getReserveStatus(reservePub); t.assertDeepEqual(reserveStatus.case, "ok"); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts @@ -43,7 +43,11 @@ import { topupReserveWithBank, } from "@gnu-taler/taler-wallet-core/dbless"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; +import { + harnessLongpollQueue, + GlobalTestState, + harnessHttpLib, +} from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -59,7 +63,11 @@ export async function runWithdrawalIdempotentTest(t: GlobalTestState) { ); const cryptoApi = cryptiDisp.cryptoApi; - const exchangeInfo = await downloadExchangeInfo(exchange.baseUrl, http); + const exchangeInfo = await downloadExchangeInfo( + exchange.baseUrl, + http, + harnessLongpollQueue, + ); const reserveKeyPair = await cryptoApi.createEddsaKeypair({}); @@ -70,6 +78,7 @@ export async function runWithdrawalIdempotentTest(t: GlobalTestState) { }); await topupReserveWithBank({ + longpollQueue: harnessLongpollQueue, amount: "TESTKUDOS:10" as AmountString, http, reservePub: reserveKeyPair.pub, @@ -83,7 +92,12 @@ export async function runWithdrawalIdempotentTest(t: GlobalTestState) { console.log(exchangeInfo); - await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); + await checkReserve( + http, + harnessLongpollQueue, + exchange.baseUrl, + reserveKeyPair.pub, + ); const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8" as AmountString); @@ -117,7 +131,10 @@ async function myWithdrawCoin(args: { value: Amounts.parseOrThrow(denom.value), }); - const exchangeClient = new TalerExchangeHttpClient(exchangeBaseUrl); + const exchangeClient = new TalerExchangeHttpClient(exchangeBaseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const sigResp = await cryptoApi.signWithdrawal({ amount: Amounts.stringify(denom.value), diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts @@ -31,6 +31,8 @@ import { makeHarnessExchangeBankAccount, } from "../harness/environments.js"; import { + harnessLongpollQueue, + harnessHttpLib, BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -107,7 +109,10 @@ export async function runWithdrawalShortenTest(t: GlobalTestState) { await exchange.start(); - const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl); + const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const keys = succeedOrThrow(await exchangeClient.getKeys()); diff --git a/packages/taler-harness/src/integrationtests/wallet-android-test-support.ts b/packages/taler-harness/src/integrationtests/wallet-android-test-support.ts @@ -33,7 +33,11 @@ import { postAmlDecisionNoRules, withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; export type AndroidEnvironment = Awaited< ReturnType<typeof createSimpleTestkudosEnvironmentV3> @@ -143,7 +147,10 @@ export async function approveAndroidKyc( __signingKey: keys.eddsaPriv as EddsaPrivP, }; await env.exchange.enableAmlAccount(officer.id, "Android KYC reviewer"); - const api = new TalerExchangeHttpClient(env.exchange.baseUrl); + const api = new TalerExchangeHttpClient(env.exchange.baseUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const pending = succeedOrThrow( await api.getAmlLegitimizations(officer, { active: true }), ); 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 @@ -23,7 +23,11 @@ import { succeedOrThrow, } from "@gnu-taler/taler-util"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; -import type { GlobalTestState } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + type GlobalTestState, +} from "../harness/harness.js"; import { confirmWithdrawalWhenReady, reserveTcpPort, @@ -79,6 +83,7 @@ export async function exerciseBrowserCheckout( await browser.setAutomaticOpening(); const client = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const port = await reserveTcpPort(); const base = `http://127.0.0.1:${port}`; diff --git a/packages/taler-harness/src/lint.ts b/packages/taler-harness/src/lint.ts @@ -50,7 +50,11 @@ import { } from "@gnu-taler/taler-util/http"; import { spawn } from "child_process"; import { URL } from "node:url"; -import { delayMs } from "./harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + delayMs, +} from "./harness/harness.js"; interface BasicConf { mainCurrency: string; @@ -580,7 +584,10 @@ export async function lintExchangeUrl(exchangeBaseUrl: string): Promise<void> { console.error(`invalid or non-canonical base url: ${exchangeBaseUrl}`); process.exit(1); } - const exchangeClient = new TalerExchangeHttpClient(canonUrl, {}); + const exchangeClient = new TalerExchangeHttpClient(canonUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const configResp = succeedOrThrow(await exchangeClient.getConfig()); const currency = configResp.currency; const keysResp = succeedOrThrow(await exchangeClient.getKeys()); diff --git a/packages/taler-harness/src/playground.ts b/packages/taler-harness/src/playground.ts @@ -31,6 +31,7 @@ import { getRandomBytes, succeedOrThrow, } from "@gnu-taler/taler-util"; +import { harnessLongpollQueue, harnessHttpLib } from "./harness/harness.js"; export interface PlaygroundBlogArgs { merchantUrl: string; @@ -60,7 +61,10 @@ export async function runPlaygroundExpiringOrders( throw Error("pay delay must be a positive, finite duration"); } - const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl); + const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const config = succeedOrThrow(await merchantClient.getConfig()); const tok = succeedOrThrow( await merchantClient.createAccessToken( @@ -101,7 +105,10 @@ export async function runPlaygroundExpiringOrders( export async function runPlaygroundBlog( args: PlaygroundBlogArgs, ): Promise<void> { - const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl); + const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const config = succeedOrThrow(await merchantClient.getConfig()); const tok = succeedOrThrow( await merchantClient.createAccessToken( @@ -201,7 +208,10 @@ export interface PlaygroundAdvancedTokensArgs { export async function runPlaygroundAdvancedTokens1( args: PlaygroundAdvancedTokensArgs, ): Promise<void> { - const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl); + const merchantClient = new TalerMerchantInstanceHttpClient(args.merchantUrl, { + httpClient: harnessHttpLib, + longpollQueue: harnessLongpollQueue, + }); const config = succeedOrThrow(await merchantClient.getConfig()); const tok = succeedOrThrow( await merchantClient.createAccessToken( diff --git a/packages/taler-harness/src/stagefright/merchant.ts b/packages/taler-harness/src/stagefright/merchant.ts @@ -35,7 +35,13 @@ import { succeedOrThrow, TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; -import { WalletClient, tryUnixConnect, delayMs } from "../harness/harness.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + WalletClient, + tryUnixConnect, + delayMs, +} from "../harness/harness.js"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import type { Page } from "playwright-core"; import fs from "node:fs"; @@ -144,6 +150,7 @@ async function loginMerchantApi( const { instanceId, password, email, phone, timeoutMs } = account; const api = new TalerMerchantInstanceHttpClient( `${baseUrl}instances/${instanceId}/`, + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, ); const request: LoginTokenRequest = { scope: LoginTokenScope.All, diff --git a/packages/taler-merchant-webui/src/api/client.test.ts b/packages/taler-merchant-webui/src/api/client.test.ts @@ -14,14 +14,18 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { HttpStatusCode, openPromise } from "@gnu-taler/taler-util"; import assert from "node:assert"; +import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import test from "node:test"; import { FakeHttpLib, noContent, notFound, ok } from "../testing/fake-http.js"; import { accountBaseUrl, confirmTanChallenge, merchantManagementClient, + merchantClient, + exchangeClient, + useHttpLibForTesting, sendTanChallenge, } from "./client.js"; import { ApiFailure, unwrap } from "./failure.js"; @@ -204,3 +208,46 @@ test("sendTanChallenge preserves a never retransmission timestamp", async () => assert.strictEqual(result.retryAfter, "never"); assert.strictEqual(result.solveExpirationMs, undefined); }); + +test("protocol helpers share admission across separately wrapped transports", async (t) => { + const gates: ReturnType<typeof openPromise<void>>[] = []; + const response = new FakeHttpLib().otherwise(notFound()); + const wrapHttp = (): HttpRequestLibrary => ({ + async fetch(url, options) { + const gate = openPromise<void>(); + gates.push(gate); + await gate.promise; + return response.fetch(url, options); + }, + }); + const restore = useHttpLibForTesting(wrapHttp()); + t.after(restore); + const tick = () => new Promise<void>((resolve) => setImmediate(resolve)); + const work = [ + merchantClient({ rootUrl, http: wrapHttp() }).getPaymentStatus("first", { + timeout: 30000, + }), + merchantManagementClient({ rootUrl, http: wrapHttp() }).getPaymentStatus( + "second", + { timeout: 30000 }, + ), + exchangeClient(rootUrl.href).getReserveStatus("reserve", true), + merchantClient({ rootUrl, http: wrapHttp() }).getPaymentStatus("fourth", { + timeout: 30000, + }), + ]; + t.after(async () => { + for (let wave = 0; wave < 2; wave++) { + for (const gate of gates) gate.resolve(); + await tick(); + } + await Promise.all(work); + }); + await tick(); + assert.equal(gates.length, 3); + const first = gates[0]; + assert.ok(first); + first.resolve(); + await tick(); + assert.equal(gates.length, 4); +}); diff --git a/packages/taler-merchant-webui/src/api/client.ts b/packages/taler-merchant-webui/src/api/client.ts @@ -15,6 +15,7 @@ */ import { + LongpollQueue, AbsoluteTime, CancellationToken, Duration, @@ -26,6 +27,7 @@ import { } from "@gnu-taler/taler-util"; import { HeadersImpl, + createPlatformHttpLib, HttpLib, type HttpRawLib, type HttpRawRequestOptions, @@ -43,10 +45,7 @@ import { isCurrentSessionIdentity, } from "../stores/session.js"; -function sessionGuardedHttp( - http: HttpRequestLibrary | undefined, -): HttpRequestLibrary | undefined { - if (!http) return undefined; +function sessionGuardedHttp(http: HttpRequestLibrary): HttpRequestLibrary { const identity = captureSessionIdentity(); if (!identity) return http; return { @@ -141,9 +140,16 @@ export function useHttpLibForTesting(http: HttpRequestLibrary): () => void { }; } -function defaultHttpLib(): HttpRequestLibrary | undefined { +// Session wrappers and protocol clients share one application budget. +const longpollQueue = new LongpollQueue(); +let platformHttpLib: HttpRequestLibrary | undefined; + +function defaultHttpLib(): HttpRequestLibrary { if (injectedHttpLib) return injectedHttpLib; - return typeof window !== "undefined" ? createBrowserHttpLib() : undefined; + return (platformHttpLib ??= + typeof window !== "undefined" + ? createBrowserHttpLib() + : createPlatformHttpLib()); } /** @@ -201,15 +207,14 @@ export function merchantClient( ): TalerMerchantInstanceHttpClient { if (config.configurationError) throw config.configurationError; const http = sessionGuardedHttp(config.http ?? defaultHttpLib()); - return new TalerMerchantInstanceHttpClient( - accountBaseUrl(config).href, - http, - // No cache evictor, ever. Invalidation is declared at the mutation that - // causes it; see F-1 in TECH-STACK.md. - undefined, - perRequest?.cancellationToken, - perRequest?.timeout, - ); + // Cache invalidation is declared at each mutation; no cache evictor here. + // See F-1 in TECH-STACK.md. + return new TalerMerchantInstanceHttpClient(accountBaseUrl(config).href, { + httpClient: http, + cancellationToken: perRequest?.cancellationToken, + timeout: perRequest?.timeout, + longpollQueue, + }); } export function merchantManagementClient( @@ -220,12 +225,11 @@ export function merchantManagementClient( ): TalerMerchantManagementHttpClient { if (config.configurationError) throw config.configurationError; const http = sessionGuardedHttp(config.http ?? defaultHttpLib()); - return new TalerMerchantManagementHttpClient( - config.rootUrl.href, - http, - undefined, - perRequest?.cancellationToken, - ); + return new TalerMerchantManagementHttpClient(config.rootUrl.href, { + httpClient: http, + cancellationToken: perRequest?.cancellationToken, + longpollQueue, + }); } /** Build an exchange client through the same injectable browser transport. */ @@ -234,6 +238,7 @@ export function exchangeClient( ): TalerExchangeHttpClient { return new TalerExchangeHttpClient(exchangeBaseUrl, { httpClient: defaultHttpLib(), + longpollQueue, }); } diff --git a/packages/taler-merchant-webui/src/api/templateCreation.test.ts b/packages/taler-merchant-webui/src/api/templateCreation.test.ts @@ -17,6 +17,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { + LongpollQueue, TalerErrorCode, TalerMerchantInstanceHttpClient, TemplateType, @@ -49,6 +50,7 @@ const collision: HandlerResult = { }; function fixture(ids: string[] = []) { + const longpollQueue = new LongpollQueue(); const state = { ids, post: (_req: Recorded): HandlerResult => noContent(), @@ -74,7 +76,7 @@ function fixture(ids: string[] = []) { const args = { client: new TalerMerchantInstanceHttpClient( "https://backend.example.test/instances/shop/", - http, + { httpClient: http, longpollQueue }, ), token: "secret-token:t" as AccessToken, body, @@ -254,6 +256,7 @@ test("an uncertain suffixed request remains pinned through a failed list refresh for (const change of ["contents", "account", "mode"] as const) { test(`changing ${change} starts a new allocation after an uncertain request`, async () => { + const longpollQueue = new LongpollQueue(); const f = fixture(); f.state.post = () => { throw new TypeError("lost response"); @@ -267,7 +270,7 @@ for (const change of ["contents", "account", "mode"] as const) { if (change === "account") args.client = new TalerMerchantInstanceHttpClient( "https://backend.example.test/instances/other/", - f.http, + { httpClient: f.http, longpollQueue }, ); if (change === "mode") { args.idMode = "manual"; diff --git a/packages/taler-merchant-webui/src/utils/inventoryTemplates.test.ts b/packages/taler-merchant-webui/src/utils/inventoryTemplates.test.ts @@ -16,6 +16,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { + LongpollQueue, TalerMerchantApi, TemplateType, TalerMerchantInstanceHttpClient, @@ -44,6 +45,7 @@ const full = { } satisfies TalerMerchantApi.TemplateContractInventoryCart; test("all inventory options survive creation, client decoding and an edited PATCH", async () => { + const longpollQueue = new LongpollQueue(); let saved: TalerMerchantApi.TemplateAddDetails | undefined; const http = new FakeHttpLib().handle((r) => { if (r.method === "GET") @@ -54,10 +56,10 @@ test("all inventory options survive creation, client decoding and an edited PATC saved = r.body as TalerMerchantApi.TemplateAddDetails; return noContent(); }); - const client = new TalerMerchantInstanceHttpClient( - "https://example.test/", - http, - ); + const client = new TalerMerchantInstanceHttpClient("https://example.test/", { + httpClient: http, + longpollQueue, + }); const token = "secret-token:t" as AccessToken; unwrap( await client.addTemplate(token, { diff --git a/packages/taler-util/src/http-client/aml-accounts.test.ts b/packages/taler-util/src/http-client/aml-accounts.test.ts @@ -16,6 +16,7 @@ import { } from "../http-common.js"; import { OfficerSession } from "../types-taler-common.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; class RecordingHttpLib implements HttpRequestLibrary { lastUrl: string | undefined; @@ -46,9 +47,11 @@ const officer: OfficerSession = { }; test("AML account list serializes negative filters", async () => { + const longpollQueue = new LongpollQueue(); const http = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await client.getAmlAccounts(officer, { investigation: false, @@ -63,9 +66,11 @@ test("AML account list serializes negative filters", async () => { }); test("AML account list serializes an exact account filter", async () => { + const longpollQueue = new LongpollQueue(); const http = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const account = "0000000000000000000000000000000000000000000000000000" as any; await client.getAmlAccounts(officer, { account }); @@ -75,9 +80,11 @@ test("AML account list serializes an exact account filter", async () => { }); test("AML account export serializes positive and negative filters", async () => { + const longpollQueue = new LongpollQueue(); const http = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await client.getAmlAccountsAsOtherFormat(officer, "text/csv", { investigation: true, @@ -92,9 +99,11 @@ test("AML account export serializes positive and negative filters", async () => }); test("AML account list omits all filters", async () => { + const longpollQueue = new LongpollQueue(); const http = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await client.getAmlAccounts(officer); assert.ok(http.lastUrl); diff --git a/packages/taler-util/src/http-client/aml-wallet-credit.test.ts b/packages/taler-util/src/http-client/aml-wallet-credit.test.ts @@ -16,6 +16,7 @@ import { } from "../http-common.js"; import { OfficerSession } from "../types-taler-common.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; class RecordingHttpLib implements HttpRequestLibrary { lastUrl: string | undefined; @@ -51,9 +52,11 @@ const officer: OfficerSession = { }; test("wallet credit requests serialize filters and return an empty list", async () => { + const longpollQueue = new LongpollQueue(); const http = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const result = await client.getWalletCredit(officer, { diff --git a/packages/taler-util/src/http-client/bank-integration.ts b/packages/taler-util/src/http-client/bank-integration.ts @@ -14,10 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { LongpollQueue } from "../longpoll-queue.js"; +import { fetchLongpoll, LongpollObserver } from "../longpoll-http.js"; import { CancellationToken } from "../CancellationToken.js"; import { HttpRequestLibrary, readTalerErrorResponse } from "../http-common.js"; import { HttpStatusCode } from "../http-status-codes.js"; -import { createPlatformHttpLib } from "../http.js"; import { LibtoolVersion } from "../libtool-version.js"; import { OperationFail, @@ -43,6 +44,16 @@ import { codecForIntegrationBankConfig } from "../types-taler-corebank.js"; import { codecForTalerErrorDetail } from "../types-taler-wallet.js"; import { addLongPollingParam, pathSegment } from "./utils.js"; +/** Dependencies and defaults for one protocol-client instance. */ +export interface TalerBankIntegrationHttpClientOptions { + httpClient: HttpRequestLibrary; + /** Share one queue across the wallet or application's protocol clients. */ + longpollQueue: LongpollQueue; + onLongpoll?: LongpollObserver; + cancellationToken?: CancellationToken; + timeout?: Duration; +} + /** * The API is used by the wallets. */ @@ -52,18 +63,18 @@ export class TalerBankIntegrationHttpClient { httpLib: HttpRequestLibrary; cancellationToken?: CancellationToken; timeout?: Duration; + readonly longpollQueue: LongpollQueue; + readonly onLongpoll?: LongpollObserver; constructor( readonly baseUrl: string, - args: { - httpClient?: HttpRequestLibrary; - cancellationToken?: CancellationToken; - timeout?: Duration; - } = {}, + options: TalerBankIntegrationHttpClientOptions, ) { - this.httpLib = args.httpClient ?? createPlatformHttpLib(); - this.cancellationToken = args.cancellationToken; - this.timeout = args.timeout; + this.httpLib = options.httpClient; + this.cancellationToken = options.cancellationToken; + this.timeout = options.timeout; + this.longpollQueue = options.longpollQueue; + this.onLongpoll = options.onLongpoll; } static isCompatible(version: string): boolean { @@ -123,12 +134,19 @@ export class TalerBankIntegrationHttpClient { url.searchParams.set("old_state", params.old_state); } } - const resp = await this.httpLib.fetch(url.href, { + const options = { readOnly: true, - method: "GET", + method: "GET" as const, cancellationToken: this.cancellationToken, timeout: this.timeout, - }); + }; + const resp = params?.timeoutMs + ? await fetchLongpoll(this.longpollQueue, this.httpLib, url, { + onLongpoll: this.onLongpoll, + ...options, + maxTimeoutMs: params.timeoutMs, + }) + : await this.httpLib.fetch(url.href, options); switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForBankWithdrawalOperationStatus()); diff --git a/packages/taler-util/src/http-client/client-construction.test.ts b/packages/taler-util/src/http-client/client-construction.test.ts @@ -0,0 +1,49 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { LongpollQueue } from "../longpoll-queue.js"; +import { HttpRequestLibrary } from "../http-common.js"; +import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { TalerBankIntegrationHttpClient } from "./bank-integration.js"; +import { + TalerMerchantInstanceHttpClient, + TalerMerchantManagementHttpClient, +} from "./merchant.js"; + +// Deliberately not executed: tsc must reject omissions from normal construction. +function requireDependencies( + httpClient: HttpRequestLibrary, + longpollQueue: LongpollQueue, +) { + const url = "https://example/"; + // @ts-expect-error Normal clients require an explicitly shared long-poll queue. + new TalerExchangeHttpClient(url, { httpClient }); + // @ts-expect-error Normal clients require an explicit transport. + new TalerExchangeHttpClient(url, { longpollQueue }); + // @ts-expect-error Normal clients require an explicitly shared long-poll queue. + new TalerBankIntegrationHttpClient(url, { httpClient }); + // @ts-expect-error Normal clients require an explicit transport. + new TalerBankIntegrationHttpClient(url, { longpollQueue }); + // @ts-expect-error Normal clients require an explicitly shared long-poll queue. + new TalerMerchantInstanceHttpClient(url, { httpClient }); + // @ts-expect-error Normal clients require an explicit transport. + new TalerMerchantInstanceHttpClient(url, { longpollQueue }); + // @ts-expect-error Management clients follow the same ownership contract. + new TalerMerchantManagementHttpClient(url, { httpClient }); + // @ts-expect-error Management clients require an explicit transport too. + new TalerMerchantManagementHttpClient(url, { longpollQueue }); +} +void requireDependencies; diff --git a/packages/taler-util/src/http-client/exchange-batch-deposit.test.ts b/packages/taler-util/src/http-client/exchange-batch-deposit.test.ts @@ -12,8 +12,10 @@ import test from "node:test"; import { FakeHttpLib } from "../http-fake.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("batch deposit exposes every documented permanent HTTP status", async () => { + const longpollQueue = new LongpollQueue(); for (const status of [ HttpStatusCode.BadRequest, HttpStatusCode.Forbidden, @@ -29,6 +31,7 @@ test("batch deposit exposes every documented permanent HTTP status", async () => }); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const result = await client.batchDeposit({ body: {} as never }); assert.strictEqual(result.case, status); diff --git a/packages/taler-util/src/http-client/exchange-client.ts b/packages/taler-util/src/http-client/exchange-client.ts @@ -22,7 +22,6 @@ import { readTalerErrorResponse, } from "../http-common.js"; import { HttpStatusCode } from "../http-status-codes.js"; -import { createPlatformHttpLib } from "../http.js"; import { LibtoolVersion } from "../libtool-version.js"; import { OperationAlternative, @@ -154,6 +153,7 @@ import { CancellationToken } from "../CancellationToken.js"; import { AmountJson, Amounts } from "../amounts.js"; import { Logger } from "../logging.js"; import { LongpollQueue } from "../longpoll-queue.js"; +import { fetchLongpoll, LongpollObserver } from "../longpoll-http.js"; import { opKnownFailureWithBody, opKnownTalerFailure } from "../operation.js"; import { PaytoHash } from "../payto.js"; import { TalerErrorCode } from "../taler-error-codes.js"; @@ -206,6 +206,18 @@ function addYesNoFilter( } } +/** Dependencies and defaults for one protocol-client instance. */ +export interface TalerExchangeHttpClientOptions { + httpClient: HttpRequestLibrary; + /** Share one queue across the wallet or application's protocol clients. */ + longpollQueue: LongpollQueue; + onLongpoll?: LongpollObserver; + cacheEvictor?: CacheEvictor<TalerExchangeCacheEviction>; + preventCompression?: boolean; + cancellationToken?: CancellationToken; + timeout?: Duration; +} + /** * Client library for the GNU Taler exchange service. */ @@ -217,8 +229,9 @@ export class TalerExchangeHttpClient { private httpLib: HttpRequestLibrary; private cacheEvictor: CacheEvictor<TalerExchangeCacheEviction>; private preventCompression: boolean; - private cancelationToken: CancellationToken; - private longPollQueue: LongpollQueue; + private cancellationToken: CancellationToken; + private longpollQueue: LongpollQueue; + private readonly onLongpoll?: LongpollObserver; /** * Timeout applied to every request made by this client. The client is * short-lived and constructed per logical operation, so the timeout is set @@ -228,22 +241,16 @@ export class TalerExchangeHttpClient { constructor( readonly baseUrl: string, - params: { - httpClient?: HttpRequestLibrary; - cacheEvictor?: CacheEvictor<TalerExchangeCacheEviction>; - preventCompression?: boolean; - cancelationToken?: CancellationToken; - longPollQueue?: LongpollQueue; - timeout?: Duration; - } = {}, + options: TalerExchangeHttpClientOptions, ) { - this.httpLib = params.httpClient ?? createPlatformHttpLib(); - this.cacheEvictor = params.cacheEvictor ?? nullEvictor; - this.preventCompression = !!params.preventCompression; - this.cancelationToken = - params.cancelationToken ?? CancellationToken.CONTINUE; - this.longPollQueue = params.longPollQueue ?? new LongpollQueue(); - this.defaultTimeout = params.timeout; + this.httpLib = options.httpClient; + this.cacheEvictor = options.cacheEvictor ?? nullEvictor; + this.preventCompression = !!options.preventCompression; + this.cancellationToken = + options.cancellationToken ?? CancellationToken.CONTINUE; + this.longpollQueue = options.longpollQueue; + this.onLongpoll = options.onLongpoll; + this.defaultTimeout = options.timeout; } static isCompatible(version: string): boolean { @@ -264,22 +271,18 @@ export class TalerExchangeHttpClient { ? new URL(url_or_path, this.baseUrl) : url_or_path; if (longpoll || url.searchParams.has("timeout_ms")) { - return this.longPollQueue.run( - url, - this.cancelationToken, - async (timeoutMs) => { - url.searchParams.set("timeout_ms", String(timeoutMs)); - return this.httpLib.fetch(url.href, { - timeout: this.defaultTimeout, - cancellationToken: this.cancelationToken, - ...opts, - }); - }, - ); + const requested = url.searchParams.get("timeout_ms"); + return fetchLongpoll(this.longpollQueue, this.httpLib, url, { + onLongpoll: this.onLongpoll, + timeout: this.defaultTimeout, + cancellationToken: this.cancellationToken, + ...opts, + maxTimeoutMs: requested === null ? 30000 : Number(requested), + }); } else { return this.httpLib.fetch(url.href, { timeout: this.defaultTimeout, - cancellationToken: this.cancelationToken, + cancellationToken: this.cancellationToken, ...opts, }); } @@ -1837,15 +1840,14 @@ export class TalerExchangeHttpClient { */ async getReserveStatus( reservePub: string, - longpoll: boolean = false, + longpoll: boolean | number = false, ): Promise< OperationOk<ReserveStatus> | OperationFail<HttpStatusCode.NotFound> > { - const resp = await this.fetch( - `reserves/${reservePub}`, - { readOnly: true }, - longpoll, - ); + const url = new URL(`reserves/${reservePub}`, this.baseUrl); + if (typeof longpoll === "number") + url.searchParams.set("timeout_ms", String(longpoll)); + const resp = await this.fetch(url, { readOnly: true }, !!longpoll); switch (resp.status) { case HttpStatusCode.Ok: return opSuccessFromHttp(resp, codecForReserveStatus()); diff --git a/packages/taler-util/src/http-client/exchange-keys.test.ts b/packages/taler-util/src/http-client/exchange-keys.test.ts @@ -23,6 +23,7 @@ import { HttpResponse, } from "../http-common.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; /** * Records the URL and headers of the last request and answers with an empty @@ -53,9 +54,11 @@ class RecordingHttpLib implements HttpRequestLibrary { } test("getKeys asks for the whole response by default", async (t) => { + const longpollQueue = new LongpollQueue(); const lib = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example.com/", { httpClient: lib, + longpollQueue, }); // The 204 is not a valid /keys response; only the request matters here. await client.getKeys().catch(() => undefined); @@ -63,9 +66,11 @@ test("getKeys asks for the whole response by default", async (t) => { }); test("getKeys passes the cherry-picking date as last_issue_date", async (t) => { + const longpollQueue = new LongpollQueue(); const lib = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example.com/", { httpClient: lib, + longpollQueue, }); await client.getKeys({ lastIssueDate: 1750000000 }).catch(() => undefined); // Seconds since the epoch, as an unsigned integer -- not an ISO string and @@ -77,9 +82,11 @@ test("getKeys passes the cherry-picking date as last_issue_date", async (t) => { }); test("getKeys combines cherry-picking with a cache break", async (t) => { + const longpollQueue = new LongpollQueue(); const lib = new RecordingHttpLib(); const client = new TalerExchangeHttpClient("https://exchange.example.com/", { httpClient: lib, + longpollQueue, }); await client .getKeys({ lastIssueDate: 1750000000, noCache: true }) diff --git a/packages/taler-util/src/http-client/exchange-longpoll.test.ts b/packages/taler-util/src/http-client/exchange-longpoll.test.ts @@ -0,0 +1,79 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { + HeadersImpl, + HttpRequestLibrary, + HttpResponse, +} from "../http-common.js"; +import { LongpollQueue } from "../longpoll-queue.js"; +import { openPromise } from "../promises.js"; +import { TalerExchangeHttpClient } from "./exchange-client.js"; + +test("exchange clients share host limits and pass adaptive timeouts to HTTP", async () => { + const longpollQueue = new LongpollQueue(); + const requests: { url: URL; finish: () => void }[] = []; + const httpClient: HttpRequestLibrary = { + async fetch(url) { + const finish = openPromise<void>(); + requests.push({ url: new URL(url), finish: () => finish.resolve() }); + await finish.promise; + const headers = new HeadersImpl(); + headers.set("content-type", "application/json"); + return { + requestUrl: url, + requestMethod: "GET", + // A valid error response avoids coupling this test to status schemas. + status: 404, + headers, + json: async () => ({ code: 1 }), + text: async () => "", + bytes: async () => new Uint8Array(), + } satisfies HttpResponse; + }, + }; + const client = () => + new TalerExchangeHttpClient("https://exchange.example/", { + httpClient, + longpollQueue, + }); + const tick = () => new Promise<void>((resolve) => setImmediate(resolve)); + const pending: Promise<unknown>[] = []; + for (let i = 0; i < 3; i++) { + pending.push(client().getReserveStatus("reserve" + i, true)); + await tick(); + } + assert.deepEqual( + requests.map((r) => r.url.searchParams.get("timeout_ms")), + ["30000", "15000", "10000"], + ); + pending.push(client().getReserveStatus("queued", true)); + await tick(); + assert.equal(requests.length, 3); + pending.push(client().getPurseStatusAtDeposit("ordinary")); + await tick(); + assert.equal(requests.length, 4); + assert.equal(requests[3].url.searchParams.has("timeout_ms"), false); + requests[0].finish(); + await tick(); + assert.equal(requests.length, 5); + assert.equal(requests[4].url.pathname, "/reserves/queued"); + assert.equal(requests[4].url.searchParams.get("timeout_ms"), "10000"); + for (const request of requests) request.finish(); + await Promise.all(pending); +}); diff --git a/packages/taler-util/src/http-client/exchange-refund.test.ts b/packages/taler-util/src/http-client/exchange-refund.test.ts @@ -20,8 +20,10 @@ import { FakeHttpLib, ok } from "../http-fake.js"; import { encodeCrock } from "../taler-crypto.js"; import { ExchangeRefundRequest } from "../types-taler-exchange.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("refundCoin preserves the signed exchange confirmation", async () => { + const longpollQueue = new LongpollQueue(); const exchangePub = encodeCrock(new Uint8Array(32)); const exchangeSig = encodeCrock(new Uint8Array(64)); const http = new FakeHttpLib().on( @@ -31,6 +33,7 @@ test("refundCoin preserves the signed exchange confirmation", async () => { ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const result = await client.refundCoin("coin", {} as ExchangeRefundRequest); diff --git a/packages/taler-util/src/http-client/exchange-reserve-close.test.ts b/packages/taler-util/src/http-client/exchange-reserve-close.test.ts @@ -20,8 +20,10 @@ import { FakeHttpLib, ok } from "../http-fake.js"; import { TalerProtocolTimestamp } from "../time.js"; import { ReserveCloseRequest } from "../ReserveStatus.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("closeReserve posts a return-to-origin request", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "POST", "/reserves/reserve-pub/close", @@ -29,6 +31,7 @@ test("closeReserve posts a return-to-origin request", async () => { ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const request = { reserve_sig: "reserve-signature", diff --git a/packages/taler-util/src/http-client/exchange-reserve-history.test.ts b/packages/taler-util/src/http-client/exchange-reserve-history.test.ts @@ -12,8 +12,10 @@ import test from "node:test"; import { FakeHttpLib, noContent, ok } from "../http-fake.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("reserve history binds the signature to the requested start offset", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/reserves/reserve-pub/history", @@ -24,6 +26,7 @@ test("reserve history binds the signature to the requested start offset", async ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const result = await client.getReserveHistory("reserve-pub", "sig-3", 3); @@ -40,6 +43,7 @@ test("reserve history binds the signature to the requested start offset", async }); test("reserve history exposes pagination terminators", async () => { + const longpollQueue = new LongpollQueue(); for (const status of [HttpStatusCode.NoContent, HttpStatusCode.NotModified]) { const http = new FakeHttpLib().otherwise( status === HttpStatusCode.NoContent @@ -48,6 +52,7 @@ test("reserve history exposes pagination terminators", async () => { ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); const result = await client.getReserveHistory( "reserve-pub", @@ -59,6 +64,7 @@ test("reserve history exposes pagination terminators", async () => { }); test("reserve history rejects incomplete merge entries", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/reserves/reserve-pub/history", @@ -69,6 +75,7 @@ test("reserve history rejects incomplete merge entries", async () => { ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await assert.rejects(client.getReserveHistory("reserve-pub", "signature")); diff --git a/packages/taler-util/src/http-client/exchange-track-deposit.test.ts b/packages/taler-util/src/http-client/exchange-track-deposit.test.ts @@ -20,6 +20,7 @@ import { FakeHttpLib } from "../http-fake.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { TalerProtocolTimestamp } from "../time.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; const accepted = { status: HttpStatusCode.Accepted, @@ -38,6 +39,7 @@ const request = { }; test("trackDeposit can return the current status without long polling", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/deposits/wire-hash/merchant-pub/contract-terms-hash/coin-pub", @@ -45,6 +47,7 @@ test("trackDeposit can return the current status without long polling", async () ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await client.trackDeposit({ ...request, longpoll: false }); @@ -59,6 +62,7 @@ test("trackDeposit can return the current status without long polling", async () }); test("trackDeposit long polls by default", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/deposits/wire-hash/merchant-pub/contract-terms-hash/coin-pub", @@ -66,6 +70,7 @@ test("trackDeposit long polls by default", async () => { ); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: http, + longpollQueue, }); await client.trackDeposit(request); diff --git a/packages/taler-util/src/http-client/merchant-abort.test.ts b/packages/taler-util/src/http-client/merchant-abort.test.ts @@ -19,8 +19,10 @@ import { test } from "node:test"; import { FakeHttpLib } from "../http-fake.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { TalerMerchantInstanceHttpClient } from "./merchant.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("merchant abort preserves per-coin results returned with HTTP 502", async () => { + const longpollQueue = new LongpollQueue(); const body = { refunds: [ { type: "undeposited" }, @@ -36,7 +38,7 @@ test("merchant abort preserves per-coin results returned with HTTP 502", async ( }); const client = new TalerMerchantInstanceHttpClient( "https://merchant.example/", - http, + { httpClient: http, longpollQueue }, ); const result = await client.abortIncompletePayment("order", { diff --git a/packages/taler-util/src/http-client/merchant-inventory.test.ts b/packages/taler-util/src/http-client/merchant-inventory.test.ts @@ -25,6 +25,7 @@ import { } from "../types-taler-merchant.js"; import { TalerErrorCode } from "../taler-error-codes.js"; import type { AccessToken } from "../types-taler-common.js"; +import { LongpollQueue } from "../longpoll-queue.js"; const token = "secret-token:test" as AccessToken; const unit = { unit_serial: 1, @@ -87,13 +88,14 @@ test("inventory codecs accept legacy responses and retain new fields", () => { }); test("unit client supports private and public reads and encoded unit identifiers", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib() .on("GET", "/private/units", ok({ units: [unit] })) .on("GET", "/private/units/bag%2Fbox", ok(unit)) .on("GET", "/units", ok({ units: [unit] })); const client = new TalerMerchantInstanceHttpClient( "https://merchant.test/instances/shop/", - http, + { httpClient: http, longpollQueue }, ); const listed = await client.listUnits(token); assert.equal(listed.type, "ok"); @@ -115,6 +117,7 @@ test("unit client supports private and public reads and encoded unit identifiers }); test("unit mutations send bodies and report built-in/unknown unit errors", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib() .on("POST", "/private/units", noContent()) .on("PATCH", "/private/units/bag", noContent()) @@ -127,10 +130,10 @@ test("unit mutations send bodies and report built-in/unknown unit errors", async status: 404, body: talerError(TalerErrorCode.MERCHANT_GENERIC_UNIT_UNKNOWN), }); - const client = new TalerMerchantInstanceHttpClient( - "https://merchant.test/", - http, - ); + const client = new TalerMerchantInstanceHttpClient("https://merchant.test/", { + httpClient: http, + longpollQueue, + }); assert.equal((await client.addUnit(token, unit)).type, "ok"); assert.deepEqual(http.lastRequest?.body, unit); assert.equal( @@ -144,6 +147,7 @@ test("unit mutations send bodies and report built-in/unknown unit errors", async }); test("inventory client supports modern creation, decimal locks, filters and public images", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib() .on("POST", "/private/products", noContent()) .on("POST", "/private/products/tea/lock", noContent()) @@ -155,7 +159,7 @@ test("inventory client supports modern creation, decimal locks, filters and publ ); const client = new TalerMerchantInstanceHttpClient( "https://merchant.test/instances/shop/", - http, + { httpClient: http, longpollQueue }, ); const body: ProductAddDetailRequest = { product_id: "tea", @@ -211,12 +215,16 @@ for (const [baseUrl, expected] of [ ], ]) test(`product image preserves the deployment prefix of ${baseUrl}`, async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", new URL(expected!).pathname, ok({ image: "data:image/png;base64,abc" }), ); - const client = new TalerMerchantInstanceHttpClient(baseUrl!, http); + const client = new TalerMerchantInstanceHttpClient(baseUrl!, { + httpClient: http, + longpollQueue, + }); assert.equal((await client.getProductImage("abc")).type, "ok"); assert.equal(http.lastRequest?.url, expected); assert.equal(http.lastRequest?.headers?.Authorization, undefined); diff --git a/packages/taler-util/src/http-client/merchant-management.test.ts b/packages/taler-util/src/http-client/merchant-management.test.ts @@ -18,6 +18,7 @@ import { import type { AccessToken } from "../types-taler-common.js"; import { MerchantAuthMethod } from "../types-taler-merchant.js"; import { TalerErrorCode } from "../taler-error-codes.js"; +import { LongpollQueue } from "../longpoll-queue.js"; const token = "secret-token:admin" as AccessToken; const baseUrl = "https://merchant.example.com/"; @@ -40,6 +41,7 @@ const configuration = { }; test("management client lists instances and decodes complete details", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib() .on("GET", "/management/instances", ok({ instances: [instance] })) .on( @@ -65,7 +67,10 @@ test("management client lists instances and decodes complete details", async () auth: { method: "token" }, }), ); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const listed = await client.listInstances(token); assert.strictEqual(listed.type, "ok"); @@ -80,12 +85,16 @@ test("management client lists instances and decodes complete details", async () }); test("management client can probe an empty backend without authorization", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/management/instances", ok({ instances: [] }), ); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const listed = await client.listInstances(); assert.strictEqual(listed.type, "ok"); @@ -94,6 +103,7 @@ test("management client can probe an empty backend without authorization", async }); test("management writes support login-token and challenge responses", async () => { + const longpollQueue = new LongpollQueue(); const challenge = { challenges: [ { @@ -120,7 +130,10 @@ test("management writes support login-token and challenge responses", async () = body: challenge, }) .on("POST", "/management/instances/shop/auth", noContent()); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const created = await client.createInstance(token, configuration); assert.strictEqual(created.type, "ok"); @@ -148,6 +161,7 @@ test("management writes support login-token and challenge responses", async () = }); test("self-service authentication requests use their distinct wire formats", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on("POST", "/private/auth", noContent()).on( "POST", "/forgot-password", @@ -158,7 +172,10 @@ test("self-service authentication requests use their distinct wire formats", asy refreshable: false, }), ); - const client = new TalerMerchantInstanceHttpClient(baseUrl, http); + const client = new TalerMerchantInstanceHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const changed = await client.updateCurrentInstanceAuthentication(token, { method: MerchantAuthMethod.TOKEN, @@ -187,13 +204,17 @@ test("self-service authentication requests use their distinct wire formats", asy }); test("self-service password changes preserve the bad-current-password error", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on("POST", "/private/auth", { status: HttpStatusCode.Unauthorized, body: talerError( TalerErrorCode.MERCHANT_PRIVATE_POST_INSTANCE_AUTH_BAD_OLD_PASSWORD, ), }); - const client = new TalerMerchantInstanceHttpClient(baseUrl, http); + const client = new TalerMerchantInstanceHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const changed = await client.updateCurrentInstanceAuthentication(token, { method: MerchantAuthMethod.TOKEN, @@ -208,6 +229,7 @@ test("self-service password changes preserve the bad-current-password error", as }); test("management deletion and KYC use the documented wire format", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib() .on("DELETE", "/management/instances/shop", noContent()) .on( @@ -228,7 +250,10 @@ test("management deletion and KYC use the documented wire format", async () => { ], }), ); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const removed = await client.deleteInstance(token, "shop", { purge: true }); assert.strictEqual(removed.type, "ok"); @@ -252,12 +277,16 @@ test("management deletion and KYC use the documented wire format", async () => { }); test("management KYC accepts an empty no-content response", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on( "GET", "/management/instances/shop/kyc", noContent(), ); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); const kyc = await client.getInstanceKycStatus(token, "shop"); assert.strictEqual(kyc.type, "ok"); @@ -265,8 +294,12 @@ test("management KYC accepts an empty no-content response", async () => { }); test("self-provisioning encodes finite and unlimited token validity as integer milliseconds", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on("POST", "/instances", noContent()); - const client = new TalerMerchantManagementHttpClient(baseUrl, http); + const client = new TalerMerchantManagementHttpClient(baseUrl, { + httpClient: http, + longpollQueue, + }); for (const [d_ms, expected] of [ ["forever", "18446744073709551615"], [300_000, "300000"], diff --git a/packages/taler-util/src/http-client/merchant-refund.test.ts b/packages/taler-util/src/http-client/merchant-refund.test.ts @@ -12,15 +12,17 @@ import test from "node:test"; import { FakeHttpLib } from "../http-fake.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { TalerMerchantInstanceHttpClient } from "./merchant.js"; +import { LongpollQueue } from "../longpoll-queue.js"; test("merchant refund models an expired refund as HTTP 410", async () => { + const longpollQueue = new LongpollQueue(); const http = new FakeHttpLib().on("POST", "/orders/order/refund", { status: HttpStatusCode.Gone, body: { code: 2000, hint: "wire deadline passed" }, }); const client = new TalerMerchantInstanceHttpClient( "https://merchant.example/", - http, + { httpClient: http, longpollQueue }, ); const result = await client.obtainRefund("order", { diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts @@ -14,6 +14,8 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { LongpollQueue } from "../longpoll-queue.js"; +import { fetchLongpoll, LongpollObserver } from "../longpoll-http.js"; import { AbsoluteTime, AccessToken, @@ -106,7 +108,6 @@ import { import { HttpRequestLibrary, HttpResponse, - createPlatformHttpLib, readTalerErrorResponse, } from "@gnu-taler/taler-util/http"; import { opSuccessFromHttp } from "../operation.js"; @@ -172,6 +173,17 @@ export enum TalerMerchantManagementCacheEviction { DELETE_INSTANCE, } +/** Dependencies and defaults for one protocol-client instance. */ +export interface TalerMerchantInstanceHttpClientOptions { + httpClient: HttpRequestLibrary; + /** Share one queue across the wallet or application's protocol clients. */ + longpollQueue: LongpollQueue; + onLongpoll?: LongpollObserver; + cacheEvictor?: CacheEvictor<TalerMerchantInstanceCacheEviction>; + cancellationToken?: CancellationToken; + timeout?: Duration; +} + /** * Protocol version spoken with the core bank. * @@ -189,17 +201,19 @@ export class TalerMerchantInstanceHttpClient { readonly cancellationToken: CancellationToken | undefined; readonly timeout: Duration | undefined; + readonly longpollQueue: LongpollQueue; + readonly onLongpoll?: LongpollObserver; + constructor( readonly baseUrl: string, - httpClient?: HttpRequestLibrary, - cacheEvictor?: CacheEvictor<TalerMerchantInstanceCacheEviction>, - cancellationToken?: CancellationToken, - timeout?: Duration, + options: TalerMerchantInstanceHttpClientOptions, ) { - this.httpLib = httpClient ?? createPlatformHttpLib(); - this.cacheEvictor = cacheEvictor ?? nullEvictor; - this.cancellationToken = cancellationToken; - this.timeout = timeout; + this.httpLib = options.httpClient; + this.longpollQueue = options.longpollQueue; + this.onLongpoll = options.onLongpoll; + this.cacheEvictor = options.cacheEvictor ?? nullEvictor; + this.cancellationToken = options.cancellationToken; + this.timeout = options.timeout; } static isCompatible(version: string): boolean { @@ -542,7 +556,9 @@ export class TalerMerchantInstanceHttpClient { async getPaymentStatus( orderId: string, - params: TalerMerchantApi.PaymentStatusRequestParams = {}, + params: TalerMerchantApi.PaymentStatusRequestParams & { + deadline?: AbsoluteTime; + } = {}, ) { const url = new URL(`orders/${pathSegment(orderId)}`, this.baseUrl); @@ -576,12 +592,21 @@ export class TalerMerchantInstanceHttpClient { url.searchParams.set("timeout_ms", String(params.timeout)); } - const resp = await this.httpLib.fetch(url.href, { + const options = { readOnly: true, - method: "GET", + method: "GET" as const, cancellationToken: this.cancellationToken, timeout: this.timeout, - }); + }; + const resp = + params.timeout !== undefined || params.deadline !== undefined + ? await fetchLongpoll(this.longpollQueue, this.httpLib, url, { + onLongpoll: this.onLongpoll, + ...options, + maxTimeoutMs: params.timeout, + deadline: params.deadline, + }) + : await this.httpLib.fetch(url.href, options); // The order status is discriminated by the HTTP status code: 200 => paid, // 202 => go to reorder URL, 402 => unpaid. We surface each as a distinct @@ -4084,21 +4109,25 @@ export class TalerMerchantInstanceHttpClient { } } +export interface TalerMerchantManagementHttpClientOptions extends Omit< + TalerMerchantInstanceHttpClientOptions, + "cacheEvictor" +> { + cacheEvictor?: CacheEvictor< + TalerMerchantInstanceCacheEviction | TalerMerchantManagementCacheEviction + >; +} + export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttpClient { readonly cacheManagementEvictor: CacheEvictor< TalerMerchantInstanceCacheEviction | TalerMerchantManagementCacheEviction >; constructor( readonly baseUrl: string, - httpClient?: HttpRequestLibrary, - // cacheManagementEvictor?: CacheEvictor<TalerMerchantManagementCacheEviction>, - cacheEvictor?: CacheEvictor< - TalerMerchantInstanceCacheEviction | TalerMerchantManagementCacheEviction - >, - cancellationToken?: CancellationToken, + options: TalerMerchantManagementHttpClientOptions, ) { - super(baseUrl, httpClient, cacheEvictor, cancellationToken); - this.cacheManagementEvictor = cacheEvictor ?? nullEvictor; + super(baseUrl, options); + this.cacheManagementEvictor = options.cacheEvictor ?? nullEvictor; } getSubInstanceAPI(instanceId: string): string { diff --git a/packages/taler-util/src/http-client/path-escaping.test.ts b/packages/taler-util/src/http-client/path-escaping.test.ts @@ -25,6 +25,7 @@ import { import { TalerCoreBankHttpClient } from "./bank-core.js"; import { TalerMerchantInstanceHttpClient } from "./merchant.js"; import { pathSegment } from "./utils.js"; +import { LongpollQueue } from "../longpoll-queue.js"; /** * Records the URL of the first request and answers with an empty 204. @@ -64,11 +65,12 @@ test("pathSegment escapes separators and traversal", (t) => { }); test("dot identifiers are rejected before merchant or bank requests", async () => { + const longpollQueue = new LongpollQueue(); for (const id of [".", ".."]) { const lib = new RecordingHttpLib(); const merchant = new TalerMerchantInstanceHttpClient( "https://merchant.example/api/", - lib, + { httpClient: lib, longpollQueue }, ); const bank = new TalerCoreBankHttpClient("https://bank.example/api/", lib); await assert.rejects( @@ -110,10 +112,11 @@ test("a hostile username cannot escape its path segment", async (t) => { }); test("a hostile order id cannot inject extra path segments", async (t) => { + const longpollQueue = new LongpollQueue(); const lib = new RecordingHttpLib(); const client = new TalerMerchantInstanceHttpClient( "https://merchant.example.com/", - lib, + { httpClient: lib, longpollQueue }, ); await client .getOrderDetails("secret-token" as any, "a/b/../../evil") @@ -126,10 +129,11 @@ test("a hostile order id cannot inject extra path segments", async (t) => { }); test("order expiration filters are sent to the merchant backend", async () => { + const longpollQueue = new LongpollQueue(); const lib = new RecordingHttpLib(); const client = new TalerMerchantInstanceHttpClient( "https://merchant.example.com/", - lib, + { httpClient: lib, longpollQueue }, ); await client .listOrders("secret-token" as any, { @@ -144,6 +148,7 @@ test("order expiration filters are sent to the merchant backend", async () => { }); test("multi-line URL builders escape their path parameters too", async (t) => { + const longpollQueue = new LongpollQueue(); const bank = new RecordingHttpLib(); const bankClient = new TalerCoreBankHttpClient( "https://bank.example.com/api/", @@ -161,7 +166,7 @@ test("multi-line URL builders escape their path parameters too", async (t) => { const merchant = new RecordingHttpLib(); const merchantClient = new TalerMerchantInstanceHttpClient( "https://merchant.example.com/", - merchant, + { httpClient: merchant, longpollQueue }, ); await merchantClient .getInstancePrivateAccountKycauth("secret-token" as any, { diff --git a/packages/taler-util/src/http-client/status-handling.test.ts b/packages/taler-util/src/http-client/status-handling.test.ts @@ -29,6 +29,7 @@ import { MonitorTimeframeParam } from "../types-taler-corebank.js"; import { TalerBankConversionHttpClient } from "./bank-conversion.js"; import { TalerCoreBankHttpClient } from "./bank-core.js"; import { TalerExchangeHttpClient } from "./exchange-client.js"; +import { LongpollQueue } from "../longpoll-queue.js"; /** * Answers every request with a canned status and body, recording the URL. @@ -66,12 +67,14 @@ class StubHttpLib implements HttpRequestLibrary { } test("AML officer resource returns identity and signs the request", async () => { + const longpollQueue = new LongpollQueue(); const lib = new StubHttpLib(200, { officer_name: "Alice Example", read_only: true, }); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: lib, + longpollQueue, }); const officer: OfficerSession = { id: "4TQZQ0M6CB0JZXJ3Z1B4H7X3EVAQXX45SB9QT0NXZYKAHQXZ3EYG" as OfficerId, @@ -92,9 +95,11 @@ test("AML officer resource returns identity and signs the request", async () => }); test("AML form rendering posts the filled form and returns PDF bytes", async () => { + const longpollQueue = new LongpollQueue(); const lib = new StubHttpLib(200, { pdf: "bytes" }); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: lib, + longpollQueue, }); const officer: OfficerSession = { id: "4TQZQ0M6CB0JZXJ3Z1B4H7X3EVAQXX45SB9QT0NXZYKAHQXZ3EYG" as OfficerId, @@ -161,8 +166,10 @@ for (const code of [ TalerErrorCode.EXCHANGE_PURSE_CREATE_EXPIRATION_IS_NEVER, ]) { test(`deposit purse creation exposes expiration error ${code}`, async () => { + const longpollQueue = new LongpollQueue(); const client = new TalerExchangeHttpClient("https://exchange.example/", { httpClient: new StubHttpLib(400, { code, hint: "invalid expiration" }), + longpollQueue, }); const res = await client.createPurseFromDeposit("PURSE", {}); assert.strictEqual(res.type, "fail"); diff --git a/packages/taler-util/src/longpoll-http.test.ts b/packages/taler-util/src/longpoll-http.test.ts @@ -26,6 +26,9 @@ import { AbsoluteTime } from "./time.js"; import { LongpollQueue } from "./longpoll-queue.js"; import { fetchLongpoll, LongpollResult } from "./longpoll-http.js"; import { openPromise } from "./promises.js"; +import { TalerExchangeHttpClient } from "./http-client/exchange-client.js"; +import { TalerBankIntegrationHttpClient } from "./http-client/bank-integration.js"; +import { TalerMerchantInstanceHttpClient } from "./http-client/merchant.js"; const tick = () => new Promise<void>((resolve) => setImmediate(resolve)); function fixture() { @@ -59,6 +62,98 @@ function fixture() { return { http, requests }; } +test("exchange, bank, and merchant polls share host limits and global capacity", async () => { + const { http, requests } = fixture(); + const queue = new LongpollQueue(); + const work: Promise<unknown>[] = []; + for (let i = 0; i < 8; i++) { + const base = "https://host" + i + ".example/"; + work.push( + new TalerExchangeHttpClient(base, { + httpClient: http, + longpollQueue: queue, + }).getReserveStatus("r", true), + ); + work.push( + new TalerBankIntegrationHttpClient(base, { + httpClient: http, + longpollQueue: queue, + }).getWithdrawalOperationById("w", { + timeoutMs: 30000, + old_state: "pending", + }), + ); + work.push( + new TalerMerchantInstanceHttpClient(base, { + httpClient: http, + longpollQueue: queue, + }).getPaymentStatus("o", { timeout: 30000 }), + ); + } + const blocked = new TalerMerchantInstanceHttpClient( + "https://host0.example/", + { httpClient: http, longpollQueue: queue }, + ).getPaymentStatus("fourth", { timeout: 30000 }); + work.push(blocked); + await tick(); + assert.equal(requests.length, 20); + assert.equal( + requests.filter((r) => r.url.hostname === "host0.example").length, + 3, + ); + const ordinary = new TalerBankIntegrationHttpClient( + "https://host0.example/", + { httpClient: http, longpollQueue: queue }, + ).getWithdrawalOperationById("snapshot"); + work.push(ordinary); + await tick(); + assert.equal(requests.length, 21); + assert.equal(requests[20].url.searchParams.has("timeout_ms"), false); + // Resolve each admitted wave without using real-time polling delays. + for (let wave = 0; wave < 4; wave++) { + for (const r of requests) r.finish(); + await tick(); + } + await Promise.all(work); +}); + +test("protocol clients share an explicit queue across HTTP wrappers", async () => { + const longpollQueue = new LongpollQueue(); + const { http, requests } = fixture(); + const wrapHttp = (): HttpRequestLibrary => ({ + fetch: (url, options) => http.fetch(url, options), + }); + const baseUrl = "https://same.example/"; + const exchange = new TalerExchangeHttpClient(baseUrl, { + httpClient: wrapHttp(), + longpollQueue, + }); + const bank = new TalerBankIntegrationHttpClient(baseUrl, { + httpClient: wrapHttp(), + longpollQueue, + }); + const merchant = new TalerMerchantInstanceHttpClient(baseUrl, { + httpClient: wrapHttp(), + longpollQueue, + }); + const work = [ + exchange.getReserveStatus("r1", 500), + bank.getWithdrawalOperationById("w1", { timeoutMs: 500 }), + merchant.getPaymentStatus("o1", { timeout: 500 }), + exchange.getReserveStatus("r2", 500), + bank.getWithdrawalOperationById("w2", { timeoutMs: 500 }), + ]; + await tick(); + assert.equal(requests.length, 3); + assert.ok( + requests.every((r) => r.url.searchParams.get("timeout_ms") === "500"), + ); + for (const r of requests) r.finish(); + await tick(); + for (const r of requests) r.finish(); + await Promise.all(work); +}); + test("deadline expiry removes a waiter and performs one immediate check", async (t) => { t.mock.timers.enable({ apis: ["Date", "setTimeout"], now: 100000 }); const { http, requests } = fixture(); diff --git a/packages/taler-util/src/longpoll-queue.test.ts b/packages/taler-util/src/longpoll-queue.test.ts @@ -30,15 +30,21 @@ function poll( const started = openPromise<number>(); const finish = openPromise<void>(); let calls = 0; - const done = queue.run( - new URL(host.includes("://") ? host : "https://" + host + "/"), - token, - (timeout) => { + const done = (async () => { + const admission = await queue.acquire( + new URL(host.includes("://") ? host : "https://" + host + "/"), + token, + ); + assert.equal(admission.status, "admitted"); + try { + token.throwIfCancelled(); calls++; - started.resolve(timeout); - return finish.promise; - }, - ); + started.resolve(admission.timeoutMs); + await finish.promise; + } finally { + admission.release(); + } + })(); return { started: started.promise, finish, done, calls: () => calls }; } @@ -175,7 +181,7 @@ test("cancellation during handoff releases both permits", async () => { ); const next = poll(queue); active[0].finish.resolve(); - // The running callback's continuation admits waiting before this microtask; + // Releasing the active permit admits waiting before this microtask; // waiting's continuation must still check cancellation before executing. queueMicrotask(() => source.cancel()); await rejected; @@ -185,7 +191,7 @@ test("cancellation during handoff releases both permits", async () => { await Promise.all([...active, next].map((p) => p.done)); }); -test("running cancellation retains capacity until the callback settles", async () => { +test("cancellation after admission retains capacity until the permit is released", async () => { const queue = new LongpollQueue(); const source = CancellationToken.create(); const running = poll(queue, "a.example", source.token); @@ -200,35 +206,3 @@ test("running cancellation retains capacity until the callback settles", async ( for (const p of [...others, next]) p.finish.resolve(); await Promise.all([running, ...others, next].map((p) => p.done)); }); - -test("callback throws and rejections release permits and preserve results", async () => { - const queue = new LongpollQueue(); - const error = new Error("request failed"); - for (let i = 0; i < 25; i++) { - await assert.rejects( - queue.run( - new URL("https://a.example"), - CancellationToken.CONTINUE, - () => { - if (i % 2) throw error; - return Promise.reject(error); - }, - ), - (e) => e === error, - ); - } - const active = Array.from({ length: 20 }, (_, i) => - poll(queue, "host" + Math.floor(i / 3) + ".example"), - ); - await Promise.all(active.map((p) => p.started)); - for (const p of active) p.finish.resolve(); - await Promise.all(active.map((p) => p.done)); - assert.equal( - await queue.run( - new URL("https://a.example"), - CancellationToken.CONTINUE, - async () => 42, - ), - 42, - ); -}); diff --git a/packages/taler-util/src/longpoll-queue.ts b/packages/taler-util/src/longpoll-queue.ts @@ -26,7 +26,6 @@ const logger = new Logger("longpoll-queue.ts"); const MAX_ACTIVE = 20; const MAX_ACTIVE_PER_HOST = 3; -type LongpollRunFn<T> = (timeoutMs: number) => Promise<T>; export type LongpollAdmission = | { status: "deadline-expired" } @@ -159,21 +158,4 @@ export class LongpollQueue { } } } - - /** Run a callback while holding a long-poll permit. */ - async run<T>( - url: URL, - cancellationToken: CancellationToken, - f: LongpollRunFn<T>, - ): Promise<T> { - const admission = await this.acquire(url, cancellationToken); - if (admission.status !== "admitted") - throw Error("unexpected queue deadline"); - try { - cancellationToken.throwIfCancelled(); - return await f(admission.timeoutMs); - } finally { - admission.release(); - } - } } diff --git a/packages/taler-wallet-cli/src/wallet-http.test.ts b/packages/taler-wallet-cli/src/wallet-http.test.ts @@ -19,6 +19,7 @@ import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; import { test } from "node:test"; import { + LongpollQueue, type AccessToken, CancellationToken, DenomKeyType, @@ -150,6 +151,7 @@ test("policy blocks before transport and preserves allowed request options and r }); test("reviewed protocol operations pass readonly policy, including long polls and a POST query", async () => { + const longpollQueue = new LongpollQueue(); const reachedTransport = new Error("request reached transport"); let calls = 0; const http = new WalletHttpLib( @@ -163,9 +165,18 @@ test("reviewed protocol operations pass readonly policy, including long polls an "readonly", ); const base = "https://example.com/prefix/"; - const exchange = new TalerExchangeHttpClient(base, { httpClient: http }); - const merchant = new TalerMerchantInstanceHttpClient(base, http); - const bank = new TalerBankIntegrationHttpClient(base, { httpClient: http }); + const exchange = new TalerExchangeHttpClient(base, { + httpClient: http, + longpollQueue, + }); + const merchant = new TalerMerchantInstanceHttpClient(base, { + httpClient: http, + longpollQueue, + }); + const bank = new TalerBankIntegrationHttpClient(base, { + httpClient: http, + longpollQueue, + }); const conversion = new TalerBankConversionHttpClient(base, http); const donau = new DonauHttpClient(base, { httpClient: http }); const operations: Array<() => Promise<unknown>> = [ @@ -229,6 +240,7 @@ test("reviewed protocol operations pass readonly policy, including long polls an }); test("readonly blocks payments, refunds, and state-changing KYC GETs", async () => { + const longpollQueue = new LongpollQueue(); let calls = 0; const http = new WalletHttpLib( { @@ -241,11 +253,12 @@ test("readonly blocks payments, refunds, and state-changing KYC GETs", async () ); const exchange = new TalerExchangeHttpClient("https://example.com/", { httpClient: http, + longpollQueue, + }); + const merchant = new TalerMerchantInstanceHttpClient("https://example.com/", { + httpClient: http, + longpollQueue, }); - const merchant = new TalerMerchantInstanceHttpClient( - "https://example.com/", - http, - ); await assert.rejects( merchant.makePayment("order", { coins: [] }), isPolicyError, diff --git a/packages/taler-wallet-core/src/dbless.ts b/packages/taler-wallet-core/src/dbless.ts @@ -25,6 +25,7 @@ /** * Imports. */ +import { LongpollQueue } from "@gnu-taler/taler-util"; import { AbsoluteTime, AgeRestriction, @@ -90,6 +91,7 @@ export interface CoinInfo { export interface TopupReserveWithBankArgs { http: HttpRequestLibrary; + longpollQueue: LongpollQueue; reservePub: string; corebankApiBaseUrl: string; exchangeInfo: ExchangeInfo; @@ -107,7 +109,11 @@ export async function topupReserveWithBank(args: TopupReserveWithBankArgs) { bankUser.username, amount, ); - const bankInfo = await getBankWithdrawalInfo(http, wopi.taler_withdraw_uri); + const bankInfo = await getBankWithdrawalInfo( + http, + wopi.taler_withdraw_uri, + args.longpollQueue, + ); if (!bankInfo.exchange) { throw Error("no suggested exchange"); } @@ -126,7 +132,7 @@ export async function topupReserveWithBank(args: TopupReserveWithBankArgs) { } const bankIntegrationClient = new TalerBankIntegrationHttpClient( uriResult.bankIntegrationApiBaseUrl, - { httpClient: http }, + { httpClient: http, longpollQueue: args.longpollQueue }, ); succeedOrThrow( await bankIntegrationClient.completeWithdrawalOperationById( @@ -144,6 +150,7 @@ export async function topupReserveWithBank(args: TopupReserveWithBankArgs) { export async function withdrawCoin(args: { http: HttpRequestLibrary; + longpollQueue: LongpollQueue; cryptoApi: TalerCryptoInterface; reserveKeyPair: ReserveKeypair; denom: DenominationInfo; @@ -161,6 +168,7 @@ export async function withdrawCoin(args: { }); const exchangeClient = new TalerExchangeHttpClient(exchangeBaseUrl, { httpClient: http, + longpollQueue: args.longpollQueue, }); const sigResp = await cryptoApi.signWithdrawal({ @@ -266,6 +274,7 @@ export function findDenomOrThrow( export async function depositCoin(args: { http: HttpRequestLibrary; + longpollQueue: LongpollQueue; cryptoApi: TalerCryptoInterface; exchangeBaseUrl: string; coin: CoinInfo; @@ -283,6 +292,7 @@ export async function depositCoin(args: { cryptoApi: args.cryptoApi, exchangeBaseUrl: args.exchangeBaseUrl, http: args.http, + longpollQueue: args.longpollQueue, merchantPriv: args.merchantPriv, depositPayto: args.depositPayto, contractTermsHash: args.contractTermsHash, @@ -293,6 +303,7 @@ export async function depositCoin(args: { export async function depositCoinBatch(args: { http: HttpRequestLibrary; + longpollQueue: LongpollQueue; cryptoApi: TalerCryptoInterface; exchangeBaseUrl: string; coins: CoinInfo[]; @@ -375,6 +386,7 @@ export async function depositCoinBatch(args: { }; const exchangeClient = new TalerExchangeHttpClient(args.exchangeBaseUrl, { httpClient: http, + longpollQueue: args.longpollQueue, }); succeedOrThrow(await exchangeClient.batchDeposit({ body: requestBody })); } @@ -409,6 +421,7 @@ async function currentRefreshProtocol( export async function refreshCoin(req: { http: HttpRequestLibrary; + longpollQueue: LongpollQueue; cryptoApi: TalerCryptoInterface; oldCoin: CoinInfo; newDenoms: DenominationInfo[]; @@ -423,6 +436,7 @@ export async function refreshCoin(req: { const { cryptoApi, oldCoin, http } = req; const exchangeClient = new TalerExchangeHttpClient(oldCoin.exchangeBaseUrl, { httpClient: http, + longpollQueue: req.longpollQueue, }); const protocolVersion = req.protocolVersion ?? (await currentRefreshProtocol(exchangeClient)); @@ -538,16 +552,18 @@ export async function createTestingReserve(args: { */ export async function checkReserve( http: HttpRequestLibrary, + longpollQueue: LongpollQueue, exchangeBaseUrl: string, reservePub: string, longpollTimeoutMs: number = 500, ): Promise<void> { const exchangeClient = new TalerExchangeHttpClient(exchangeBaseUrl, { httpClient: http, + longpollQueue, }); const resp = await exchangeClient.getReserveStatus( reservePub, - longpollTimeoutMs > 0, + longpollTimeoutMs, ); if (resp.case !== "ok") { throw new Error("reserve not okay"); diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -81,6 +81,7 @@ import { ListWithdrawalExchangeCandidatesRequest, ListWithdrawalExchangeCandidatesResponse, Logger, + LongpollQueue, NotificationType, Paytos, PurgeExchangeLegacyKeysRequest, @@ -1439,22 +1440,12 @@ export type ExchangeKeysDownloadResult = * When @a lastIssueDate is given, the exchange is asked to cherry-pick, i.e. * to leave out the denominations that started before that timestamp. See * {@link getKeysCherryPickDate} for how the caller arrives at it. - * - * FIXME: Use the HTTP client lib for this! */ async function downloadExchangeKeysInfo( - baseUrl: string, - http: HttpRequestLibrary, - timeout: Duration, - cancellationToken: CancellationToken, + exchangeClient: TalerExchangeHttpClient, noCache: boolean, lastIssueDate?: number, ): Promise<ExchangeKeysDownloadResult> { - const exchangeClient = new TalerExchangeHttpClient(baseUrl, { - httpClient: http, - cancelationToken: cancellationToken, - timeout, - }); const resp = await exchangeClient.getKeys({ noCache, lastIssueDate }); logger.trace("got response to /keys request"); @@ -1474,7 +1465,7 @@ async function downloadExchangeKeysInfo( throw TalerError.fromDetail( TalerErrorCode.WALLET_EXCHANGE_DENOMINATIONS_INSUFFICIENT, { - exchangeBaseUrl: baseUrl, + exchangeBaseUrl: exchangeClient.baseUrl, }, "exchange doesn't offer any denominations", ); @@ -2463,10 +2454,7 @@ export async function updateExchangeFromUrlHandler( try { keysInfoRes = await downloadExchangeKeysInfo( - exchangeBaseUrl, - wex.http, - timeout, - wex.cancellationToken, + walletExchangeClient(exchangeBaseUrl, wex, { timeout }), oldExchangeRec.cachebreakNextUpdate ?? false, cherryPickDate, ); @@ -3859,10 +3847,7 @@ export async function getExchangeTos( }; } - const exchangeClient = new TalerExchangeHttpClient(exchangeBaseUrl, { - cancelationToken: wex.cancellationToken, - httpClient: wex.http, - }); + const exchangeClient = walletExchangeClient(exchangeBaseUrl, wex); let tosDownload: ExchangeTosDownloadResult = await runWithProgressRetries( wex, @@ -3924,12 +3909,14 @@ export interface ExchangeInfo { export async function downloadExchangeInfo( exchangeBaseUrl: string, http: HttpRequestLibrary, + longpollQueue: LongpollQueue, ): Promise<ExchangeInfo> { const keysInfo = await downloadExchangeKeysInfo( - exchangeBaseUrl, - http, - Duration.getForever(), - CancellationToken.CONTINUE, + new TalerExchangeHttpClient(exchangeBaseUrl, { + httpClient: http, + timeout: Duration.getForever(), + longpollQueue, + }), false, ); if (keysInfo.type !== "ok") { diff --git a/packages/taler-wallet-core/src/http-injection.test.ts b/packages/taler-wallet-core/src/http-injection.test.ts @@ -15,6 +15,7 @@ */ import { + LongpollQueue, AmountString, DenominationInfo, WithdrawTestBalanceRequest, @@ -72,6 +73,7 @@ test("test-balance withdrawal uses the wallet HTTP client", async () => { }); test("DB-less withdrawal uses its supplied HTTP client", async () => { + const longpollQueue = new LongpollQueue(); const failure = new Error("injected DB-less withdrawal HTTP client"); const http = new RejectingHttp(failure); const cryptoApi = { @@ -95,6 +97,7 @@ test("DB-less withdrawal uses its supplied HTTP client", async () => { await assert.rejects( withdrawCoin({ + longpollQueue, http, cryptoApi, reserveKeyPair: { @@ -113,6 +116,7 @@ test("DB-less withdrawal uses its supplied HTTP client", async () => { }); test("DB-less refresh uses its supplied HTTP client", async () => { + const longpollQueue = new LongpollQueue(); const failure = new Error("injected DB-less refresh HTTP client"); const http = new RejectingHttp(failure); const cryptoApi = { @@ -148,6 +152,7 @@ test("DB-less refresh uses its supplied HTTP client", async () => { await assert.rejects( refreshCoin({ + longpollQueue, http, cryptoApi, oldCoin, diff --git a/packages/taler-wallet-core/src/kyc.test.ts b/packages/taler-wallet-core/src/kyc.test.ts @@ -19,6 +19,7 @@ import { Duration, HttpStatusCode, LimitOperationType, + LongpollQueue, } from "@gnu-taler/taler-util"; import { HeadersImpl, HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import assert from "node:assert"; @@ -166,8 +167,11 @@ test("an unchanged hard denial still reaches the owning transaction", async () = access_token: "access-token", limits: [limit("KUDOS:5" as AmountString, false)], }; + let waiting = false; + let waitPhases = 0; const http: HttpRequestLibrary = { async fetch(url, opt) { + assert.equal(waiting, true); return { requestMethod: opt?.method ?? "GET", requestUrl: url, @@ -187,7 +191,18 @@ test("an unchanged hard denial still reaches the owning transaction", async () = }; const wex = { http, - ws: { longpollQueue: undefined }, + taskExecution: { + async suspend<T>(wait: () => Promise<T>): Promise<T> { + waiting = true; + waitPhases++; + try { + return await wait(); + } finally { + waiting = false; + } + }, + }, + ws: { longpollQueue: new LongpollQueue() }, cryptoApi: { async signWalletKycAuth() { return { sig: "account-signature" }; @@ -209,6 +224,8 @@ test("an unchanged hard denial still reaches the owning transaction", async () = const result = await runKycCheckAlgo(wex, state); + assert.equal(waiting, false); + assert.equal(waitPhases, 1); assert.strictEqual(result.hardLimitExceeded, true); assert.ok(result.updatedStatus); assert.strictEqual( @@ -245,7 +262,12 @@ test("limits returned with HTTP 200 are enforced", async () => { }; const wex = { http, - ws: { longpollQueue: undefined }, + taskExecution: { + suspend() { + assert.fail("snapshot must not suspend task"); + }, + }, + ws: { longpollQueue: new LongpollQueue() }, cryptoApi: { async signWalletKycAuth() { return { sig: "account-signature" }; diff --git a/packages/taler-wallet-core/src/pay-merchant.test.ts b/packages/taler-wallet-core/src/pay-merchant.test.ts @@ -18,6 +18,7 @@ import { AmountString, buildSigPS, CancellationToken, + LongpollQueue, ContractTermsUtil, decodeCrock, eddsaGetPublic, @@ -389,7 +390,7 @@ for (const makeRunner of runnerFactories) { }); const urls: URL[] = []; const wex = { - ws: { networkAvailable: true }, + ws: { networkAvailable: true, longpollQueue: new LongpollQueue() }, runWalletDbTx: runner.runReadWriteTx.bind(runner), http: { fetch: async (url: string) => { diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -4217,7 +4217,7 @@ async function processPurchasePay( const merchantClient = walletMerchantClient( download.contractTerms.merchant_base_url, wex, - getPayRequestTimeout(purchase), + { timeout: getPayRequestTimeout(purchase) }, ); const resp = await wex.ws.runSequentialized( [EXCHANGE_COINS_LOCK], @@ -5525,10 +5525,8 @@ async function processPurchaseAutoRefund( // After resuming past the deadline, still ask the merchant once. A // refund may have been granted while the wallet was offline. Bound // earlier long polls by the deadline so completion is not delayed. - timeout: Math.min( - MERCHANT_ORDER_STATUS_LONGPOLL_MS, - Duration.toMilliseconds(AbsoluteTime.remaining(deadline)), - ), + timeout: MERCHANT_ORDER_STATUS_LONGPOLL_MS, + deadline, }, ); diff --git a/packages/taler-wallet-core/src/pay-paivana.ts b/packages/taler-wallet-core/src/pay-paivana.ts @@ -22,7 +22,6 @@ import { succeedOrThrow, TalerError, TalerErrorCode, - TalerMerchantInstanceHttpClient, TalerPayTemplateUri, TalerProtocolTimestamp, TalerUriAction, @@ -50,7 +49,7 @@ import { makeTransactionNotFoundError, parseTransactionIdentifier, } from "./transactions.js"; -import { WalletExecutionContext } from "./wallet.js"; +import { walletMerchantClient, WalletExecutionContext } from "./wallet.js"; import { canonicalizePaivanaUrl } from "./pay-paivana-common.js"; export { canonicalizePaivanaUrl } from "./pay-paivana-common.js"; @@ -193,12 +192,7 @@ export async function preparePaivanaTemplate( ); } - const merchantApi = new TalerMerchantInstanceHttpClient( - parsed.merchantBaseUrl, - wex.http, - undefined, - wex.cancellationToken, - ); + const merchantApi = walletMerchantClient(parsed.merchantBaseUrl, wex); const templateInfo = await runWithProgressRetries(wex, async () => succeedOrThrow(await merchantApi.useTemplateGetInfo(parsed.templateId)), ); diff --git a/packages/taler-wallet-core/src/pay-peer-common.test.ts b/packages/taler-wallet-core/src/pay-peer-common.test.ts @@ -14,6 +14,7 @@ import { TalerProtocolTimestamp, WalletAccountMergeFlags, encodeCrock, + LongpollQueue, } from "@gnu-taler/taler-util"; import type { HttpRequestLibrary, @@ -128,7 +129,7 @@ test("shared reserve recovery traverses all history pages", async () => { const wex = { http, cancellationToken: CancellationToken.CONTINUE, - ws: { longpollQueue: undefined }, + ws: { longpollQueue: new LongpollQueue() }, cryptoApi: { async eddsaGetPublic() { return { pub: expected.mergePub }; diff --git a/packages/taler-wallet-core/src/pay-repurchase.test.ts b/packages/taler-wallet-core/src/pay-repurchase.test.ts @@ -18,6 +18,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { CancellationToken, + LongpollQueue, codecForMerchantContractTerms, decodeCrock, TalerProtocolTimestamp, @@ -204,6 +205,7 @@ test("wallet-generated Paivana sessions bind the remaining access period", async const tx = selectionTx([[purchase("old"), contract(deadline)]]); const wex = { cancellationToken: CancellationToken.CONTINUE, + ws: { longpollQueue: new LongpollQueue() }, runWalletDbTx: (f: (tx: WalletDbTransaction) => Promise<unknown>) => f(tx), http: { fetch: async (requestUrl: string) => ({ @@ -255,7 +257,7 @@ for (const factory of runnerFactories) { }); let replays = 0; const wex = { - ws: {}, + ws: { longpollQueue: new LongpollQueue() }, runWalletDbTx: (f: (tx: WalletDbTransaction) => Promise<unknown>) => runner.runReadWriteTx(f), taskScheduler: { diff --git a/packages/taler-wallet-core/src/pay-template.test.ts b/packages/taler-wallet-core/src/pay-template.test.ts @@ -18,6 +18,7 @@ import { AmountString, Amounts, CancellationToken, + LongpollQueue, HostPortPath, RefreshReason, ScopeType, @@ -113,7 +114,7 @@ function templateBalanceContext( throw Error("unexpected HTTP request"); }, }, - ws: { devExperimentState: {} }, + ws: { devExperimentState: {}, longpollQueue: new LongpollQueue() }, runWalletDbTx: async <T>(f: (tx: WalletDbTransaction) => Promise<T>) => f(tx), } as unknown as WalletExecutionContext; @@ -323,6 +324,7 @@ test("template order creation is not retried after an ambiguous failure", async }, }, ws: { + longpollQueue: new LongpollQueue(), notify(): void {}, timerGroup: { async resolveAfter(): Promise<boolean> { @@ -353,10 +355,22 @@ test("template order creation is not retried after an ambiguous failure", async assert.strictEqual(requestCount, 1); }); +function noHttpContext(): WalletExecutionContext { + return { + cancellationToken: CancellationToken.CONTINUE, + ws: { longpollQueue: new LongpollQueue() }, + http: { + async fetch(): Promise<never> { + throw Error("unexpected HTTP request during template validation"); + }, + }, + } as unknown as WalletExecutionContext; +} + test("Paivana instantiation requires its session and fulfillment URL", async () => { await assert.rejects( instantiateTemplateRaw( - {} as WalletExecutionContext, + noHttpContext(), { talerPayTemplateUri: "taler://pay-template/merchant.example/template-id", @@ -391,7 +405,7 @@ test("Paivana instantiation rejects unredeemable URI bindings", async () => { await assert.rejects( instantiateTemplateRaw( - {} as WalletExecutionContext, + noHttpContext(), { talerPayTemplateUri: makeUri( futureSession, @@ -406,7 +420,7 @@ test("Paivana instantiation rejects unredeemable URI bindings", async () => { ); await assert.rejects( instantiateTemplateRaw( - {} as WalletExecutionContext, + noHttpContext(), { talerPayTemplateUri: makeUri( "1-not-a-dd76-session", diff --git a/packages/taler-wallet-core/src/pay-template.ts b/packages/taler-wallet-core/src/pay-template.ts @@ -28,7 +28,6 @@ import { TalerError, TalerErrorCode, TalerMerchantApi, - TalerMerchantInstanceHttpClient, TalerPayTemplateUri, TalerUriAction, TalerUris, @@ -43,7 +42,7 @@ import { runWithMaybeProgressContext, runWithProgressRetries, } from "./progress.js"; -import { WalletExecutionContext } from "./wallet.js"; +import { walletMerchantClient, WalletExecutionContext } from "./wallet.js"; import { getBalancesInsideTransaction } from "./balance.js"; import { canonicalizePaivanaUrl, @@ -209,12 +208,7 @@ async function internalCheckPayForTemplate( ); } - const merchantApi = new TalerMerchantInstanceHttpClient( - parsedUri.merchantBaseUrl, - wex.http, - undefined, - wex.cancellationToken, - ); + const merchantApi = walletMerchantClient(parsedUri.merchantBaseUrl, wex); // Retried under a progress context, like the other merchant queries here. const templateDetails = await runWithProgressRetries(wex, async () => @@ -283,12 +277,7 @@ export async function instantiateTemplateRaw( ); } - const merchantApi = new TalerMerchantInstanceHttpClient( - parsedUri.merchantBaseUrl, - wex.http, - undefined, - wex.cancellationToken, - ); + const merchantApi = walletMerchantClient(parsedUri.merchantBaseUrl, wex); logger.trace(`parsed URI: ${j2s(parsedUri)}`); // Retried under a progress context. diff --git a/packages/taler-wallet-core/src/purse-deposit-reconciliation.test.ts b/packages/taler-wallet-core/src/purse-deposit-reconciliation.test.ts @@ -20,6 +20,7 @@ import { HttpStatusCode, TalerErrorCode, CoinPurseDepositTransaction, + LongpollQueue, } from "@gnu-taler/taler-util"; import assert from "node:assert/strict"; import { test } from "node:test"; @@ -122,7 +123,7 @@ function unknownCoinContext( http, cancellationToken: CancellationToken.CONTINUE, ws: { - longpollQueue: undefined, + longpollQueue: new LongpollQueue(), denomInfoCache: { async getOrPut() { return { value: "TESTKUDOS:5" }; diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts @@ -1273,11 +1273,9 @@ async function refreshMelt( denoms_h: newDenomsFlat, value_with_fee: Amounts.stringify(derived.meltValueWithFee), }; - const exchangeClient = walletExchangeClient( - oldCoin.exchangeBaseUrl, - wex, - getRefreshRequestTimeout(refreshGroup), - ); + const exchangeClient = walletExchangeClient(oldCoin.exchangeBaseUrl, wex, { + timeout: getRefreshRequestTimeout(refreshGroup), + }); const resp = await wex.ws.runSequentialized( [EXCHANGE_COINS_LOCK], async () => { @@ -2077,11 +2075,9 @@ async function refreshReveal( ? { batch_seeds: derived.batchSeeds.filter(disclosed) } : { signatures: derived.signatures.filter(disclosed) }), }; - const exchangeClient = walletExchangeClient( - oldCoin.exchangeBaseUrl, - wex, - getRefreshRequestTimeout(refreshGroup), - ); + const exchangeClient = walletExchangeClient(oldCoin.exchangeBaseUrl, wex, { + timeout: getRefreshRequestTimeout(refreshGroup), + }); const resp = await wex.ws.runSequentialized([EXCHANGE_COINS_LOCK], async () => exchangeClient.postRevealMelt({ body: req }), ); diff --git a/packages/taler-wallet-core/src/testing-check-coins.test.ts b/packages/taler-wallet-core/src/testing-check-coins.test.ts @@ -25,6 +25,7 @@ import { DenomKeyType, TalerErrorCode, codecForTestingCheckCoinsRequest, + LongpollQueue, } from "@gnu-taler/taler-util"; import { HttpRequestLibrary, HttpResponse } from "@gnu-taler/taler-util/http"; import { @@ -175,7 +176,7 @@ function fixture() { const wex = { http, cancellationToken: CancellationToken.CONTINUE, - ws: { longpollQueue: undefined }, + ws: { longpollQueue: new LongpollQueue() }, runWalletDbTx: async <T>(f: (t: WalletDbTransaction) => Promise<T>) => f(tx), cryptoApi: { diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts @@ -50,7 +50,6 @@ import { TalerCorebankApiClient, TalerError, TalerErrorCode, - TalerMerchantInstanceHttpClient, TestingWaitBalanceRequest, WaitTransactionStateRequest, WaitTransactionStateResponse, @@ -65,7 +64,6 @@ import { TransactionType, WithdrawTestBalanceRequest, } from "@gnu-taler/taler-util"; -import { HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import { getBalanceDetail, getBalances } from "./balance.js"; import { genericWaitForState } from "./common.js"; import { timestampAbsoluteFromDb } from "./db/records.js"; @@ -99,7 +97,7 @@ import { parseTransactionIdentifier, retryTransaction, } from "./transactions.js"; -import type { WalletExecutionContext } from "./wallet.js"; +import { walletMerchantClient, type WalletExecutionContext } from "./wallet.js"; import { acceptBankIntegratedWithdrawal, getBankWithdrawalInfo, @@ -246,6 +244,7 @@ async function withdrawTestBalanceImpl( const info = await getBankWithdrawalInfo( wex.http, wresp.taler_withdraw_uri, + wex.ws.longpollQueue, ); if (info.status === "confirmed") return; } @@ -264,16 +263,13 @@ async function withdrawTestBalanceImpl( } async function refund( - http: HttpRequestLibrary, + wex: WalletExecutionContext, merchantBackend: MerchantBackendInfo, orderId: string, reason: string, refundAmount: string, ): Promise<string> { - const merchantClient = new TalerMerchantInstanceHttpClient( - merchantBackend.baseUrl, - http, - ); + const merchantClient = walletMerchantClient(merchantBackend.baseUrl, wex); const r = succeedOrThrow( await merchantClient.addRefund( merchantBackend.authToken as AccessToken, @@ -292,17 +288,14 @@ async function refund( } async function createOrder( - http: HttpRequestLibrary, + wex: WalletExecutionContext, merchantBackend: MerchantBackendInfo, amount: string, summary: string, fulfillmentUrl: string, ): Promise<{ orderId: string }> { const t = Math.floor(new Date().getTime() / 1000) + 15 * 60; - const merchantClient = new TalerMerchantInstanceHttpClient( - merchantBackend.baseUrl, - http, - ); + const merchantClient = walletMerchantClient(merchantBackend.baseUrl, wex); const r = succeedOrThrow( await merchantClient.createOrder(merchantBackend.authToken as AccessToken, { order: { @@ -322,14 +315,11 @@ async function createOrder( } async function checkPayment( - http: HttpRequestLibrary, + wex: WalletExecutionContext, merchantBackend: MerchantBackendInfo, orderId: string, ): Promise<CheckPaymentResponse> { - const merchantClient = new TalerMerchantInstanceHttpClient( - merchantBackend.baseUrl, - http, - ); + const merchantClient = walletMerchantClient(merchantBackend.baseUrl, wex); return succeedOrThrow( await merchantClient.getOrderDetails( merchantBackend.authToken as AccessToken, @@ -350,7 +340,7 @@ async function makePayment( summary: string, ): Promise<MakePaymentResult> { const orderResp = await createOrder( - wex.http, + wex, merchant, amount, summary, @@ -359,7 +349,7 @@ async function makePayment( logger.trace("created order with orderId", orderResp.orderId); - let paymentStatus = await checkPayment(wex.http, merchant, orderResp.orderId); + let paymentStatus = await checkPayment(wex, merchant, orderResp.orderId); logger.trace("payment status", paymentStatus); @@ -401,7 +391,7 @@ async function makePayment( logger.trace("confirmPayResult", confirmPayResult); - paymentStatus = await checkPayment(wex.http, merchant, orderResp.orderId); + paymentStatus = await checkPayment(wex, merchant, orderResp.orderId); logger.trace("payment status after wallet payment:", paymentStatus); @@ -488,7 +478,7 @@ async function runIntegrationTestImpl( ); const refundUri = await refund( - wex.http, + wex, myMerchant, refundOrderId, "test refund", @@ -967,7 +957,7 @@ async function runIntegrationTest2Impl( ); const refundUri = await refund( - wex.http, + wex, myMerchant, refundOrderId, "test refund", @@ -1111,18 +1101,14 @@ export async function testPay( baseUrl: args.merchantBaseUrl, }; const orderResp = await createOrder( - wex.http, + wex, merchant, args.amount, args.summary, "taler://fulfillment-success/thank+you", ); logger.trace("created new order with order ID", orderResp.orderId); - const checkPayResp = await checkPayment( - wex.http, - merchant, - orderResp.orderId, - ); + const checkPayResp = await checkPayment(wex, merchant, orderResp.orderId); const talerPayUri = checkPayResp.taler_pay_uri; if (!talerPayUri) { console.error("fatal: no taler pay URI received from backend"); diff --git a/packages/taler-wallet-core/src/transaction-reasons.test.ts b/packages/taler-wallet-core/src/transaction-reasons.test.ts @@ -21,6 +21,7 @@ import { join } from "node:path"; import { Amounts, CancellationToken, + LongpollQueue, ContractTermsUtil, encodeCrock, HttpStatusCode, @@ -181,6 +182,7 @@ for (const makeRunner of runnerFactories) { const wex = { ws: { networkAvailable: true, + longpollQueue: new LongpollQueue(), leftoverClaims: new Set(), timerGroup: new TimerGroup(new SetTimeoutTimerAPI()), addNotificationListener: () => () => {}, diff --git a/packages/taler-wallet-core/src/wallet-http-clients.test.ts b/packages/taler-wallet-core/src/wallet-http-clients.test.ts @@ -0,0 +1,128 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { + CancellationToken, + Duration, + LongpollQueue, + openPromise, +} from "@gnu-taler/taler-util"; +import { + dummyHttpResponse, + HeadersImpl, + HttpRequestLibrary, + HttpRequestOptions, +} from "@gnu-taler/taler-util/http"; +import { + WalletExecutionContext, + walletExchangeClient, + walletBankIntegrationClient, + walletMerchantClient, +} from "./wallet.js"; + +const tick = () => new Promise<void>((resolve) => setImmediate(resolve)); + +test("wallet factories preserve transport and budget with named request overrides", async () => { + const requests: { options: HttpRequestOptions; finish: () => void }[] = []; + const http: HttpRequestLibrary = { + async fetch(url, options = {}) { + const gate = openPromise<void>(); + requests.push({ options, finish: () => gate.resolve() }); + await gate.promise; + const headers = new HeadersImpl(); + headers.set("content-type", "application/json"); + return { + ...dummyHttpResponse, + headers, + requestUrl: url, + status: 404, + json: async () => ({ code: 1 }), + }; + }, + }; + const defaultCancellation = CancellationToken.create(); + const overrideCancellation = CancellationToken.create(); + const polls: unknown[] = []; + const wex = { + http, + onLongpoll: (event: unknown) => polls.push(event), + cancellationToken: defaultCancellation.token, + ws: { longpollQueue: new LongpollQueue() }, + } as unknown as WalletExecutionContext; + const url = "https://same.example/"; + const timeout = Duration.fromSpec({ seconds: 45 }); + const exchange = walletExchangeClient(url, wex); + const bank = walletBankIntegrationClient(url, wex, { timeout }); + const merchant = walletMerchantClient(url, wex, { + timeout, + cancellationToken: overrideCancellation.token, + }); + const work = [ + exchange.getReserveStatus("r", true), + bank.getWithdrawalOperationById("w", { timeoutMs: 30000 }), + merchant.getPaymentStatus("o", { timeout: 30000 }), + walletExchangeClient( + url, + { ...wex, http: { fetch: (url, options) => http.fetch(url, options) } }, + { + cancellationToken: overrideCancellation.token, + }, + ).getReserveStatus("next", true), + ]; + await tick(); + assert.equal(requests.length, 3); + assert.equal( + requests[0].options.cancellationToken, + defaultCancellation.token, + ); + assert.equal(requests[0].options.timeout, undefined); + assert.equal( + requests[1].options.cancellationToken, + defaultCancellation.token, + ); + assert.equal(requests[1].options.timeout, timeout); + assert.equal( + requests[2].options.cancellationToken, + overrideCancellation.token, + ); + assert.equal(requests[2].options.timeout, timeout); + requests[0].finish(); + await tick(); + assert.equal(requests.length, 4); + assert.equal( + requests[3].options.cancellationToken, + overrideCancellation.token, + ); + for (const request of requests) request.finish(); + await Promise.all(work); + assert.equal(polls.length, 4); +}); + +function forbidDependencyOverrides( + wex: WalletExecutionContext, + httpClient: HttpRequestLibrary, + longpollQueue: LongpollQueue, +) { + // @ts-expect-error Wallet factories always use the execution context's transport. + walletMerchantClient("https://example/", wex, { httpClient }); + // @ts-expect-error Wallet factories always share the wallet's concurrency budget. + walletExchangeClient("https://example/", wex, { longpollQueue }); + // @ts-expect-error Bank clients cannot replace the wallet budget either. + walletBankIntegrationClient("https://example/", wex, { longpollQueue }); +} +void forbidDependencyOverrides; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -23,6 +23,7 @@ /** * Imports. */ +import { LongpollObserver } from "@gnu-taler/taler-util"; import { TaskIdentifiers, PendingTaskType, @@ -145,6 +146,7 @@ const logger = new Logger("wallet.ts"); * request handler or for a shepherded task. */ export interface WalletExecutionContext { + onLongpoll?: LongpollObserver; /** * Start a database transaction. * Uses the database abstraction layer. @@ -361,44 +363,55 @@ export class AdmittedWalletDbHandle implements WalletDbHandle { } } +/** Per-operation overrides; transport and long-poll ownership stay with the wallet. */ +export interface WalletClientOptions { + timeout?: Duration; + cancellationToken?: CancellationToken; +} + +/** Clients are scoped to this execution context; do not retain them across tasks. */ export function walletExchangeClient( baseUrl: string, wex: WalletExecutionContext, - timeout?: Duration, - cancellationToken: CancellationToken = wex.cancellationToken, + options: WalletClientOptions = {}, ): TalerExchangeHttpClient { return new TalerExchangeHttpClient(baseUrl, { httpClient: wex.http, - cancelationToken: cancellationToken, - longPollQueue: wex.ws.longpollQueue, - timeout, + longpollQueue: wex.ws.longpollQueue, + onLongpoll: wex.onLongpoll, + timeout: options.timeout, + cancellationToken: options.cancellationToken ?? wex.cancellationToken, }); } +/** Bank client using the current task/request transport and wallet admission budget. */ export function walletBankIntegrationClient( baseUrl: string, wex: WalletExecutionContext, - timeout?: Duration, + options: WalletClientOptions = {}, ): TalerBankIntegrationHttpClient { return new TalerBankIntegrationHttpClient(baseUrl, { httpClient: wex.http, - cancellationToken: wex.cancellationToken, - timeout, + longpollQueue: wex.ws.longpollQueue, + onLongpoll: wex.onLongpoll, + timeout: options.timeout, + cancellationToken: options.cancellationToken ?? wex.cancellationToken, }); } +/** Merchant client using the current task/request transport and wallet admission budget. */ export function walletMerchantClient( baseUrl: string, wex: WalletExecutionContext, - timeout?: Duration, + options: WalletClientOptions = {}, ): TalerMerchantInstanceHttpClient { - return new TalerMerchantInstanceHttpClient( - baseUrl, - wex.http, - undefined, - wex.cancellationToken, - timeout, - ); + return new TalerMerchantInstanceHttpClient(baseUrl, { + httpClient: wex.http, + longpollQueue: wex.ws.longpollQueue, + onLongpoll: wex.onLongpoll, + timeout: options.timeout, + cancellationToken: options.cancellationToken ?? wex.cancellationToken, + }); } export const EXCHANGE_COINS_LOCK = "exchange-coins-lock"; diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -61,6 +61,7 @@ import { HttpStatusCode, LibtoolVersion, Logger, + LongpollQueue, NotificationType, ObservabilityEventType, Paytos, @@ -1366,6 +1367,7 @@ async function processWithdrawalGroupDialogProposed( export async function getBankWithdrawalInfo( http: HttpRequestLibrary, talerWithdrawUri: string, + longpollQueue: LongpollQueue, ): Promise<BankWithdrawDetails> { const uriResult = Result.orUndefined( TalerUris.parseRestricted(talerWithdrawUri, TalerUriAction.Withdraw), @@ -1376,9 +1378,7 @@ export async function getBankWithdrawalInfo( const bankApi = new TalerBankIntegrationHttpClient( uriResult.bankIntegrationApiBaseUrl, - { - httpClient: http, - }, + { httpClient: http, longpollQueue }, ); const { body: config } = await bankApi.getConfig(); @@ -2124,7 +2124,7 @@ async function processPlanchetExchangeBatchRequest( const exchangeClient = walletExchangeClient( withdrawalGroup.exchangeBaseUrl, wex, - Duration.fromSpec({ seconds: 40 }), + { timeout: Duration.fromSpec({ seconds: 40 }) }, ); try { @@ -2496,8 +2496,10 @@ async function queryReserveStatus( const exchangeClient = walletExchangeClient( withdrawalGroup.exchangeBaseUrl, wex, - getReserveRequestTimeout(withdrawalGroup), - cancellationToken, + { + timeout: getReserveRequestTimeout(withdrawalGroup), + cancellationToken, + }, ); logger.trace(`querying reserve status for ${reservePub}`); @@ -3701,7 +3703,7 @@ export async function getWithdrawalDetailsForUri( // Retried under a progress context: the bank integration API is the network // hop most likely to be slow or briefly unavailable here. const info = await runWithProgressRetries(wex, () => - getBankWithdrawalInfo(wex.http, talerWithdrawUri), + getBankWithdrawalInfo(wex.http, talerWithdrawUri, wex.ws.longpollQueue), ); logger.trace(`got bank info`); return getWithdrawalDetailsForBankInfo(wex, info); @@ -3818,7 +3820,7 @@ async function registerReserveWithBank( const bankClient = walletBankIntegrationClient( uriResult.bankIntegrationApiBaseUrl, wex, - getReserveRequestTimeout(withdrawalGroup), + { timeout: getReserveRequestTimeout(withdrawalGroup) }, ); const completeResp = await bankClient.completeWithdrawalOperationById( uriResult.withdrawalOperationId, @@ -3974,7 +3976,7 @@ async function processBankRegisterReserve( const bankClient = walletBankIntegrationClient( uriResult.bankIntegrationApiBaseUrl, wex, - getReserveRequestTimeout(withdrawalGroup), + { timeout: getReserveRequestTimeout(withdrawalGroup) }, ); const statusResp = await bankClient.getWithdrawalOperationById( uriResult.withdrawalOperationId, @@ -4125,10 +4127,10 @@ async function processReserveBankStatus( wex.cancellationToken, pollCts.token, ); - const bankClient = new TalerBankIntegrationHttpClient( + const bankClient = walletBankIntegrationClient( uriResult.bankIntegrationApiBaseUrl, + wex, { - httpClient: wex.http, cancellationToken: pollCancellation, timeout: getReserveRequestTimeout(withdrawalGroup), }, @@ -4495,7 +4497,7 @@ export async function prepareBankIntegratedWithdrawal( // Retried under a progress context: the bank integration API is the network // hop most likely to be slow or briefly unavailable here. const withdrawInfo = await runWithProgressRetries(wex, () => - getBankWithdrawalInfo(wex.http, req.talerWithdrawUri), + getBankWithdrawalInfo(wex.http, req.talerWithdrawUri, wex.ws.longpollQueue), ); const info = await getWithdrawalDetailsForBankInfo(wex, withdrawInfo); @@ -4676,7 +4678,7 @@ export async function confirmWithdrawal( // Retried under a progress context, like the other bank integration // queries in this file. const withdrawInfo = await runWithProgressRetries(wex, () => - getBankWithdrawalInfo(wex.http, talerWithdrawUri), + getBankWithdrawalInfo(wex.http, talerWithdrawUri, wex.ws.longpollQueue), ); bankWireTypes = withdrawInfo.wireTypes; bankCurrency = withdrawInfo.currency; diff --git a/packages/taler-wallet-core/src/withdrawal-kyc.test.ts b/packages/taler-wallet-core/src/withdrawal-kyc.test.ts @@ -26,6 +26,7 @@ import { TalerErrorCode, TalerPreciseTimestamp, TransactionIdStr, + LongpollQueue, } from "@gnu-taler/taler-util"; import { HeadersImpl, HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import assert from "node:assert/strict"; @@ -255,7 +256,7 @@ function fixture() { const wex = { http, cancellationToken: source.token, - ws: { longpollQueue: undefined }, + ws: { longpollQueue: new LongpollQueue() }, cryptoApi: { async signWalletKycAuth(args: unknown) { assert.deepEqual(args, { diff --git a/packages/taler-wallet-core/src/withdrawal-kyc.ts b/packages/taler-wallet-core/src/withdrawal-kyc.ts @@ -191,11 +191,9 @@ export async function getWithdrawalVolumeKycStatus( accountPriv: credential.reservePriv, }); wex.cancellationToken.throwIfCancelled(); - const client = walletExchangeClient( - args.exchangeBaseUrl, - wex, - Duration.fromSpec({ seconds: 5 }), - ); + const client = walletExchangeClient(args.exchangeBaseUrl, wex, { + timeout: Duration.fromSpec({ seconds: 5 }), + }); let response: Awaited<ReturnType<typeof client.checkKycStatus>>; try { response = await client.checkKycStatus({ diff --git a/packages/web-util/src/context/exchange-api.ts b/packages/web-util/src/context/exchange-api.ts @@ -15,6 +15,7 @@ */ import { + LongpollQueue, CacheEvictor, LibtoolVersion, ObservabilityEvent, @@ -233,6 +234,9 @@ export const ExchangeApiProvider = ({ }); }; +// All exchange providers, including their unthrottled clients, share capacity. +const longpollQueue = new LongpollQueue(); + function buildExchangeApiClient( url: URL, evictors: Evictors, @@ -255,6 +259,7 @@ function buildExchangeApiClient( httpClient: httpLib, cacheEvictor: evictors.exchange, preventCompression, + longpollQueue, }); async function getRemoteConfig(): Promise<KeysAndConfigType> {