taler-typescript-core

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

commit 4b9cbe58025bf7082d0c79ee596200628b5d8c47
parent 53faa440d146b4658fdad48ef545092325dda475
Author: Florian Dold <florian@dold.me>
Date:   Thu, 28 Mar 2024 12:27:26 +0100

wallet-core: count peer-push-debit towards pending outgoing balance

Also check balance in the integration test.

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts | 14++++++++++++++
Mpackages/taler-wallet-core/src/balance.ts | 24++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts @@ -76,6 +76,15 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { ), ); + const checkResp0 = await w1.walletClient.call( + WalletApiOperation.CheckPeerPushDebit, + { + amount: "TESTKUDOS:5" as AmountString, + }, + ); + + t.assertAmountEquals(checkResp0.amountEffective, "TESTKUDOS:5.49"); + { const resp = await w1.walletClient.call( WalletApiOperation.InitiatePeerPushDebit, @@ -91,6 +100,11 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { console.log(resp); } + { + const bal = await w1.walletClient.call(WalletApiOperation.GetBalances, {}); + t.assertAmountEquals(bal.balances[0].pendingOutgoing, "TESTKUDOS:5.49"); + } + await w1.walletClient.call(WalletApiOperation.TestingWaitRefreshesFinal, {}); const resp = await w1.walletClient.call( diff --git a/packages/taler-wallet-core/src/balance.ts b/packages/taler-wallet-core/src/balance.ts @@ -70,6 +70,7 @@ import { ExchangeEntryDbRecordStatus, OPERATION_STATUS_ACTIVE_FIRST, OPERATION_STATUS_ACTIVE_LAST, + PeerPushDebitStatus, RefreshGroupRecord, RefreshOperationStatus, WalletDbReadOnlyTransaction, @@ -295,6 +296,7 @@ export async function getBalancesInsideTransaction( "withdrawalGroups", "globalCurrencyAuditors", "globalCurrencyExchanges", + "peerPushDebit", ] >, ): Promise<BalancesResponse> { @@ -399,6 +401,27 @@ export async function getBalancesInsideTransaction( ); }); + await tx.peerPushDebit.indexes.byStatus + .iter(keyRangeActive) + .forEachAsync(async (ppdRecord) => { + switch (ppdRecord.status) { + case PeerPushDebitStatus.AbortingDeletePurse: + case PeerPushDebitStatus.SuspendedAbortingDeletePurse: + case PeerPushDebitStatus.SuspendedReady: + case PeerPushDebitStatus.SuspendedReady: + case PeerPushDebitStatus.PendingCreatePurse: + case PeerPushDebitStatus.SuspendedCreatePurse: { + const currency = Amounts.currencyOf(ppdRecord.amount); + await balanceStore.addPendingOutgoing( + currency, + ppdRecord.exchangeBaseUrl, + ppdRecord.totalCost, + ); + break; + } + } + }); + await tx.depositGroups.indexes.byStatus .iter(keyRangeActive) .forEachAsync(async (dgRecord) => { @@ -460,6 +483,7 @@ export async function getBalances( "purchases", "refreshGroups", "withdrawalGroups", + "peerPushDebit", ], async (tx) => { return getBalancesInsideTransaction(wex, tx);