gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -fix reserve history, include in


From: gnunet
Subject: [taler-exchange] branch master updated: -fix reserve history, include in tests
Date: Mon, 30 May 2022 19:31:55 +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 d55b093d -fix reserve history, include in tests
d55b093d is described below

commit d55b093de8d5a39d7796ca68a4990ee4e9669c16
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 30 19:31:49 2022 +0200

    -fix reserve history, include in tests
---
 src/exchange/taler-exchange-httpd_responses.c |  2 +-
 src/exchangedb/plugin_exchangedb_postgres.c   |  6 ++---
 src/include/taler_exchange_service.h          | 10 --------
 src/lib/exchange_api_common.c                 |  5 ++--
 src/lib/exchange_api_reserves_history.c       | 35 +++++++++++++++++++--------
 src/testing/test_exchange_api.c               | 33 +++++++++++++++++++------
 src/testing/testing_api_cmd_batch_withdraw.c  |  2 ++
 src/testing/testing_api_cmd_reserve_history.c | 28 ++++++++++++++-------
 src/testing/testing_api_cmd_reserve_status.c  | 21 +++++++++++-----
 src/testing/testing_api_helpers_exchange.c    |  1 +
 src/util/wallet_signatures.c                  |  2 +-
 11 files changed, 96 insertions(+), 49 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_responses.c 
b/src/exchange/taler-exchange-httpd_responses.c
index afbf2476..40e702bd 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -820,7 +820,7 @@ TEH_RESPONSE_compile_reserve_history (
                                             &history->reserve_sig),
                 GNUNET_JSON_pack_timestamp ("request_timestamp",
                                             history->request_timestamp),
-                TALER_JSON_pack_amount ("history_fee",
+                TALER_JSON_pack_amount ("amount",
                                         &history->history_fee))))
         {
           GNUNET_break (0);
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 77b20051..b2a72764 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -6315,9 +6315,9 @@ add_history_requests (void *cls,
       }
     }
     GNUNET_assert (0 <=
-                   TALER_amount_subtract (&rhc->balance_out,
-                                          &rhc->balance_out,
-                                          &history->history_fee));
+                   TALER_amount_add (&rhc->balance_out,
+                                     &rhc->balance_out,
+                                     &history->history_fee));
     history->reserve_pub = *rhc->reserve_pub;
     tail = append_rh (rhc);
     tail->type = TALER_EXCHANGEDB_RO_HISTORY_REQUEST;
diff --git a/src/include/taler_exchange_service.h 
b/src/include/taler_exchange_service.h
index 6ff9ce5b..2577aaf3 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -1814,16 +1814,6 @@ struct TALER_EXCHANGE_ReserveHistory
        */
       unsigned int history_len;
 
