fix test issues

This commit is contained in:
Christian Grothoff 2020-01-15 11:14:11 +01:00
parent b1b0465f54
commit 3fa213e41e
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 158 additions and 129 deletions

View File

@ -209,9 +209,10 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
aai->cb_cls = res_cb_cls; aai->cb_cls = res_cb_cls;
aai->request_url = TALER_BANK_path_to_url_ (account_base_url, aai->request_url = TALER_BANK_path_to_url_ (account_base_url,
"/admin/add-incoming"); "/admin/add-incoming");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting administrative transaction at `%s'\n", "Requesting administrative transaction at `%s' for reserve %s\n",
aai->request_url); aai->request_url,
TALER_B2S (reserve_pub));
aai->post_ctx.headers = curl_slist_append aai->post_ctx.headers = curl_slist_append
(aai->post_ctx.headers, (aai->post_ctx.headers,
"Content-Type: application/json"); "Content-Type: application/json");

View File

@ -888,112 +888,6 @@ parse_history_common_args (struct MHD_Connection *connection,
* @return MHD result code * @return MHD result code
*/ */
static int 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, handle_debit_history (struct TALER_FAKEBANK_Handle *h,
struct MHD_Connection *connection, struct MHD_Connection *connection,
const char *account) const char *account)
@ -1047,6 +941,119 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
{ {
if ( (0 == strcasecmp (pos->debit_account, if ( (0 == strcasecmp (pos->debit_account,
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) ) (T_CREDIT == pos->type) )
{ {
json_t *trans; json_t *trans;
@ -1057,14 +1064,20 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
pos->credit_account); pos->credit_account);
debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl, debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl,
account); account);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Returning transaction %s->%s (%s)\n",
debit_payto,
credit_payto,
TALER_B2S (&pos->subject));
trans = json_pack 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, "row_id", (json_int_t) pos->row_id,
"date", GNUNET_JSON_from_time_abs (pos->date), "date", GNUNET_JSON_from_time_abs (pos->date),
"amount", TALER_JSON_from_amount (&pos->amount), "amount", TALER_JSON_from_amount (&pos->amount),
"credit_account", credit_payto, "credit_account", credit_payto,
"debit_account", debit_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 (credit_payto);
GNUNET_free (debit_payto); GNUNET_free (debit_payto);
GNUNET_assert (0 == GNUNET_assert (0 ==
@ -1075,6 +1088,14 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
else else
ha.delta++; 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) if (ha.delta > 0)
pos = pos->prev; pos = pos->prev;
else else
@ -1148,17 +1169,17 @@ serve (struct TALER_FAKEBANK_Handle *h,
(NULL != account) && (NULL != account) &&
(0 == strcasecmp (method, (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) ) MHD_HTTP_METHOD_GET)) )
return handle_debit_history (h, return handle_credit_history (h,
connection, connection,
account); account);
if ( (0 == strcmp (url, if ( (0 == strcmp (url,
"/history/outgoing")) && "/history/outgoing")) &&
(NULL != account) && (NULL != account) &&
(0 == strcasecmp (method, (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) ) MHD_HTTP_METHOD_GET)) )
return handle_credit_history (h, return handle_debit_history (h,
connection, connection,
account); account);
/* Unexpected URL path, just close the connection. */ /* Unexpected URL path, just close the connection. */
/* we're rather impolite here, but it's a testcase. */ /* we're rather impolite here, but it's a testcase. */

View File

@ -412,6 +412,7 @@ MAH_path_to_url (struct TALER_AUDITOR_Handle *h,
/** /**
* Obtain the URL to use for an API request. * 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 base_url base URL of the auditor (i.e. "http://auditor/")
* @param path Taler API path (i.e. "/deposit-confirmation") * @param path Taler API path (i.e. "/deposit-confirmation")

View File

@ -1051,6 +1051,9 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (wsh); GNUNET_free (wsh);
return NULL; return NULL;
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Attempting to withdraw from reserve %s\n",
TALER_B2S (reserve_pub));
wsh->ps = *ps; wsh->ps = *ps;
wsh->url = TEAH_path_to_url (exchange, "/reserve/withdraw"); wsh->url = TEAH_path_to_url (exchange, "/reserve/withdraw");

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -363,8 +363,10 @@ withdraw_traits (void *cls,
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK != TALER_TESTING_get_trait_reserve_priv if (GNUNET_OK !=
(reserve_cmd, 0, &reserve_priv)) TALER_TESTING_get_trait_reserve_priv (reserve_cmd,
0,
&reserve_priv))
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_TESTING_interpreter_fail (ws->is); TALER_TESTING_interpreter_fail (ws->is);
@ -479,16 +481,17 @@ TALER_TESTING_cmd_withdraw_denomination
ws->reserve_reference = reserve_reference; ws->reserve_reference = reserve_reference;
ws->pk = dk; ws->pk = dk;
ws->expected_response_code = expected_response_code; 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 = { return cmd;
.cls = ws, }
.label = label,
.run = &withdraw_run,
.cleanup = &withdraw_cleanup,
.traits = &withdraw_traits
};
return cmd;
} }