gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 219/277: tests for new db methods


From: gnunet
Subject: [taler-merchant] 219/277: tests for new db methods
Date: Sun, 05 Jul 2020 20:52:12 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit af158318c6923a51ec8a75bbf2f857ce60cec139
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Mon Jun 15 17:03:02 2020 -0400

    tests for new db methods
---
 src/backenddb/test_merchantdb.c | 305 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 289 insertions(+), 16 deletions(-)

diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index c9c3240..93a7cae 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1331,6 +1331,18 @@ test_lookup_payment_status (uint64_t order_id,
 }
 
 
+static int
+test_mark_order_wired (uint64_t order_id,
+                       enum GNUNET_DB_QueryStatus expected_result)
+{
+  TEST_COND_RET_ON_FAIL (expected_result ==
+                         plugin->mark_order_wired (plugin->cls,
+                                                   order_id),
+                         "Mark order wired failed\n");
+  return 0;
+}
+
+
 /**
  * Closure for order tests.
  */
@@ -1518,6 +1530,15 @@ run_test_orders (struct TestOrders_Closure *cls)
                                         &filter,
                                         1,
                                         cls->orders));
+  /* Test marking orders as wired */
+  TEST_RET_ON_FAIL (test_mark_order_wired (1,
+                                           
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+                                                NULL,
+                                                true,
+                                                true));
+  TEST_RET_ON_FAIL (test_mark_order_wired (1007,
+                                           
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
   /* Test deleting contract terms */
   TEST_RET_ON_FAIL (test_delete_contract_terms (&cls->instance,
                                                 &cls->orders[0],
@@ -1942,6 +1963,86 @@ test_lookup_deposits_contract_and_coin (const struct 
InstanceData *instance,
 }
 
 
+static void
+lookup_deposits_order_cb (void *cls,
+                          uint64_t deposit_serial,
+                          const char *exchange_url,
+                          const struct GNUNET_HashCode *h_wire,
+                          const struct TALER_Amount *amount_with_fee,
+                          const struct TALER_Amount *deposit_fee,
+                          const struct TALER_CoinSpendPublicKeyP *coin_pub)
+{
+  struct TestLookupDeposits_Closure *cmp = cls;
+  if (NULL == cmp)
+    return;
+  cmp->results_length += 1;
+  for (unsigned int i = 0; i < cmp->deposits_to_cmp_length; ++i)
+  {
+    if ((0 == strcmp (cmp->deposits_to_cmp[i].exchange_url,
+                      exchange_url)) &&
+        (0 == GNUNET_memcmp (&cmp->deposits_to_cmp[i].h_wire,
+                             h_wire)) &&
+        (GNUNET_OK == TALER_amount_cmp_currency (
+           &cmp->deposits_to_cmp[i].amount_with_fee,
+           amount_with_fee)) &&
+        (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].amount_with_fee,
+                                amount_with_fee)) &&
+        (GNUNET_OK == TALER_amount_cmp_currency (
+           &cmp->deposits_to_cmp[i].deposit_fee,
+           deposit_fee)) &&
+        (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].deposit_fee,
+                                deposit_fee)) &&
+        (0 == GNUNET_memcmp (&cmp->deposits_to_cmp[i].coin_pub,
+                             coin_pub)))
+      cmp->results_matching[i] += 1;
+  }
+}
+
+
+static int
+test_lookup_deposits_by_order (uint64_t order_serial,
+                               unsigned int deposits_length,
+                               const struct DepositData *deposits)
+{
+  unsigned int results_matching[deposits_length];
+  struct TestLookupDeposits_Closure cmp = {
+    .deposits_to_cmp_length = deposits_length,
+    .deposits_to_cmp = deposits,
+    .results_matching = results_matching,
+    .results_length = 0
+  };
+  memset (results_matching,
+          0,
+          sizeof (unsigned int) * deposits_length);
+  if (deposits_length != plugin->lookup_deposits_by_order (plugin->cls,
+                                                           order_serial,
+                                                           &
+                                                           
lookup_deposits_order_cb,
+                                                           &cmp))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup deposits by order failed\n");
+    return 1;
+  }
+  if (deposits_length != cmp.results_length)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup deposits by order failed: incorrect number of 
results\n");
+    return 1;
+  }
+  for (unsigned int i = 0; i < deposits_length; ++i)
+  {
+    if (1 != cmp.results_matching[i])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Lookup deposits by order failed: mismatched data\n");
+      return 1;
+    }
+  }
+  return 0;
+}
+
+
 /**
  * Closure for deposit tests.
  */
