gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 261/277: removed hardcoded row numbers from backenddb t


From: gnunet
Subject: [taler-merchant] 261/277: removed hardcoded row numbers from backenddb tests
Date: Sun, 05 Jul 2020 20:52:54 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit c7465ea592f0cd34d259e3f94227e3320f62208a
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat Jun 27 16:35:04 2020 -0400

    removed hardcoded row numbers from backenddb tests
---
 src/backenddb/plugin_merchantdb_postgres.c |  42 +-
 src/backenddb/test_merchantdb.c            | 645 ++++++++++++++++++++++++-----
 2 files changed, 569 insertions(+), 118 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index efb5891..54d99d6 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1449,20 +1449,36 @@ postgres_lookup_contract_terms (void *cls,
     GNUNET_PQ_query_param_string (order_id),
     GNUNET_PQ_query_param_end
   };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    TALER_PQ_result_spec_json ("contract_terms",
-                               contract_terms),
-    GNUNET_PQ_result_spec_uint64 ("order_serial",
-                                  order_serial),
-    GNUNET_PQ_result_spec_end
-  };
-
-  *contract_terms = NULL;
   check_connection (pg);
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "lookup_contract_terms",
-                                                   params,
-                                                   rs);
+  if (NULL == contract_terms)
+  {
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("order_serial",
+                                    order_serial),
+      GNUNET_PQ_result_spec_end
+    };
+
+    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                     "lookup_contract_terms",
+                                                     params,
+                                                     rs);
+  }
+  else
+  {
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      TALER_PQ_result_spec_json ("contract_terms",
+                                 contract_terms),
+      GNUNET_PQ_result_spec_uint64 ("order_serial",
+                                    order_serial),
+      GNUNET_PQ_result_spec_end
+    };
+
+    *contract_terms = NULL;
+    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                     "lookup_contract_terms",
+                                                     params,
+                                                     rs);
+  }
 }
 
 
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index cc7ca65..cc63b89 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -657,7 +657,7 @@ run_test_instances (struct TestInstances_Closure *cls)
  * @return 0 on success, 1 otherwise.
  */
 static int
