gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core,harness: get p2p


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core,harness: get p2p tests to pass again
Date: Wed, 30 Aug 2023 09:54:50 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 557213f9c wallet-core,harness: get p2p tests to pass again
557213f9c is described below

commit 557213f9c4fd834fadb189799073dc64cdb00a07
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Aug 30 09:54:47 2023 +0200

    wallet-core,harness: get p2p tests to pass again
---
 .../src/integrationtests/test-peer-to-peer-push.ts |  2 +
 .../taler-wallet-core/src/operations/testing.ts    | 54 ++++++++++++++++++++++
 .../taler-wallet-core/src/util/coinSelection.ts    |  3 ++
 packages/taler-wallet-core/src/wallet-api-types.ts | 11 +++++
 packages/taler-wallet-core/src/wallet.ts           |  3 ++
 5 files changed, 73 insertions(+)

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 4817b572a..26f70a5cc 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
@@ -89,6 +89,8 @@ export async function runPeerToPeerPushTest(t: 
GlobalTestState) {
     console.log(resp);
   }
 
+  await w1.walletClient.call(WalletApiOperation.TestingWaitRefreshesFinal, {});
+
   const resp = await w1.walletClient.call(
     WalletApiOperation.InitiatePeerPushDebit,
     {
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",
 }
 
@@ -976,6 +977,15 @@ export type TestingWaitTransactionsFinal = {
   response: EmptyObject;
 };
 
+/**
+ * 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);
   }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]