merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 60e2a7848465684a35041df7f56cd57d54941d16
parent 9458a7ddacc7b3939777fa9a5b802484451849a5
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  6 Aug 2026 00:14:37 +0200

fix stock update to include monotonicity constraint on fractional stock

Diffstat:
Msrc/backenddb/test_merchantdb.c | 33+++++++++++++++++++++++++++++++++
Msrc/backenddb/update_product.sql | 7++++++-
2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -2070,6 +2070,39 @@ run_test_products (struct TestProducts_Closure *cls) false, -1)); + /* Stock is the pair (total_stock, total_stock_frac): raise the + fractional part, then check that lowering only the fractional part + is refused just like lowering the integer part. */ + cls->products[0].product.total_stock_frac = 500000; + TEST_RET_ON_FAIL (test_update_product ( + &cls->instance, + &cls->products[0], + 0, + NULL, + GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, + false, + false, + false, + false, + false, + -1)); + { + struct ProductData frac_dec = cls->products[0]; + + frac_dec.product.total_stock_frac = 400000; + TEST_RET_ON_FAIL (test_update_product ( + &cls->instance, + &frac_dec, + 0, + NULL, + GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, + false, + false, + false, + false, + true, + -1)); + } { struct ProductData stock_dec = cls->products[0]; diff --git a/src/backenddb/update_product.sql b/src/backenddb/update_product.sql @@ -103,7 +103,12 @@ END IF; my_product_serial = rec.product_serial; -IF rec.total_stock > in_total_stock +-- Stock is the pair (total_stock, total_stock_frac); comparing only the +-- integer part would let a PATCH that keeps total_stock but lowers +-- total_stock_frac slip past this guard. +IF (rec.total_stock > in_total_stock) + OR ( (rec.total_stock = in_total_stock) + AND (rec.total_stock_frac > in_total_stock_frac) ) THEN out_stocked_reduced=TRUE; RETURN;