taler-typescript-core

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

commit abc9cad5358c3361b10112cd513f37df8fca249a
parent fc93706981d8cd64ff55503d357c8092bebc7be4
Author: Florian Dold <dold@taler.net>
Date:   Wed, 22 Jul 2026 10:56:51 +0200

wallet: test the maximum deposit amount against unspendable coins

Offering coins whose deposit fee exceeds their value must not lower the
reported maximum.

Diffstat:
Mpackages/taler-wallet-core/src/coinSelection.test.ts | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/packages/taler-wallet-core/src/coinSelection.test.ts b/packages/taler-wallet-core/src/coinSelection.test.ts @@ -562,3 +562,51 @@ test("prefer exact denom", (t) => { }, }); }); + +test("deposit max ignores coins that cost more to deposit than they are worth", (t) => { + // The 0.005 denomination has a deposit fee of 0.01, so spending it takes + // more from the deposit than it adds. selectGreedy skips such coins, so + // offering them must not lower the reported maximum either. + const args = (coinAvailability: AvailableCoinsOfDenom[]) => + [ + { + currency: "KUDOS", + }, + { + coinAvailability, + currentWireFeePerExchange: { + "2": kudos`0`, + }, + }, + ] as const; + + const withoutDust = testing_getMaxDepositAmountForAvailableCoins( + ...args([defaultFeeConfig(kudos`5`, 1)]), + ); + const withDust = testing_getMaxDepositAmountForAvailableCoins( + ...args([defaultFeeConfig(kudos`5`, 1), defaultFeeConfig(kudos`0.005`, 10)]), + ); + + assert.strictEqual(Amounts.stringifyValue(withoutDust.rawAmount), "4.99"); + assert.strictEqual( + Amounts.stringifyValue(withDust.rawAmount), + Amounts.stringifyValue(withoutDust.rawAmount), + ); +}); + +test("deposit max is zero when only unspendable coins are available", (t) => { + const result = testing_getMaxDepositAmountForAvailableCoins( + { + currency: "KUDOS", + }, + { + coinAvailability: [defaultFeeConfig(kudos`0.005`, 10)], + currentWireFeePerExchange: { + "2": kudos`1`, + }, + }, + ); + + assert.strictEqual(Amounts.stringifyValue(result.rawAmount), "0"); + assert.strictEqual(Amounts.stringifyValue(result.effectiveAmount), "0"); +});