gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: removed more old code, more test


From: gnunet
Subject: [taler-merchant] branch master updated: removed more old code, more tests for post order, some twister tests for merchant-exchange requests
Date: Wed, 08 Jul 2020 22:39:04 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 071554a  removed more old code, more tests for post order, some 
twister tests for merchant-exchange requests
071554a is described below

commit 071554a7ac031cc859355b5ee353a708c0c5cea5
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Wed Jul 8 16:38:55 2020 -0400

    removed more old code, more tests for post order, some twister tests for 
merchant-exchange requests
---
 .../taler-merchant-httpd_private-post-orders.c     |   4 +-
 src/include/taler_merchant_testing_lib.h           |  19 +++
 src/testing/test_merchant_api.c                    | 140 +++++----------------
 src/testing/test_merchant_api_twisted.c            |  46 +++++++
 src/testing/testing_api_cmd_post_orders.c          | 108 ++++++++++++++++
 5 files changed, 208 insertions(+), 109 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 5ccad64..7fff722 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -815,7 +815,9 @@ add_payment_details (struct MHD_Connection *connection,
                               wm->wire_method) ) )
       wm = wm->next;
   }
-  if (GNUNET_YES != wm->active)
+
+  if ((NULL != wm) &&
+      (GNUNET_YES != wm->active))
     wm = NULL;
   if (NULL == wm)
   {
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index e1908fd..a1a283f 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -485,6 +485,25 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
                                         const char *order);
 
 
+/**
+ * Make the "proposal" command.
+ *
+ * @param label command label
+ * @param merchant_url base URL of the merchant serving
+ *        the proposal request.
+ * @param http_status expected HTTP status.
+ * @param order the order to PUT to the merchant.
+ * @param payment_target payment target for the order.
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
+                                         const char *merchant_url,
+                                         unsigned int http_status,
+                                         const char *order,
+                                         const char *payment_target);
+
+
 /**
  * Define a "GET /orders" CMD.
  *
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index ca4a447..10a378e 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -88,11 +88,6 @@ static char *merchant_url;
  */
 static struct GNUNET_OS_Process *merchantd;
 
-/**
- * Map for #intern()
- */
-static struct GNUNET_CONTAINER_MultiHashMap *interned_strings;
-
 /**
  * Account number of the exchange at the bank.
  */
@@ -157,70 +152,6 @@ cmd_transfer_to_exchange (const char *label,
 }
 
 
