taler-typescript-core

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

commit 1fa663f93fca3b066dd3f0dbdeea0ca0eea77ad1
parent d04f9051f73b06b1234301283e8a85dc96fcbff6
Author: Florian Dold <dold@taler.net>
Date:   Wed, 25 Nov 2026 19:34:31 +0100

wallet CLI and harness: use the V2 peer-push balance check

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-peer-push-large.ts | 3++-
Mpackages/taler-harness/src/integrationtests/test-peer-push.ts | 5+++--
Mpackages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts | 47+++++++++++++++++++++++------------------------
Mpackages/taler-wallet-cli/src/index.ts | 38+++++++++++++++++++++++++-------------
4 files changed, 53 insertions(+), 40 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-peer-push-large.ts b/packages/taler-harness/src/integrationtests/test-peer-push-large.ts @@ -63,9 +63,10 @@ export async function runPeerPushLargeTest(t: GlobalTestState) { }); await withdrawRes.withdrawalFinishedCond; - const check = await wallet1.call(WalletApiOperation.CheckPeerPushDebit, { + const check = await wallet1.call(WalletApiOperation.CheckPeerPushDebitV2, { amount: "TESTKUDOS:200", }); + t.assertTrue(check.type === "ok"); t.assertAmountEquals(check.amountEffective, "TESTKUDOS:200"); const initiate = await wallet1.call( diff --git a/packages/taler-harness/src/integrationtests/test-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-push.ts @@ -118,7 +118,7 @@ export async function runPeerPushTest(t: GlobalTestState) { wallet1.call(WalletApiOperation.GetMaxPeerPushDebitAmount, { currency: "TESTKUDOS", }), - wallet1.call(WalletApiOperation.CheckPeerPushDebit, { + wallet1.call(WalletApiOperation.CheckPeerPushDebitV2, { amount: "TESTKUDOS:5", }), ]); @@ -128,7 +128,7 @@ export async function runPeerPushTest(t: GlobalTestState) { t.assertAmountEquals(maxpeer.effectiveAmount, "TESTKUDOS:199.71"); const zeroAmountError = await t.assertThrowsTalerErrorAsync(() => - wallet1.call(WalletApiOperation.CheckPeerPushDebit, { + wallet1.call(WalletApiOperation.CheckPeerPushDebitV2, { amount: "TESTKUDOS:0", }), ); @@ -137,6 +137,7 @@ export async function runPeerPushTest(t: GlobalTestState) { TalerErrorCode.WALLET_CORE_API_BAD_REQUEST, ); + t.assertTrue(checkfive.type === "ok"); t.assertAmountEquals(checkfive.amountRaw, "TESTKUDOS:5"); t.assertAmountEquals(checkfive.amountEffective, "TESTKUDOS:5.16"); } diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -202,22 +202,21 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { }); await wres2.withdrawalFinishedCond; - const exc = await t.assertThrowsTalerErrorAsync( - async () => - await walletClient.call(WalletApiOperation.CheckPeerPushDebit, { - amount: "TESTKUDOS:20" as AmountString, - }), + const check = await walletClient.call( + WalletApiOperation.CheckPeerPushDebitV2, + { + amount: "TESTKUDOS:20", + }, ); - - const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = - exc.errorDetail.insufficientBalanceDetails; + t.assertTrue(check.type === "insufficient-balance"); + const insufficientBalanceDetails = check.insufficientBalanceDetails; const perMyExchange = insufficientBalanceDetails.perExchange[exchange.baseUrl]; t.assertTrue(!!perMyExchange); - console.log(j2s(exc.errorDetail)); + console.log(j2s(insufficientBalanceDetails)); t.assertAmountEquals( insufficientBalanceDetails.amountRequested, @@ -252,14 +251,14 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { "TESTKUDOS:0", ); - const fragmentationExc = await t.assertThrowsTalerErrorAsync( - async () => - await walletClient.call(WalletApiOperation.CheckPeerPushDebit, { - amount: "TESTKUDOS:12" as AmountString, - }), + const fragmentation = await walletClient.call( + WalletApiOperation.CheckPeerPushDebitV2, + { + amount: "TESTKUDOS:12", + }, ); - const fragmentationDetails = fragmentationExc.errorDetail - .insufficientBalanceDetails as PaymentInsufficientBalanceDetails; + t.assertTrue(fragmentation.type === "insufficient-balance"); + const fragmentationDetails = fragmentation.insufficientBalanceDetails; t.assertTrue(fragmentationDetails.reasons != null); t.assertTrue( fragmentationDetails.reasons.some( @@ -272,15 +271,15 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { ), ); - const feeExc = await t.assertThrowsTalerErrorAsync( - async () => - await walletClient.call(WalletApiOperation.CheckPeerPushDebit, { - amount: "TESTKUDOS:9.8" as AmountString, - exchangeBaseUrl: exchange.baseUrl, - }), + const feeCheck = await walletClient.call( + WalletApiOperation.CheckPeerPushDebitV2, + { + amount: "TESTKUDOS:9.8", + exchangeBaseUrl: exchange.baseUrl, + }, ); - const feeDetails = feeExc.errorDetail - .insufficientBalanceDetails as PaymentInsufficientBalanceDetails; + t.assertTrue(feeCheck.type === "insufficient-balance"); + const feeDetails = feeCheck.insufficientBalanceDetails; t.assertTrue(feeDetails.reasons != null); t.assertTrue( feeDetails.reasons.some( diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts @@ -22,6 +22,7 @@ import { AgeRestriction, Amounts, AmountString, + CheckPeerPushDebitRequest, ChoiceSelectionDetailType, codecForList, codecForString, @@ -2181,6 +2182,23 @@ walletCli }); }); +async function checkPeerPushAmount( + client: WalletCoreApiClient, + request: CheckPeerPushDebitRequest, +) { + const result = await client.call( + WalletApiOperation.CheckPeerPushDebitV2, + request, + ); + if (result.type === "insufficient-balance") { + throw TalerError.fromDetail( + TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE, + { insufficientBalanceDetails: result.insufficientBalanceDetails }, + ); + } + return result; +} + walletCli .subcommand("payPush", "peer-send", { help: "Initiate a peer-push payment.", @@ -2202,13 +2220,10 @@ walletCli if (args.payPush.check) { await runCliAction(() => withWallet(args, { lazyTaskLoop: true }, async (wallet) => { - const resp = await wallet.client.call( - WalletApiOperation.CheckPeerPushDebit, - { - amount: args.payPush.amount, - exchangeBaseUrl: args.payPush.exchange, - }, - ); + const resp = await checkPeerPushAmount(wallet.client, { + amount: args.payPush.amount, + exchangeBaseUrl: args.payPush.exchange, + }); console.log(`Check peer-send result: ${j2s(resp)}`); }), ); @@ -3263,12 +3278,9 @@ peerCli }) .action(async (args) => { await withWallet(args, { lazyTaskLoop: true }, async (wallet) => { - const resp = await wallet.client.call( - WalletApiOperation.CheckPeerPushDebit, - { - amount: args.checkPayPush.amount, - }, - ); + const resp = await checkPeerPushAmount(wallet.client, { + amount: args.checkPayPush.amount, + }); console.log(JSON.stringify(resp, undefined, 2)); }); });