commit d30f404c29ea7f48b8cd9ee63f25b3ae41047058
parent ffc5c64b22ea520d1fc057469a878b7b8db683d0
Author: Florian Dold <dold@taler.net>
Date: Wed, 22 Jul 2026 10:41:39 +0200
wallet: test the transaction identifier round trip
Constructs one identifier per parsed variant and parses it back.
Diffstat:
1 file changed, 58 insertions(+), 0 deletions(-)
diff --git a/packages/taler-wallet-core/src/transactions.test.ts b/packages/taler-wallet-core/src/transactions.test.ts
@@ -0,0 +1,58 @@
+/*
+ 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 { TransactionType } from "@gnu-taler/taler-util";
+import assert from "node:assert";
+import { test } from "node:test";
+import {
+ constructTransactionIdentifier,
+ ParsedTransactionIdentifier,
+ parseTransactionIdentifier,
+} from "./transactions.js";
+
+const allIdentifiers: ParsedTransactionIdentifier[] = [
+ { tag: TransactionType.Deposit, depositGroupId: "dg" },
+ { tag: TransactionType.Payment, proposalId: "prop" },
+ { tag: TransactionType.PeerPullDebit, peerPullDebitId: "ppd" },
+ { tag: TransactionType.PeerPullCredit, pursePub: "purse" },
+ { tag: TransactionType.PeerPushCredit, peerPushCreditId: "ppc" },
+ { tag: TransactionType.PeerPushDebit, pursePub: "purse" },
+ { tag: TransactionType.Refresh, refreshGroupId: "rg" },
+ { tag: TransactionType.Refund, refundGroupId: "rfg" },
+ { tag: TransactionType.Withdrawal, withdrawalGroupId: "wg" },
+ { tag: TransactionType.InternalWithdrawal, withdrawalGroupId: "wg" },
+ { tag: TransactionType.Recoup, recoupGroupId: "rcg" },
+ { tag: TransactionType.DenomLoss, denomLossEventId: "dl" },
+];
+
+test("every constructed transaction identifier parses back", (t) => {
+ for (const pTxId of allIdentifiers) {
+ const txId = constructTransactionIdentifier(pTxId);
+ assert.deepStrictEqual(
+ parseTransactionIdentifier(txId),
+ pTxId,
+ `round trip failed for ${txId}`,
+ );
+ }
+});
+
+test("an unknown transaction type does not parse", (t) => {
+ assert.strictEqual(parseTransactionIdentifier("txn:bogus:x"), undefined);
+});
+
+test("a malformed transaction identifier is rejected", (t) => {
+ assert.throws(() => parseTransactionIdentifier("txn:deposit"));
+ assert.throws(() => parseTransactionIdentifier("nottxn:deposit:x"));
+});