gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: fix DB test: total_sold must be


From: gnunet
Subject: [taler-merchant] branch master updated: fix DB test: total_sold must be ignored
Date: Sat, 24 Apr 2021 20:30:16 +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 6e86f307 fix DB test: total_sold must be ignored
6e86f307 is described below

commit 6e86f307ba68972063f18702e63221b76738c320
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Apr 24 20:30:14 2021 +0200

    fix DB test: total_sold must be ignored
---
 .../taler-merchant-httpd_private-patch-products-ID.c      |  4 +++-
 src/backenddb/plugin_merchantdb_postgres.c                | 15 ++++++++-------
 src/backenddb/test_merchantdb.c                           |  8 --------
 src/include/taler_merchantdb_plugin.h                     |  2 +-
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
index f9f7bc67..3ea9b112 100644
--- a/src/backend/taler-merchant-httpd_private-patch-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
@@ -83,9 +83,11 @@ determine_cause (struct MHD_Connection *connection,
     ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     if (pdx.total_lost > pd->total_lost)
       ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_LOST_REDUCED;
+    if (pdx.total_sold > pd->total_sold)
+      ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_SOLD_REDUCED;
     if (pdx.total_stock > pd->total_stock)
       ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_STOCKED_REDUCED;
-    if (pd->total_stock - pdx.total_sold < pd->total_lost)
+    if (pd->total_stock < pd->total_sold + pd->total_lost)
       ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_LOST_EXCEEDS_STOCKS;
     TALER_MERCHANTDB_product_details_free (&pdx);
     GNUNET_break (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE != ec);
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 84c3827e..b5a75222 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1114,13 +1114,16 @@ postgres_update_product (void *cls,
     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);
+  if (pd->total_stock < pd->total_lost + pd->total_sold)
+  {
+    GNUNET_break (0);
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  }
   check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "update_product",
@@ -6319,18 +6322,16 @@ postgres_connect (void *cls)
                             ",price_frac=$9"
                             ",total_stock=$10"
                             ",total_lost=$11"
-                            ",total_sold=$12"
-                            ",address=$13"
-                            ",next_restock=$14"
+                            ",address=$12"
+                            ",next_restock=$13"
                             " WHERE merchant_serial="
                             "   (SELECT merchant_serial"
                             "      FROM merchant_instances"
                             "      WHERE merchant_id=$1)"
                             "   AND product_id=$2"
                             "   AND total_stock <= $10"
-                            "   AND total_sold <= $12"
                             "   AND total_lost <= $11",
-                            14),
+                            13),
 
     /* 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 bd357ae8..aabc431a 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1151,14 +1151,6 @@ run_test_products (struct TestProducts_Closure *cls)
                                            &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,
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index b0af068b..09063897 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -953,7 +953,7 @@ struct TALER_MERCHANTDB_Plugin
    * @param product_id product to lookup
    * @param pd set to the product details on success, can be NULL
    *             (in that case we only want to check if the product exists);
-   *             total_sold in @a pd is ignored, total_lost must not
+   *             total_sold in @a pd is ignored (!), total_lost must not
    *             exceed total_stock minus the existing total_sold;
    *             total_sold and total_stock must be larger or equal to
    *             the existing value;

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