taler-typescript-core

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

commit 46c97c2b361c58ccf4d5ab3b915c20dc12df8a92
parent 79fc1f13f908040b209d1ebae785ff3bc8d05729
Author: Florian Dold <dold@taler.net>
Date:   Thu, 20 Aug 2026 19:06:41 +0200

wallet-core: resolve waiters with falsy notification values

Diffstat:
Apackages/taler-wallet-core/src/remote.test.ts | 43+++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/remote.ts | 2+-
2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/packages/taler-wallet-core/src/remote.test.ts b/packages/taler-wallet-core/src/remote.test.ts @@ -0,0 +1,43 @@ +/* + 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 { WalletNotification } from "@gnu-taler/taler-util"; +import assert from "node:assert"; +import { test } from "node:test"; +import { makeNotificationWaiter } from "./remote.js"; + +async function requirePromptResolution<T>(promise: Promise<T>): Promise<T> { + const timedOut = Symbol("timed out"); + const result = await Promise.race([ + promise, + new Promise<typeof timedOut>((resolve) => + setTimeout(() => resolve(timedOut), 20), + ), + ]); + assert.notStrictEqual(result, timedOut, "notification waiter did not resolve"); + return result as T; +} + +test("notification waiters resolve falsey non-sentinel results", async () => { + const zeroWaiter = makeNotificationWaiter(); + const zeroResult = zeroWaiter.waitForNotificationCond(() => 0); + zeroWaiter.notify({} as WalletNotification); + assert.strictEqual(await requirePromptResolution(zeroResult), 0); + + const emptyWaiter = makeNotificationWaiter(); + const emptyResult = emptyWaiter.waitForNotificationCond(() => ""); + emptyWaiter.notify({} as WalletNotification); + assert.strictEqual(await requirePromptResolution(emptyResult), ""); +}); diff --git a/packages/taler-wallet-core/src/remote.ts b/packages/taler-wallet-core/src/remote.ts @@ -221,7 +221,7 @@ export function makeNotificationWaiter(): WalletNotificationWaiter { function onNotification(n: WalletNotification) { condMap.forEach((cond, condKey) => { const res = cond.condition(n); - if (res) { + if (res !== false && res !== undefined) { // The promise settles once, so the condition must not be // re-evaluated on later notifications. condMap.delete(condKey);