diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-03-22 14:05:42 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-03-22 14:05:42 +0100 |
commit | 6d41df4ffbc0d921aecb265ecb49b15df5c7178e (patch) | |
tree | c0423a7df97f57a41ab3dc2ea620b22d1cb133b0 /src/testing | |
parent | 110b61ff12208ffbb022296097b85d28cc1cfe7e (diff) |
add logic to preserve and possibly update minimum_age in contract terms
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_merchant_api.c | 33 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_merchant_get_order.c | 61 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_products.c | 28 |
3 files changed, 112 insertions, 10 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index e9b492b3..ed07bce6 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -599,6 +599,20 @@ run (void *cls, "a product", "EUR:1", MHD_HTTP_NO_CONTENT), + TALER_TESTING_cmd_merchant_post_products2 ("post-products-p4", + merchant_url, + "product-4age", + "an age-restricted product", + NULL, + "unit", + "EUR:1", + "", /* image */ + NULL, + 4, + 16 /* minimum age */, + NULL, + GNUNET_TIME_UNIT_FOREVER_TS, + MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_patch_product ("patch-products-p3", merchant_url, "product-3", @@ -673,6 +687,25 @@ run (void *cls, "product-3/3", "lock-product-p3", NULL), + TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p4-age", + cred.cfg, + merchant_url, + MHD_HTTP_OK, + "order-p4-age", + GNUNET_TIME_UNIT_ZERO_TS, + GNUNET_TIME_UNIT_FOREVER_TS, + false, + "EUR:5.0", + "x-taler-bank", + "product-4age", + "", /* locks */ + NULL), + TALER_TESTING_cmd_merchant_get_order4 ("get-order-merchant-p4-age", + merchant_url, + "create-proposal-p4-age", + TALER_MERCHANT_OSC_CLAIMED, + 16, + MHD_HTTP_OK), TALER_TESTING_cmd_merchant_delete_order ("delete-order-paid", merchant_url, "1", diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index 1b235c93..6301c9f6 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -106,6 +106,11 @@ struct MerchantGetOrderState const char *repurchase_order_ref; /** + * Expected minimum age. + */ + unsigned int expected_min_age; + + /** * True if we should pass the 'allow_refunded_for_repurchase' flag. */ bool allow_refunded_for_repurchase; @@ -176,7 +181,9 @@ merchant_get_order_cb ( if (gos->osc != osr->details.ok.status) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Order paid does not match\n"); + "Order paid does not match: %d vs %d\n", + gos->osc, + osr->details.ok.status); TALER_TESTING_interpreter_fail (gos->is); return; } @@ -187,6 +194,17 @@ merchant_get_order_cb ( const struct TALER_TESTING_Command *order_cmd; struct TALER_Amount refunded_total; + if ( (0 != gos->expected_min_age) && + (gos->expected_min_age != + json_integer_value ( + json_object_get ( + osr->details.ok.details.paid.contract_terms, + "minimum_age"))) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (gos->is); + return; + } order_cmd = TALER_TESTING_interpreter_lookup_command ( gos->is, gos->order_reference); @@ -422,6 +440,17 @@ merchant_get_order_cb ( break; case TALER_MERCHANT_OSC_CLAIMED: /* FIXME: Check contract terms... */ + if ( (0 != gos->expected_min_age) && + (gos->expected_min_age != + json_integer_value ( + json_object_get ( + osr->details.ok.details.claimed.contract_terms, + "minimum_age"))) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (gos->is); + return; + } break; case TALER_MERCHANT_OSC_UNPAID: { @@ -754,6 +783,36 @@ TALER_TESTING_cmd_merchant_get_order3 ( } +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_order4 ( + const char *label, + const char *merchant_url, + const char *order_reference, + enum TALER_MERCHANT_OrderStatusCode osc, + uint32_t expected_min_age, + unsigned int expected_http_status) +{ + struct MerchantGetOrderState *gos; + + gos = GNUNET_new (struct MerchantGetOrderState); + gos->merchant_url = merchant_url; + gos->order_reference = order_reference; + gos->osc = osc; + gos->expected_min_age = expected_min_age; + gos->http_status = expected_http_status; + { + struct TALER_TESTING_Command cmd = { + .cls = gos, + .label = label, + .run = &merchant_get_order_run, + .cleanup = &merchant_get_order_cleanup + }; + + return cmd; + } +} + + struct MerchantPollOrderConcludeState { /** diff --git a/src/testing/testing_api_cmd_post_products.c b/src/testing/testing_api_cmd_post_products.c index e98ea3c5..4ffafddc 100644 --- a/src/testing/testing_api_cmd_post_products.c +++ b/src/testing/testing_api_cmd_post_products.c @@ -95,6 +95,11 @@ struct PostProductsState json_t *address; /** + * Minimum age requirement to use for the product. + */ + unsigned int minimum_age; + + /** * when the next restocking is expected to happen, 0 for unknown, */ struct GNUNET_TIME_Timestamp next_restock; @@ -168,7 +173,7 @@ post_products_run (void *cls, struct PostProductsState *pis = cls; pis->is = is; - pis->iph = TALER_MERCHANT_products_post ( + pis->iph = TALER_MERCHANT_products_post2 ( TALER_TESTING_interpreter_get_context (is), pis->merchant_url, pis->product_id, @@ -181,6 +186,7 @@ post_products_run (void *cls, pis->total_stock, pis->address, pis->next_restock, + pis->minimum_age, &post_products_cb, pis); GNUNET_assert (NULL != pis->iph); @@ -197,7 +203,7 @@ post_products_run (void *cls, * @param index index number of the object to extract. * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue post_products_traits (void *cls, const void **ret, const char *trait, @@ -265,6 +271,7 @@ TALER_TESTING_cmd_merchant_post_products2 ( const char *image, json_t *taxes, int64_t total_stock, + uint32_t minimum_age, json_t *address, struct GNUNET_TIME_Timestamp next_restock, unsigned int http_status) @@ -288,6 +295,7 @@ TALER_TESTING_cmd_merchant_post_products2 ( pis->image = GNUNET_strdup (image); pis->taxes = taxes; /* ownership taken */ pis->total_stock = total_stock; + pis->minimum_age = minimum_age; pis->address = address; /* ownership taken */ pis->next_restock = next_restock; { @@ -305,12 +313,13 @@ TALER_TESTING_cmd_merchant_post_products2 ( struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_post_products (const char *label, - const char *merchant_url, - const char *product_id, - const char *description, - const char *price, - unsigned int http_status) +TALER_TESTING_cmd_merchant_post_products ( + const char *label, + const char *merchant_url, + const char *product_id, + const char *description, + const char *price, + unsigned int http_status) { return TALER_TESTING_cmd_merchant_post_products2 ( label, @@ -322,7 +331,8 @@ TALER_TESTING_cmd_merchant_post_products (const char *label, price, "", json_array (), - 4, + 4, /* total stock */ + 0, /* minimum age */ json_pack ("{s:s}", "street", "my street"), GNUNET_TIME_UNIT_ZERO_TS, http_status); |