From 566408fa02acf56bbf6063c6d17d739e491e27f2 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Thu, 18 Jun 2020 20:27:04 -0400 Subject: stricter tests for tips/reserves --- src/testing/testing_api_cmd_merchant_get_tip.c | 175 ++++++++++++++++++++++++- 1 file changed, 174 insertions(+), 1 deletion(-) (limited to 'src/testing/testing_api_cmd_merchant_get_tip.c') diff --git a/src/testing/testing_api_cmd_merchant_get_tip.c b/src/testing/testing_api_cmd_merchant_get_tip.c index f70356c7..085f9575 100644 --- a/src/testing/testing_api_cmd_merchant_get_tip.c +++ b/src/testing/testing_api_cmd_merchant_get_tip.c @@ -43,6 +43,16 @@ struct MerchantTipGetState */ unsigned int http_status; + /** + * Whether to fetch and compare pickups. + */ + bool fetch_pickups; + + /** + * The NULL-terminated list of pickup commands associated with the tip. + */ + const char **pickup_refs; + /** * The handle to the current GET /tips/$TIP_ID request. */ @@ -86,8 +96,15 @@ merchant_get_tip_cb (void *cls, { /* FIXME, deeper checks should be implemented here. */ struct MerchantTipGetState *gts = cls; + const struct TALER_TESTING_Command *authorize_cmd; + struct TALER_Amount expected_total_picked_up; + + authorize_cmd = TALER_TESTING_interpreter_lookup_command (gts->is, + gts->tip_reference); gts->tgh = NULL; + GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (total_picked_up->currency, + &expected_total_picked_up)); if (gts->http_status != hr->http_status) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -103,6 +120,123 @@ merchant_get_tip_cb (void *cls, case MHD_HTTP_OK: // FIXME: use gts->tip_reference here to // check if the data returned matches that from the POST / PATCH + { + const struct TALER_Amount *initial_amount; + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (authorize_cmd, + 0, + &initial_amount)) + TALER_TESTING_FAIL (gts->is); + if ((GNUNET_OK != TALER_amount_cmp_currency (total_authorized, + initial_amount)) || + (0 != TALER_amount_cmp (total_authorized, + initial_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Tip authorized amount does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const char *justification; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (authorize_cmd, + 0, + &justification)) + TALER_TESTING_FAIL (gts->is); + if (0 != strcmp (reason, + justification)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Tip authorized reason does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const struct GNUNET_TIME_Absolute *tip_expiration; + if (GNUNET_OK != + TALER_TESTING_get_trait_absolute_time (authorize_cmd, + 0, + &tip_expiration)) + TALER_TESTING_FAIL (gts->is); + if (tip_expiration->abs_value_us != expiration.abs_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Tip authorized expiration does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + for (unsigned int i = 0; i < pickups_length; ++i) + { + const struct TALER_TESTING_Command *pickup_cmd; + if (NULL == gts->pickup_refs[i]) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of pickup array does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + + pickup_cmd = TALER_TESTING_interpreter_lookup_command (gts->is, + gts->pickup_refs[ + i]); + { + const uint64_t *num_planchets; + + if (GNUNET_OK != + TALER_TESTING_get_trait_uint64 (pickup_cmd, + 0, + &num_planchets)) + TALER_TESTING_FAIL (gts->is); + + if (*num_planchets != pickups[i].num_planchets) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Pickup planchet count does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const struct TALER_Amount *total; + + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (pickup_cmd, + pickups[i].num_planchets, + &total)) + TALER_TESTING_FAIL (gts->is); + + if ((GNUNET_OK != TALER_amount_cmp_currency (total, + &pickups[i]. + requested_amount)) || + (0 != TALER_amount_cmp (total, + &pickups[i].requested_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Pickup planchet sum does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + GNUNET_assert (0 < TALER_amount_add (&expected_total_picked_up, + &expected_total_picked_up, + total)); + } + } + if ((GNUNET_OK != TALER_amount_cmp_currency (&expected_total_picked_up, + total_picked_up)) || + (0 != TALER_amount_cmp (&expected_total_picked_up, + total_picked_up))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Tip picked up amount does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -141,7 +275,7 @@ merchant_get_tip_run (void *cls, tgs->tgh = TALER_MERCHANT_merchant_tip_get (is->ctx, tgs->merchant_url, tip_id, - false, + tgs->fetch_pickups, &merchant_get_tip_cb, tgs); GNUNET_assert (NULL != tgs->tgh); @@ -204,4 +338,43 @@ TALER_TESTING_cmd_merchant_get_tip (const char *label, } +/** + * Define a GET /private/tips/$TIP_ID CMD. + * + * @param label the command label + * @param merchant_url base URL of the merchant which will + * serve the request. + * @param tip_reference reference to a command that created a tip. + * @param pickup_refs a NULL-terminated list of pickup commands + * associated with the tip. + * @param http_status expected HTTP response code for the request. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_tip_with_pickups (const char *label, + const char *merchant_url, + const char *tip_reference, + const char *pickup_refs[], + unsigned int http_status) +{ + struct MerchantTipGetState *tgs; + + tgs = GNUNET_new (struct MerchantTipGetState); + tgs->merchant_url = merchant_url; + tgs->tip_reference = tip_reference; + tgs->fetch_pickups = true; + tgs->pickup_refs = pickup_refs; + tgs->http_status = http_status; + { + struct TALER_TESTING_Command cmd = { + .cls = tgs, + .label = label, + .run = &merchant_get_tip_run, + .cleanup = &merchant_get_tip_cleanup + }; + + return cmd; + } +} + + /* end of testing_api_cmd_merchant_get_tip.c */ -- cgit v1.2.3