gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (cde4d13d -> 7863bcbc)


From: gnunet
Subject: [taler-wallet-core] branch master updated (cde4d13d -> 7863bcbc)
Date: Sun, 06 Sep 2020 14:47:37 +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 cde4d13d fix outdated test case
     new c0861f06 handle permanent refund failure
     new 7863bcbc add integration test for permanent refund failure

The 2 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:
 packages/taler-integrationtests/src/harness.ts     | 16 ++++--
 .../src/{test-refund.ts => test-refund-gone.ts}    | 36 +++++++++++--
 .../taler-wallet-core/src/operations/refund.ts     | 60 ++++++++++++++++++++--
 packages/taler-wallet-core/src/types/talerTypes.ts |  4 +-
 4 files changed, 103 insertions(+), 13 deletions(-)
 copy packages/taler-integrationtests/src/{test-refund.ts => 
test-refund-gone.ts} (76%)

diff --git a/packages/taler-integrationtests/src/harness.ts 
b/packages/taler-integrationtests/src/harness.ts
index cc5ffa16..d974bdd0 100644
--- a/packages/taler-integrationtests/src/harness.ts
+++ b/packages/taler-integrationtests/src/harness.ts
@@ -899,10 +899,20 @@ export class ExchangeService implements 
ExchangeServiceInterface {
   }
 
   async runWirewatchOnce() {
-    await sh(
+    await runCommand(
+      this.globalState,
+      `exchange-${this.name}-wirewatch-once`,
+      "taler-exchange-wirewatch",
+      [...this.timetravelArgArr, "-c", this.configFilename, "-t"],
+    );
+  }
+
+  async runAggregatorOnce() {
+    await runCommand(
       this.globalState,
-      "wirewatch-test",
-      `taler-exchange-wirewatch ${this.timetravelArg} -c 
'${this.configFilename}' -t`,
+      `exchange-${this.name}-aggregator-once`,
+      "taler-exchange-aggregator",
+      [...this.timetravelArgArr, "-c", this.configFilename, "-t"],
     );
   }
 
diff --git a/packages/taler-integrationtests/src/test-refund.ts 
b/packages/taler-integrationtests/src/test-refund-gone.ts
similarity index 76%
copy from packages/taler-integrationtests/src/test-refund.ts
copy to packages/taler-integrationtests/src/test-refund-gone.ts
index bda609c9..764d5c28 100644
--- a/packages/taler-integrationtests/src/test-refund.ts
+++ b/packages/taler-integrationtests/src/test-refund-gone.ts
@@ -18,7 +18,17 @@
  * Imports.
  */
 import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
-import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
+import {
+  createSimpleTestkudosEnvironment,
+  withdrawViaBank,
+  applyTimeTravel,
+} from "./helpers";
+import {
+  durationFromSpec,
+  timestampAddDuration,
+  getTimestampNow,
+  timestampTruncateToSecond,
+} from "taler-wallet-core";
 
 /**
  * Run test for basic, bank-integrated withdrawal.
@@ -44,7 +54,16 @@ runTest(async (t: GlobalTestState) => {
       summary: "Buy me!",
       amount: "TESTKUDOS:5",
       fulfillment_url: "taler://fulfillment-success/thx",
+      pay_deadline: timestampTruncateToSecond(
+        timestampAddDuration(
+          getTimestampNow(),
+          durationFromSpec({
+            minutes: 10,
+          }),
+        ),
+      ),
     },
+    refund_delay: durationFromSpec({ minutes: 1 }),
   });
 
   let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, 
{
@@ -74,6 +93,12 @@ runTest(async (t: GlobalTestState) => {
 
   t.assertTrue(orderStatus.order_status === "paid");
 
+  console.log(orderStatus);
+
+  await applyTimeTravel(durationFromSpec({ hours: 1 }), { exchange, wallet });
+
+  await exchange.runAggregatorOnce();
+
   const ref = await MerchantPrivateApi.giveRefund(merchant, {
     amount: "TESTKUDOS:5",
     instance: "default",
@@ -83,15 +108,16 @@ runTest(async (t: GlobalTestState) => {
 
   console.log(ref);
 
-  let r = await wallet.apiRequest("applyRefund", {
+  let rr = await wallet.applyRefund({
     talerRefundUri: ref.talerRefundUri,
   });
-  t.assertTrue(r.type === "response");
-  console.log(r);
+
+  t.assertAmountEquals(rr.amountRefundGone, "TESTKUDOS:5");
+  console.log(rr);
 
   await wallet.runUntilDone();
 
-  r = await wallet.apiRequest("getBalances", {});
+  let r = await wallet.apiRequest("getBalances", {});
   console.log(JSON.stringify(r, undefined, 2));
 
   r = await wallet.apiRequest("getTransactions", {});
diff --git a/packages/taler-wallet-core/src/operations/refund.ts 
b/packages/taler-wallet-core/src/operations/refund.ts
index 373e17a1..0c89e524 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -47,8 +47,6 @@ import {
   MerchantCoinRefundStatus,
   MerchantCoinRefundSuccessStatus,
   MerchantCoinRefundFailureStatus,
-  codecForMerchantOrderStatusPaid,
-  AmountString,
   codecForMerchantOrderRefundPickupResponse,
 } from "../types/talerTypes";
 import { guardOperationException } from "./errors";
@@ -202,6 +200,56 @@ async function storePendingRefund(
   };
 }
 
+async function storeFailedRefund(
+  tx: TransactionHandle,
+  p: PurchaseRecord,
+  r: MerchantCoinRefundFailureStatus,
+): Promise<void> {
+  const refundKey = getRefundKey(r);
+
+  const coin = await tx.get(Stores.coins, r.coin_pub);
+  if (!coin) {
+    console.warn("coin not found, can't apply refund");
+    return;
+  }
+  const denom = await tx.getIndexed(
+    Stores.denominations.denomPubHashIndex,
+    coin.denomPubHash,
+  );
+
+  if (!denom) {
+    throw Error("inconsistent database");
+  }
+
+  const allDenoms = await tx
+    .iterIndexed(
+      Stores.denominations.exchangeBaseUrlIndex,
+      coin.exchangeBaseUrl,
+    )
+    .toArray();
+
+  const amountLeft = Amounts.sub(
+    Amounts.add(coin.currentAmount, Amounts.parseOrThrow(r.refund_amount))
+      .amount,
+    denom.feeRefund,
+  ).amount;
+
+  const totalRefreshCostBound = getTotalRefreshCost(
+    allDenoms,
+    denom,
+    amountLeft,
+  );
+
+  p.refunds[refundKey] = {
+    type: RefundState.Failed,
+    obtainedTime: getTimestampNow(),
+    executionTime: r.execution_time,
+    refundAmount: Amounts.parseOrThrow(r.refund_amount),
+    refundFee: denom.feeRefund,
+    totalRefreshCostBound,
+  };
+}
+
 async function acceptRefunds(
   ws: InternalWalletState,
   proposalId: string,
@@ -232,6 +280,10 @@ async function acceptRefunds(
         const refundKey = getRefundKey(refundStatus);
         const existingRefundInfo = p.refunds[refundKey];
 
+        const isPermanentFailure =
+          refundStatus.type === "failure" &&
+          refundStatus.exchange_status === 410;
+
         // Already failed.
         if (existingRefundInfo?.type === RefundState.Failed) {
           continue;
@@ -244,7 +296,7 @@ async function acceptRefunds(
 
         // Still pending.
         if (
-          refundStatus.type === "failure" &&
+          refundStatus.type === "failure" && !isPermanentFailure &&
           existingRefundInfo?.type === RefundState.Pending
         ) {
           continue;
@@ -254,6 +306,8 @@ async function acceptRefunds(
 
         if (refundStatus.type === "success") {
           await applySuccessfulRefund(tx, p, refreshCoinsMap, refundStatus);
+        } else if (isPermanentFailure) {
+          await storeFailedRefund(tx, p, refundStatus);
         } else {
           await storePendingRefund(tx, p, refundStatus);
         }
diff --git a/packages/taler-wallet-core/src/types/talerTypes.ts 
b/packages/taler-wallet-core/src/types/talerTypes.ts
index 0b4afda1..c944f156 100644
--- a/packages/taler-wallet-core/src/types/talerTypes.ts
+++ b/packages/taler-wallet-core/src/types/talerTypes.ts
@@ -1325,13 +1325,13 @@ export const codecForMerchantCoinRefundFailureStatus = 
(): Codec<
   buildCodecForObject<MerchantCoinRefundFailureStatus>()
     .property("type", codecForConstString("failure"))
     .property("coin_pub", codecForString())
-    .property("exchange_status", codecForConstNumber(200))
+    .property("exchange_status", codecForNumber())
     .property("rtransaction_id", codecForNumber())
     .property("refund_amount", codecForString())
     .property("exchange_code", codecOptional(codecForNumber()))
     .property("exchange_reply", codecOptional(codecForAny()))
     .property("execution_time", codecForTimestamp)
-    .build("MerchantCoinRefundSuccessStatus");
+    .build("MerchantCoinRefundFailureStatus");
 
 export const codecForMerchantCoinRefundStatus = (): Codec<
   MerchantCoinRefundStatus

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