gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated: also test reserve h


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: also test reserve history after payback
Date: Mon, 10 Apr 2017 17:56:12 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 1fe26d5  also test reserve history after payback
1fe26d5 is described below

commit 1fe26d5d2e7094045fa5c319b047e901ff617d84
Author: Christian Grothoff <address@hidden>
AuthorDate: Mon Apr 10 17:59:33 2017 +0200

    also test reserve history after payback
---
 src/exchange-lib/exchange_api_reserve.c       | 11 ++++-
 src/exchange-lib/test_exchange_api.c          | 62 ++++++++++++++++++++++++++-
 src/exchange/taler-exchange-httpd_responses.c |  5 ++-
 3 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/src/exchange-lib/exchange_api_reserve.c 
b/src/exchange-lib/exchange_api_reserve.c
index 6dd4886..0ed8cca 100644
--- a/src/exchange-lib/exchange_api_reserve.c
+++ b/src/exchange-lib/exchange_api_reserve.c
@@ -274,7 +274,7 @@ parse_reserve_history (struct TALER_EXCHANGE_Handle 
*exchange,
                                      
&rhistory[off].details.payback_details.exchange_sig),
         GNUNET_JSON_spec_fixed_auto ("exchange_pub",
                                      
&rhistory[off].details.payback_details.exchange_pub),
-        GNUNET_JSON_spec_absolute_time ("timetamp",
+        GNUNET_JSON_spec_absolute_time ("timestamp",
                                         &timestamp),
         TALER_JSON_spec_amount ("amount",
                                 &rhistory[off].amount),
@@ -325,6 +325,15 @@ parse_reserve_history (struct TALER_EXCHANGE_Handle 
*exchange,
         GNUNET_break_op (0);
         return GNUNET_SYSERR;
       }
+      if (GNUNET_OK !=
+          TALER_amount_add (&total_in,
+                            &total_in,
+                            &rhistory[off].amount))
+      {
+        /* overflow in history already!? inconceivable! Bad exchange! */
+        GNUNET_break_op (0);
+        return GNUNET_SYSERR;
+      }
       /* end type==PAYBACK */
     }
     else if (0 == strcasecmp (type,
diff --git a/src/exchange-lib/test_exchange_api.c 
b/src/exchange-lib/test_exchange_api.c
index b4cd108..5b64e79 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -922,6 +922,38 @@ compare_reserve_withdraw_history (const struct 
TALER_EXCHANGE_ReserveHistory *h,
 
 
 /**
+ * Check if the given historic event @a h corresponds to the given
+ * command @a cmd.
+ *
+ * @param h event in history
+ * @param cmd an #OC_WITHDRAW_SIGN command
+ * @return #GNUNET_OK if they match, #GNUNET_SYSERR if not
+ */
+static int
+compare_reserve_payback_history (const struct TALER_EXCHANGE_ReserveHistory *h,
+                                 const struct Command *cmd)
+{
+  struct TALER_Amount amount;
+
+  if (TALER_EXCHANGE_RTT_PAYBACK != h->type)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount (cmd->details.payback.amount,
+                                         &amount));
+  if (0 != TALER_amount_cmp (&amount,
+                             &h->amount))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
+/**
  * Function called with the result of a /reserve/status request.
  *
  * @param cls closure with the interpreter state
@@ -945,6 +977,7 @@ reserve_status_cb (void *cls,
   struct InterpreterState *is = cls;
   struct Command *cmd = &is->commands[is->ip];
   struct Command *rel;
+  const struct Command *xrel;
   unsigned int i;
   unsigned int j;
   struct TALER_Amount amount;
@@ -1007,6 +1040,24 @@ reserve_status_cb (void *cls,
           j++;
         }
         break;
+      case OC_PAYBACK:
+        xrel = find_command (is,
+                             rel->details.payback.ref);
+        if (0 == strcmp (cmd->details.reserve_status.reserve_reference,
+                         xrel->details.reserve_withdraw.reserve_reference))
+        {
+          if ( (j >= history_length) ||
+               (GNUNET_OK !=
+                compare_reserve_payback_history (&history[j],
+                                                 rel)) )
+          {
+            GNUNET_break (0);
+            fail (is);
+            return;
+          }
+          j++;
+        }
+        break;
       default:
         /* unreleated, just skip */
         break;
@@ -1088,6 +1139,9 @@ reserve_withdraw_cb (void *cls,
   case MHD_HTTP_FORBIDDEN:
     /* nothing to check */
     break;
+  case MHD_HTTP_NOT_FOUND:
+    /* nothing to check */
+    break;
   default:
     /* Unsupported status code (by test harness) */
     GNUNET_break (0);
@@ -2666,7 +2720,7 @@ interpreter_run (void *cls)
       const struct Command *ref;
 
       ref = find_command (is,
-                          cmd->details.revoke.ref);
+                          cmd->details.payback.ref);
       GNUNET_assert (NULL != ref);
       cmd->details.payback.ph
         = TALER_EXCHANGE_payback (exchange,
@@ -3399,6 +3453,12 @@ run (void *cls)
       .expected_response_code = MHD_HTTP_OK,
       .details.payback.ref = "payback-withdraw-coin-1",
       .details.payback.amount = "EUR:5" },
+    /* Check the money is back with the reserve */
+    { .oc = OC_WITHDRAW_STATUS,
+      .label = "payback-reserve-status-1",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.reserve_status.reserve_reference = "payback-create-reserve-1",
+      .details.reserve_status.expected_balance = "EUR:5.00" },
 
 
     /* Fill reserve with EUR:2.02, as withdraw fee is 1 ct per config,
diff --git a/src/exchange/taler-exchange-httpd_responses.c 
b/src/exchange/taler-exchange-httpd_responses.c
index 111337c..eea5341 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -745,12 +745,13 @@ compile_reserve_history (const struct 
TALER_EXCHANGEDB_ReserveHistory *rh,
 
       GNUNET_assert (0 ==
                      json_array_append_new (json_history,
-                                            json_pack ("{s:s, s:o, s:o, s:o, 
s:o}",
+                                            json_pack ("{s:s, s:o, s:o, s:o, 
s:o, s:o}",
                                                        "type", "PAYBACK",
                                                        "exchange_pub", 
GNUNET_JSON_from_data_auto (&pub),
                                                        "exchange_sig", 
GNUNET_JSON_from_data_auto (&sig),
                                                        "timestamp", 
GNUNET_JSON_from_time_abs (payback->timestamp),
-                                                       "amount", 
TALER_JSON_from_amount (&payback->value))));
+                                                       "amount", 
TALER_JSON_from_amount (&payback->value),
+                                                       "details", 
GNUNET_JSON_from_data_auto (&pc))));
       break;
     case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
       value = pos->details.bank->amount;

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



reply via email to

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