summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-04-24 20:30:14 +0200
committerChristian Grothoff <christian@grothoff.org>2021-04-24 20:30:14 +0200
commit6e86f307ba68972063f18702e63221b76738c320 (patch)
treecd68f40ff5362a7d193f18494b9bc86072e0d274
parent50f2485ae6ce6e99dcf29712c2008eae17e3ddc3 (diff)
downloadmerchant-6e86f307ba68972063f18702e63221b76738c320.tar.gz
merchant-6e86f307ba68972063f18702e63221b76738c320.tar.bz2
merchant-6e86f307ba68972063f18702e63221b76738c320.zip
fix DB test: total_sold must be ignored
-rw-r--r--src/backend/taler-merchant-httpd_private-patch-products-ID.c4
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c15
-rw-r--r--src/backenddb/test_merchantdb.c8
-rw-r--r--src/include/taler_merchantdb_plugin.h2
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;