-      /**
-       * KYC passed?
-       */
-      bool kyc_ok;
-
-      /**
-       * KYC required to withdraw?
-       */
-      bool kyc_required;
-
     } ok;
 
   } details;
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index 92bfee6e..cfab9a30 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -476,8 +476,6 @@ parse_history (struct TALER_EXCHANGE_ReserveHistoryEntry 
*rh,
   struct GNUNET_JSON_Specification history_spec[] = {
     GNUNET_JSON_spec_fixed_auto ("reserve_sig",
                                  &rh->details.history_details.reserve_sig),
-    TALER_JSON_spec_amount_any ("history_fee",
-                                &rh->amount),
     GNUNET_JSON_spec_timestamp ("request_timestamp",
                                 
&rh->details.history_details.request_timestamp),
     GNUNET_JSON_spec_end ()
@@ -578,6 +576,9 @@ TALER_EXCHANGE_parse_reserve_history (
                            NULL, NULL))
     {
       GNUNET_break_op (0);
+      json_dumpf (transaction,
+                  stderr,
+                  JSON_INDENT (2));
       return GNUNET_SYSERR;
     }
     rh->amount = amount;
diff --git a/src/lib/exchange_api_reserves_history.c 
b/src/lib/exchange_api_reserves_history.c
index 2925b025..1d3891c2 100644
--- a/src/lib/exchange_api_reserves_history.c
+++ b/src/lib/exchange_api_reserves_history.c
@@ -110,10 +110,6 @@ handle_reserves_history_ok (struct 
TALER_EXCHANGE_ReservesHistoryHandle *rsh,
   struct GNUNET_JSON_Specification spec[] = {
     TALER_JSON_spec_amount_any ("balance",
                                 &rs.details.ok.balance),
-    GNUNET_JSON_spec_bool ("kyc_passed",
-                           &rs.details.ok.kyc_ok),
-    GNUNET_JSON_spec_bool ("kyc_required",
-                           &rs.details.ok.kyc_required),
     GNUNET_JSON_spec_json ("history",
                            &history),
     GNUNET_JSON_spec_end ()
@@ -197,6 +193,7 @@ handle_reserves_history_finished (void *cls,
         handle_reserves_history_ok (rsh,
                                     j))
     {
+      GNUNET_break_op (0);
       rs.hr.http_status = 0;
       rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
     }
@@ -221,6 +218,11 @@ handle_reserves_history_finished (void *cls,
     rs.hr.ec = TALER_JSON_get_error_code (j);
     rs.hr.hint = TALER_JSON_get_error_hint (j);
     break;
+  case MHD_HTTP_CONFLICT:
+    /* Insufficient balance to inquire for reserve history */
+    rs.hr.ec = TALER_JSON_get_error_code (j);
+    rs.hr.hint = TALER_JSON_get_error_hint (j);
+    break;
   case MHD_HTTP_INTERNAL_SERVER_ERROR:
     /* Server had an internal issue; we should retry, but this API
        leaves this to the application */
@@ -306,10 +308,22 @@ TALER_EXCHANGE_reserves_history (
     return NULL;
   }
   keys = TALER_EXCHANGE_get_keys (exchange);
-  GNUNET_assert (NULL != keys);
+  if (NULL == keys)
+  {
+    GNUNET_break (0);
+    GNUNET_free (rsh->url);
+    GNUNET_free (rsh);
+    return NULL;
+  }
   gf = TALER_EXCHANGE_get_global_fee (keys,
                                       rsh->ts);
-  GNUNET_assert (NULL != gf);
+  if (NULL == gf)
+  {
+    GNUNET_break_op (0);
+    GNUNET_free (rsh->url);
+    GNUNET_free (rsh);
+    return NULL;
+  }
   TALER_wallet_reserve_history_sign (rsh->ts,
                                      &gf->fees.history,
                                      reserve_priv,
@@ -336,10 +350,11 @@ TALER_EXCHANGE_reserves_history (
     json_decref (history_obj);
   }
   ctx = TEAH_handle_to_context (exchange);
-  rsh->job = GNUNET_CURL_job_add (ctx,
-                                  eh,
-                                  &handle_reserves_history_finished,
-                                  rsh);
+  rsh->job = GNUNET_CURL_job_add2 (ctx,
+                                   eh,
+                                   rsh->post_ctx.headers,
+                                   &handle_reserves_history_finished,
+                                   rsh);
   return rsh;
 }
 
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c
index ea929460..f7318d64 100644
--- a/src/testing/test_exchange_api.c
+++ b/src/testing/test_exchange_api.c
@@ -565,8 +565,8 @@ run (void *cls,
                                MHD_HTTP_OK),
     CMD_EXEC_AGGREGATOR ("aggregation-attempt"),
 
-    TALER_TESTING_cmd_check_bank_empty
-      ("far-future-aggregation-b"),
+    TALER_TESTING_cmd_check_bank_empty (
+      "far-future-aggregation-b"),
 
     TALER_TESTING_cmd_end ()
   };
@@ -1136,14 +1136,14 @@ run (void *cls,
      * Move money to the exchange's bank account.
      */
     CMD_TRANSFER_TO_EXCHANGE ("create-batch-reserve-1",
-                              "EUR:6.02"),
+                              "EUR:6.03"),
     TALER_TESTING_cmd_reserve_poll ("poll-batch-reserve-1",
                                     "create-batch-reserve-1",
-                                    "EUR:6.02",
+                                    "EUR:6.03",
                                     GNUNET_TIME_UNIT_MINUTES,
                                     MHD_HTTP_OK),
     TALER_TESTING_cmd_check_bank_admin_transfer 
("check-create-batch-reserve-1",
-                                                 "EUR:6.02",
+                                                 "EUR:6.03",
                                                  bc.user42_payto,
                                                  bc.exchange_payto,
                                                  "create-batch-reserve-1"),
@@ -1166,11 +1166,19 @@ run (void *cls,
                                       "EUR:1",
                                       NULL),
     /**
-     * Check the reserve is depleted.
+     * Check the reserve is (almost) depleted.
      */
     TALER_TESTING_cmd_status ("status-batch-1",
                               "create-batch-reserve-1",
-                              "EUR:0",
+                              "EUR:0.01",
+                              MHD_HTTP_OK),
+    TALER_TESTING_cmd_reserve_history ("history-batch-1",
+                                       "create-batch-reserve-1",
+                                       "EUR:0",
+                                       MHD_HTTP_OK),
+    TALER_TESTING_cmd_status ("status-batch-2",
+                              "create-batch-reserve-1",
+                              "EUR:0.0",
                               MHD_HTTP_OK),
     /**
      * Spend the coins.
@@ -1240,6 +1248,17 @@ run (void *cls,
                                   
"payto://x-taler-bank/localhost/2?receiver-name=2",
                                   MHD_HTTP_NO_CONTENT,
                                   false),
+      TALER_TESTING_cmd_exec_offline_sign_global_fees (
+        "offline-sign-global-fees",
+        config_file,
+        "EUR:0.01",
+        "EUR:0.01",
+        "EUR:0.01",
+        "EUR:0.01",
+        GNUNET_TIME_UNIT_MINUTES,
+        GNUNET_TIME_UNIT_MINUTES,
+        GNUNET_TIME_UNIT_DAYS,
+        1),
       TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
                                                 config_file),
       TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
diff --git a/src/testing/testing_api_cmd_batch_withdraw.c 
b/src/testing/testing_api_cmd_batch_withdraw.c
index f135f5de..fb290f1e 100644
--- a/src/testing/testing_api_cmd_batch_withdraw.c
+++ b/src/testing/testing_api_cmd_batch_withdraw.c
@@ -429,6 +429,8 @@ batch_withdraw_traits (void *cls,
     TALER_TESTING_trait_end ()
   };
 
+  if (index >= ws->num_coins)
+    return GNUNET_NO;
   return TALER_TESTING_get_trait ((ws->expected_response_code == MHD_HTTP_OK)
                                   ? &traits[0]   /* we have reserve history */
                                   : &traits[1],  /* skip reserve history */
diff --git a/src/testing/testing_api_cmd_reserve_history.c 
b/src/testing/testing_api_cmd_reserve_history.c
index e63cca86..96a0a1de 100644
--- a/src/testing/testing_api_cmd_reserve_history.c
+++ b/src/testing/testing_api_cmd_reserve_history.c
@@ -114,8 +114,6 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
     {
       struct TALER_TESTING_Command *step = &(*bcmd)[i];
 
-      if (step == cur)
-        break; /* if *we* are in a batch, make sure not to analyze commands 
past 'now' */
       if (GNUNET_OK !=
           analyze_command (reserve_pub,
                            step,
@@ -128,10 +126,12 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
                     step->label);
         return GNUNET_SYSERR;
       }
+      if (step == cur)
+        break; /* if *we* are in a batch, make sure not to analyze commands 
past 'now' */
     }
     return GNUNET_OK;
   }
-  else
+
   {
     const struct TALER_ReservePublicKeyP *rp;
 
@@ -146,6 +146,7 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
     for (unsigned int j = 0; true; j++)
     {
       const struct TALER_EXCHANGE_ReserveHistoryEntry *he;
+      bool matched = false;
 
       if (GNUNET_OK !=
           TALER_TESTING_get_trait_reserve_history (cmd,
@@ -168,14 +169,18 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
                                              &history[i]))
         {
           found[i] = true;
-          return GNUNET_OK;
+          matched = true;
+          break;
         }
       }
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Command `%s' reserve history entry #%u not found\n",
-                  cmd->label,
-                  j);
-      return GNUNET_SYSERR;
+      if (! matched)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Command `%s' reserve history entry #%u not found\n",
+                    cmd->label,
+                    j);
+        return GNUNET_SYSERR;
+      }
     }
   }
 }