@@ -2068,6 +2169,10 @@ run_test_deposits (struct TestDeposits_Closure *cls)
                                           &cls->deposits[0].h_contract_terms,
                                           2,
                                           cls->deposits));
+  /* Test lookup deposits by order */
+  TEST_RET_ON_FAIL (test_lookup_deposits_by_order (4,
+                                                   2,
+                                                   cls->deposits));
   return 0;
 }
 
@@ -2310,7 +2415,9 @@ test_lookup_transfer_details (const char *exchange_url,
     .results_matching = results_matching,
     .results_length = 0
   };
-  memset (results_matching, 0, sizeof (unsigned int) * details_length);
+  memset (results_matching,
+          0,
+          sizeof (unsigned int) * details_length);
   if (1 != plugin->lookup_transfer_details (plugin->cls,
                                             exchange_url,
                                             wtid,
@@ -2341,6 +2448,112 @@ test_lookup_transfer_details (const char *exchange_url,
 }
 
 
+struct TransferContainer
+{
+  struct TALER_WireTransferIdentifierRawP wtid;
+  const char *exchange_url;
+  struct GNUNET_TIME_Absolute execution_time;
+  struct TALER_Amount deposit_value;
+  struct TALER_Amount deposit_fee;
+  bool confirmed;
+};
+
+
+struct TestLookupTransferDetailsByOrder_Closure
+{
+  unsigned int transfers_to_cmp_length;
+
+  const struct TransferContainer *transfers_to_cmp;
+
+  unsigned int *results_matching;
+
+  unsigned int results_length;
+};
+
+
+static void
+lookup_transfer_details_order_cb (void *cls,
+                                  const struct
+                                  TALER_WireTransferIdentifierRawP *wtid,
+                                  const char *exchange_url,
+                                  struct GNUNET_TIME_Absolute execution_time,
+                                  const struct TALER_Amount *deposit_value,
+                                  const struct TALER_Amount *deposit_fee,
+                                  bool transfer_confirmed)
+{
+  struct TestLookupTransferDetailsByOrder_Closure *cmp = cls;
+  if (NULL == cmp)
+    return;
+  cmp->results_length += 1;
+  for (unsigned int i = 0; i < cmp->transfers_to_cmp_length; ++i)
+  {
+    if ((0 == GNUNET_memcmp (&cmp->transfers_to_cmp[i].wtid,
+                             wtid)) &&
+        (0 == strcmp (cmp->transfers_to_cmp[i].exchange_url,
+                      exchange_url)) &&
+        (cmp->transfers_to_cmp[i].execution_time.abs_value_us ==
+         execution_time.abs_value_us) &&
+        (GNUNET_OK == TALER_amount_cmp_currency (
+           &cmp->transfers_to_cmp[i].deposit_value,
+           deposit_value)) &&
+        (0 == TALER_amount_cmp (&cmp->transfers_to_cmp[i].deposit_value,
+                                deposit_value)) &&
+        (GNUNET_OK == TALER_amount_cmp_currency (
+           &cmp->transfers_to_cmp[i].deposit_fee,
+           deposit_fee)) &&
+        (0 == TALER_amount_cmp (&cmp->transfers_to_cmp[i].deposit_fee,
+                                deposit_fee)) &&
+        (cmp->transfers_to_cmp[i].confirmed == transfer_confirmed))
+      cmp->results_matching[i] += 1;
+  }
+}
+
+
+static int
+test_lookup_transfer_details_by_order (uint64_t order_serial,
+                                       unsigned int transfers_length,
+                                       const struct
+                                       TransferContainer *transfers)
+{
+  unsigned int results_matching[transfers_length];
+  struct TestLookupTransferDetailsByOrder_Closure cmp = {
+    .transfers_to_cmp_length = transfers_length,
+    .transfers_to_cmp = transfers,
+    .results_matching = results_matching,
+    .results_length = 0
+  };
+  memset (results_matching,
+          0,
+          sizeof (unsigned int) * transfers_length);
+  if (transfers_length != plugin->lookup_transfer_details_by_order 
(plugin->cls,
+                                                                    
order_serial,
+                                                                    &
+                                                                    
lookup_transfer_details_order_cb,
+                                                                    &cmp))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup transfer details by order failed\n");
+    return 1;
+  }
+  if (transfers_length != cmp.results_length)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup transfer details by order failed: incorrect number of 
results\n");
+    return 1;
+  }
+  for (unsigned int i = 0; i < transfers_length; ++i)
+  {
+    if (1 != cmp.results_matching[i])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Lookup transfer details by order failed: mismatched 
data\n");
+      return 1;
+    }
+  }
+  return 0;
+}
+
+
 static int
 test_insert_wire_fee (const struct ExchangeSignkeyData *signkey,
                       const struct WireFeeData *wire_fee,
@@ -2580,7 +2793,6 @@ post_test_transfers (struct TestTransfers_Closure *cls)
 static int
 run_test_transfers (struct TestTransfers_Closure *cls)
 {
-  const char *exchange_url = "exch-url";
   struct TALER_WireTransferIdentifierRawP wtid = {
     .raw = {0}
   };
@@ -2655,7 +2867,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
                          plugin->insert_transfer (plugin->cls,
                                                   cls->instance.instance.id,
-                                                  exchange_url,
+                                                  cls->deposit.exchange_url,
                                                   &wtid,
                                                   &amount,
                                                   cls->account.payto_uri,
@@ -2665,7 +2877,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
                          plugin->insert_transfer (plugin->cls,
                                                   cls->instance.instance.id,
-                                                  exchange_url,
+                                                  cls->deposit.exchange_url,
                                                   &wtid,
                                                   &amount,
                                                   cls->account.payto_uri,
@@ -2682,7 +2894,8 @@ run_test_transfers (struct TestTransfers_Closure *cls)
                          plugin->insert_transfer_details (plugin->cls,
                                                           
cls->instance.instance
                                                           .id,
-                                                          "exch-url",
+                                                          cls->deposit.
+                                                          exchange_url,
                                                           
cls->account.payto_uri,
                                                           &wtid,
                                                           &transfer_data),
@@ -2691,7 +2904,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   GNUNET_assert (0 <= TALER_amount_add (&total_with_fee,
                                         &transfer_data.total_amount,
                                         &transfer_data.wire_fee));
-  TEST_RET_ON_FAIL (test_lookup_transfer (exchange_url,
+  TEST_RET_ON_FAIL (test_lookup_transfer (cls->deposit.exchange_url,
                                           &wtid,
                                           &total_with_fee,
                                           &transfer_data.wire_fee,
@@ -2700,23 +2913,44 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   /* Test set status to verified */
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
                          plugin->set_transfer_status_to_verified (plugin->cls,
+                                                                  cls->deposit.
                                                                   exchange_url,
                                                                   &wtid),
                          "Set transfer status to verified failed\n");
-  TEST_RET_ON_FAIL (test_lookup_transfer (exchange_url,
+  TEST_RET_ON_FAIL (test_lookup_transfer (cls->deposit.exchange_url,
                                           &wtid,
                                           &total_with_fee,
                                           &transfer_data.wire_fee,
                                           &transfer_data.execution_time,
                                           true));
+  /* Test insert deposit to transfer */
+  {
+    const struct TALER_EXCHANGE_DepositData deposit_data = {
+      .exchange_pub = cls->signkey.exchange_pub,
+      .exchange_sig = cls->deposit.exchange_sig,
+      .wtid = wtid,
+      .execution_time = transfer_data.execution_time,
+      .coin_contribution = transfer_data.total_amount
+    };
+    TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+                           plugin->insert_deposit_to_transfer (plugin->cls,
+                                                               3,
+                                                               &deposit_data),
+                           "Insert deposit to transfer failed\n");
+    TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+                           plugin->insert_deposit_to_transfer (plugin->cls,
+                                                               3,
+                                                               &deposit_data),
+                           "Insert deposit to transfer failed\n");
+  }
   /* Test lookup transfer summary */
-  TEST_RET_ON_FAIL (test_lookup_transfer_summary (exchange_url,
+  TEST_RET_ON_FAIL (test_lookup_transfer_summary (cls->deposit.exchange_url,
                                                   &wtid,
                                                   cls->order.id,
                                                   
&cls->deposit.amount_with_fee,
                                                   &cls->deposit.deposit_fee));
   /* Test lookup transfer details */
-  TEST_RET_ON_FAIL (test_lookup_transfer_details (exchange_url,
+  TEST_RET_ON_FAIL (test_lookup_transfer_details (cls->deposit.exchange_url,
                                                   &wtid,
                                                   1,
                                                   &transfer_detail));
@@ -2731,7 +2965,22 @@ run_test_transfers (struct TestTransfers_Closure *cls)
                                            TALER_EXCHANGE_YNA_ALL,
                                            1,
                                            &full_transfer_data));
-
+  /* Test lookup transfer details by order */
+  {
+    const struct TransferContainer transfers[] = {
+      {
+        .wtid = wtid,
+        .exchange_url = cls->deposit.exchange_url,
+        // .execution_time = transfer_data.execution_time,
+        .deposit_value = cls->deposit.amount_with_fee,
+        .deposit_fee = cls->deposit.deposit_fee,
+        // .confirmed = true
+      }
+    };
+    TEST_RET_ON_FAIL (test_lookup_transfer_details_by_order (5,
+                                                             1,
+                                                             transfers));
+  }
   return 0;
 }
 
@@ -4225,7 +4474,7 @@ run_test_lookup_orders_all_filters (struct
     .refunded = TALER_EXCHANGE_YNA_ALL,
     .wired = TALER_EXCHANGE_YNA_ALL,
     .date = GNUNET_TIME_UNIT_FOREVER_ABS,
-    .start_row = 23, /* Why does this need to be 20 and not 18? */
+    .start_row = 23,
     .delta = -16
   };
 
@@ -4245,6 +4494,7 @@ run_test_lookup_orders_all_filters (struct
     TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
                                                   &cls->orders[i],
                                                   
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+
     /* Mark every other order as paid for */
     if (0 == i % 2)
       TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
@@ -4267,6 +4517,10 @@ run_test_lookup_orders_all_filters (struct
                                                   cls->refunds[i].coin_pub,
                                                   cls->refunds[i].reason),
                              "Refund coin failed\n");
+      /* Mark every eigth as wired */
+      if (0 == i % 8)
+        TEST_RET_ON_FAIL (test_mark_order_wired (7 + i,
+                                                 
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
     }
   }
 
@@ -4299,7 +4553,6 @@ run_test_lookup_orders_all_filters (struct
                                         &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];
@@ -4338,8 +4591,26 @@ run_test_lookup_orders_all_filters (struct
                                         5,
                                         expected_orders));
   /* lookup_orders_inc_wired */
+  expected_orders[0] = cls->orders[0];
+  expected_orders[1] = cls->orders[8];
+  filter_inc.refunded = TALER_EXCHANGE_YNA_ALL;
+  filter_inc.wired = TALER_EXCHANGE_YNA_YES;
+  TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+                                        &filter_inc,
+                                        2,
+                                        expected_orders));
   /* lookup_orders_dec_wired */
+  filter_dec.refunded = TALER_EXCHANGE_YNA_ALL;
+  filter_dec.wired = TALER_EXCHANGE_YNA_YES;
+  reverse_order_data_array (2,
+                            expected_orders);
+  TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+                                        &filter_dec,
+                                        2,
+                                        expected_orders));
   /* lookup_orders_inc_paid_refunded */
+  filter_inc.refunded = TALER_EXCHANGE_YNA_YES;
+  filter_inc.wired = TALER_EXCHANGE_YNA_ALL;
   filter_inc.paid = TALER_EXCHANGE_YNA_YES;
   for (unsigned int i = 0; i < 4; ++i)
     expected_orders[i] = cls->orders[4 * i];
@@ -4348,6 +4619,8 @@ run_test_lookup_orders_all_filters (struct
                                         4,
                                         expected_orders));
   /* lookup_orders_dec_paid_refunded */
+  filter_dec.refunded = TALER_EXCHANGE_YNA_YES;
+  filter_dec.wired = TALER_EXCHANGE_YNA_ALL;
   filter_dec.paid = TALER_EXCHANGE_YNA_YES;
   reverse_order_data_array (4,
                             expected_orders);
@@ -4432,13 +4705,13 @@ run (void *cls)
   result = run_tests (cls);
 
   /* Test dropping tables */
-  if (GNUNET_OK != plugin->drop_tables (plugin->cls))
+  /*if (GNUNET_OK != plugin->drop_tables (plugin->cls))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Dropping tables failed\n");
     result = 77;
     return;
-  }
+  }*/
 
   /* Unload the plugin */
   TALER_MERCHANTDB_plugin_unload (plugin);
@@ -4450,8 +4723,8 @@ run (void *cls)
     return;
   }
 
-  GNUNET_break (GNUNET_OK ==
-                plugin->drop_tables (plugin->cls));
+  /*GNUNET_break (GNUNET_OK ==
+                plugin->drop_tables (plugin->cls));*/
   TALER_MERCHANTDB_plugin_unload (plugin);
   plugin = NULL;
 }

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