From 3fa213e41e82a93f8f5c5cd59b599ff78d0acc3a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 15 Jan 2020 11:14:11 +0100 Subject: [PATCH] fix test issues --- src/bank-lib/bank_api_admin.c | 7 +- src/bank-lib/fakebank.c | 249 ++++++++++++++++------------- src/lib/auditor_api_handle.c | 1 + src/lib/exchange_api_reserve.c | 3 + src/lib/testing_api_cmd_withdraw.c | 27 ++-- 5 files changed, 158 insertions(+), 129 deletions(-) diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index 2b6e45f45..6e4d937c5 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c @@ -209,9 +209,10 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx, aai->cb_cls = res_cb_cls; aai->request_url = TALER_BANK_path_to_url_ (account_base_url, "/admin/add-incoming"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Requesting administrative transaction at `%s'\n", - aai->request_url); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Requesting administrative transaction at `%s' for reserve %s\n", + aai->request_url, + TALER_B2S (reserve_pub)); aai->post_ctx.headers = curl_slist_append (aai->post_ctx.headers, "Content-Type: application/json"); diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index b99b78816..b12b04378 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -888,112 +888,6 @@ parse_history_common_args (struct MHD_Connection *connection, * @return MHD result code */ static int -handle_credit_history (struct TALER_FAKEBANK_Handle *h, - struct MHD_Connection *connection, - const char *account) -{ - struct HistoryArgs ha; - struct Transaction *pos; - json_t *history; - - if (GNUNET_OK != - parse_history_common_args (connection, - &ha)) - { - GNUNET_break (0); - return MHD_NO; - } - - if (! ha.have_start) - { - pos = (0 > ha.delta) - ? h->transactions_tail - : h->transactions_head; - } - else if (NULL != h->transactions_head) - { - for (pos = h->transactions_head; - NULL != pos; - pos = pos->next) - if (pos->row_id == ha.start_idx) - break; - if (NULL == pos) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid start specified, transaction %llu not known!\n", - (unsigned long long) ha.start_idx); - return MHD_NO; - } - /* range is exclusive, skip the matching entry */ - if (ha.delta > 0) - pos = pos->next; - if (ha.delta < 0) - pos = pos->prev; - } - else - { - /* list is empty */ - pos = NULL; - } - history = json_array (); - while ( (0 != ha.delta) && - (NULL != pos) ) - { - if ( (0 == strcasecmp (pos->credit_account, - account)) && - (T_DEBIT == pos->type) ) - { - json_t *trans; - char *credit_payto; - char *debit_payto; - - credit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, - account); - debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, - pos->debit_account); - trans = json_pack - ("{s:I, s:o, s:o, s:s, s:s, s:s, s:o}", - "row_id", (json_int_t) pos->row_id, - "date", GNUNET_JSON_from_time_abs (pos->date), - "amount", TALER_JSON_from_amount (&pos->amount), - "credit_account", credit_payto, - "debit_account", debit_payto, - "exchange_base_url", - pos->subject.debit.exchange_base_url, - "wtid", GNUNET_JSON_from_data_auto ( - &pos->subject.debit.wtid)); - GNUNET_free (credit_payto); - GNUNET_free (debit_payto); - GNUNET_assert (0 == - json_array_append_new (history, - trans)); - if (ha.delta > 0) - ha.delta--; - else - ha.delta++; - } - if (ha.delta > 0) - pos = pos->prev; - else - pos = pos->next; - } - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "outgoing_transactions", - history); -} - - -/** - * Handle incoming HTTP request for /history/incoming - * - * @param h the fakebank handle - * @param connection the connection - * @param account which account the request is about - * @return MHD result code - */ -static int handle_debit_history (struct TALER_FAKEBANK_Handle *h, struct MHD_Connection *connection, const char *account) @@ -1047,6 +941,119 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, { if ( (0 == strcasecmp (pos->debit_account, account)) && + (T_DEBIT == pos->type) ) + { + json_t *trans; + char *credit_payto; + char *debit_payto; + + credit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, + account); + debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, + pos->debit_account); + trans = json_pack + ("{s:I, s:o, s:o, s:s, s:s, s:s, s:o}", + "row_id", (json_int_t) pos->row_id, + "date", GNUNET_JSON_from_time_abs (pos->date), + "amount", TALER_JSON_from_amount (&pos->amount), + "credit_account", credit_payto, + "debit_account", debit_payto, + "exchange_base_url", + pos->subject.debit.exchange_base_url, + "wtid", GNUNET_JSON_from_data_auto ( + &pos->subject.debit.wtid)); + GNUNET_free (credit_payto); + GNUNET_free (debit_payto); + GNUNET_assert (0 == + json_array_append_new (history, + trans)); + if (ha.delta > 0) + ha.delta--; + else + ha.delta++; + } + else + { + fprintf (stderr, + "Skipping transaction %s->%s: only care about %s\n", + pos->debit_account, + pos->credit_account, + account); + } + if (ha.delta > 0) + pos = pos->prev; + else + pos = pos->next; + } + return TALER_MHD_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:o}", + "outgoing_transactions", + history); +} + + +/** + * Handle incoming HTTP request for /history/incoming + * + * @param h the fakebank handle + * @param connection the connection + * @param account which account the request is about + * @return MHD result code + */ +static int +handle_credit_history (struct TALER_FAKEBANK_Handle *h, + struct MHD_Connection *connection, + const char *account) +{ + struct HistoryArgs ha; + struct Transaction *pos; + json_t *history; + + if (GNUNET_OK != + parse_history_common_args (connection, + &ha)) + { + GNUNET_break (0); + return MHD_NO; + } + if (! ha.have_start) + { + pos = (0 > ha.delta) + ? h->transactions_tail + : h->transactions_head; + } + else if (NULL != h->transactions_head) + { + for (pos = h->transactions_head; + NULL != pos; + pos = pos->next) + if (pos->row_id == ha.start_idx) + break; + if (NULL == pos) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid start specified, transaction %llu not known!\n", + (unsigned long long) ha.start_idx); + return MHD_NO; + } + /* range is exclusive, skip the matching entry */ + if (ha.delta > 0) + pos = pos->next; + if (ha.delta < 0) + pos = pos->prev; + } + else + { + /* list is empty */ + pos = NULL; + } + history = json_array (); + while ( (0 != ha.delta) && + (NULL != pos) ) + { + if ( (0 == strcasecmp (pos->credit_account, + account)) && (T_CREDIT == pos->type) ) { json_t *trans; @@ -1057,14 +1064,20 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, pos->credit_account); debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, account); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Returning transaction %s->%s (%s)\n", + debit_payto, + credit_payto, + TALER_B2S (&pos->subject)); trans = json_pack - ("{s:I, s:o, s:o, s:s, s:s, s:s}", + ("{s:I, s:o, s:o, s:s, s:s, s:o}", "row_id", (json_int_t) pos->row_id, "date", GNUNET_JSON_from_time_abs (pos->date), "amount", TALER_JSON_from_amount (&pos->amount), "credit_account", credit_payto, "debit_account", debit_payto, - "reserve_pub", pos->subject /* we "know" it is OK */); + "reserve_pub", GNUNET_JSON_from_data_auto ( + &pos->subject.credit)); GNUNET_free (credit_payto); GNUNET_free (debit_payto); GNUNET_assert (0 == @@ -1075,6 +1088,14 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, else ha.delta++; } + else + { + fprintf (stderr, + "Skipping transaction %s->%s: only care about %s\n", + pos->debit_account, + pos->credit_account, + account); + } if (ha.delta > 0) pos = pos->prev; else @@ -1148,17 +1169,17 @@ serve (struct TALER_FAKEBANK_Handle *h, (NULL != account) && (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) ) - return handle_debit_history (h, - connection, - account); + return handle_credit_history (h, + connection, + account); if ( (0 == strcmp (url, "/history/outgoing")) && (NULL != account) && (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) ) - return handle_credit_history (h, - connection, - account); + return handle_debit_history (h, + connection, + account); /* Unexpected URL path, just close the connection. */ /* we're rather impolite here, but it's a testcase. */ diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c index a3264c020..f1df204cb 100644 --- a/src/lib/auditor_api_handle.c +++ b/src/lib/auditor_api_handle.c @@ -412,6 +412,7 @@ MAH_path_to_url (struct TALER_AUDITOR_Handle *h, /** * Obtain the URL to use for an API request. + * FIXME: duplicates TEAH_path_to_url2, and likely also logic in util! * * @param base_url base URL of the auditor (i.e. "http://auditor/") * @param path Taler API path (i.e. "/deposit-confirmation") diff --git a/src/lib/exchange_api_reserve.c b/src/lib/exchange_api_reserve.c index 2c62cac20..d63d169b3 100644 --- a/src/lib/exchange_api_reserve.c +++ b/src/lib/exchange_api_reserve.c @@ -1051,6 +1051,9 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange, GNUNET_free (wsh); return NULL; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Attempting to withdraw from reserve %s\n", + TALER_B2S (reserve_pub)); wsh->ps = *ps; wsh->url = TEAH_path_to_url (exchange, "/reserve/withdraw"); diff --git a/src/lib/testing_api_cmd_withdraw.c b/src/lib/testing_api_cmd_withdraw.c index f559faf2c..09ab234dd 100644 --- a/src/lib/testing_api_cmd_withdraw.c +++ b/src/lib/testing_api_cmd_withdraw.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018-2020 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 @@ -363,8 +363,10 @@ withdraw_traits (void *cls, return GNUNET_SYSERR; } - if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv - (reserve_cmd, 0, &reserve_priv)) + if (GNUNET_OK != + TALER_TESTING_get_trait_reserve_priv (reserve_cmd, + 0, + &reserve_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (ws->is); @@ -479,16 +481,17 @@ TALER_TESTING_cmd_withdraw_denomination ws->reserve_reference = reserve_reference; ws->pk = dk; ws->expected_response_code = expected_response_code; + { + struct TALER_TESTING_Command cmd = { + .cls = ws, + .label = label, + .run = &withdraw_run, + .cleanup = &withdraw_cleanup, + .traits = &withdraw_traits + }; - struct TALER_TESTING_Command cmd = { - .cls = ws, - .label = label, - .run = &withdraw_run, - .cleanup = &withdraw_cleanup, - .traits = &withdraw_traits - }; - - return cmd; + return cmd; + } }