@@ -237,9 +242,13 @@ reserve_history_cb (void *cls,
   if (0 != TALER_amount_cmp (&eb,
                              &rs->details.ok.balance))
   {
+    GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected amount in reserve: %s\n",
                 TALER_amount_to_string (&rs->details.ok.balance));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Expected balance of: %s\n",
+                TALER_amount_to_string (&eb));
     TALER_TESTING_interpreter_fail (ss->is);
     return;
   }
@@ -351,6 +360,7 @@ history_traits (void *cls,
     /* history entry MUST be first due to response code logic below! */
     TALER_TESTING_make_trait_reserve_history (0,
                                               &hs->reserve_history),
+    TALER_TESTING_make_trait_reserve_pub (&hs->reserve_pub),
     TALER_TESTING_trait_end ()
   };
 
diff --git a/src/testing/testing_api_cmd_reserve_status.c 
b/src/testing/testing_api_cmd_reserve_status.c
index 9abd99f0..76639e49 100644
--- a/src/testing/testing_api_cmd_reserve_status.c
+++ b/src/testing/testing_api_cmd_reserve_status.c
@@ -138,6 +138,7 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
     for (unsigned int j = 0; true; j++)
     {
       const struct TALER_EXCHANGE_ReserveHistoryEntry *he;
+      bool matched = false;
 
       if (GNUNET_OK !=
           TALER_TESTING_get_trait_reserve_history (cmd,
@@ -159,14 +160,18 @@ analyze_command (const struct TALER_ReservePublicKeyP 
*reserve_pub,
                                              &history[i]))
         {
           found[i] = true;
-          return GNUNET_OK;
+          matched = true;
+          break;
         }
       }
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Command `%s' reserve history entry #%u not found\n",
-                  cmd->label,
-                  j);
-      return GNUNET_SYSERR;
+      if (! matched)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Command `%s' reserve history entry #%u not found\n",
+                    cmd->label,
+                    j);
+        return GNUNET_SYSERR;
+      }
     }
   }
 }
