From 4b9cbe58025bf7082d0c79ee596200628b5d8c47 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 28 Mar 2024 12:27:26 +0100 Subject: wallet-core: count peer-push-debit towards pending outgoing balance Also check balance in the integration test. --- .../src/integrationtests/test-peer-to-peer-push.ts | 14 +++++++++++++ packages/taler-wallet-core/src/balance.ts | 24 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'packages') 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 index 5a1959cc6..21e0d384a 100644 --- 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 index 50996b8de..67ce73d41 100644 --- 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 { @@ -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); -- cgit v1.2.3