taler-typescript-core

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

commit bf7a8fad03fccb32e77c34c66befbac12d86d123
parent 0b34da8334d34114b845cbab2f3260326e99b5b6
Author: Florian Dold <florian@dold.me>
Date:   Tue, 29 Apr 2025 00:31:59 +0200

harness: simplify denom-unoffered

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-denom-unoffered.ts | 57+++++++--------------------------------------------------
Mpackages/taler-wallet-core/src/pay-merchant.ts | 22+++++-----------------
2 files changed, 12 insertions(+), 67 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts b/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts @@ -18,19 +18,14 @@ * Imports. */ import { - codecForTalerErrorDetail, - Duration, - j2s, Logger, PreparePayResultType, succeedOrThrow, TalerErrorCode, - TalerErrorDetail, TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, withdrawViaBankV3, } from "../harness/environments.js"; @@ -113,38 +108,21 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { t.logStep("order confirmed"); + // Currently, the payment transaction will be aborted. + // In the future, the wallet should also do coin re-selection + // when a denomination is lost. But we might want to ask the user + // first, since they lost money. + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + const tx = await walletClient.call(WalletApiOperation.GetTransactionById, { transactionId: confirmResp.transactionId, }); - t.assertTrue(tx.error != null); - t.assertTrue( - tx.error.code === TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR, - ); - - logger.info(`tx error: ${j2s(tx.error)}`); - - t.assertDeepEqual((tx.error as any).requestError.httpStatusCode, 502); - - const merchantErrorResp: TalerErrorDetail = (tx.error as any).requestError - .errorResponse; - - t.assertDeepEqual(merchantErrorResp.exchange_http_status, 404); - t.assertDeepEqual( - merchantErrorResp.code, + (tx.abortReason?.errorDetails as any)?.code, TalerErrorCode.MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS, ); - const exchangeResp = codecForTalerErrorDetail().decode( - merchantErrorResp.exchange_reply, - ); - - t.assertDeepEqual( - exchangeResp.code, - TalerErrorCode.EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN, - ); - // Force updating the exchange entry so that the wallet knows about the new denominations. await walletClient.call(WalletApiOperation.UpdateExchangeEntry, { exchangeBaseUrl: exchange.baseUrl, @@ -163,27 +141,6 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { await wres2.withdrawalFinishedCond; - logger.info(`withdrawal done`); - - // Time trave so merchant doens't refuse to download /keys - // from the exchange anymore. - await applyTimeTravelV2( - Duration.toMilliseconds(Duration.fromSpec({ minutes: 6 })), - { - exchange, - merchant, - walletClient, - }, - ); - - logger.info(`timetravel done`); - - // Currently, the payment transaction will be aborted. - // In the future, the wallet should also do coin re-selection - // when a denomination is lost. But we might want to ask the user - // first, since they lost money. - await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - const txs = await walletClient.call(WalletApiOperation.GetTransactions, { sort: "stable-ascending", }); diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -116,7 +116,6 @@ import { readSuccessResponseJsonOrErrorCode, readSuccessResponseJsonOrThrow, readTalerErrorResponse, - readUnexpectedResponseDetails, throwUnexpectedRequestError, } from "@gnu-taler/taler-util/http"; import { @@ -3375,19 +3374,6 @@ async function processPurchasePay( logger.trace(`got resp ${JSON.stringify(resp)}`); - if (resp.status >= 500 && resp.status <= 599) { - const errDetails = await readUnexpectedResponseDetails(resp); - return { - type: TaskRunResultType.Error, - errorDetail: makeErrorDetail( - TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR, - { - requestError: errDetails, - }, - ), - }; - } - if (resp.status === HttpStatusCode.Conflict) { const err = await readTalerErrorResponse(resp); if ( @@ -3449,13 +3435,15 @@ async function processPurchasePay( return TaskRunResult.progress(); } - if (resp.status >= 400 && resp.status <= 499) { - logger.trace("got generic 4xx from merchant"); + if (resp.status != 200) { + logger.info( + `got error response (http status ${resp.status}) from merchant`, + ); const err = await readTalerErrorResponse(resp); if (logger.shouldLogTrace()) { logger.trace(`error body: ${j2s(err)}`); } - throwUnexpectedRequestError(resp, err); + return throwUnexpectedRequestError(resp, err); } const merchantResp = await readSuccessResponseJsonOrThrow(