@@ -213,9 +218,13 @@ reserve_status_cb (void *cls,
   if (0 != TALER_amount_cmp (&eb,
                              &rs->details.ok.balance))
   {
+    GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected amount in reserve: %s\n",
                 TALER_amount_to_string (&rs->details.ok.balance));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Expected balance of: %s\n",
+                TALER_amount_to_string (&eb));
     TALER_TESTING_interpreter_fail (ss->is);
     return;
   }
diff --git a/src/testing/testing_api_helpers_exchange.c 
b/src/testing/testing_api_helpers_exchange.c
index c47a1c2f..d813021b 100644
--- a/src/testing/testing_api_helpers_exchange.c
+++ b/src/testing/testing_api_helpers_exchange.c
@@ -184,6 +184,7 @@ TALER_TESTING_exchange_db_reset (const char 
*config_filename)
                                   "taler-exchange-dbinit",
                                   "taler-exchange-dbinit",
                                   "-c", config_filename,
+                                  "-L", "WARNING",
                                   "-r",
                                   NULL);
   if (NULL == proc)
diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c
index 27a28256..9c566965 100644
--- a/src/util/wallet_signatures.c
+++ b/src/util/wallet_signatures.c
@@ -668,7 +668,7 @@ TALER_wallet_reserve_history_verify (
   TALER_amount_hton (&rhr.history_fee,
                      history_fee);
   return GNUNET_CRYPTO_eddsa_verify (
-    TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW,
+    TALER_SIGNATURE_WALLET_RESERVE_HISTORY,
     &rhr,
     &reserve_sig->eddsa_signature,
     &reserve_pub->eddsa_pub);

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