From e35244074480faa18f6370e4d5b800ed35d8ef94 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Fri, 19 Jun 2020 02:30:17 -0400 Subject: stricter tests for query reserve(s) methods --- src/testing/testing_api_cmd_get_reserves.c | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'src/testing/testing_api_cmd_get_reserves.c') diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c index b9909cad..068d7e6e 100644 --- a/src/testing/testing_api_cmd_get_reserves.c +++ b/src/testing/testing_api_cmd_get_reserves.c @@ -44,6 +44,16 @@ struct GetReservesState */ struct TALER_TESTING_Interpreter *is; + /** + * Whether to compare the reserves that were found. + */ + bool cmp_reserves; + + /** + * A list of reserves to compare with. + */ + const char **reserve_refs; + /** * Base URL of the merchant serving the request. */ @@ -80,6 +90,61 @@ get_reserves_cb (void *cls, { case MHD_HTTP_OK: // FIXME: check if the data returned matches that from the POST / PATCH + if (! grs->cmp_reserves) + break; + for (unsigned int i = 0; i < reserves_length; ++i) + { + if (NULL == grs->reserve_refs[i]) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Number of reserves found does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + + const struct TALER_TESTING_Command *reserve_cmd; + + reserve_cmd = TALER_TESTING_interpreter_lookup_command ( + grs->is, + grs->reserve_refs[i]); + { + const struct TALER_ReservePublicKeyP *reserve_pub; + + if (GNUNET_OK != + TALER_TESTING_get_trait_reserve_pub (reserve_cmd, + 0, + &reserve_pub)) + TALER_TESTING_interpreter_fail (grs->is); + if (0 != GNUNET_memcmp (&reserves[i].reserve_pub, + reserve_pub)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Reserve public key does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + } + { + const struct TALER_Amount *initial; + + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (reserve_cmd, + 0, + &initial)) + TALER_TESTING_interpreter_fail (grs->is); + if ((GNUNET_OK != TALER_amount_cmp_currency ( + &reserves[i].merchant_initial_amount, + initial)) || + (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount, + initial))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Reserve initial amount does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -155,6 +220,43 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label, grs = GNUNET_new (struct GetReservesState); grs->merchant_url = merchant_url; + grs->cmp_reserves = false; + grs->http_status = http_status; + { + struct TALER_TESTING_Command cmd = { + .cls = grs, + .label = label, + .run = &get_reserves_run, + .cleanup = &get_reserves_cleanup + }; + + return cmd; + } +} + + +/** + * Define a "GET /reserves" CMD + * + * @param label command label. + * @param merchant_url url to the merchant. + * @param reserve_refs a NULL-terminated list of references to + * commands that created reserves. + * @param http_status expected HTTP response code. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label, + const char *merchant_url, + const char *reserve_refs + [], + unsigned int http_status) +{ + struct GetReservesState *grs; + + grs = GNUNET_new (struct GetReservesState); + grs->merchant_url = merchant_url; + grs->cmp_reserves = true; + grs->reserve_refs = reserve_refs; grs->http_status = http_status; { struct TALER_TESTING_Command cmd = { -- cgit v1.2.3