gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 09/24: fix post order trait usage


From: gnunet
Subject: [taler-merchant] 09/24: fix post order trait usage
Date: Wed, 17 Nov 2021 12:44:32 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

commit a5f6348f7a738774fdef49a1b26f56ff88aeedf1
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Wed Nov 3 00:18:31 2021 +0100

    fix post order trait usage
---
 .../taler-merchant-httpd_private-post-orders.c     |  1 -
 src/include/taler_merchant_service.h               |  2 +-
 src/include/taler_merchant_testing_lib.h           |  1 +
 src/testing/testing_api_cmd_post_orders.c          | 91 +++++++++-------------
 4 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index e148bc0d..c244966f 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -905,7 +905,6 @@ patch_order (struct MHD_Connection *connection,
       MHD_HTTP_BAD_REQUEST,
       TALER_EC_MERCHANT_PRIVATE_POST_ORDERS_REFUND_AFTER_WIRE_DEADLINE,
       "order:wire_transfer_deadline;order:refund_deadline");
-
   }
 
   /* Note: total amount currency match checked
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 92ea69d2..fc297219 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -679,7 +679,7 @@ struct TALER_MERCHANT_Account
   /**
    * salt used to compute h_wire
    */
-  struct GNUNET_HashCode salt;
+  struct TALER_WireSalt salt;
 
   /**
    * payto:// URI of the account.
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 9fbb4f56..98668b67 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1500,6 +1500,7 @@ TALER_TESTING_cmd_tip_pickup (const char *label,
   op (wire_delay, const struct GNUNET_TIME_Relative) \
   op (pay_delay, const struct GNUNET_TIME_Relative) \
   op (refund_entry, const struct TALER_MERCHANT_RefundDetail) \
+  op (order_terms, const json_t) \
   op (h_contract_terms, const struct TALER_PrivateContractHash) \
   op (proposal_reference, const char *)
 
diff --git a/src/testing/testing_api_cmd_post_orders.c 
b/src/testing/testing_api_cmd_post_orders.c
index 1813385d..1568d151 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -35,11 +35,6 @@
 struct OrdersState
 {
 
-  /**
-   * The order.
-   */
-  char *order;
-
   /**
    * Expected status code.
    */
@@ -60,6 +55,11 @@ struct OrdersState
    */
   json_t *contract_terms;
 
+  /**
+   * Order submitted to the backend.
+   */
+  json_t *order_terms;
+
   /**
    * Contract terms hash code.
    */
@@ -159,6 +159,7 @@ orders_traits (void *cls,
   struct TALER_TESTING_Trait traits[] = {
     TALER_TESTING_make_trait_order_id (&ps->order_id),
     TALER_TESTING_make_trait_contract_terms (ps->contract_terms),
+    TALER_TESTING_make_trait_order_terms (ps->order_terms),
     TALER_TESTING_make_trait_h_contract_terms (&ps->h_contract_terms),
     TALER_TESTING_make_trait_merchant_sig (&ps->merchant_sig),
     TALER_TESTING_make_trait_merchant_pub (&ps->merchant_pub),
@@ -368,23 +369,9 @@ orders_run (void *cls,
             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,
+  if (NULL == json_object_get (ps->order_terms,
                                "order_id"))
   {
     struct GNUNET_TIME_Absolute now;
@@ -396,7 +383,7 @@ orders_run (void *cls,
                  (&now.abs_value_us,
                  sizeof (now.abs_value_us));
     GNUNET_assert (0 ==
-                   json_object_set_new (order,
+                   json_object_set_new (ps->order_terms,
                                         "order_id",
                                         json_string (order_id)));
     GNUNET_free (order_id);
@@ -406,11 +393,10 @@ orders_run (void *cls,
                               sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
   ps->po = TALER_MERCHANT_orders_post (is->ctx,
                                        ps->merchant_url,
-                                       order,
+                                       ps->order_terms,
                                        GNUNET_TIME_UNIT_ZERO,
                                        &order_cb,
                                        ps);
-  json_decref (order);
   GNUNET_assert (NULL != ps->po);
 }
 
@@ -428,8 +414,7 @@ orders_run2 (void *cls,
              struct TALER_TESTING_Interpreter *is)
 {
   struct OrdersState *ps = cls;
-  const char *order_str = ps->order;
-  json_t *order;
+  const json_t *order;
   json_error_t error;
   char *products_string = GNUNET_strdup (ps->products);
   char *locks_string = GNUNET_strdup (ps->locks);
@@ -449,21 +434,35 @@ orders_run2 (void *cls,
       is,
       ps->duplicate_of);
     if (GNUNET_OK !=
-        TALER_TESTING_get_trait_contract_terms (order_cmd,
-                                                &ct))
+        TALER_TESTING_get_trait_order_terms (order_cmd,
+                                             &ct))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Could not fetch previous order string\n");
       TALER_TESTING_interpreter_fail (is);
       return;
     }
-    order = json_incref ((json_t *) ct);
+    order = (json_t *) ct;
   }
   else
   {
-    order = json_loads (order_str,
-                        JSON_REJECT_DUPLICATES,
-                        &error);
+    if (NULL == json_object_get (ps->order_terms,
+                                 "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 (ps->order_terms,
+                           "order_id",
+                           json_string (order_id));
+      GNUNET_free (order_id);
+    }
+    order = ps->order_terms;
   }
   if (NULL == order)
   {
@@ -474,22 +473,6 @@ orders_run2 (void *cls,
     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));
@@ -561,7 +544,6 @@ orders_run2 (void *cls,
                                         ps->make_claim_token,
                                         &order_cb,
                                         ps);
-  json_decref (order);
   GNUNET_free (products_string);
   GNUNET_free (locks_string);
   GNUNET_array_grow (products,
@@ -606,7 +588,7 @@ orders_cleanup (void *cls,
   }
 
   json_decref (ps->contract_terms);
-  GNUNET_free (ps->order);
+  json_decref (ps->order_terms);
   GNUNET_free_nz ((void *) ps->order_id);
   GNUNET_free (ps);
 }
@@ -644,7 +626,7 @@ make_order_json (const char *order_id,
                  struct GNUNET_TIME_Absolute refund_deadline,
                  struct GNUNET_TIME_Absolute pay_deadline,
                  const char *amount,
-                 char **order)
+                 json_t **order)
 {
   struct GNUNET_TIME_Absolute refund = refund_deadline;
   struct GNUNET_TIME_Absolute pay = pay_deadline;
@@ -678,8 +660,7 @@ make_order_json (const char *order_id,
                                          "$.dummy_array[*].item",
                                          &mark_forgettable,
                                          NULL));
-  *order = json_dumps (contract_terms, 0);
-  json_decref (contract_terms);
+  *order = contract_terms;
 }
 
 
@@ -700,7 +681,7 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   &ps->order);
+                   &ps->order_terms);
   ps->http_status = http_status;
   ps->expected_order_id = order_id;
   ps->merchant_url = merchant_url;
@@ -736,7 +717,7 @@ TALER_TESTING_cmd_merchant_post_orders (
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   &ps->order);
+                   &ps->order_terms);
   ps->http_status = http_status;
   ps->expected_order_id = order_id;
   ps->merchant_url = merchant_url;
@@ -777,7 +758,7 @@ TALER_TESTING_cmd_merchant_post_orders2 (
                    refund_deadline,
                    pay_deadline,
                    amount,
-                   &ps->order);
+                   &ps->order_terms);
   ps->http_status = http_status;
   ps->expected_order_id = order_id;
   ps->merchant_url = merchant_url;

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