taler-typescript-core

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

commit aab96ecf602d51fb682aa37d2182f9838cf27393
parent 937d9204e6c66bdc13e7b770a125d008bdfc6587
Author: Florian Dold <florian@dold.me>
Date:   Tue, 23 Jan 2024 23:50:36 +0100

wallet-core: fix getTransactionById for refreshes, test it

Fixes bugs.taler.net/n/8234

Diffstat:
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 2++
Mpackages/taler-wallet-core/src/operations/transactions.ts | 38+++++++++++++++++++++++++++-----------
2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -100,6 +100,7 @@ import { runPaymentDeletedTest } from "./test-payment-deleted.js"; import { runWithdrawalNotifyBeforeTxTest } from "./test-withdrawal-notify-before-tx.js"; import { runWalletDd48Test } from "./test-wallet-dd48.js"; import { runMultiExchangeTest } from "./test-multiexchange.js"; +import { runWalletRefreshTest } from "./test-wallet-refresh.js"; /** * Test runner. @@ -189,6 +190,7 @@ const allTests: TestMainFunction[] = [ runPaymentDeletedTest, runWalletDd48Test, runCurrencyScopeTest, + runWalletRefreshTest, ]; export interface TestRunSpec { diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts @@ -280,8 +280,21 @@ export async function getTransactionById( } case TransactionType.Refresh: { - // FIXME: We should return info about the refresh here! - throw Error(`no tx for refresh`); + // FIXME: We should return info about the refresh here!; + const refreshGroupId = parsedTx.refreshGroupId; + return await ws.db.runReadOnlyTx( + ["refreshGroups", "operationRetries"], + async (tx) => { + const refreshGroupRec = await tx.refreshGroups.get(refreshGroupId); + if (!refreshGroupRec) { + throw Error("not found"); + } + const retries = await tx.operationRetries.get( + TaskIdentifiers.forRefresh(refreshGroupRec), + ); + return buildTransactionForRefresh(refreshGroupRec, retries); + }, + ); } case TransactionType.Reward: { @@ -522,7 +535,7 @@ function buildTransactionForPeerPullCredit( const silentWithdrawalErrorForInvoice = wsrOrt?.lastError && wsrOrt.lastError.code === - TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE && + TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE && Object.values(wsrOrt.lastError.errorsPerCoin ?? {}).every((e) => { return ( e.code === TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR && @@ -552,10 +565,10 @@ function buildTransactionForPeerPullCredit( kycUrl: pullCredit.kycUrl, ...(wsrOrt?.lastError ? { - error: silentWithdrawalErrorForInvoice - ? undefined - : wsrOrt.lastError, - } + error: silentWithdrawalErrorForInvoice + ? undefined + : wsrOrt.lastError, + } : {}), }; } @@ -770,7 +783,9 @@ function buildTransactionForRefresh( txState: computeRefreshTransactionState(refreshGroupRecord), txActions: computeRefreshTransactionActions(refreshGroupRecord), refreshReason: refreshGroupRecord.reason, - amountEffective: Amounts.stringify(Amounts.sub(outputAmount, inputAmount).amount), + amountEffective: Amounts.stringify( + Amounts.sub(outputAmount, inputAmount).amount, + ), amountRaw: Amounts.stringify( Amounts.zeroOfCurrency(refreshGroupRecord.currency), ), @@ -960,9 +975,10 @@ export async function getWithdrawalTransactionByUri( x.operationRetries, ]) .runReadWrite(async (tx) => { - const withdrawalGroupRecord = await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get( - request.talerWithdrawUri, - ); + const withdrawalGroupRecord = + await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get( + request.talerWithdrawUri, + ); if (!withdrawalGroupRecord) { return undefined;