-test_instances ()
+test_instances (void)
 {
   struct TestInstances_Closure test_cls;
   pre_test_instances (&test_cls);
@@ -1177,7 +1177,7 @@ run_test_products (struct TestProducts_Closure *cls)
  * @return 0 on success, 1 otherwise.
  */
 static int
-test_products ()
+test_products (void)
 {
   struct TestProducts_Closure test_cls;
   pre_test_products (&test_cls);
@@ -1435,6 +1435,81 @@ test_lookup_orders (const struct InstanceData *instance,
 }
 
 
+/**
+ * Container for data used for looking up the row number of an order.
+ */
+struct LookupOrderSerial_Closure
+{
+  /**
+   * The order that is being looked up.
+   */
+  const struct OrderData *order;
+
+  /**
+   * The serial of the order that was found.
+   */
+  uint64_t serial;
+};
+
+
+/**
+ * Called after @e test_lookup_orders.
+ *
+ * @param cls the lookup closure.
+ * @param order_id the identifier of the order found.
+ * @param order_serial the row number of the order found.
+ * @param timestamp when the order was added to the database.
+ */
+static void
+get_order_serial_cb (void *cls,
+                     const char *order_id,
+                     uint64_t order_serial,
+                     struct GNUNET_TIME_Absolute timestamp)
+{
+  struct LookupOrderSerial_Closure *lookup_cls = cls;
+  if (NULL == lookup_cls)
+    return;
+  if (0 == strcmp (lookup_cls->order->id,
+                   order_id))
+    lookup_cls->serial = order_serial;
+}
+
+
+/**
+ * Convenience function for getting the row number of an order.
+ *
+ * @param instance the instance to look up from.
+ * @param order the order to lookup the serial for.
+ * @return the row number of the order.
+ */
+static uint64_t
+get_order_serial (const struct InstanceData *instance,
+                  const struct OrderData *order)
+{
+  struct LookupOrderSerial_Closure lookup_cls = {
+    .order = order,
+    .serial = 0
+  };
+  struct TALER_MERCHANTDB_OrderFilter filter = {
+    .paid = TALER_EXCHANGE_YNA_ALL,
+    .refunded = TALER_EXCHANGE_YNA_ALL,
+    .wired = TALER_EXCHANGE_YNA_ALL,
+    .date = GNUNET_TIME_UNIT_ZERO_ABS,
+    .start_row = 0,
+    .delta = 256
+  };
+
+  GNUNET_assert (0 < plugin->lookup_orders (plugin->cls,
+                                            instance->instance.id,
+                                            &filter,
+                                            &get_order_serial_cb,
+                                            &lookup_cls));
+  GNUNET_assert (0 != lookup_cls.serial);
+
+  return lookup_cls.serial;
+}
+
+
 /**
  * Tests deleting an order from the database.
  *
@@ -1789,6 +1864,7 @@ run_test_orders (struct TestOrders_Closure *cls)
     .start_row = 0,
     .delta = 8
   };
+  uint64_t serial;
 
   /* Insert the instance */
   TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
@@ -1894,14 +1970,27 @@ 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,
+  serial = get_order_serial (&cls->instance,
+                             &cls->orders[0]);
+  TEST_RET_ON_FAIL (test_lookup_payment_status (serial,
                                                 NULL,
                                                 true,
                                                 false));
-  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+  TEST_RET_ON_FAIL (test_lookup_payment_status (serial,
                                                 "test_orders_session",
                                                 true,
                                                 false));
+  {
+    bool paid;
+    bool wired;
+    TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+                           plugin->lookup_payment_status (plugin->cls,
+                                                          serial,
+                                                          "bad_session",
+                                                          &paid,
+                                                          &wired),
+                           "Lookup payment status failed\n");
+  }
   /* Test lookup order by fulfillment */
   TEST_RET_ON_FAIL (test_lookup_order_by_fulfillment (&cls->instance,
                                                       &cls->orders[0],
@@ -1919,9 +2008,9 @@ run_test_orders (struct TestOrders_Closure *cls)
                                         1,
                                         cls->orders));
   /* Test marking orders as wired */
-  TEST_RET_ON_FAIL (test_mark_order_wired (1,
+  TEST_RET_ON_FAIL (test_mark_order_wired (serial,
                                            
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-  TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+  TEST_RET_ON_FAIL (test_lookup_payment_status (serial,
                                                 NULL,
                                                 true,
                                                 true));
@@ -1958,7 +2047,7 @@ run_test_orders (struct TestOrders_Closure *cls)
  * @return 0 when successful, 1 otherwise.
  */
 static int
-test_orders ()
+test_orders (void)
 {
   struct TestOrders_Closure test_cls;
   pre_test_orders (&test_cls);
@@ -1968,24 +2057,61 @@ test_orders ()
 }
 
 
-/* Deposits */
+/* ********** Deposits ********** */
 
 
+/**
+ * A container for exchange signing key data.
+ */
 struct ExchangeSignkeyData
 {
+  /**
+   * The master private key of the exchange.
+   */
   struct TALER_MasterPrivateKeyP master_priv;
+
+  /**
+   * The master public key of the exchange.
+   */
   struct TALER_MasterPublicKeyP master_pub;
+
+  /**
+   * A signature made with the master keys.
+   */
   struct TALER_MasterSignatureP master_sig;
 
+  /**
+   * The private key of the exchange.
+   */
   struct TALER_ExchangePrivateKeyP exchange_priv;
+
+  /**
+   * The public key of the exchange.
+   */
   struct TALER_ExchangePublicKeyP exchange_pub;
 
+  /**
+   * When the signing key becomes valid.
+   */
   struct GNUNET_TIME_Absolute start_date;
+
+  /**
+   * When the signing key stops being used.
+   */
   struct GNUNET_TIME_Absolute expire_date;
+
+  /**
+   * When the signing key becomes invalid for proof.
+   */
   struct GNUNET_TIME_Absolute end_date;
 };
 
 
+/**
+ * Creates an exchange signing key.
+ *
+ * @param signkey the signing key data to fill.
+ */
 static void
 make_exchange_signkey (struct ExchangeSignkeyData *signkey)
 {
@@ -2018,29 +2144,68 @@ make_exchange_signkey (struct ExchangeSignkeyData 
*signkey)
  */
 struct DepositData
 {
+  /**
+   * When the deposit was made.
+   */
   struct GNUNET_TIME_Absolute timestamp;
 
+  /**
+   * Hash of the associated order's contract terms.
+   */
   struct GNUNET_HashCode h_contract_terms;
 
+  /**
+   * Public key of the coin that has been deposited.
+   */
   struct TALER_CoinSpendPublicKeyP coin_pub;
 
+  /**
+   * URL of the exchange.
+   */
   const char *exchange_url;
 
+  /**
+   * Value of the coin with fees applied.
+   */
   struct TALER_Amount amount_with_fee;
 
+  /**
+   * Fee charged for deposit.
+   */
   struct TALER_Amount deposit_fee;
 
+  /**
+   * Fee to be charged in case of a refund.
+   */
   struct TALER_Amount refund_fee;
 
+  /**
+   * Fee charged after the money is wired.
+   */
   struct TALER_Amount wire_fee;
 
+  /**
+   * Hash of the wire details.
+   */
   struct GNUNET_HashCode h_wire;
 
+  /**
+   * Signature the exchange made on this deposit.
+   */
   struct TALER_ExchangeSignatureP exchange_sig;
 
 };
 
 
+/**
+ * Generates deposit data for an order.
+ *
+ * @param instance the instance to make the deposit to.
+ * @param account the merchant account to use.
+ * @param order the order this deposit is for.
+ * @param signkey the signing key to use.
+ * @param deposit the deposit data to fill.
+ */
 static void
 make_deposit (const struct InstanceData *instance,
               const struct TALER_MERCHANTDB_AccountDetails *account,
@@ -2097,6 +2262,64 @@ make_deposit (const struct InstanceData *instance,
 }
 
 
+/**
+ * Tests inserting an exchange signing key into the database.
+ *
+ * @param signkey the signing key to insert.
+ * @param expected_result the result we expect the database to return.
+ * @return 0 on success, 1 otherwise.
+ */
+static int
+test_insert_exchange_signkey (const struct ExchangeSignkeyData *signkey,
+                              enum GNUNET_DB_QueryStatus expected_result)
+{
+  TEST_COND_RET_ON_FAIL (expected_result ==
+                         plugin->insert_exchange_signkey (plugin->cls,
+                                                          &signkey->master_pub,
+                                                          
&signkey->exchange_pub,
+                                                          signkey->start_date,
+                                                          signkey->expire_date,
+                                                          signkey->end_date,
+                                                          
&signkey->master_sig),
+                         "Insert exchange signkey failed\n");
+  return 0;
+}
+
+
+/**
+ * Tests inserting a deposit into the database.
+ *
+ * @param instance the instance the deposit was made to.
+ * @param signkey the signing key used.
+ * @param deposit the deposit information to insert.
+ * @param expected_result the result we expect the database to return.
+ * @return 0 on success, 1 otherwise.
+ */
+static int
+test_insert_deposit (const struct InstanceData *instance,
+                     const struct ExchangeSignkeyData *signkey,
+                     const struct DepositData *deposit,
+                     enum GNUNET_DB_QueryStatus expected_result)
+{
+  TEST_COND_RET_ON_FAIL (expected_result ==
+                         plugin->insert_deposit (plugin->cls,
+                                                 instance->instance.id,
+                                                 deposit->timestamp,
+                                                 &deposit->h_contract_terms,
+                                                 &deposit->coin_pub,
+                                                 deposit->exchange_url,
+                                                 &deposit->amount_with_fee,
+                                                 &deposit->deposit_fee,
+                                                 &deposit->refund_fee,
+                                                 &deposit->wire_fee,
+                                                 &deposit->h_wire,
+                                                 &deposit->exchange_sig,
+                                                 &signkey->exchange_pub),
+                         "Insert deposit failed\n");
+  return 0;
+}
+
+
 /**
  * Closure for testing deposit lookup
  */
@@ -2124,6 +2347,16 @@ struct TestLookupDeposits_Closure
 };
 
 
+/**
+ * Called after 'test_lookup_deposits'.
+ *
+ * @param cls pointer to the test lookup closure.
+ * @param coin_pub public key of the coin deposited.
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param deposit_fee fee charged for the deposit.
+ * @param refund_fee fee charged in case of a refund.
+ * @param wire_fee fee charged when the money is wired.
+ */
 static void
 lookup_deposits_cb (void *cls,
                     const char *exchange_url,
@@ -2167,6 +2400,72 @@ lookup_deposits_cb (void *cls,
 }
 
 
+/**
+ * Tests looking up deposits from the database.
+ *
+ * @param instance the instance to lookup deposits from.
+ * @param h_contract_terms the contract terms that the deposits should have.
+ * @param deposits_length length of @e deposits.
+ * @param deposits the deposits we expect to be found.
+ * @return 0 on success, 1 otherwise.
+ */
+static int
+test_lookup_deposits (const struct InstanceData *instance,
+                      const struct GNUNET_HashCode *h_contract_terms,
+                      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);
+  TEST_COND_RET_ON_FAIL (deposits_length ==
+                         plugin->lookup_deposits (plugin->cls,
+                                                  instance->instance.id,
+                                                  h_contract_terms,
+                                                  &lookup_deposits_cb,
+                                                  &cmp),
+                         "Lookup deposits failed\n");
+  if (deposits_length != cmp.results_length)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup deposits failed: incorrect number of results 
returned\n");
+    return 1;
+  }
+  for (unsigned int i = 0; deposits_length > i; ++i)
+  {
+    if (cmp.results_matching[i] != 1)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Lookup deposits failed: mismatched data\n");
+      return 1;
+    }
+  }
+  return 0;
+}
+
+
+/**
+ * Called after 'test_lookup_deposits_contract_and_coin'.
+ *
+ * @param cls pointer to the test lookup closure.
+ * @param exchange_url URL to the exchange
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param deposit_fee fee charged for the deposit.
+ * @param refund_fee fee charged in case of a refund.
+ * @param wire_fee fee charged when the money is wired.
+ * @param h_wire hash of the wire transfer details.
+ * @param deposit_timestamp when the deposit was made.
+ * @param refund_deadline deadline for refunding the deposit.
+ * @param exchange_sig signature the exchange made on the deposit.
+ * @param exchange_pub public key of the exchange.
+ */
 static void
 lookup_deposits_contract_coin_cb (void *cls,
                                   const char *exchange_url,
@@ -2223,90 +2522,16 @@ lookup_deposits_contract_coin_cb (void *cls,
 }
 
 
-static int
-test_insert_exchange_signkey (const struct ExchangeSignkeyData *signkey,
-                              enum GNUNET_DB_QueryStatus expected_result)
-{
-  TEST_COND_RET_ON_FAIL (expected_result ==
-                         plugin->insert_exchange_signkey (plugin->cls,
-                                                          &signkey->master_pub,
-                                                          
&signkey->exchange_pub,
-                                                          signkey->start_date,
-                                                          signkey->expire_date,
-                                                          signkey->end_date,
-                                                          
&signkey->master_sig),
-                         "Insert exchange signkey failed\n");
-  return 0;
-}
-
-
-static int
-test_insert_deposit (const struct InstanceData *instance,
-                     const struct ExchangeSignkeyData *signkey,
-                     const struct DepositData *deposit,
-                     enum GNUNET_DB_QueryStatus expected_result)
-{
-  TEST_COND_RET_ON_FAIL (expected_result ==
-                         plugin->insert_deposit (plugin->cls,
-                                                 instance->instance.id,
-                                                 deposit->timestamp,
-                                                 &deposit->h_contract_terms,
-                                                 &deposit->coin_pub,
-                                                 deposit->exchange_url,
-                                                 &deposit->amount_with_fee,
-                                                 &deposit->deposit_fee,
-                                                 &deposit->refund_fee,
-                                                 &deposit->wire_fee,
-                                                 &deposit->h_wire,
-                                                 &deposit->exchange_sig,
-                                                 &signkey->exchange_pub),
-                         "Insert deposit failed\n");
-  return 0;
-}
-
-
-static int
-test_lookup_deposits (const struct InstanceData *instance,
-                      const struct GNUNET_HashCode *h_contract_terms,
-                      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);
-  TEST_COND_RET_ON_FAIL (deposits_length ==
-                         plugin->lookup_deposits (plugin->cls,
-                                                  instance->instance.id,
-                                                  h_contract_terms,
-                                                  &lookup_deposits_cb,
-                                                  &cmp),
-                         "Lookup deposits failed\n");
-  if (deposits_length != cmp.results_length)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Lookup deposits failed: incorrect number of results 
returned\n");
-    return 1;
-  }
-  for (unsigned int i = 0; deposits_length > i; ++i)
-  {
-    if (cmp.results_matching[i] != 1)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Lookup deposits failed: mismatched data\n");
-      return 1;
-    }
-  }
-  return 0;
-}
-
-
+/**
+ * Tests lookup of deposits by contract and coin.
+ *
+ * @param instance the instance to lookup from.
+ * @param h_contract the contract terms the deposits should have.
+ * @param coin_pub the public key of the coin the deposits should have.
+ * @param deposits_length length of @e deposits.
+ * @param deposits the deposits the db is expected to find.
+ * @return 0 on success, 1 otherwise.
+ */
 static int
 test_lookup_deposits_contract_and_coin (const struct InstanceData *instance,
                                         const struct
@@ -2356,6 +2581,18 @@ test_lookup_deposits_contract_and_coin (const struct 
InstanceData *instance,
 }
 
 
+/**
+ * Called after 'test_lookup_deposits_by_order'.
+ *
+ * @param cls pointer to the test lookup closure.
+ * @param deposit_serial row number of the deposit in the database.
+ * @param exchange_url URL to the exchange
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param h_wire hash of the wire transfer details.
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param deposit_fee fee charged for the deposit.
+ * @param coin_pub public key of the coin deposited.
+ */
 static void
 lookup_deposits_order_cb (void *cls,
                           uint64_t deposit_serial,
@@ -2392,6 +2629,14 @@ lookup_deposits_order_cb (void *cls,
 }
 
 
+/**
+ * Tests looking up deposits by associated order.
+ *
+ * @param order_serial row number of the order to lookup for.
+ * @param deposits_length length of @e deposits_length.
+ * @param deposits the deposits we expect to be found.
+ * @return 0 on success, 1 otherwise.
+ */
 static int
 test_lookup_deposits_by_order (uint64_t order_serial,
                                unsigned int deposits_length,
@@ -2436,6 +2681,98 @@ test_lookup_deposits_by_order (uint64_t order_serial,
 }
 
 
+/**
+ * Container for information for looking up the row number of a deposit.
+ */
+struct LookupDepositSerial_Closure
+{
+  /**
+   * The deposit we're looking for.
+   */
+  const struct DepositData *deposit;
+
+  /**
+   * The serial found.
+   */
+  uint64_t serial;
+};
+
+
+/**
+ * Called after 'get_deposit_serial'.
+ *
+ * @param cls pointer to the test lookup closure.
+ * @param deposit_serial row number of the deposit in the database.
+ * @param exchange_url URL to the exchange
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param h_wire hash of the wire transfer details.
+ * @param amount_with_fee amount of the deposit with fees.
+ * @param deposit_fee fee charged for the deposit.
+ * @param coin_pub public key of the coin deposited.
+ */
+static void
+get_deposit_serial_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 LookupDepositSerial_Closure *lookup_cls = cls;
+  if (NULL == lookup_cls)
+    return;
+  if ((0 == strcmp (lookup_cls->deposit->exchange_url,
+                    exchange_url)) &&
+      (0 == GNUNET_memcmp (&lookup_cls->deposit->h_wire,
+                           h_wire)) &&
+      (GNUNET_OK == TALER_amount_cmp_currency (
+         &lookup_cls->deposit->amount_with_fee,
+         amount_with_fee)) &&
+      (0 == TALER_amount_cmp (&lookup_cls->deposit->amount_with_fee,
+                              amount_with_fee)) &&
+      (GNUNET_OK == TALER_amount_cmp_currency (
+         &lookup_cls->deposit->deposit_fee,
+         deposit_fee)) &&
+      (0 == TALER_amount_cmp (&lookup_cls->deposit->deposit_fee,
+                              deposit_fee)) &&
+      (0 == GNUNET_memcmp (&lookup_cls->deposit->coin_pub,
+                           coin_pub)))
+    lookup_cls->serial = deposit_serial;
+}
+
+
+/**
+ * Convenience function to retrive the row number of a deposit in the database.
+ *
+ * @param instance the instance to get deposits from.
+ * @param order the order associated with the deposit.
+ * @param deposit the deposit to lookup the serial for.
+ * @return the row number of the deposit.
+ */
+static uint64_t
+get_deposit_serial (const struct InstanceData *instance,
+                    const struct OrderData *order,
+                    const struct DepositData *deposit)
+{
+  uint64_t order_serial = get_order_serial (instance,
+                                            order);
+  struct LookupDepositSerial_Closure lookup_cls = {
+    .deposit = deposit,
+    .serial = 0
+  };
+
+  GNUNET_assert (0 <
+                 plugin->lookup_deposits_by_order (plugin->cls,
+                                                   order_serial,
+                                                   &get_deposit_serial_cb,
+                                                   &lookup_cls));
+  GNUNET_assert (0 != lookup_cls.serial);
+
+  return lookup_cls.serial;
+}
+
+
 /**
  * Closure for deposit tests.
  */
@@ -2468,6 +2805,11 @@ struct TestDeposits_Closure
 };
 
 
+/**
+ * Initializes data for testing deposits.
+ *
+ * @param cls the test closure to initialize.
+ */
 static void
 pre_test_deposits (struct TestDeposits_Closure *cls)
 {
@@ -2502,6 +2844,11 @@ pre_test_deposits (struct TestDeposits_Closure *cls)
 }
 
 
+/**
+ * Cleans up memory after testing deposits.
+ *
+ * @param cls the closure containing memory to free.
+ */
 static void
 post_test_deposits (struct TestDeposits_Closure *cls)
 {
@@ -2510,6 +2857,12 @@ post_test_deposits (struct TestDeposits_Closure *cls)
 }
 
 
+/**
+ * Runs tests for deposits.
+ *
+ * @param cls the closure containing test data.
+ * @return 0 on success, 1 otherwise.
+ */
 static int
 run_test_deposits (struct TestDeposits_Closure *cls)
 {
@@ -2563,15 +2916,24 @@ run_test_deposits (struct TestDeposits_Closure *cls)
                                           2,
                                           cls->deposits));
   /* Test lookup deposits by order */
-  TEST_RET_ON_FAIL (test_lookup_deposits_by_order (4,
-                                                   2,
-                                                   cls->deposits));
+  {
+    uint64_t order_serial = get_order_serial (&cls->instance,
+                                              &cls->order);
+    TEST_RET_ON_FAIL (test_lookup_deposits_by_order (order_serial,
+                                                     2,
+                                                     cls->deposits));
+  }
   return 0;
 }
 
 
+/**
+ * Handles functionality for testing deposits.
+ *
+ * @return 0 on success, 1 otherwise.
+ */
 static int
-test_deposits (void *cls)
+test_deposits (void)
 {
   struct TestDeposits_Closure test_cls;
   pre_test_deposits (&test_cls);
@@ -3206,6 +3568,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   struct TransferWithDetails full_transfer_data = {
     .wtid = wtid
   };
+  uint64_t order_serial;
 
   /* Test lookup wire fee fails when it isn't in the db */
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
@@ -3248,6 +3611,8 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
                                                 &cls->order,
                                                 
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  order_serial = get_order_serial (&cls->instance,
+                                   &cls->order);
   /* Insert the deposit */
   TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
                                          &cls->signkey,
@@ -3285,7 +3650,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:0.49",
                                          &transfer_data.wire_fee));
