gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: fix product update logic


From: gnunet
Subject: [taler-merchant] branch master updated: fix product update logic
Date: Sat, 24 Apr 2021 20:14:43 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 50f2485a fix product update logic
50f2485a is described below

commit 50f2485ae6ce6e99dcf29712c2008eae17e3ddc3
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Apr 24 20:14:41 2021 +0200

    fix product update logic
---
 src/backenddb/plugin_merchantdb_postgres.c | 17 ++++++++++-------
 src/backenddb/test_merchantdb.c            | 22 ++++++++++++++--------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index efdfff9a..84c3827e 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1111,14 +1111,16 @@ postgres_update_product (void *cls,
     GNUNET_PQ_query_param_string (pd->unit),
     GNUNET_PQ_query_param_string (pd->image), /* $6 */
     TALER_PQ_query_param_json (pd->taxes),
-    TALER_PQ_query_param_amount (&pd->price),
-    GNUNET_PQ_query_param_uint64 (&pd->total_stock),
-    GNUNET_PQ_query_param_uint64 (&pd->total_lost), /* $10 */
+    TALER_PQ_query_param_amount (&pd->price), /* $8+$9 */
+    GNUNET_PQ_query_param_uint64 (&pd->total_stock),  /* $10 */
+    GNUNET_PQ_query_param_uint64 (&pd->total_lost),
+    GNUNET_PQ_query_param_uint64 (&pd->total_sold),
     TALER_PQ_query_param_json (pd->address),
     GNUNET_PQ_query_param_absolute_time (&pd->next_restock),
     GNUNET_PQ_query_param_end
   };
 
+  GNUNET_assert (pd->total_stock >= pd->total_lost + pd->total_sold);
   check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "update_product",
@@ -6317,17 +6319,18 @@ postgres_connect (void *cls)
                             ",price_frac=$9"
                             ",total_stock=$10"
                             ",total_lost=$11"
-                            ",address=$12"
-                            ",next_restock=$13"
+                            ",total_sold=$12"
+                            ",address=$13"
+                            ",next_restock=$14"
                             " WHERE merchant_serial="
                             "   (SELECT merchant_serial"
                             "      FROM merchant_instances"
                             "      WHERE merchant_id=$1)"
                             "   AND product_id=$2"
                             "   AND total_stock <= $10"
-                            "   AND $10 - total_sold >= $11"
+                            "   AND total_sold <= $12"
                             "   AND total_lost <= $11",
-                            13),
+                            14),
 
     /* for postgres_lock_product() */
     GNUNET_PQ_make_prepare ("lock_product",
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index dd32e652..bd357ae8 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -40,12 +40,14 @@ static struct TALER_MERCHANTDB_Plugin *plugin;
 #define TEST_WITH_FAIL_CLAUSE(test, on_fail) \
   if (0 != (test)) \
   { \
+    GNUNET_break (0); \
     on_fail \
   }
 
 #define TEST_COND_RET_ON_FAIL(cond, msg) \
   if (! (cond)) \
   { \
+    GNUNET_break (0); \
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
                 msg); \
     return 1; \
@@ -872,6 +874,7 @@ test_lookup_product (const struct InstanceData *instance,
   if (0 != check_products_equal (&lookup_result,
                                  to_cmp))
   {
+    GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Lookup product failed: incorrect product returned\n");
     TALER_MERCHANTDB_product_details_free (&lookup_result);
@@ -1120,7 +1123,7 @@ run_test_products (struct TestProducts_Closure *cls)
                  json_array_append_new (cls->products[0].product.taxes,
                                         json_string ("2% sales tax")));
   cls->products[0].product.total_stock = 100;
-  cls->products[0].product.total_sold = 10;
+  cls->products[0].product.total_sold = 0; /* will be ignored! */
   cls->products[0].product.total_lost = 7;
   GNUNET_free (cls->products[0].product.image);
   cls->products[0].product.image = GNUNET_strdup ("image");
@@ -1134,25 +1137,28 @@ run_test_products (struct TestProducts_Closure *cls)
 
   {
     struct ProductData stock_dec = cls->products[0];
+
     stock_dec.product.total_stock = 40;
     TEST_RET_ON_FAIL (test_update_product (&cls->instance,
                                            &stock_dec,
                                            
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
   }
-  {
-    struct ProductData sold_dec = cls->products[0];
-    sold_dec.product.total_sold = 5;
-    TEST_RET_ON_FAIL (test_update_product (&cls->instance,
-                                           &sold_dec,
-                                           
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
-  }
   {
     struct ProductData lost_dec = cls->products[0];
+
     lost_dec.product.total_lost = 1;
     TEST_RET_ON_FAIL (test_update_product (&cls->instance,
                                            &lost_dec,
                                            
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
   }
+  cls->products[0].product.total_sold = 5;
+  {
+    struct ProductData sold_dec = cls->products[0];
+
+    TEST_RET_ON_FAIL (test_update_product (&cls->instance,
+                                           &sold_dec,
+                                           
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  }
   TEST_RET_ON_FAIL (test_lookup_product (&cls->instance,
                                          &cls->products[0]));
   TEST_RET_ON_FAIL (test_update_product (&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]