From badec7af6eab1f0972f7d49527f5f0772589bb3f Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Wed, 22 Jul 2020 05:03:04 -0400 Subject: tests for forget results --- src/testing/testing_api_cmd_merchant_get_order.c | 102 ++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) (limited to 'src/testing/testing_api_cmd_merchant_get_order.c') diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index 7364291b..4ae459a3 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -92,9 +92,39 @@ struct MerchantGetOrderState * The length of @e transfers. */ unsigned int transfers_length; + + /** + * A list of forget commands that apply to this order's contract terms. + */ + const char **forgets; + + /** + * The length of @e forgets. + */ + unsigned int forgets_length; }; +/** + * Forget part of the contract terms. + * + * @param cls pointer to the result of the forget operation. + * @param object_id name of the object to forget. + * @param parent parent of the object at @e object_id. + */ +static void +apply_forget (void *cls, + const char *object_id, + json_t *parent) +{ + int *res = cls; + if (GNUNET_OK != + TALER_JSON_contract_part_forget (parent, + object_id)) + *res = GNUNET_SYSERR; +} + + /** * Callback to process a GET /orders/$ID request * @@ -149,6 +179,7 @@ merchant_get_order_cb ( { const json_t *expected_contract_terms; + json_t *ct; if (GNUNET_OK != TALER_TESTING_get_trait_contract_terms (order_cmd, @@ -160,7 +191,56 @@ merchant_get_order_cb ( TALER_TESTING_interpreter_fail (gos->is); return; } - if (1 != json_equal (expected_contract_terms, + + ct = json_deep_copy (expected_contract_terms); + + /* Apply all forgets, then compare */ + for (unsigned int i = 0; i < gos->forgets_length; ++i) + { + const struct TALER_TESTING_Command *forget_cmd; + const unsigned int *paths_length; + + forget_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->forgets[i]); + + if (GNUNET_OK != + TALER_TESTING_get_trait_uint32 (forget_cmd, + 0, + &paths_length)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Couldn't fetch forget paths length\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + + for (unsigned int j = 0; j < *paths_length; ++j) + { + const char *path; + int res = GNUNET_OK; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (forget_cmd, + j, + &path)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Couldn't fetch forget path\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + + GNUNET_assert (GNUNET_OK == + TALER_JSON_expand_path (ct, + path, + &apply_forget, + &res)); + GNUNET_assert (GNUNET_OK == res); + } + } + + if (1 != json_equal (ct, osr->details.paid.contract_terms)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -168,6 +248,8 @@ merchant_get_order_cb ( TALER_TESTING_interpreter_fail (gos->is); return; } + + json_decref (ct); } if (gos->wired != osr->details.paid.wired) { @@ -437,6 +519,9 @@ merchant_get_order_cleanup (void *cls, GNUNET_array_grow (gos->refunds, gos->refunds_length, 0); + GNUNET_array_grow (gos->forgets, + gos->forgets_length, + 0); GNUNET_free (gos); } @@ -518,6 +603,9 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, * refunds (commands) we expect to be aggregated in the order * (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false, * this parameter is ignored. + * @param forgets a NULL-terminated list of references to forget commands + * that apply to the order we are querying. If NULL, this is + * interpreted as no forgets are expected. * @param http_status expected HTTP response code for the request. */ struct TALER_TESTING_Command @@ -529,6 +617,7 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label, const char **transfers, bool refunded, const char **refunds, + const char **forgets, unsigned int http_status) { struct MerchantGetOrderState *gos; @@ -544,6 +633,8 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label, gos->transfers_length = 0; gos->refunds = NULL; gos->refunds_length = 0; + gos->forgets = NULL; + gos->forgets_length = 0; if (wired) { for (const char **clabel = transfers; *clabel != NULL; ++clabel) @@ -562,6 +653,15 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label, *clabel); } } + if (NULL != forgets) + { + for (const char **clabel = forgets; *clabel != NULL; ++clabel) + { + GNUNET_array_append (gos->forgets, + gos->forgets_length, + *clabel); + } + } { struct TALER_TESTING_Command cmd = { .cls = gos, -- cgit v1.2.3