-  TEST_RET_ON_FAIL (test_lookup_payment_status (5,
+  TEST_RET_ON_FAIL (test_lookup_payment_status (order_serial,
                                                 NULL,
                                                 false,
                                                 false));
@@ -3298,14 +3663,17 @@ run_test_transfers (struct TestTransfers_Closure *cls)
       .execution_time = transfer_data.execution_time,
       .coin_contribution = transfer_data.total_amount
     };
+    uint64_t deposit_serial = get_deposit_serial (&cls->instance,
+                                                  &cls->order,
+                                                  &cls->deposit);
     TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
                            plugin->insert_deposit_to_transfer (plugin->cls,
-                                                               4,
+                                                               deposit_serial,
                                                                &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,
-                                                               4,
+                                                               deposit_serial,
                                                                &deposit_data),
                            "Insert deposit to transfer failed\n");
   }
@@ -3319,7 +3687,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
                                                           &wtid,
                                                           &transfer_data),
                          "Insert transfer details failed\n");
-  TEST_RET_ON_FAIL (test_lookup_payment_status (5,
+  TEST_RET_ON_FAIL (test_lookup_payment_status (order_serial,
                                                 NULL,
                                                 false,
                                                 true));
@@ -3380,7 +3748,7 @@ run_test_transfers (struct TestTransfers_Closure *cls)
         .confirmed = true
       }
     };
