commit 18878e5ed7d22711d05907bf25e9ee61e4bc6368
parent 5b1d5b17e65d095c66e7b37b6119377ae2ce2ed3
Author: Florian Dold <dold@taler.net>
Date: Fri, 27 Nov 2026 18:14:31 +0100
wallet harness: exercise a legal refusal in a two-exchange payment
Issue: https://bugs.taler.net/n/12291
Diffstat:
2 files changed, 217 insertions(+), 50 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-multiexchange.ts b/packages/taler-harness/src/integrationtests/test-multiexchange.ts
@@ -18,7 +18,9 @@
* Imports.
*/
import {
+ AmountString,
Duration,
+ encodeCrock,
openPromise,
RefreshReason,
succeedOrThrow,
@@ -31,7 +33,11 @@ import {
TransactionType,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { defaultCoinConfig } from "../harness/denomStructures.js";
+import {
+ CoinConfig,
+ defaultCoinConfig,
+ makeNoFeeCoinConfig,
+} from "../harness/denomStructures.js";
import {
createWalletDaemonWithClient,
makeTestPaymentV2,
@@ -57,50 +63,11 @@ import {
setupDb,
} from "../harness/harness.js";
-/**
- * Verify that one payment can combine funds withdrawn from two exchanges.
- */
-export async function runMultiExchangeTest(t: GlobalTestState) {
- // Set up test environment
- t.allowLog({
- file: "exchange-httpd-testexchange-1-stderr.log",
- level: "WARNING",
- message:
- /^External protocol violation detected at \.\.\/src\/exchange\/taler-exchange-httpd_post-melt\.c:\d+\.$/,
- maxOccurrences: 9,
- justification:
- "the test aborts a payment after one exchange deposited its nine selected coins, so their precautionary refresh melts encounter spent balances",
- });
- t.allowLogs({
- file: "merchant-httpd-testmerchant-1-stderr.log",
- level: "WARNING",
- messages: [
- [
- "Request to `http://localhost:9281/batch-deposit' was expected to return a body of type `application/json', got `(null)'",
- 2,
- ],
- ["Deposit operation failed with HTTP code 500/10", 2],
- ],
- justification:
- "the fault proxy deliberately returns two headerless HTTP 500 responses from the second exchange to exercise partial multi-exchange payment abort",
- });
- t.allowLogs({
- file: "wallet-wallet-stderr.log",
- level: "ERROR",
- messages: [
- [
- /^melt request for TESTKUDOS:0\.09 failed in refresh group [0-9A-Z]+ due to conflict$/,
- 8,
- ],
- [
- /^melt request for TESTKUDOS:3\.99 failed in refresh group [0-9A-Z]+ due to conflict$/,
- 1,
- ],
- ],
- justification:
- "the aborted first-exchange deposit leaves eight small and one large selected coin spent, which the wallet records as terminal refresh conflicts",
- });
-
+async function setupFundedMultiExchangeWallet(
+ t: GlobalTestState,
+ coins: CoinConfig[],
+ withdrawalAmount: AmountString,
+) {
const dbDefault = await setupDb(t);
const dbExchangeTwo = await setupDb(t, {
@@ -188,13 +155,13 @@ export async function runMultiExchangeTest(t: GlobalTestState) {
// Set up the first exchange
- exchangeOne.addOfferedCoins(defaultCoinConfig);
+ exchangeOne.addCoinConfigList(coins);
await exchangeOne.start();
await exchangeOne.pingUntilAvailable();
// Set up the second exchange
- exchangeTwo.addOfferedCoins(defaultCoinConfig);
+ exchangeTwo.addCoinConfigList(coins);
await exchangeTwo.start();
await exchangeTwo.pingUntilAvailable();
@@ -240,18 +207,86 @@ export async function runMultiExchangeTest(t: GlobalTestState) {
walletClient,
bank,
exchange: faultyExchangeOne,
- amount: "TESTKUDOS:6",
+ amount: withdrawalAmount,
});
await withdrawViaBankV4(t, {
walletClient,
bank,
exchange: faultyExchangeTwo,
- amount: "TESTKUDOS:6",
+ amount: withdrawalAmount,
});
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+ return {
+ walletClient,
+ bank,
+ faultyExchangeOne,
+ faultyExchangeTwo,
+ faultyMerchant,
+ adminAccessToken,
+ };
+}
+
+/**
+ * Verify that one payment can combine funds withdrawn from two exchanges.
+ */
+export async function runMultiExchangeTest(t: GlobalTestState) {
+ // Set up test environment
+ t.allowLog({
+ file: "exchange-httpd-testexchange-1-stderr.log",
+ level: "WARNING",
+ message:
+ /^External protocol violation detected at \.\.\/src\/exchange\/taler-exchange-httpd_post-melt\.c:\d+\.$/,
+ maxOccurrences: 9,
+ justification:
+ "the test aborts a payment after one exchange deposited its nine selected coins, so their precautionary refresh melts encounter spent balances",
+ });
+ t.allowLogs({
+ file: "merchant-httpd-testmerchant-1-stderr.log",
+ level: "WARNING",
+ messages: [
+ [
+ "Request to `http://localhost:9281/batch-deposit' was expected to return a body of type `application/json', got `(null)'",
+ 2,
+ ],
+ ["Deposit operation failed with HTTP code 500/10", 2],
+ ["Processing /pay in phase 11w: HTTP error 500/10", 2],
+ ],
+ justification:
+ "the fault proxy deliberately returns two headerless HTTP 500 responses from the second exchange to exercise partial multi-exchange payment abort",
+ });
+ t.allowLogs({
+ file: "wallet-wallet-stderr.log",
+ level: "ERROR",
+ messages: [
+ [
+ /^melt request for TESTKUDOS:0\.09 failed in refresh group [0-9A-Z]+ due to conflict$/,
+ 8,
+ ],
+ [
+ /^melt request for TESTKUDOS:3\.99 failed in refresh group [0-9A-Z]+ due to conflict$/,
+ 1,
+ ],
+ ],
+ justification:
+ "the aborted first-exchange deposit leaves eight small and one large selected coin spent, which the wallet records as terminal refresh conflicts",
+ });
+
+ const {
+ walletClient,
+ bank,
+ faultyExchangeOne,
+ faultyExchangeTwo,
+ faultyMerchant,
+ adminAccessToken,
+ } = await setupFundedMultiExchangeWallet(
+ t,
+ defaultCoinConfig.map((make) => make("TESTKUDOS")),
+ "TESTKUDOS:6",
+ );
+
const fundedBalances = await walletClient.call(
WalletApiOperation.GetBalances,
{},
@@ -447,3 +482,131 @@ runMultiExchangeTest.suites = ["wallet"];
// The test intentionally drives nine conflict/recovery cycles through two
// exchanges; loaded builders can legitimately need more than the default minute.
runMultiExchangeTest.timeoutMs = 120_000;
+
+/** A 451 from one exchange must recover the balance at each issuer. */
+export async function runMultiExchangeLegalRefusalTest(t: GlobalTestState) {
+ t.allowLogs({
+ file: "wallet-wallet-stderr.log",
+ level: "WARNING",
+ messages: [
+ [
+ "Extra property hint for TalerMerchantApi.PaymentDeniedLegallyResponse at (TalerMerchantApi.PaymentDeniedLegallyResponse)",
+ 1,
+ ],
+ ["exchange refused merchant payment for legal reasons", 1],
+ ],
+ justification:
+ "the merchant reports the injected legal refusal with a diagnostic hint",
+ });
+ t.allowLog({
+ file: "exchange-httpd-testexchange-1-stderr.log",
+ level: "WARNING",
+ message:
+ /^External protocol violation detected at \.\.\/src\/exchange\/taler-exchange-httpd_post-melt\.c:\d+\.$/,
+ maxOccurrences: 1,
+ justification:
+ "the precautionary melt can reach the exchange while the deposited coin awaits its refund",
+ });
+ t.allowLog({
+ file: "wallet-wallet-stderr.log",
+ level: "ERROR",
+ message:
+ /^melt request for TESTKUDOS:2\.56 failed in refresh group [0-9A-Z]+ due to conflict$/,
+ maxOccurrences: 1,
+ justification:
+ "the precautionary melt can encounter the already-deposited coin",
+ });
+ const value = "TESTKUDOS:2.56";
+ const {
+ walletClient,
+ faultyMerchant,
+ faultyExchangeOne,
+ faultyExchangeTwo,
+ adminAccessToken,
+ } = await setupFundedMultiExchangeWallet(
+ t,
+ makeNoFeeCoinConfig("TESTKUDOS").filter((coin) => coin.value === value),
+ value,
+ );
+ const merchant = new TalerMerchantInstanceHttpClient(
+ faultyMerchant.makeInstanceBaseUrl(),
+ {
+ httpClient: harnessHttpLib,
+ longpollQueue: harnessLongpollQueue,
+ },
+ );
+ const order = succeedOrThrow(
+ await merchant.createOrder(adminAccessToken, {
+ order: {
+ summary: "Partial payment refused by one exchange",
+ amount: "TESTKUDOS:5.12",
+ },
+ }),
+ );
+ const status = succeedOrThrow(
+ await merchant.getOrderDetails(adminAccessToken, order.order_id),
+ );
+ t.assertDeepEqual(status.order_status, "unpaid");
+ const { transactionId } = await walletClient.call(
+ WalletApiOperation.PreparePayForUriV2,
+ { talerPayUri: status.taler_pay_uri },
+ );
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId,
+ txState: {
+ major: TransactionMajorState.Dialog,
+ minor: TransactionMinorState.Proposed,
+ },
+ });
+ faultyExchangeTwo.faultProxy.addFault({
+ async modifyRequest(ctx) {
+ if (!new URL(ctx.requestUrl).pathname.endsWith("/batch-deposit")) return;
+ ctx.dropRequest = true;
+ ctx.substituteResponseStatusCode = 451;
+ ctx.substituteResponseHeaders = { "Content-Type": "application/json" };
+ ctx.substituteResponseBody = Buffer.from(
+ JSON.stringify({
+ code: TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED,
+ h_payto: encodeCrock(new Uint8Array(32)),
+ requirement_row: 1,
+ }),
+ );
+ },
+ });
+ const confirmed = await walletClient.call(WalletApiOperation.ConfirmPay, {
+ transactionId,
+ choiceIndex: 0,
+ });
+ t.assertDeepEqual(confirmed.transactionId, transactionId);
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId,
+ txState: { major: TransactionMajorState.Failed },
+ });
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+ const payment = await walletClient.call(
+ WalletApiOperation.GetTransactionById,
+ { transactionId },
+ );
+ t.assertTrue(payment.type === TransactionType.Payment);
+ t.assertDeepEqual(
+ payment.failReason?.code,
+ TalerErrorCode.MERCHANT_POST_ORDERS_ID_PAY_EXCHANGE_LEGALLY_REFUSED,
+ );
+ t.assertTrue(payment.totalRefundRaw !== undefined);
+ t.assertAmountEquals(payment.totalRefundRaw, value);
+ const { balances } = await walletClient.call(
+ WalletApiOperation.GetBalances,
+ {},
+ );
+ t.assertDeepEqual(balances.length, 2);
+ for (const issuer of [faultyExchangeOne, faultyExchangeTwo]) {
+ const balance = balances.find(
+ (b) => "url" in b.scopeInfo && b.scopeInfo.url === issuer.baseUrl,
+ );
+ t.assertTrue(!!balance);
+ t.assertAmountEquals(balance.available, value);
+ }
+}
+
+runMultiExchangeLegalRefusalTest.suites = ["wallet"];
+runMultiExchangeLegalRefusalTest.timeoutMs = 120_000;
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -154,7 +154,10 @@ import { runMerchantTemplatesTest } from "./test-merchant-templates.js";
import { runMerchantTokenfamiliesTest } from "./test-merchant-tokenfamilies.js";
import { runMerchantSettlementTest } from "./test-merchant-settlement.js";
import { runMerchantWireTest } from "./test-merchant-wire.js";
-import { runMultiExchangeTest } from "./test-multiexchange.js";
+import {
+ runMultiExchangeTest,
+ runMultiExchangeLegalRefusalTest,
+} from "./test-multiexchange.js";
import { runRiegelTest } from "./test-riegel.js";
import { runWalletFountainsTest } from "./test-wallet-fountains.js";
import {
@@ -435,6 +438,7 @@ const allTests: TestMainFunction[] = [
runPayPaidTest,
runPeerRepairTest,
runMultiExchangeTest,
+ runMultiExchangeLegalRefusalTest,
runWalletBalanceTest,
runPaywallFlowTest,
runPeerAbortBalanceTest,