diff options
Diffstat (limited to 'src/testing/testing_api_cmd_wire.c')
-rw-r--r-- | src/testing/testing_api_cmd_wire.c | 117 |
1 files changed, 68 insertions, 49 deletions
diff --git a/src/testing/testing_api_cmd_wire.c b/src/testing/testing_api_cmd_wire.c index 4b0a177b5..41ff7a978 100644 --- a/src/testing/testing_api_cmd_wire.c +++ b/src/testing/testing_api_cmd_wire.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018, 2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,6 +39,11 @@ struct WireState struct TALER_EXCHANGE_WireHandle *wh; /** + * Our command. + */ + const struct TALER_TESTING_Command *cmd; + + /** * Which wire-method we expect is offered by the exchange. */ const char *expected_method; @@ -72,19 +77,14 @@ struct WireState * that the wire fee is acceptable too. * * @param cls closure. - * @param hr HTTP response details - * @param accounts_len length of the @a accounts array. - * @param accounts list of wire accounts of the exchange, - * NULL on error. + * @param wr response details */ static void wire_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - unsigned int accounts_len, - const struct TALER_EXCHANGE_WireAccount *accounts) + const struct TALER_EXCHANGE_WireResponse *wr) { struct WireState *ws = cls; - struct TALER_TESTING_Command *cmd = &ws->is->commands[ws->is->ip]; + const struct TALER_EXCHANGE_HttpResponse *hr = &wr->hr; struct TALER_Amount expected_fee; TALER_LOG_DEBUG ("Checking parsed /wire response\n"); @@ -100,41 +100,70 @@ wire_cb (void *cls, if (MHD_HTTP_OK == hr->http_status) { + unsigned int accounts_len + = wr->details.ok.accounts_len; + unsigned int fees_len + = wr->details.ok.fees_len; + const struct TALER_EXCHANGE_WireAccount *accounts + = wr->details.ok.accounts; + const struct TALER_EXCHANGE_WireFeesByMethod *fees + = wr->details.ok.fees; + for (unsigned int i = 0; i<accounts_len; i++) { char *method; method = TALER_payto_get_method (accounts[i].payto_uri); + if (NULL == method) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ws->is); + return; + } if (0 == strcmp (ws->expected_method, method)) { ws->method_found = GNUNET_OK; - if (NULL != ws->expected_fee) + } + GNUNET_free (method); + } + if (NULL != ws->expected_fee) + { + bool fee_found = false; + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (ws->expected_fee, + &expected_fee)); + for (unsigned int i = 0; i<fees_len; i++) + { + if (0 != strcmp (fees[i].method, + ws->expected_method)) + continue; + for (const struct TALER_EXCHANGE_WireAggregateFees *waf + = fees[i].fees_head; + NULL != waf; + waf = waf->next) { - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (ws->expected_fee, - &expected_fee)); - for (const struct TALER_EXCHANGE_WireAggregateFees *waf - = accounts[i].fees; - NULL != waf; - waf = waf->next) + if (0 != TALER_amount_cmp (&waf->fees.wire, + &expected_fee)) { - if (0 != TALER_amount_cmp (&waf->fees.wire, - &expected_fee)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Wire fee mismatch to command %s\n", - cmd->label); - TALER_TESTING_interpreter_fail (ws->is); - GNUNET_free (method); - return; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire fee mismatch to command %s\n", + ws->cmd->label); + TALER_TESTING_interpreter_fail (ws->is); + return; } + fee_found = true; } } - TALER_LOG_DEBUG ("Freeing method '%s'\n", - method); - GNUNET_free (method); + if (! fee_found) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "/wire does not contain expected fee '%s'\n", + ws->expected_fee); + TALER_TESTING_interpreter_fail (ws->is); + return; + } } if (GNUNET_OK != ws->method_found) { @@ -163,11 +192,14 @@ wire_run (void *cls, { struct WireState *ws = cls; - (void) cmd; + ws->cmd = cmd; ws->is = is; - ws->wh = TALER_EXCHANGE_wire (is->exchange, - &wire_cb, - ws); + ws->wh = TALER_EXCHANGE_wire ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), + &wire_cb, + ws); } @@ -186,10 +218,8 @@ wire_cleanup (void *cls, if (NULL != ws->wh) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Command %u (%s) did not complete\n", - ws->is->ip, - cmd->label); + TALER_TESTING_command_incomplete (ws->is, + cmd->label); TALER_EXCHANGE_wire_cancel (ws->wh); ws->wh = NULL; } @@ -197,17 +227,6 @@ wire_cleanup (void *cls, } -/** - * Create a "wire" command. - * - * @param label the command label. - * @param expected_method which wire-transfer method is expected - * to be offered by the exchange. - * @param expected_fee the fee the exchange should charge. - * @param expected_response_code the HTTP response the exchange - * should return. - * @return the command. - */ struct TALER_TESTING_Command TALER_TESTING_cmd_wire (const char *label, const char *expected_method, |