From a043ee5eed5eae2d1629fe7fd7546767b74bf586 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Fri, 10 Jul 2020 03:32:03 -0400 Subject: checks for refunds and transfers returned in merchant get order --- src/testing/test_merchant_api.c | 13 +++ src/testing/testing_api_cmd_merchant_get_order.c | 127 +++++++++++++++++++++-- src/testing/testing_api_cmd_post_transfers.c | 7 ++ 3 files changed, 141 insertions(+), 6 deletions(-) diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 9fee2e3e..7f418c99 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -445,6 +445,10 @@ run (void *cls, TALER_TESTING_cmd_end () }; + const char *order_1r_refunds[] = { + "refund-increase-1r", + NULL + }; struct TALER_TESTING_Command refund[] = { cmd_transfer_to_exchange ("create-reserve-1r", "EUR:10.02"), @@ -520,6 +524,15 @@ run (void *cls, MHD_HTTP_OK, "refund-increase-1r", NULL), + TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1r-2", + merchant_url, + "create-proposal-1r", + true, + false, + NULL, + true, + order_1r_refunds, + MHD_HTTP_OK), #if 0 TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-refund-conclude-1", MHD_HTTP_OK, diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index cf0263ba..7364291b 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -169,7 +169,112 @@ merchant_get_order_cb ( return; } } + if (gos->wired != osr->details.paid.wired) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Order wired does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (gos->transfers_length != osr->details.paid.wts_len) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Number of transfers found does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + for (unsigned int i = 0; i < gos->transfers_length; ++i) + { + const struct TALER_TESTING_Command *transfer_cmd; + + transfer_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->transfers[i]); + { + const struct TALER_WireTransferIdentifierRawP *wtid; + + if (GNUNET_OK != + TALER_TESTING_get_trait_wtid (transfer_cmd, + 0, + &wtid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer id\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (0 != GNUNET_memcmp (wtid, + &osr->details.paid.wts[i].wtid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer id does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + { + const char *exchange_url; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (transfer_cmd, + 1, + &exchange_url)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer exchange url\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (0 != strcmp (exchange_url, + osr->details.paid.wts[i].exchange_url)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer exchange url does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + { + struct TALER_Amount transfer_total; + const struct TALER_Amount *transfer_amount; + const struct TALER_Amount *transfer_fee; + if ((GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (transfer_cmd, + 0, + &transfer_amount)) || + (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (transfer_cmd, + 1, + &transfer_fee))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer amount/fee\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (0 > TALER_amount_add (&transfer_total, + transfer_amount, + transfer_fee)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not total wire transfer\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if ((GNUNET_OK != TALER_amount_cmp_currency (&transfer_total, + &osr->details.paid.wts[i] + .total_amount)) || + (0 != TALER_amount_cmp (&transfer_total, + &osr->details.paid.wts[i].total_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer total does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + } if (gos->refunded != osr->details.paid.refunded) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -326,6 +431,12 @@ merchant_get_order_cleanup (void *cls, TALER_LOG_WARNING ("Get tip operation did not complete\n"); TALER_MERCHANT_merchant_order_get_cancel (gos->ogh); } + GNUNET_array_grow (gos->transfers, + gos->transfers_length, + 0); + GNUNET_array_grow (gos->refunds, + gos->refunds_length, + 0); GNUNET_free (gos); } @@ -429,24 +540,28 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label, gos->wired = wired; gos->refunded = refunded; gos->http_status = http_status; - /*if (paid) + gos->transfers = NULL; + gos->transfers_length = 0; + gos->refunds = NULL; + gos->refunds_length = 0; + if (wired) { - for (const char *clabel = transfers[0]; clabel != NULL; ++clabel) + for (const char **clabel = transfers; *clabel != NULL; ++clabel) { GNUNET_array_append (gos->transfers, gos->transfers_length, - clabel); + *clabel); } } if (refunded) { - for (const char *clabel = refunds[0]; clabel != NULL; ++clabel) + for (const char **clabel = refunds; *clabel != NULL; ++clabel) { GNUNET_array_append (gos->refunds, gos->refunds_length, - clabel); + *clabel); } - }*/ + } { struct TALER_TESTING_Command cmd = { .cls = gos, diff --git a/src/testing/testing_api_cmd_post_transfers.c b/src/testing/testing_api_cmd_post_transfers.c index 53d4911d..bb3cd8c7 100644 --- a/src/testing/testing_api_cmd_post_transfers.c +++ b/src/testing/testing_api_cmd_post_transfers.c @@ -79,6 +79,11 @@ struct PostTransfersState */ struct TALER_Amount credit_amount; + /** + * The fee incurred on the wire transfer. + */ + struct TALER_Amount wire_fee; + /** * Expected HTTP response code. */ @@ -150,6 +155,7 @@ transfers_cb (void *cls, // struct TALER_Amount total; pts->execution_time = execution_time; + pts->wire_fee = *wire_fee; /* if (0 > TALER_amount_subtract (&total, @@ -309,6 +315,7 @@ post_transfers_traits (void *cls, TALER_TESTING_make_trait_wtid (0, &pts->wtid), TALER_TESTING_make_trait_string (0, pts->payto_uri), TALER_TESTING_make_trait_amount_obj (0, &pts->credit_amount), + TALER_TESTING_make_trait_amount_obj (1, &pts->wire_fee), TALER_TESTING_make_trait_string (1, pts->exchange_url), TALER_TESTING_make_trait_absolute_time (0, &pts->execution_time), TALER_TESTING_trait_end (), -- cgit v1.2.3