diff options
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/testing.ts | 54 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.ts | 3 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet-api-types.ts | 11 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 3 |
4 files changed, 71 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index aff92622a..1962c965c 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -29,6 +29,7 @@ import { TestPayResult, TransactionMajorState, TransactionMinorState, + TransactionType, WithdrawTestBalanceRequest, } from "@gnu-taler/taler-util"; import { @@ -498,6 +499,59 @@ export async function waitUntilDone(ws: InternalWalletState): Promise<void> { logger.info("done waiting until all transactions are in a final state"); } +export async function waitUntilRefreshesDone( + ws: InternalWalletState, +): Promise<void> { + logger.info("waiting until all refresh transactions are in a final state"); + ws.ensureTaskLoopRunning(); + let p: OpenedPromise<void> | undefined = undefined; + const cancelNotifs = ws.addNotificationListener((notif) => { + if (!p) { + return; + } + if (notif.type === NotificationType.TransactionStateTransition) { + switch (notif.newTxState.major) { + case TransactionMajorState.Pending: + case TransactionMajorState.Aborting: + break; + default: + p.resolve(); + } + } + }); + while (1) { + p = openPromise(); + const txs = await getTransactions(ws, { + includeRefreshes: true, + filterByState: "nonfinal", + }); + let finished = true; + for (const tx of txs.transactions) { + if (tx.type !== TransactionType.Refresh) { + continue; + } + switch (tx.txState.major) { + case TransactionMajorState.Pending: + case TransactionMajorState.Aborting: + case TransactionMajorState.Suspended: + case TransactionMajorState.SuspendedAborting: + finished = false; + logger.info( + `continuing waiting, ${tx.transactionId} in ${tx.txState.major}(${tx.txState.minor})`, + ); + break; + } + } + if (finished) { + break; + } + // Wait until transaction state changed + await p.promise; + } + cancelNotifs(); + logger.info("done waiting until all refreshes are in a final state"); +} + async function waitUntilPendingReady( ws: InternalWalletState, transactionId: string, diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index 39f667496..daba2ead5 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -945,6 +945,9 @@ function greedySelectPeer( denom.feeDeposit, ); tally.amountAcc = Amounts.add(tally.amountAcc, coinSpend).amount; + // Since this is a peer payment, there is no merchant to + // potentially cover the deposit fees. + tally.amountAcc = Amounts.sub(tally.amountAcc, denom.feeDeposit).amount; tally.depositFeesAcc = Amounts.add( tally.depositFeesAcc, denom.feeDeposit, diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 2a7c96ad1..06ccdf6f3 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -212,6 +212,7 @@ export enum WalletApiOperation { ApplyDevExperiment = "applyDevExperiment", ValidateIban = "validateIban", TestingWaitTransactionsFinal = "testingWaitTransactionsFinal", + TestingWaitRefreshesFinal = "testingWaitRefreshesFinal", GetScopedCurrencyInfo = "getScopedCurrencyInfo", } @@ -977,6 +978,15 @@ export type TestingWaitTransactionsFinal = { }; /** + * Wait until all refresh transactions are in a final state. + */ +export type TestingWaitRefreshesFinal = { + op: WalletApiOperation.TestingWaitRefreshesFinal; + request: EmptyObject; + response: EmptyObject; +}; + +/** * Set a coin as (un-)suspended. * Suspended coins won't be used for payments. */ @@ -1080,6 +1090,7 @@ export type WalletOperations = { [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; [WalletApiOperation.ValidateIban]: ValidateIbanOp; [WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal; + [WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal; [WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp; }; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index f05f11da4..194894e52 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -247,6 +247,7 @@ import { runIntegrationTest2, testPay, waitUntilDone, + waitUntilRefreshesDone, withdrawTestBalance, } from "./operations/testing.js"; import { @@ -1586,6 +1587,8 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( } case WalletApiOperation.TestingWaitTransactionsFinal: return await waitUntilDone(ws); + case WalletApiOperation.TestingWaitRefreshesFinal: + return await waitUntilRefreshesDone(ws); // default: // assertUnreachable(operation); } |