-static const char *
-intern (const char *str)
-{
-  struct GNUNET_HashCode hash;
-  const char *hs;
-
-  if (NULL == interned_strings)
-    interned_strings = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
-  GNUNET_assert (NULL != interned_strings);
-  GNUNET_CRYPTO_hash (str, strlen (str), &hash);
-  hs = GNUNET_CONTAINER_multihashmap_get (interned_strings, &hash);
-  if (NULL != hs)
-    return hs;
-  hs = GNUNET_strdup (str);
-  GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
-                   interned_strings,
-                   &hash,
-                   (void *) hs,
-                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  return hs;
-}
-
-
-#define BUF_SZ 512
-
-static const char *
-merchant_url_internal (const char *instance_id)
-{
-  char buf[BUF_SZ];
-
-  if (NULL == instance_id)
-    GNUNET_snprintf (buf,
-                     BUF_SZ,
-                     "%s",
-                     merchant_url);
-  else
-    GNUNET_snprintf (buf,
-                     BUF_SZ,
-                     "%sinstances/%s/",
-                     merchant_url,
-                     instance_id);
-  return intern (buf);
-}
-
-
-static const char *
-merchant_url_external (const char *instance_id)
-{
-  char buf[BUF_SZ];
-  if (NULL == instance_id)
-    GNUNET_snprintf (buf,
-                     BUF_SZ,
-                     "%spublic/",
-                     merchant_url);
-  else
-    GNUNET_snprintf (buf,
-                     BUF_SZ,
-                     "%spublic/instances/%s/",
-                     merchant_url,
-                     instance_id);
-  return intern (buf);
-}
-
-
 /**
  * Main function that will tell the interpreter what commands to
  * run.
@@ -310,31 +241,6 @@ run (void *cls,
                                           false,
                                           false,
                                           MHD_HTTP_OK),
-#if 0
-    TALER_TESTING_cmd_check_payment ("check-payment-1",
-                                     merchant_url,
-                                     MHD_HTTP_OK,
-                                     "create-proposal-1",
-                                     GNUNET_NO),
-    TALER_TESTING_cmd_poll_payment_start ("poll-payment-1",
-                                          merchant_url,
-                                          "create-proposal-1",
-                                          NULL,
-                                          GNUNET_TIME_UNIT_MILLISECONDS),
-    TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-1",
-                                             MHD_HTTP_OK,
-                                             "poll-payment-1",
-                                             GNUNET_NO),
-    TALER_TESTING_cmd_poll_payment_start ("poll-payment-2",
-                                          merchant_url,
-                                          "create-proposal-1",
-                                          NULL,
-                                          GNUNET_TIME_UNIT_MINUTES),
-    TALER_TESTING_cmd_check_payment_start ("check-payment-2",
-                                           merchant_url,
-                                           "create-proposal-1",
-                                           GNUNET_TIME_UNIT_MINUTES),
-#endif
     TALER_TESTING_cmd_poll_order_start ("poll-order-merchant-1-start",
                                         merchant_url,
                                         "1",
@@ -361,20 +267,6 @@ run (void *cls,
                                           true,
                                           false,
                                           MHD_HTTP_OK),
-#if 0
-    TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-2",
-                                             MHD_HTTP_OK,
-                                             "poll-payment-2",
-                                             GNUNET_YES),
-    TALER_TESTING_cmd_check_payment_conclude ("check-payment-conclude-2",
-                                              MHD_HTTP_OK,
-                                              "check-payment-2",
-                                              GNUNET_YES),
-    TALER_TESTING_cmd_merchant_order_abort ("pay-abort-2",
-                                            merchant_url,
-                                            "deposit-simple",
-                                            MHD_HTTP_FORBIDDEN),
-#endif
     TALER_TESTING_cmd_merchant_pay_order ("replay-simple",
                                           merchant_url,
                                           MHD_HTTP_OK,
@@ -412,6 +304,38 @@ run (void *cls,
                                            false,
                                            NULL,
                                            MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_post_products ("post-products-p3",
+                                              merchant_url,
+                                              "product-3",
+                                              "a product",
+                                              "EUR:1",
+                                              MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-wm-nx",
+                                             merchant_url,
+                                             MHD_HTTP_NOT_FOUND,
+                                             "{\"max_fee\":\"EUR:0.5\",\
+        \"order_id\":\"order-p3\",\
+        \"refund_deadline\": {\"t_ms\": 0},\
+        \"pay_deadline\": {\"t_ms\": \"never\" },\
+        \"amount\":\"EUR:5.0\",\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }",
+                                             "unsupported-wire-method"),
+    TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "{\"max_fee\":\"EUR:0.5\",\
+        \"order_id\":\"order-p3\",\
+        \"refund_deadline\": {\"t_ms\": 0},\
+        \"pay_deadline\": {\"t_ms\": \"never\" },\
+        \"amount\":\"EUR:5.0\",\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }",
+                                             "x-taler-bank"),
     TALER_TESTING_cmd_merchant_delete_order ("delete-order-1",
                                              merchant_url,
                                              "1",
diff --git a/src/testing/test_merchant_api_twisted.c 
b/src/testing/test_merchant_api_twisted.c
index d07c2ed..8f94ac1 100644
--- a/src/testing/test_merchant_api_twisted.c
+++ b/src/testing/test_merchant_api_twisted.c
@@ -339,6 +339,52 @@ run (void *cls,
                                                MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_batch ("pay",
                              pay),
+    /* Malform the response from the exchange. */
+    /**
+     * Move money to the exchange's bank account.
+     */
+    CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
+                              "EUR:10.02"),
+    /**
+     * Make a reserve exist,
+     * according to the previous
+     * transfer.
+     *///
+    CMD_EXEC_WIREWATCH ("wirewatch-1"),
+    TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2",
+                                                 "EUR:10.02",
+                                                 payer_payto,
+                                                 exchange_payto,
+                                                 "create-reserve-1"),
+    TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
+                                       "create-reserve-1",
+                                       "EUR:5",
+                                       MHD_HTTP_OK),
+    TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
+                                       "create-reserve-1",
+                                       "EUR:5",
+                                       MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1",
+                                            merchant_url,
+                                            MHD_HTTP_OK,
+                                            "{\"max_fee\":\"EUR:0.5\",\
+        \"order_id\":\"1\",\
+        \"refund_deadline\": {\"t_ms\": 0},\
+        \"pay_deadline\": {\"t_ms\": \"never\" },\
+        \"amount\":\"EUR:5.0\",\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }"),
+    TALER_TESTING_cmd_malform_response ("malform-exchange-reponse-1",
+                                        PROXY_EXCHANGE_CONFIG_FILE),
+    TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
+                                          merchant_url,
+                                          MHD_HTTP_FAILED_DEPENDENCY,
+                                          "create-proposal-1",
+                                          "withdraw-coin-1",
+                                          "EUR:5",
+                                          "EUR:4.99"),
     TALER_TESTING_cmd_end ()
   };
 
