summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-16 15:06:09 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-16 15:06:16 +0100
commit14ab704cde389ae8eea94f08f29ac3af955729c9 (patch)
tree6772dce9df0c675105b14b51aa8617050d851f7c
parent1fc8fd22dc417f151e28a63dfc6fd58cf4b10b2e (diff)
downloadexchange-14ab704cde389ae8eea94f08f29ac3af955729c9.tar.gz
exchange-14ab704cde389ae8eea94f08f29ac3af955729c9.tar.bz2
exchange-14ab704cde389ae8eea94f08f29ac3af955729c9.zip
fix fakebank logic
-rw-r--r--src/bank-lib/bank_api_debit.c13
-rw-r--r--src/bank-lib/fakebank.c2
-rw-r--r--src/lib/test_bank_api.c6
-rw-r--r--src/lib/testing_api_cmd_bank_history_debit.c63
-rw-r--r--src/lib/testing_api_cmd_bank_transfer.c9
5 files changed, 62 insertions, 31 deletions
diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c
index ea3ddeebc..5688d4772 100644
--- a/src/bank-lib/bank_api_debit.c
+++ b/src/bank-lib/bank_api_debit.c
@@ -41,11 +41,6 @@ struct TALER_BANK_DebitHistoryHandle
char *request_url;
/**
- * The base URL of the bank.
- */
- char *bank_base_url;
-
- /**
* Handle for the request.
*/
struct GNUNET_CURL_Job *job;
@@ -220,7 +215,7 @@ handle_history_finished (void *cls,
* Request the debit history of the exchange's bank account.
*
* @param ctx curl context for the event loop
- * @param bank_base_url URL of the base INCLUDING account number
+ * @param account_base_url URL of the base INCLUDING account number
* @param auth authentication data to use
* @param start_row from which row on do we want to get results,
* use UINT64_MAX for the latest; exclusive
@@ -237,7 +232,7 @@ handle_history_finished (void *cls,
*/
struct TALER_BANK_DebitHistoryHandle *
TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
- const char *bank_base_url,
+ const char *account_base_url,
const struct TALER_BANK_AuthenticationData *auth,
uint64_t start_row,
int64_t num_results,
@@ -269,8 +264,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
hh = GNUNET_new (struct TALER_BANK_DebitHistoryHandle);
hh->hcb = hres_cb;
hh->hcb_cls = hres_cb_cls;
- hh->bank_base_url = GNUNET_strdup (bank_base_url);
- hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
+ hh->request_url = TALER_BANK_path_to_url_ (account_base_url,
url);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -317,7 +311,6 @@ TALER_BANK_debit_history_cancel (struct TALER_BANK_DebitHistoryHandle *hh)
hh->job = NULL;
}
GNUNET_free (hh->request_url);
- GNUNET_free (hh->bank_base_url);
GNUNET_free (hh);
}
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 2286d8ec1..15b21ba39 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -951,7 +951,7 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
char *debit_payto;
credit_payto = TALER_payto_xtalerbank_make (h->my_baseurl,
- account);
+ pos->credit_account);
debit_payto = TALER_payto_xtalerbank_make (h->my_baseurl,
pos->debit_account);
trans = json_pack
diff --git a/src/lib/test_bank_api.c b/src/lib/test_bank_api.c
index 21dbe74b5..f950f28ab 100644
--- a/src/lib/test_bank_api.c
+++ b/src/lib/test_bank_api.c
@@ -73,7 +73,7 @@ run (void *cls,
&bc.exchange_auth,
NULL,
1),
- TALER_TESTING_cmd_admin_add_incoming ("debit-1",
+ TALER_TESTING_cmd_admin_add_incoming ("credit-1",
"KUDOS:5.01",
bc.exchange_account_url,
&bc.exchange_auth,
@@ -88,12 +88,12 @@ run (void *cls,
&bc.exchange_auth,
NULL,
5),
- TALER_TESTING_cmd_admin_add_incoming ("debit-2",
+ TALER_TESTING_cmd_admin_add_incoming ("credit-2",
"KUDOS:3.21",
bc.exchange_account_url,
&bc.exchange_auth,
bc.user42_payto),
- TALER_TESTING_cmd_transfer ("credit-2",
+ TALER_TESTING_cmd_transfer ("debit-1",
"KUDOS:3.22",
bc.exchange_account_url,
&bc.exchange_auth,
diff --git a/src/lib/testing_api_cmd_bank_history_debit.c b/src/lib/testing_api_cmd_bank_history_debit.c
index 746a4ef12..64b464af7 100644
--- a/src/lib/testing_api_cmd_bank_history_debit.c
+++ b/src/lib/testing_api_cmd_bank_history_debit.c
@@ -50,7 +50,12 @@ struct History
/**
* URL to free.
*/
- char *url;
+ char *c_url;
+
+ /**
+ * URL to free.
+ */
+ char *d_url;
};
@@ -65,6 +70,11 @@ struct HistoryState
const char *account_url;
/**
+ * Payto URL of the debited account offering the "history" operation.
+ */
+ char *debit_payto;
+
+ /**
* Reference to command defining the
* first row number we want in the result.
*/
@@ -189,8 +199,8 @@ build_history (struct TALER_TESTING_Interpreter *is,
struct History *h;
const struct TALER_TESTING_Command *add_incoming_cmd;
int inc;
- unsigned int start;
- unsigned int end;
+ int start;
+ int end;
/* #GNUNET_YES whenever either no 'start' value was given for the history
* query, or the given value is found in the list of all the CMDs. */
int ok;
@@ -222,15 +232,15 @@ build_history (struct TALER_TESTING_Interpreter *is,
/* AKA 'delta' */
if (hs->num_results > 0)
{
- inc = 1; /* _inc_rement */
+ inc = 1; /* _inc_rement: go forwards */
start = 0;
- end = is->ip - 1;
+ end = is->ip;
}
else
{
- inc = -1;
+ inc = -1; /* decrement: we go backwards */
start = is->ip - 1;
- end = 0;
+ end = -1; /* range is exclusive, do look at 0! */
}
ok = GNUNET_NO;
@@ -242,7 +252,11 @@ build_history (struct TALER_TESTING_Interpreter *is,
total,
4);
pos = 0;
- for (unsigned int off = start; off != end + inc; off += inc)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Checking commands %u to %u for debit history\n",
+ start,
+ end);
+ for (int off = start; off != end; off += inc)
{
const struct TALER_TESTING_Command *cmd = &is->commands[off];
const uint64_t *row_id;
@@ -250,8 +264,11 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *credit_account;
const struct TALER_Amount *amount;
const struct TALER_WireTransferIdentifierRawP *wtid;
- const char *account_debit_url;
+ const char *exchange_base_url;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Checking if command %s is relevant for debit history\n",
+ cmd->label);
if ( (GNUNET_OK !=
TALER_TESTING_get_trait_bank_row (cmd,
&row_id)) ||
@@ -274,9 +291,12 @@ build_history (struct TALER_TESTING_Interpreter *is,
(GNUNET_OK !=
TALER_TESTING_get_trait_url (cmd,
0,
- &account_debit_url)) )
+ &exchange_base_url)) )
continue; /* not an event we care about */
/* Seek "/history" starting row. */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Command %s is relevant for debit history!\n",
+ cmd->label);
if ( (NULL != row_id_start) &&
(*row_id_start == *row_id) &&
(GNUNET_NO == ok) )
@@ -288,9 +308,15 @@ build_history (struct TALER_TESTING_Interpreter *is,
/* when 'start' was _not_ given, then ok == GNUNET_YES */
if (GNUNET_NO == ok)
continue; /* skip until we find the marker */
- if (0 != strcasecmp (hs->account_url,
+ if (0 != strcasecmp (hs->debit_payto,
debit_account))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account %s does not match desired account %s\n",
+ debit_account,
+ hs->debit_payto);
continue; /* account missmatch */
+ }
if (total >= GNUNET_MAX (hs->num_results,
-hs->num_results) )
{
@@ -306,12 +332,14 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_array_grow (h,
total,
pos * 2);
- h[pos].url = GNUNET_strdup (credit_account);
- h[pos].details.credit_account_url = h[pos].url;
+ h[pos].c_url = GNUNET_strdup (credit_account);
+ h[pos].d_url = GNUNET_strdup (debit_account);
+ h[pos].details.credit_account_url = h[pos].c_url;
+ h[pos].details.debit_account_url = h[pos].d_url;
h[pos].details.amount = *amount;
h[pos].row_id = *row_id;
h[pos].details.wtid = *wtid;
- h[pos].details.debit_account_url = account_debit_url;
+ h[pos].details.exchange_base_url = exchange_base_url;
pos++;
}
GNUNET_assert (GNUNET_YES == ok);
@@ -539,7 +567,11 @@ history_cleanup (void *cls,
TALER_BANK_debit_history_cancel (hs->hh);
}
for (unsigned int off = 0; off<hs->total; off++)
- GNUNET_free (hs->h[off].url);
+ {
+ GNUNET_free (hs->h[off].c_url);
+ GNUNET_free (hs->h[off].d_url);
+ }
+ GNUNET_free (hs->debit_payto);
GNUNET_free_non_null (hs->h);
GNUNET_free (hs);
}
@@ -572,6 +604,7 @@ TALER_TESTING_cmd_bank_debits (const char *label,
hs->start_row_reference = start_row_reference;
hs->num_results = num_results;
hs->auth = *auth;
+ hs->debit_payto = TALER_payto_xtalerbank_make2 (account_url);
{
struct TALER_TESTING_Command cmd = {
diff --git a/src/lib/testing_api_cmd_bank_transfer.c b/src/lib/testing_api_cmd_bank_transfer.c
index 938890911..7e89ec610 100644
--- a/src/lib/testing_api_cmd_bank_transfer.c
+++ b/src/lib/testing_api_cmd_bank_transfer.c
@@ -228,6 +228,11 @@ transfer_run (void *cls,
void *buf;
size_t buf_size;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Transfer of %s from %s to %s\n",
+ TALER_amount2s (&fts->amount),
+ fts->account_debit_url,
+ fts->payto_credit_account);
TALER_BANK_prepare_wire_transfer (fts->payto_credit_account,
&fts->amount,
fts->exchange_base_url,
@@ -304,7 +309,7 @@ transfer_traits (void *cls,
struct TransferState *fts = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_url (0,
- fts->account_debit_url),
+ fts->exchange_base_url),
TALER_TESTING_make_trait_bank_row (&fts->serial_id),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT,
fts->payto_credit_account),
@@ -352,7 +357,7 @@ TALER_TESTING_cmd_transfer
fts = GNUNET_new (struct TransferState);
fts->account_debit_url = account_base_url;
fts->exchange_base_url = exchange_base_url;
- fts->payto_debit_account = TALER_payto_xtalerbank_make2 (exchange_base_url);
+ fts->payto_debit_account = TALER_payto_xtalerbank_make2 (account_base_url);
fts->payto_credit_account = payto_credit_account;
fts->auth = *auth;
fts->wtid = *wtid;