-    TEST_RET_ON_FAIL (test_lookup_transfer_details_by_order (5,
+    TEST_RET_ON_FAIL (test_lookup_transfer_details_by_order (order_serial,
                                                              1,
                                                              transfers));
   }
@@ -4595,6 +4963,65 @@ test_lookup_refunds_detailed (const char *instance_id,
 }
 
 
+struct LookupRefundSerial_Closure
+{
+  const struct RefundData *refund;
+
+  uint64_t serial;
+};
+
+
+static void
+get_refund_serial_cb (void *cls,
+                      uint64_t refund_serial,
+                      struct GNUNET_TIME_Absolute timestamp,
+                      const struct TALER_CoinSpendPublicKeyP *coin_pub,
+                      const char *exchange_url,
+                      uint64_t rtransaction_id,
+                      const char *reason,
+                      const struct TALER_Amount *refund_amount)
+{
+  struct LookupRefundSerial_Closure *lookup_cls = cls;
+  if (NULL == lookup_cls)
+    return;
+  if ((lookup_cls->refund->timestamp.abs_value_us ==
+       timestamp.abs_value_us) &&
+      (0 == GNUNET_memcmp (lookup_cls->refund->coin_pub,
+                           coin_pub)) &&
+      (0 == strcmp (lookup_cls->refund->exchange_url,
+                    exchange_url)) &&
+      (0 == strcmp (lookup_cls->refund->reason,
+                    reason)) &&
+      (GNUNET_OK == TALER_amount_cmp_currency (
+         &lookup_cls->refund->refund_amount,
+         refund_amount)) &&
+      (0 == TALER_amount_cmp (&lookup_cls->refund->refund_amount,
+                              refund_amount)))
+    lookup_cls->serial = refund_serial;
+}
+
+
+static uint64_t
+get_refund_serial (const struct InstanceData *instance,
+                   const struct GNUNET_HashCode *h_contract_terms,
+                   const struct RefundData *refund)
+{
+  struct LookupRefundSerial_Closure lookup_cls = {
+    .refund = refund,
+    .serial = 0
+  };
+
+  GNUNET_assert (0 < plugin->lookup_refunds_detailed (plugin->cls,
+                                                      instance->instance.id,
+                                                      h_contract_terms,
+                                                      &get_refund_serial_cb,
+                                                      &lookup_cls));
+  GNUNET_assert (0 != lookup_cls.serial);
+
+  return lookup_cls.serial;
+}
+
+
 static int
 test_lookup_refund_proof (uint64_t refund_serial,
                           const struct
@@ -4726,6 +5153,7 @@ static int
 run_test_refunds (struct TestRefunds_Closure *cls)
 {
   struct TALER_Amount inc;
+  uint64_t refund_serial;
 
   /* Insert an instance */
   TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
@@ -4767,6 +5195,9 @@ run_test_refunds (struct TestRefunds_Closure *cls)
                                               cls->refund.coin_pub,
                                               cls->refund.reason),
                          "Refund coin failed\n");
+  refund_serial = get_refund_serial (&cls->instance,
+                                     &cls->deposits[0].h_contract_terms,
+                                     &cls->refund);
   /* Test double refund fails */
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
                          plugin->refund_coin (plugin->cls,
@@ -4791,7 +5222,7 @@ run_test_refunds (struct TestRefunds_Closure *cls)
   /* Test insert refund proof */
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
                          plugin->insert_refund_proof (plugin->cls,
-                                                      1, // TODO: get this 
from lookup
+                                                      refund_serial,
                                                       &cls->refund_proof.
                                                       refund_fee,
                                                       &cls->refund_proof.
@@ -4800,7 +5231,7 @@ run_test_refunds (struct TestRefunds_Closure *cls)
                          "Insert refund proof failed\n");
   TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
                          plugin->insert_refund_proof (plugin->cls,
-                                                      1, // TODO: get this 
from lookup
+                                                      refund_serial,
                                                       &cls->refund_proof.
                                                       refund_fee,
                                                       &cls->refund_proof.
@@ -4957,9 +5388,13 @@ run_test_lookup_orders_all_filters (struct
                                                   
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
   for (unsigned int i = 0; i < 64; ++i)
   {
+    uint64_t order_serial;
+
     TEST_RET_ON_FAIL (test_insert_order (&cls->instance,
                                          &cls->orders[i],
                                          GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+    order_serial = get_order_serial (&cls->instance,
+                                     &cls->orders[i]);
 
     if (order_status[i].claimed)
     {
@@ -4994,7 +5429,7 @@ run_test_lookup_orders_all_filters (struct
     }
 
     if (order_status[i].wired)
-      TEST_RET_ON_FAIL (test_mark_order_wired (7 + i,
+      TEST_RET_ON_FAIL (test_mark_order_wired (order_serial,
                                                
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
   }
 
@@ -5078,7 +5513,7 @@ run_tests (void *cls)
   TEST_RET_ON_FAIL (test_instances ());
   TEST_RET_ON_FAIL (test_products ());
   TEST_RET_ON_FAIL (test_orders ());
-  TEST_RET_ON_FAIL (test_deposits (cls));
+  TEST_RET_ON_FAIL (test_deposits ());
   TEST_RET_ON_FAIL (test_transfers (cls));
   TEST_RET_ON_FAIL (test_tips (cls));
   TEST_RET_ON_FAIL (test_refunds (cls));

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