diff --git a/src/testing/testing_api_cmd_post_orders.c 
b/src/testing/testing_api_cmd_post_orders.c
index 0a1db61..243dbca 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -96,6 +96,11 @@ struct OrdersState
    * Merchant public key.
    */
   struct TALER_MerchantPublicKeyP merchant_pub;
+
+  /**
+   * The payment target for the order
+   */
+  const char *payment_target;
 };
 
 
@@ -319,6 +324,70 @@ orders_run (void *cls,
 }
 
 
+/**
+ * Run a "orders" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+orders_run2 (void *cls,
+             const struct TALER_TESTING_Command *cmd,
+             struct TALER_TESTING_Interpreter *is)
+{
+  struct OrdersState *ps = cls;
+  json_t *order;
+  json_error_t error;
+
+  ps->is = is;
+  order = json_loads (ps->order,
+                      JSON_REJECT_DUPLICATES,
+                      &error);
+  if (NULL == order)
+  {
+    // human error here.
+    GNUNET_break (0);
+    fprintf (stderr, "%s\n", error.text);
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+
+  if (NULL == json_object_get (order,
+                               "order_id"))
+  {
+    struct GNUNET_TIME_Absolute now;
+    char *order_id;
+
+    // FIXME: should probably use get_monotone() to ensure uniqueness!
+    now = GNUNET_TIME_absolute_get ();
+    order_id = GNUNET_STRINGS_data_to_string_alloc
+                 (&now.abs_value_us,
+                 sizeof (now.abs_value_us));
+    json_object_set_new (order,
+                         "order_id",
+                         json_string (order_id));
+    GNUNET_free (order_id);
+  }
+  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                              &ps->nonce,
+                              sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+  ps->po = TALER_MERCHANT_orders_post2 (is->ctx,
+                                        ps->merchant_url,
+                                        order,
+                                        GNUNET_TIME_UNIT_ZERO,
+                                        ps->payment_target,
+                                        0,
+                                        NULL,
+                                        0,
+                                        NULL,
+                                        &order_cb,
+                                        ps);
+  json_decref (order);
+  GNUNET_assert (NULL != ps->po);
+}
+
+
 /**
  * Free the state of a "orders" CMD, and possibly
  * cancel it if it did not complete.
@@ -392,3 +461,42 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
     return cmd;
   }
 }
+
+
+/**
+ * Make the "proposal" command.
+ *
+ * @param label command label
+ * @param merchant_url base URL of the merchant serving
+ *        the proposal request.
+ * @param http_status expected HTTP status.
+ * @param order the order to PUT to the merchant.
+ * @param payment_target payment target for the order.
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
+                                         const char *merchant_url,
+                                         unsigned int http_status,
+                                         const char *order,
+                                         const char *payment_target)
+{
+  struct OrdersState *ps;
+
+  ps = GNUNET_new (struct OrdersState);
+  ps->order = order;
+  ps->http_status = http_status;
+  ps->merchant_url = merchant_url;
+  ps->payment_target = payment_target;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ps,
+      .label = label,
+      .run = &orders_run2,
+      .cleanup = &orders_cleanup,
+      .traits = &orders_traits
+    };
+
+    return cmd;
+  }
+}

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