diff options
author | Florian Dold <florian@dold.me> | 2024-01-23 23:50:36 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-01-23 23:50:36 +0100 |
commit | aab96ecf602d51fb682aa37d2182f9838cf27393 (patch) | |
tree | 3547589991185170b0c771efbc1de753bfb2755d | |
parent | 937d9204e6c66bdc13e7b770a125d008bdfc6587 (diff) | |
download | wallet-core-aab96ecf602d51fb682aa37d2182f9838cf27393.tar.xz |
wallet-core: fix getTransactionById for refreshes, test it
Fixes bugs.taler.net/n/8234
-rw-r--r-- | packages/taler-harness/src/integrationtests/testrunner.ts | 2 | ||||
-rw-r--r-- | packages/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 index 1b4bdc218..35b179d87 100644 --- 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 index 74bc20320..89f756ae9 100644 --- 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; |