taler-typescript-core

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

commit 5813d225627958049143956bb90a2170622737d5
parent 50476c0adbc48883537fa82893044d1592aaf1fa
Author: Florian Dold <florian@dold.me>
Date:   Fri,  1 Aug 2025 16:20:39 +0200

wallet-core: introduce ref counting for ignoring ToS during tests

Diffstat:
Mpackages/taler-wallet-core/src/common.ts | 7+++++++
Mpackages/taler-wallet-core/src/pay-peer-pull-credit.ts | 2+-
Mpackages/taler-wallet-core/src/pay-peer-push-credit.ts | 2+-
Mpackages/taler-wallet-core/src/testing.ts | 51+++++++++++++++++++++++++++++++++++++--------------
Mpackages/taler-wallet-core/src/wallet.ts | 6++++++
Mpackages/taler-wallet-core/src/withdraw.ts | 2+-
6 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts @@ -985,8 +985,15 @@ export async function genericWaitForStateVal<T>( } export function requireExchangeTosAcceptedOrThrow( + wex: WalletExecutionContext, exchange: ReadyExchangeSummary, ): void { + if (wex.ws.refcntIgnoreTos > 0) { + logger.warn( + `ignoring ToS acceptance state, refcntIgnoreTos=${wex.ws.refcntIgnoreTos}`, + ); + return; + } switch (exchange.tosStatus) { case ExchangeTosStatus.Accepted: case ExchangeTosStatus.MissingTos: diff --git a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts @@ -1045,7 +1045,7 @@ export async function initiatePeerPullPayment( const exchangeBaseUrl = maybeExchangeBaseUrl; const exchange = await fetchFreshExchange(wex, exchangeBaseUrl); - requireExchangeTosAcceptedOrThrow(exchange); + requireExchangeTosAcceptedOrThrow(wex, exchange); if ( checkPeerCreditHardLimitExceeded(exchange, req.partialContractTerms.amount) diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts @@ -1162,7 +1162,7 @@ export async function confirmPeerPushCredit( const peerInc = res.peerInc; const exchange = await fetchFreshExchange(wex, peerInc.exchangeBaseUrl); - requireExchangeTosAcceptedOrThrow(exchange); + requireExchangeTosAcceptedOrThrow(wex, exchange); if (checkPeerCreditHardLimitExceeded(exchange, res.contractTerms.amount)) { throw Error("peer credit would exceed hard KYC limit"); diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts @@ -34,7 +34,6 @@ import { codecForCheckPaymentResponse, ConfirmPayResultType, Duration, - ExchangeTosStatus, IntegrationTestArgs, IntegrationTestV2Args, j2s, @@ -62,11 +61,7 @@ import { import { getBalances } from "./balance.js"; import { genericWaitForState } from "./common.js"; import { createDepositGroup } from "./deposits.js"; -import { - acceptExchangeTermsOfService, - fetchFreshExchange, - forgetExchangeTermsOfService, -} from "./exchanges.js"; +import { fetchFreshExchange } from "./exchanges.js"; import { confirmPay, preparePayForUri, @@ -114,6 +109,18 @@ export async function withdrawTestBalance( wex: WalletExecutionContext, req: WithdrawTestBalanceRequest, ): Promise<WithdrawTestBalanceResult> { + wex.ws.refcntIgnoreTos += 1; + try { + return await withdrawTestBalanceImpl(wex, req); + } finally { + wex.ws.refcntIgnoreTos -= 1; + } +} + +async function withdrawTestBalanceImpl( + wex: WalletExecutionContext, + req: WithdrawTestBalanceRequest, +): Promise<WithdrawTestBalanceResult> { const amount = req.amount; const exchangeBaseUrl = req.exchangeBaseUrl; const corebankApiBaseUrl = req.corebankApiBaseUrl; @@ -134,9 +141,6 @@ export async function withdrawTestBalance( amount, ); - const exchangeBefore = await fetchFreshExchange(wex, req.exchangeBaseUrl); - await acceptExchangeTermsOfService(wex, req.exchangeBaseUrl); - const acceptResp = await acceptBankIntegratedWithdrawal(wex, { talerWithdrawUri: wresp.taler_withdraw_uri, selectedExchange: exchangeBaseUrl, @@ -158,11 +162,6 @@ export async function withdrawTestBalance( withdrawalOperationId: wresp.withdrawal_id, }); - /* If the ToS weren't accepted before, restore the status. */ - if (exchangeBefore.tosStatus === ExchangeTosStatus.Proposed) { - await forgetExchangeTermsOfService(wex, req.exchangeBaseUrl); - } - return { transactionId: acceptResp.transactionId, accountPaytoUri: bankUser.accountPaytoUri, @@ -327,6 +326,18 @@ export async function runIntegrationTest( wex: WalletExecutionContext, args: IntegrationTestArgs, ): Promise<void> { + wex.ws.refcntIgnoreTos += 1; + try { + return await runIntegrationTestImpl(wex, args); + } finally { + wex.ws.refcntIgnoreTos -= 1; + } +} + +async function runIntegrationTestImpl( + wex: WalletExecutionContext, + args: IntegrationTestArgs, +): Promise<void> { logger.info("running test with arguments", args); const parsedSpendAmount = Amounts.parseOrThrow(args.amountToSpend); @@ -700,6 +711,18 @@ export async function runIntegrationTest2( wex: WalletExecutionContext, args: IntegrationTestV2Args, ): Promise<void> { + wex.ws.refcntIgnoreTos += 1; + try { + return await runIntegrationTest2Impl(wex, args); + } finally { + wex.ws.refcntIgnoreTos -= 1; + } +} + +async function runIntegrationTest2Impl( + wex: WalletExecutionContext, + args: IntegrationTestV2Args, +): Promise<void> { await wex.taskScheduler.ensureRunning(); logger.info("running test with arguments", args); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -2862,6 +2862,12 @@ export class InternalWalletState { this._networkAvailable = status; } + /** + * Reference counter for active integration tests + * that ignore ToS acceptance rules. + */ + refcntIgnoreTos: number = 0; + clearAllCaches(): void { this.exchangeCache.clear(); this.denomInfoCache.clear(); diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -3834,7 +3834,7 @@ export async function confirmWithdrawal( } const exchange = await fetchFreshExchange(wex, selectedExchange); - requireExchangeTosAcceptedOrThrow(exchange); + requireExchangeTosAcceptedOrThrow(wex, exchange); if (req.amount && checkWithdrawalHardLimitExceeded(exchange, req.amount)) { throw Error("withdrawal would exceed hard KYC limit");