commit 7b73df63d2c02bda0acaf987ff4f2eb54daafd63
parent 72856ccb6d7f1604ffb30ef3fb31533090d8ab79
Author: Florian Dold <dold@taler.net>
Date: Tue, 24 Nov 2026 16:00:25 +0100
taler-harness: spend partial coins in wallet refresh tests
An exact deposit leaves no change to refresh. Fund the wallet with two
10-unit coins and follow the refresh belonging to each 8-unit deposit.
Diffstat:
2 files changed, 65 insertions(+), 99 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-network-availability.ts b/packages/taler-harness/src/integrationtests/test-wallet-network-availability.ts
@@ -18,25 +18,20 @@
* Imports.
*/
import {
- AmountString,
NotificationType,
ObservabilityEventType,
TransactionMajorState,
- TransactionType,
} from "@gnu-taler/taler-util";
import {
TaskRunResultType,
WalletApiOperation,
- parseTransactionIdentifier,
} from "@gnu-taler/taler-wallet-core";
import {
createSimpleTestkudosEnvironmentV3,
withdrawViaBankV4,
} from "../harness/environments.js";
-import {
- GlobalTestState,
- getTestHarnessPaytoForLabel,
-} from "../harness/harness.js";
+import { GlobalTestState } from "../harness/harness.js";
+import { depositAndGetChangeRefresh } from "./test-wallet-refresh.js";
/**
* Run test for hintNetworkAvailability in wallet-core
@@ -49,11 +44,12 @@ export async function runWalletNetworkAvailabilityTest(t: GlobalTestState) {
walletTestObservability: true,
});
+ // With two 10-unit coins the 8-unit deposit must return change.
await withdrawViaBankV4(t, {
walletClient,
bank,
exchange,
- amount: "TESTKUDOS:20",
+ amount: "TESTKUDOS:20.02",
});
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
@@ -62,35 +58,19 @@ export async function runWalletNetworkAvailabilityTest(t: GlobalTestState) {
return (
x.type === NotificationType.TaskObservabilityEvent &&
x.event.type === ObservabilityEventType.ShepherdTaskResult &&
+ x.taskId.startsWith("refresh:") &&
x.event.resultType === TaskRunResultType.NetworkRequired
);
});
- const refreshCreatedCond = walletClient.waitForNotificationCond((x) => {
- return (
- x.type === NotificationType.TransactionStateTransition &&
- parseTransactionIdentifier(x.transactionId)?.tag ===
- TransactionType.Refresh
- );
- });
-
- const refreshDoneCond = walletClient.waitForNotificationCond((x) => {
- return (
- x.type === NotificationType.TransactionStateTransition &&
- parseTransactionIdentifier(x.transactionId)?.tag ===
- TransactionType.Refresh &&
- x.newTxState.major === TransactionMajorState.Done
- );
- });
-
await walletClient.call(WalletApiOperation.HintNetworkAvailability, {
isNetworkAvailable: false,
});
- await walletClient.client.call(WalletApiOperation.CreateDepositGroup, {
- amount: "TESTKUDOS:10.5" as AmountString,
- depositPaytoUri: getTestHarnessPaytoForLabel("foo"),
- });
+ const refreshTransactionId = await depositAndGetChangeRefresh(
+ t,
+ walletClient,
+ );
// refresh should not continue due to network-required
await networkRequiredCond;
@@ -99,10 +79,10 @@ export async function runWalletNetworkAvailabilityTest(t: GlobalTestState) {
isNetworkAvailable: true,
});
- await refreshCreatedCond;
-
- // refresh should finish due to network being restored
- await refreshDoneCond;
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: refreshTransactionId,
+ txState: { major: TransactionMajorState.Done },
+ });
}
runWalletNetworkAvailabilityTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts
@@ -18,18 +18,12 @@
* Imports.
*/
import {
- AmountString,
- NotificationType,
TalerMerchantApi,
- TransactionIdStr,
TransactionMajorState,
TransactionType,
j2s,
} from "@gnu-taler/taler-util";
-import {
- WalletApiOperation,
- parseTransactionIdentifier,
-} from "@gnu-taler/taler-wallet-core";
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import {
createSimpleTestkudosEnvironmentV3,
makeTestPaymentV2,
@@ -38,8 +32,34 @@ import {
import {
GlobalTestState,
getTestHarnessPaytoForLabel,
+ WalletClient,
} from "../harness/harness.js";
+export async function depositAndGetChangeRefresh(
+ t: GlobalTestState,
+ walletClient: WalletClient,
+) {
+ const deposit = await walletClient.call(
+ WalletApiOperation.CreateDepositGroup,
+ {
+ amount: "TESTKUDOS:8",
+ depositPaytoUri: getTestHarnessPaytoForLabel("foo"),
+ },
+ );
+ const { transactions } = await walletClient.call(
+ WalletApiOperation.GetTransactions,
+ { includeRefreshes: true },
+ );
+ const refresh = transactions.find(
+ (tx) =>
+ tx.type === TransactionType.Refresh &&
+ tx.originatingTransactionId === deposit.transactionId,
+ );
+ t.assertTrue(!!refresh, "the deposit must leave change to refresh");
+ t.assertDeepEqual(refresh.txState.major, TransactionMajorState.Pending);
+ return refresh.transactionId;
+}
+
/**
* Run test for refresh after a payment.
*/
@@ -49,13 +69,14 @@ export async function runWalletRefreshTest(t: GlobalTestState) {
const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } =
await createSimpleTestkudosEnvironmentV3(t);
- // Withdraw digital cash into the wallet.
-
+ // Two 10-unit coins plus withdrawal fees. Both the payment and the deposits
+ // must spend part of a coin to exercise the refresh lifecycle.
+ const withdrawalAmount = "TESTKUDOS:20.02";
await withdrawViaBankV4(t, {
walletClient,
bank,
exchange,
- amount: "TESTKUDOS:20",
+ amount: withdrawalAmount,
});
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
@@ -99,45 +120,28 @@ export async function runWalletRefreshTest(t: GlobalTestState) {
// Now we test a pending refresh operation.
{
- await exchange.stop();
-
- const refreshCreatedCond = walletClient.waitForNotificationCond((x) => {
- if (
- x.type === NotificationType.TransactionStateTransition &&
- parseTransactionIdentifier(x.transactionId)?.tag ===
- TransactionType.Refresh
- ) {
- return true;
- }
- return false;
+ t.allowLog({
+ file: "wallet-wallet-stderr.log",
+ level: "WARNING",
+ message: "exception in refresh session: {",
+ maxOccurrences: 2,
+ justification:
+ "the two deposits can each attempt a melt while the exchange is stopped",
});
+ await exchange.stop();
- const refreshDoneCond = walletClient.waitForNotificationCond((x) => {
- if (
- x.type === NotificationType.TransactionStateTransition &&
- parseTransactionIdentifier(x.transactionId)?.tag ===
- TransactionType.Refresh &&
- x.newTxState.major === TransactionMajorState.Done
- ) {
- return true;
- }
- return false;
- });
-
- await walletClient.client.call(WalletApiOperation.CreateDepositGroup, {
- amount: "TESTKUDOS:10.5" as AmountString,
- depositPaytoUri: getTestHarnessPaytoForLabel("foo"),
- });
-
- await refreshCreatedCond;
-
- // Here, the refresh operation should be in a pending state.
-
+ const refreshTransactionId = await depositAndGetChangeRefresh(
+ t,
+ walletClient,
+ );
const bal1 = await walletClient.call(WalletApiOperation.GetBalances, {});
await exchange.start();
- await refreshDoneCond;
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: refreshTransactionId,
+ txState: { major: TransactionMajorState.Done },
+ });
const bal2 = await walletClient.call(WalletApiOperation.GetBalances, {});
@@ -153,7 +157,7 @@ export async function runWalletRefreshTest(t: GlobalTestState) {
walletClient,
bank,
exchange,
- amount: "TESTKUDOS:20",
+ amount: withdrawalAmount,
});
await wres.withdrawalFinishedCond;
@@ -163,28 +167,10 @@ export async function runWalletRefreshTest(t: GlobalTestState) {
{
await exchange.stop();
- let refreshTransactionId: TransactionIdStr | undefined = undefined;
-
- const refreshCreatedCond = walletClient.waitForNotificationCond((x) => {
- if (
- x.type === NotificationType.TransactionStateTransition &&
- parseTransactionIdentifier(x.transactionId)?.tag ===
- TransactionType.Refresh
- ) {
- refreshTransactionId = x.transactionId as TransactionIdStr;
- return true;
- }
- return false;
- });
-
- await walletClient.client.call(WalletApiOperation.CreateDepositGroup, {
- amount: "TESTKUDOS:10.5" as AmountString,
- depositPaytoUri: getTestHarnessPaytoForLabel("foo"),
- });
-
- await refreshCreatedCond;
-
- t.assertTrue(!!refreshTransactionId);
+ const refreshTransactionId = await depositAndGetChangeRefresh(
+ t,
+ walletClient,
+ );
await walletClient.call(WalletApiOperation.SuspendTransaction, {
transactionId: refreshTransactionId,