From 9d0a68e578a77cbe9c1443dc1831de157b8a0fa8 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Thu, 25 Jun 2020 01:55:15 -0400 Subject: wallet get order handles refunds properly --- src/testing/testing_api_cmd_wallet_get_order.c | 74 +++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'src/testing/testing_api_cmd_wallet_get_order.c') diff --git a/src/testing/testing_api_cmd_wallet_get_order.c b/src/testing/testing_api_cmd_wallet_get_order.c index 7cc9c352..86072f4f 100644 --- a/src/testing/testing_api_cmd_wallet_get_order.c +++ b/src/testing/testing_api_cmd_wallet_get_order.c @@ -67,6 +67,16 @@ struct WalletGetOrderState * Whether the order was refunded or not. */ bool refunded; + + /** + * A NULL-terminated list of refunds associated with this order. + */ + const char **refunds; + + /** + * The length of @e refunds. + */ + unsigned int refunds_length; }; @@ -138,6 +148,48 @@ wallet_get_order_cb ( TALER_TESTING_interpreter_fail (gos->is); return; } + if (gos->refunds_length != num_refunds) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Order refunds count does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + for (unsigned int i = 0; i < num_refunds; ++i) + { + const struct TALER_TESTING_Command *refund_cmd; + const char *expected_amount_str; + struct TALER_Amount expected_amount; + + refund_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->refunds[i]); + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (refund_cmd, + 0, + &expected_amount_str)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch refund amount\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (expected_amount_str, + &expected_amount)); + if ((GNUNET_OK != + TALER_amount_cmp_currency (&expected_amount, + &refunds[i].refund_amount)) || + (0 != TALER_amount_cmp (&expected_amount, + &refunds[i].refund_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Refund amounts do not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -225,6 +277,10 @@ wallet_get_order_cleanup (void *cls, * @param paid whether the order has been paid for or not. * @param refunded whether the order has been refunded. * @param http_status expected HTTP response code for the request. + * @param ... NULL-terminated list of labels (const char *) of + * refunds (commands) we expect to be aggregated in the transfer + * (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false, + * this parameter is ignored. */ struct TALER_TESTING_Command TALER_TESTING_cmd_wallet_get_order (const char *label, @@ -232,7 +288,8 @@ TALER_TESTING_cmd_wallet_get_order (const char *label, const char *order_reference, bool paid, bool refunded, - unsigned int http_status) + unsigned int http_status, + ...) { struct WalletGetOrderState *gos; @@ -242,6 +299,21 @@ TALER_TESTING_cmd_wallet_get_order (const char *label, gos->http_status = http_status; gos->paid = paid; gos->refunded = refunded; + gos->refunds_length = 0; + if (refunded) + { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gos->refunds, + gos->refunds_length, + clabel); + } + va_end (ap); + } { struct TALER_TESTING_Command cmd = { .cls = gos, -- cgit v1.2.3