gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated: Add error when coin


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: Add error when coins are not sufficient to pay a refund back.
Date: Tue, 13 Jun 2017 21:06:09 +0200

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

marcello pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new f432e22  Add error when coins are not sufficient to pay a refund back.
f432e22 is described below

commit f432e22ff0e34ae0573cee58b783adbfbc54d1ec
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Jun 13 21:05:32 2017 +0200

    Add error when coins are not sufficient to pay a refund
    back.
---
 src/backenddb/plugin_merchantdb_postgres.c | 15 +++++++++++++++
 src/backenddb/test_merchantdb.c            | 23 ++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index dee509c..d51f401 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -2039,6 +2039,9 @@ process_deposits_cb (void *cls,
 
   }
 
+  /**
+   * Check if the refund is bigger than the previous awarded.
+   */
   if (-1 == TALER_amount_cmp (&attempted_refund,
                               &previous_refund))
   {
@@ -2053,6 +2056,18 @@ process_deposits_cb (void *cls,
   }
 
   /**
+   * Check if all the refund has been allocated
+   */
+  if ( (0 != ctx->refund->value) ||
+       (0 != ctx->refund->fraction) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "This refund is bigger than the coins capacity\n");
+    ctx->err = GNUNET_NO;
+    return;
+  }
+
+  /**
    * NOTE: we don't check if all the refund has been covered.
    * Although this should be checked, it's safe to assume yes,
    * as the business will never issue a refund bigger than the
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index d1ddaa4..0c9b455 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -136,6 +136,12 @@ static struct TALER_Amount little_refund_amount;
 static struct TALER_Amount right_second_refund_amount;
 
 /**
+ * Refund amount meant to raise an error because the
+ * contract's coins aren't enough to pay it back
+ */
+static struct TALER_Amount too_big_refund_amount;
+
+/**
  * Public key of the coin.  Set to some random value.
  */
 static struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -394,7 +400,7 @@ run (void *cls)
   refund_deadline = GNUNET_TIME_absolute_get();
   GNUNET_TIME_round_abs (&refund_deadline);
   GNUNET_assert (GNUNET_OK ==
-                 TALER_string_to_amount (CURRENCY ":2",
+                 TALER_string_to_amount (CURRENCY ":5",
                                          &amount_with_fee));
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount (CURRENCY ":0.000010",
@@ -409,8 +415,11 @@ run (void *cls)
                  TALER_string_to_amount (CURRENCY ":1",
                                          &little_refund_amount));
   GNUNET_assert (GNUNET_OK ==
-                 TALER_string_to_amount (CURRENCY ":4",
+                 TALER_string_to_amount (CURRENCY ":3",
                                          &right_second_refund_amount));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount (CURRENCY ":30",
+                                         &too_big_refund_amount));
   RND_BLK (&coin_pub);
   deposit_proof = json_object ();
   GNUNET_assert (0 ==
@@ -578,7 +587,15 @@ run (void *cls)
                                                 &h_contract_terms,
                                                 &merchant_pub,
                                                 &right_second_refund_amount,
-                                                "make refund testing fail"));
+                                                "right refund increase"));
+
+  FAILIF (GNUNET_NO !=
+          plugin->increase_refund_for_contract (plugin->cls,
+                                                &h_contract_terms,
+                                                &merchant_pub,
+                                                &too_big_refund_amount,
+                                                "make refund testing fail due"
+                                                " to too big refund amount"));
 
   if (-1 == result)
     result = 0;

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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