gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: purge instance and more merchant


From: gnunet
Subject: [taler-merchant] branch master updated: purge instance and more merchant api purge tests
Date: Wed, 08 Jul 2020 08:20:14 +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 a5e33f1  purge instance and more merchant api purge tests
a5e33f1 is described below

commit a5e33f1a6d3f865a7c169783c63007cfdd3c30eb
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Wed Jul 8 02:19:55 2020 -0400

    purge instance and more merchant api purge tests
---
 src/backenddb/plugin_merchantdb_postgres.c |   2 +-
 src/backenddb/test_merchantdb.c            | 122 +++++++++++++++++++++++++++--
 src/testing/test_merchant_api.c            |  16 ++++
 3 files changed, 133 insertions(+), 7 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index d44ac15..aab9a55 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -5992,7 +5992,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             " AND merchant_instances.merchant_id = $1",
                             1),
     /* for postgres_purge_instance() */
-    GNUNET_PQ_make_prepare ("purge_keys",
+    GNUNET_PQ_make_prepare ("purge_instance",
                             "DELETE FROM merchant_instances"
                             " WHERE merchant_instances.merchant_id = $1",
                             1),
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index cf3fa58..5f3def2 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -423,6 +423,25 @@ test_delete_instance_private_key (const struct 
InstanceData *instance,
 }
 
 
+/**
+ * Tests purging all data for an instance from the database.
+ *
+ * @param instance the instance to purge.
+ * @param expected_result the result we expect the db to return.
+ * @return 0 on success, 1 otherwise.
+ */
+static int
+test_purge_instance (const struct InstanceData *instance,
+                     enum GNUNET_DB_QueryStatus expected_result)
+{
+  TEST_COND_RET_ON_FAIL (expected_result ==
+                         plugin->purge_instance (plugin->cls,
+                                                 instance->instance.id),
+                         "Purge instance failed\n");
+  return 0;
+}
+
+
 /**
  * Tests inserting an account for a merchant instance.
  *
@@ -647,6 +666,14 @@ run_test_instances (struct TestInstances_Closure *cls)
   TEST_RET_ON_FAIL (test_lookup_instances (true,
                                            1,
                                            &instances[1]));
+  TEST_RET_ON_FAIL (test_purge_instance (&cls->instances[1],
+                                         GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  TEST_RET_ON_FAIL (test_purge_instance (&cls->instances[1],
+                                         GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
+  /* Test that the instance is gone. */
+  TEST_RET_ON_FAIL (test_lookup_instances (false,
+                                           1,
+                                           instances));
   return 0;
 }
 
@@ -4264,6 +4291,14 @@ struct ReserveData
 };
 
 
