gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 206/277: more backenddb tests


From: gnunet
Subject: [taler-merchant] 206/277: more backenddb tests
Date: Sun, 05 Jul 2020 20:51:59 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit f0411396fada5862ce16b56dc57513b9aa79b706
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat Jun 13 02:04:35 2020 -0400

    more backenddb tests
---
 src/backenddb/plugin_merchantdb_postgres.c | 42 +++++++++----
 src/backenddb/test_merchantdb.c            | 96 +++++++++++++++++++++++++++++-
 2 files changed, 127 insertions(+), 11 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 0f338ff..a6c1041 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -2024,11 +2024,6 @@ postgres_lookup_payment_status (void *cls,
   uint8_t paid8;
   uint8_t wired8;
   enum GNUNET_DB_QueryStatus qs;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint64 (&order_serial),
-    GNUNET_PQ_query_param_string (session_id),
-    GNUNET_PQ_query_param_end
-  };
   struct GNUNET_PQ_ResultSpec rs[] = {
     GNUNET_PQ_result_spec_auto_from_type ("paid",
                                           &paid8),
@@ -2036,12 +2031,32 @@ postgres_lookup_payment_status (void *cls,
                                           &wired8),
     GNUNET_PQ_result_spec_end
   };
-
   check_connection (pg);
-  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                 "lookup_payment_status",
-                                                 params,
-                                                 rs);
+  if (NULL == session_id)
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_uint64 (&order_serial),
+      GNUNET_PQ_query_param_end
+    };
+
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "lookup_payment_status",
+                                                   params,
+                                                   rs);
+  }
+  else
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_uint64 (&order_serial),
+      GNUNET_PQ_query_param_string (session_id),
+      GNUNET_PQ_query_param_end
+    };
+
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   
"lookup_payment_status_session_id",
+                                                   params,
+                                                   rs);
+  }
   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
   {
     *paid = (0 != paid8);
@@ -6914,6 +6929,13 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             2),
     /* for postgres_lookup_payment_status() */
     GNUNET_PQ_make_prepare ("lookup_payment_status",
+                            "SELECT"
+                            " wired"
+                            ",paid"
+                            " FROM merchant_contract_terms"
+                            " WHERE order_serial=$1",
+                            1),
+    GNUNET_PQ_make_prepare ("lookup_payment_status_session_id",
                             "SELECT"
                             " wired"
                             ",paid"
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 43208e8..c9c3240 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1132,7 +1132,8 @@ test_lookup_orders (const struct InstanceData *instance,
     if (false == cls.results_match[i])
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Lookup orders failed: mismatched data\n");
+                  "Lookup orders failed: mismatched data (index %d)\n",
+                  i);
       return 1;
     }
   }
@@ -1269,6 +1270,67 @@ test_lookup_order_status (const struct InstanceData 
*instance,
 }
 
 
+static int
+test_lookup_order_by_fulfillment (const struct InstanceData *instance,
+                                  const struct OrderData *order,
+                                  const char *session_id)
+{
+  char *order_id;
+  const char *fulfillment_url =
+    json_string_value (json_object_get (order->contract,
+                                        "fulfillment_url"));
+  GNUNET_assert (NULL != fulfillment_url);
+  if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+      plugin->lookup_order_by_fulfillment (plugin->cls,
+                                           instance->instance.id,
+                                           fulfillment_url,
+                                           session_id,
+                                           &order_id))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup order by fulfillment failed\n");
+    GNUNET_free (order_id);
+    return 1;
+  }
+  if (0 != strcmp (order->id,
+                   order_id))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup order by fulfillment failed\n");
+    GNUNET_free (order_id);
+    return 1;
+  }
+  GNUNET_free (order_id);
+  return 0;
+}
+
+
+static int
+test_lookup_payment_status (uint64_t order_id,
+                            const char *session_id,
+                            bool expected_paid,
+                            bool expected_wired)
+{
+  bool paid;
+  bool wired;
+  TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+                         plugin->lookup_payment_status (plugin->cls,
+                                                        order_id,
+                                                        session_id,
+                                                        &paid,
+                                                        &wired),
+                         "Lookup payment status failed\n");
+  if ((expected_paid != paid) ||
+      (expected_wired != wired))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup payment status failed\n");
+    return 1;
+  }
+  return 0;
+}
+
+
 /**
  * Closure for order tests.
  */
@@ -1407,6 +1469,11 @@ run_test_orders (struct TestOrders_Closure *cls)
   TEST_RET_ON_FAIL (test_lookup_order_status (&cls->instance,
                                               &cls->orders[0],
                                               false));
+  /* Test lookup payment status */
+  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+                                                NULL,
+                                                false,
+                                                false));
   /* Test lookup order status fails for nonexistent order */
   {
     struct GNUNET_HashCode h_contract_terms;
@@ -1427,6 +1494,18 @@ run_test_orders (struct TestOrders_Closure *cls)
   TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
                                              &cls->orders[0],
                                              
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+                                                NULL,
+                                                true,
+                                                false));
+  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+                                                "test_orders_session",
+                                                true,
+                                                false));
+  /* Test lookup order by fulfillment */
+  TEST_RET_ON_FAIL (test_lookup_order_by_fulfillment (&cls->instance,
+                                                      &cls->orders[0],
+                                                      "test_orders_session"));
   /* Test mark as paid fails for nonexistent order */
   TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
                                              &cls->orders[1],
@@ -4214,6 +4293,21 @@ run_test_lookup_orders_all_filters (struct
                                         expected_orders));
   /* lookup_orders_dec_paid */
   filter_dec.paid = TALER_EXCHANGE_YNA_YES;
+  reverse_order_data_array (8,
+                            expected_orders);
+  TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+                                        &filter_dec,
+                                        8,
+                                        expected_orders));
+  /* */
+  filter_inc.paid = TALER_EXCHANGE_YNA_NO;
+  for (unsigned int i = 0; i < 8; ++i)
+    expected_orders[i] = cls->orders[(2 * i) + 1];
+  TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+                                        &filter_inc,
+                                        8,
+                                        expected_orders));
+  filter_dec.paid = TALER_EXCHANGE_YNA_NO;
   reverse_order_data_array (8,
                             expected_orders);
   TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,

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