gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (96995103 -> 1c0cce3f)


From: gnunet
Subject: [taler-wallet-core] branch master updated (96995103 -> 1c0cce3f)
Date: Mon, 12 Jul 2021 15:55:35 +0200

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

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

    from 96995103 refactored ui add provider
     new 0b854299 formatting
     new 2a48caa3 improve error messages in DB transactions
     new 2667d741 add test for zero-value payments
     new 1c0cce3f tolerate zero-value payments

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ...payment-forgettable.ts => test-payment-zero.ts} | 71 ++++++++++++----------
 .../src/integrationtests/testrunner.ts             |  4 +-
 .../src/operations/backup/import.ts                | 11 +++-
 packages/taler-wallet-core/src/operations/pay.ts   |  3 +-
 packages/taler-wallet-core/src/util/query.ts       | 21 ++++++-
 5 files changed, 69 insertions(+), 41 deletions(-)
 copy 
packages/taler-wallet-cli/src/integrationtests/{test-payment-forgettable.ts => 
test-payment-zero.ts} (57%)

diff --git 
a/packages/taler-wallet-cli/src/integrationtests/test-payment-forgettable.ts 
b/packages/taler-wallet-cli/src/integrationtests/test-payment-zero.ts
similarity index 57%
copy from 
packages/taler-wallet-cli/src/integrationtests/test-payment-forgettable.ts
copy to packages/taler-wallet-cli/src/integrationtests/test-payment-zero.ts
index 49ffadc9..3ab12e39 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-payment-forgettable.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-zero.ts
@@ -17,6 +17,7 @@
 /**
  * Imports.
  */
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
 import { GlobalTestState } from "./harness";
 import {
   createSimpleTestkudosEnvironment,
@@ -25,9 +26,10 @@ import {
 } from "./helpers";
 
 /**
- * Run test for payment with a contract that has forgettable fields.
+ * Run test for a payment for a "free" order with
+ * an amount of zero.
  */
-export async function runPaymentForgettableTest(t: GlobalTestState) {
+export async function runPaymentZeroTest(t: GlobalTestState) {
   // Set up test environment
 
   const {
@@ -37,45 +39,48 @@ export async function runPaymentForgettableTest(t: 
GlobalTestState) {
     merchant,
   } = await createSimpleTestkudosEnvironment(t);
 
-  // Withdraw digital cash into the wallet.
+  // First, make a "free" payment when we don't even have
+  // any money in the
 
+  // Withdraw digital cash into the wallet.
   await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:20" });
 
-  {
-    const order = {
-      summary: "Buy me!",
-      amount: "TESTKUDOS:5",
+  await wallet.runUntilDone();
+
+  await makeTestPayment(t, {
+    wallet,
+    merchant,
+    order: {
+      summary: "I am free!",
+      amount: "TESTKUDOS:0",
       fulfillment_url: "taler://fulfillment-success/thx",
-      extra: {
-        foo: { bar: "baz" },
-        $forgettable: {
-          foo: "gnu",
-        },
-      },
-    };
-
-    await makeTestPayment(t, { wallet, merchant, order });
-  }
+    },
+  });
 
-  console.log("testing with forgettable field without hash");
+  await wallet.runUntilDone();
 
-  {
-    const order = {
-      summary: "Buy me!",
-      amount: "TESTKUDOS:5",
+  // Now try to "pay" for something where we don't even have the
+  // currency.
+  await makeTestPayment(t, {
+    wallet,
+    merchant,
+    order: {
+      summary: "I am also free!",
+      amount: "BLURP:0",
       fulfillment_url: "taler://fulfillment-success/thx",
-      extra: {
-        foo: { bar: "baz" },
-        $forgettable: {
-          foo: true,
-        },
-      },
-    };
-
-    await makeTestPayment(t, { wallet, merchant, order });
-  }
+    },
+  });
 
   await wallet.runUntilDone();
+
+  const transactions = await wallet.client.call(
+    WalletApiOperation.GetTransactions,
+    {},
+  );
+
+  for (const tr of transactions.transactions) {
+    t.assertDeepEqual(tr.pending, false);
+  }
 }
 
-runPaymentForgettableTest.suites = ["wallet", "merchant"];
+runPaymentZeroTest.suites = ["wallet"];
diff --git a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts 
b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
index 82f4c24a..8162eccd 100644
--- a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
@@ -73,6 +73,7 @@ import { runWalletBackupBasicTest } from 
"./test-wallet-backup-basic";
 import { runMerchantInstancesDeleteTest } from 
"./test-merchant-instances-delete";
 import { runWalletBackupDoublespendTest } from 
"./test-wallet-backup-doublespend";
 import { runPaymentForgettableTest } from "./test-payment-forgettable.js";
+import { runPaymentZeroTest } from "./test-payment-zero.js";
 
 /**
  * Test runner.
@@ -118,6 +119,7 @@ const allTests: TestMainFunction[] = [
   runPaymentTest,
   runPaymentDemoTest,
   runPaymentTransientTest,
+  runPaymentZeroTest,
   runPayPaidTest,
   runPaywallFlowTest,
   runRefundAutoTest,
@@ -150,7 +152,7 @@ export interface TestInfo {
 function updateCurrentSymlink(testDir: string): void {
   const currLink = path.join(
     os.tmpdir(),
-    `taler-integrationtests-${os.userInfo().username}-current`
+    `taler-integrationtests-${os.userInfo().username}-current`,
   );
   try {
     fs.unlinkSync(currLink);
diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts 
b/packages/taler-wallet-core/src/operations/backup/import.ts
index 28bd5ec0..e2064a80 100644
--- a/packages/taler-wallet-core/src/operations/backup/import.ts
+++ b/packages/taler-wallet-core/src/operations/backup/import.ts
@@ -48,7 +48,10 @@ import {
 } from "../../db.js";
 import { PayCoinSelection } from "../../util/coinSelection.js";
 import { j2s } from "@gnu-taler/taler-util";
-import { checkDbInvariant, checkLogicInvariant } from 
"../../util/invariants.js";
+import {
+  checkDbInvariant,
+  checkLogicInvariant,
+} from "../../util/invariants.js";
 import { Logger } from "@gnu-taler/taler-util";
 import { initRetryInfo } from "../../util/retries.js";
 import { InternalWalletState } from "../../common.js";
@@ -244,7 +247,9 @@ export async function importBackup(
         });
       }
 
-      const tombstoneSet = new Set(backupBlob.tombstones);
+      const tombstoneSet = new Set(
+        (await tx.tombstones.iter().toArray()).map((x) => x.id),
+      );
 
       // FIXME:  Validate that the "details pointer" is correct
 
@@ -877,7 +882,7 @@ export async function importBackup(
       // importing things that are tombstoned,
       // but we do tombstone processing last just to be sure.
 
-      for (const tombstone of backupBlob.tombstones) {
+      for (const tombstone of tombstoneSet) {
         const [type, ...rest] = tombstone.split(":");
         if (type === TombstoneTag.DeleteDepositGroup) {
           await tx.depositGroups.delete(rest[0]);
diff --git a/packages/taler-wallet-core/src/operations/pay.ts 
b/packages/taler-wallet-core/src/operations/pay.ts
index 33d3bc83..fed61428 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -145,7 +145,8 @@ export async function getTotalPaymentCost(
         costs.push(pcs.coinContributions[i]);
         costs.push(refreshCost);
       }
-      return Amounts.sum(costs).amount;
+      const zero = Amounts.getZero(pcs.paymentAmount.currency);
+      return Amounts.sum([zero, ...costs]).amount;
     });
 }
 
diff --git a/packages/taler-wallet-core/src/util/query.ts 
b/packages/taler-wallet-core/src/util/query.ts
index c7c08b47..b76bf6b6 100644
--- a/packages/taler-wallet-core/src/util/query.ts
+++ b/packages/taler-wallet-core/src/util/query.ts
@@ -87,6 +87,15 @@ interface CursorValueResult<T> {
   value: T;
 }
 
+class TransactionAbortedError extends Error {
+  constructor(m: string) {
+    super(m);
+
+    // Set the prototype explicitly.
+    Object.setPrototypeOf(this, TransactionAbortedError.prototype);
+  }
+}
+
 class ResultStream<T> {
   private currentPromise: Promise<void>;
   private gotCursorEnd = false;
@@ -396,6 +405,7 @@ function runTx<Arg, Res>(
   return new Promise((resolve, reject) => {
     let funResult: any = undefined;
     let gotFunResult = false;
+    let transactionException: any = undefined;
     tx.oncomplete = () => {
       // This is a fatal error: The transaction completed *before*
       // the transaction function returned.  Likely, the transaction
@@ -416,12 +426,16 @@ function runTx<Arg, Res>(
       logger.error(`${stack}`);
     };
     tx.onabort = () => {
+      let msg: string;
       if (tx.error) {
-        logger.error("Transaction aborted with error:", tx.error);
+        msg = `Transaction aborted (transaction error): ${tx.error}`;
+      } else if (transactionException !== undefined) {
+        msg = `Transaction aborted (exception thrown): 
${transactionException}`;
       } else {
-        logger.error("Transaction aborted (no error)");
+        msg = "Transaction aborted (no DB error)";
       }
-      reject(TransactionAbort);
+      logger.error(msg);
+      reject(new TransactionAbortedError(msg));
     };
     const resP = Promise.resolve().then(() => f(arg));
     resP
@@ -433,6 +447,7 @@ function runTx<Arg, Res>(
         if (e == TransactionAbort) {
           logger.trace("aborting transaction");
         } else {
+          transactionException = e;
           console.error("Transaction failed:", e);
           console.error(stack);
           tx.abort();

-- 
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]