+/**
+ * Tests inserting a reserve into the database.
+ * @paper instance the instance the reserve is for.
+ * @param reserve the reserve to insert.
+ * @param expected_result the result we expect to receive from the db.
+ *
+ * @return 0 on success, 1 otherwise.
+ */
 static int
 test_insert_reserve (const struct InstanceData *instance,
                      const struct ReserveData *reserve,
@@ -4282,18 +4317,50 @@ test_insert_reserve (const struct InstanceData 
*instance,
 }
 
 
+/**
+ * Container for looking up reserves.
+ */
 struct TestLookupReserve_Closure
 {
+  /**
+   * The reserve we expect to find.
+   */
   const struct ReserveData *reserve_to_cmp;
 
+  /**
+   * The length of @e tips.
+   */
   unsigned int tips_length;
 
+  /**
+   * The tips that have been authorized from the reserve.
+   */
   const struct TALER_MERCHANTDB_TipDetails *tips;
 
+  /**
+   * 1 if the result matches, 0 otherwise.
+   */
   int result_matches;
 };
 
 
+/**
+ * Called after test_lookup_reserve.
+ * @param cls a pointer to TestLookupReserve_Closure.
+ * @param creation_time time when the reserve was setup
+ * @param expiration_time time when the reserve will be closed by the exchange
+ * @param merchant_initial_amount initial amount that the merchant claims to 
have filled the
+ *           reserve with
+ * @param exchange_initial_amount initial amount that the exchange claims to 
have received
+ * @param picked_up_amount total of tips that were picked up from this reserve
+ * @param committed_amount total of tips that the merchant committed to, but 
that were not
+ *           picked up yet
+ * @param active true if the reserve is still active (we have the private key)
+ * @param tips_length length of the @a tips array
+ * @param tips information about the tips created by this reserve
+ *
+ * @return 0 on success, 1 otherwise.
+ */
 static void
 lookup_reserve_cb (void *cls,
                    struct GNUNET_TIME_Absolute creation_time,
@@ -4350,8 +4417,16 @@ lookup_reserve_cb (void *cls,
 }
 
 
+/**
+ * Tests looking up details of a reserve from the database.
+ * @param instance the instance to lookup the reserve from.
+ * @param reserve_pub the public key of the reserve we are looking for.
+ * @param reserve the data we expect to find.
+ *
+ * @return 0 on success, 1 otherwise.
+ */
 static int
-test_lookup_reserve (const char *instance_id,
+test_lookup_reserve (const struct InstanceData *instance,
                      const struct TALER_ReservePublicKeyP *reserve_pub,
                      const struct ReserveData *reserve)
 {
@@ -4362,7 +4437,7 @@ test_lookup_reserve (const char *instance_id,
     .result_matches = 0
   };
   if (1 != plugin->lookup_reserve (plugin->cls,
-                                   instance_id,
+                                   instance->instance.id,
                                    reserve_pub,
                                    false,
                                    &lookup_reserve_cb,
@@ -4382,18 +4457,47 @@ test_lookup_reserve (const char *instance_id,
 }
 
 
+/**
+ * Container for looking up multiple reserves.
+ */
 struct TestLookupReserves_Closure
 {
+  /**
+   * The length of @e reserves_to_cmp.
+   */
   unsigned int reserves_to_cmp_length;
 
+  /**
+   * The reserves we expect to find from the lookup.
+   */
   const struct ReserveData *reserves_to_cmp;
 
+  /**
+   * The number of results matching each reserve we were looking for.
+   */
   unsigned int *results_matching;
 
+  /**
+   * The total number of results found from the lookup.
+   */
   unsigned int results_length;
 };
 
 
+/**
+ * Called after test_lookup_reserves.
+ * @param cls pointer to a TestLookupReserves_Closure.
+ * @param reserve_pub public key of the reserve
+ * @param creation_time time when the reserve was setup
+ * @param expiration_time time when the reserve will be closed by the exchange
+ * @param merchant_initial_amount initial amount that the merchant claims to 
have filled the
+ *           reserve with
+ * @param exchange_initial_amount initial amount that the exchange claims to 
have received
+ * @param pickup_amount total of tips that were picked up from this reserve
+ * @param committed_amount total of tips that the merchant committed to, but 
that were not
+ *           picked up yet
+ * @param active true if the reserve is still active (we have the private key)
+ */
 static void
 lookup_reserves_cb (void *cls,
                     const struct TALER_ReservePublicKeyP *reserve_pub,
@@ -4427,8 +4531,14 @@ lookup_reserves_cb (void *cls,
 }
 
 
+/**
+ * Test looking up reserves for an instance.
+ * @param instance the instance to get the reserves from.
+ *
+ * @returns 0 on success, 1 otherwise.
+ */
 static int
-test_lookup_reserves (const char *instance_id,
+test_lookup_reserves (const struct InstanceData *instance,
                       unsigned int reserves_length,
                       const struct ReserveData *reserves)
 {
@@ -4441,7 +4551,7 @@ test_lookup_reserves (const char *instance_id,
   };
   memset (results_matching, 0, sizeof (unsigned int) * reserves_length);
   if (1 != plugin->lookup_reserves (plugin->cls,
-                                    instance_id,
+                                    instance->instance.id,
                                     GNUNET_TIME_absolute_get_zero_ (),
                                     TALER_EXCHANGE_YNA_ALL,
                                     TALER_EXCHANGE_YNA_ALL,
@@ -5022,7 +5132,7 @@ run_test_tips (struct TestTips_Closure *cls)
                                          &cls->reserve,
                                          TALER_EC_NONE));
   /* Test lookup reserve */
-  TEST_RET_ON_FAIL (test_lookup_reserve (cls->instance.instance.id,
+  TEST_RET_ON_FAIL (test_lookup_reserve (&cls->instance,
                                          &cls->reserve.reserve_pub,
                                          &cls->reserve));
   /* Test lookup pending reserves */
@@ -5097,7 +5207,7 @@ run_test_tips (struct TestTips_Closure *cls)
                                       1,
                                       &cls->tip));
   /* Test lookup reserves */
-  TEST_RET_ON_FAIL (test_lookup_reserves (cls->instance.instance.id,
+  TEST_RET_ON_FAIL (test_lookup_reserves (&cls->instance,
                                           1,
                                           &cls->reserve));
   {
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index e79c9ab..ca4a447 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -271,6 +271,10 @@ run (void *cls,
                               "create-reserve-1",
                               "EUR:0",
                               MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_delete_order ("delete-order-nx",
+                                             merchant_url,
+                                             "1",
+                                             MHD_HTTP_NOT_FOUND),
     TALER_TESTING_cmd_poll_orders_start ("poll-orders-1-start",
                                          merchant_url,
                                          GNUNET_TIME_UNIT_MINUTES),
@@ -1153,6 +1157,18 @@ run (void *cls,
                                              GNUNET_TIME_UNIT_MINUTES,
                                              2,
                                              MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_delete_product ("delete-product-locked",
+                                               merchant_url,
+                                               "product-2",
+                                               MHD_HTTP_CONFLICT),
+    TALER_TESTING_cmd_merchant_purge_instance ("instance-purge-i1",
+                                               merchant_url,
+                                               "i1",
+                                               MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_delete_instance ("instance-delete-i1-again",
+                                                merchant_url,
+                                                "i1",
+                                                MHD_HTTP_NOT_FOUND),
     TALER_TESTING_cmd_batch ("pay",
                              pay),
     TALER_TESTING_cmd_batch ("double-spending",

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