clean up history building/checking logic a bit

This commit is contained in:
Christian Grothoff 2020-01-15 22:29:09 +01:00
parent 77281fa319
commit 85c285be79
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 113 additions and 76 deletions

View File

@ -49,15 +49,6 @@
} while (0) } while (0)
// FIXME: replace these
#define TALER_TESTING_GET_TRAIT_ROW_ID(cmd,out) \
TALER_TESTING_get_trait_uint64 (cmd, 3, out)
// FIXME: replace these
#define TALER_TESTING_MAKE_TRAIT_ROW_ID(data) \
TALER_TESTING_make_trait_uint64 (3, data)
/** /**
* Allocate and return a piece of wire-details. Combines * Allocate and return a piece of wire-details. Combines
* a @a payto -URL and adds some salt to create the JSON. * a @a payto -URL and adds some salt to create the JSON.
@ -1727,6 +1718,27 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
/* ****** Specific traits supported by this component ******* */ /* ****** Specific traits supported by this component ******* */
/**
* Obtain a bank transaction row value from @a cmd.
*
* @param cmd command to extract the number from.
* @param row[out] set to the number coming from @a cmd.
* @return #GNUNET_OK on success.
*/
int
TALER_TESTING_get_trait_bank_row (const struct TALER_TESTING_Command *cmd,
const uint64_t **row);
/**
* Offer bank transaction row trait.
*
* @param row number to offer.
*/
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_bank_row (const uint64_t *row);
/** /**
* Offer a reserve private key. * Offer a reserve private key.
* *
@ -1857,7 +1869,7 @@ TALER_TESTING_get_trait_exchange_pub (const struct TALER_TESTING_Command *cmd,
int int
TALER_TESTING_get_trait_process (const struct TALER_TESTING_Command *cmd, TALER_TESTING_get_trait_process (const struct TALER_TESTING_Command *cmd,
unsigned int index, unsigned int index,
struct GNUNET_OS_Process ***processp); // FIXME: why is this a ***!? ** should do! struct GNUNET_OS_Process ***processp);
/** /**
@ -1871,7 +1883,7 @@ TALER_TESTING_get_trait_process (const struct TALER_TESTING_Command *cmd,
*/ */
struct TALER_TESTING_Trait struct TALER_TESTING_Trait
TALER_TESTING_make_trait_process (unsigned int index, TALER_TESTING_make_trait_process (unsigned int index,
struct GNUNET_OS_Process **processp); // FIXME: why is this a "**"? * should do! struct GNUNET_OS_Process **processp);
/** /**

View File

@ -404,7 +404,7 @@ admin_add_incoming_traits (void *cls,
{ {
struct AdminAddIncomingState *fts = cls; struct AdminAddIncomingState *fts = cls;
struct TALER_TESTING_Trait traits[] = { struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_MAKE_TRAIT_ROW_ID (&fts->serial_id), TALER_TESTING_make_trait_bank_row (&fts->serial_id),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT,
fts->payto_debit_account), fts->payto_debit_account),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT,

View File

@ -217,7 +217,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_assert (0 != hs->num_results); GNUNET_assert (0 != hs->num_results);
if (0 == is->ip) if (0 == is->ip)
{ {
TALER_LOG_DEBUG ("Checking history at first CMD (empty history)\n"); TALER_LOG_DEBUG ("Checking history at FIRST transaction (EMPTY)\n");
*rh = NULL; *rh = NULL;
return 0; return 0;
} }
@ -241,6 +241,9 @@ build_history (struct TALER_TESTING_Interpreter *is,
if (NULL == row_id_start) if (NULL == row_id_start)
ok = GNUNET_YES; ok = GNUNET_YES;
// FIXME: simplify logic by folding the TWO loops into ONE,
// (first doubling h if needed, and finally shrinking h to required size)
/* This loop counts how many commands _later than "start"_ belong /* This loop counts how many commands _later than "start"_ belong
* to the history of the caller. This is stored in the @var total * to the history of the caller. This is stored in the @var total
* variable. */ * variable. */
@ -251,12 +254,11 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *credit_account; const char *credit_account;
const char *debit_account; const char *debit_account;
/** /* The following command allows us to skip over those CMDs
* The following command allows us to skip over those CMDs
* that do not offer a "row_id" trait. Such skipped CMDs are * that do not offer a "row_id" trait. Such skipped CMDs are
* not interesting for building a history. * not interesting for building a history. *///
*/if (GNUNET_OK != TALER_TESTING_get_trait_uint64 (pos, if (GNUNET_OK !=
0, TALER_TESTING_get_trait_bank_row (pos,
&row_id)) &row_id))
continue; continue;
@ -309,7 +311,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
if (0 == total) if (0 == total)
{ {
TALER_LOG_DEBUG ("Checking history at first CMD.. (2)\n"); TALER_LOG_DEBUG ("Checking history with ZERO transactions\n");
*rh = NULL; *rh = NULL;
return 0; return 0;
} }
@ -334,7 +336,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *debit_account; const char *debit_account;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_GET_TRAIT_ROW_ID (pos, TALER_TESTING_get_trait_bank_row (pos,
&row_id)) &row_id))
continue; continue;
@ -377,8 +379,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
TALER_TESTING_get_trait_payto (pos, TALER_TESTING_get_trait_payto (pos,
TALER_TESTING_PT_DEBIT, TALER_TESTING_PT_DEBIT,
&debit_account)); &debit_account));
TALER_LOG_INFO ("Potential history bit:" TALER_LOG_INFO ("Potential history bit: %s->%s; my account: %s\n",
" %s->%s; my account: %s\n",
debit_account, debit_account,
credit_account, credit_account,
hs->account_url); hs->account_url);
@ -399,14 +400,16 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *account_url; const char *account_url;
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_amount_obj TALER_TESTING_get_trait_amount_obj (pos,
(pos, 0, &amount)); 0,
&amount));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_reserve_pub TALER_TESTING_get_trait_reserve_pub (pos,
(pos, 0, &reserve_pub)); 0,
&reserve_pub));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_url TALER_TESTING_get_trait_url (pos,
(pos, 1, 1,
&account_url)); &account_url));
h[total].url = GNUNET_strdup (debit_account); h[total].url = GNUNET_strdup (debit_account);
h[total].details.debit_account_url = h[total].url; h[total].details.debit_account_url = h[total].url;

View File

@ -239,6 +239,9 @@ build_history (struct TALER_TESTING_Interpreter *is,
if (NULL == row_id_start) if (NULL == row_id_start)
ok = GNUNET_YES; ok = GNUNET_YES;
// FIXME: simplify logic by folding the TWO loops into ONE,
// (first doubling h if needed, and finally shrinking h to required size)
/* This loop counts how many commands _later than "start"_ belong /* This loop counts how many commands _later than "start"_ belong
* to the history of the caller. This is stored in the @var total * to the history of the caller. This is stored in the @var total
* variable. */ * variable. */
@ -251,10 +254,9 @@ build_history (struct TALER_TESTING_Interpreter *is,
/* The following command allows us to skip over those CMDs /* The following command allows us to skip over those CMDs
* that do not offer a "row_id" trait. Such skipped CMDs are * that do not offer a "row_id" trait. Such skipped CMDs are
* not interesting for building a history. * not interesting for building a history. *///
*/ if (GNUNET_OK !=
if (GNUNET_OK != TALER_TESTING_get_trait_uint64 (pos, TALER_TESTING_get_trait_bank_row (pos,
0,
&row_id)) &row_id))
continue; continue;
@ -275,7 +277,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
continue; /* skip until we find the marker */ continue; /* skip until we find the marker */
TALER_LOG_DEBUG ("Found first row\n"); TALER_LOG_DEBUG ("Found first row\n");
if (total >= GNUNET_MAX (hs->num_results, if (total >= GNUNET_MAX (hs->num_results,
-hs->num_results) ) -hs->num_results) )
{ {
@ -287,7 +288,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
TALER_TESTING_get_trait_payto (pos, TALER_TESTING_get_trait_payto (pos,
TALER_TESTING_PT_DEBIT, TALER_TESTING_PT_DEBIT,
&debit_account)); &debit_account));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_payto (pos, TALER_TESTING_get_trait_payto (pos,
TALER_TESTING_PT_CREDIT, TALER_TESTING_PT_CREDIT,
@ -333,7 +333,7 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *debit_account; const char *debit_account;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_TESTING_GET_TRAIT_ROW_ID (pos, TALER_TESTING_get_trait_bank_row (pos,
&row_id)) &row_id))
continue; continue;
@ -353,7 +353,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
} }
TALER_LOG_INFO ("Found first row (2)\n"); TALER_LOG_INFO ("Found first row (2)\n");
if (GNUNET_NO == ok) if (GNUNET_NO == ok)
{ {
TALER_LOG_INFO ("Skip on `%s'\n", TALER_LOG_INFO ("Skip on `%s'\n",
@ -380,17 +379,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
debit_account, debit_account,
credit_account, credit_account,
hs->account_url); hs->account_url);
/* Discard transactions where the audited account played _both_ the debit
* and the debit roles, but _only if_ the audit goes on both directions..
* This needs more explaination!
*/
if (0 == strcasecmp (hs->account_url,
debit_account))
{
GNUNET_break (0);
continue;
}
bank_hostname = strchr (hs->account_url, ':'); bank_hostname = strchr (hs->account_url, ':');
GNUNET_assert (NULL != bank_hostname); GNUNET_assert (NULL != bank_hostname);
bank_hostname += 3; bank_hostname += 3;
@ -407,14 +395,16 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *account_url; const char *account_url;
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_amount_obj TALER_TESTING_get_trait_amount_obj (pos,
(pos, 0, &amount)); 0,
&amount));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_wtid TALER_TESTING_get_trait_wtid (pos,
(pos, 0, &wtid)); 0,
&wtid));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_url TALER_TESTING_get_trait_url (pos,
(pos, 1, 1,
&account_url)); &account_url));
h[total].url = GNUNET_strdup (credit_account); h[total].url = GNUNET_strdup (credit_account);
h[total].details.credit_account_url = h[total].url; h[total].details.credit_account_url = h[total].url;

View File

@ -298,7 +298,7 @@ transfer_traits (void *cls,
struct TransferState *fts = cls; struct TransferState *fts = cls;
struct TALER_TESTING_Trait traits[] = { struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_url (1, fts->account_debit_url), TALER_TESTING_make_trait_url (1, fts->account_debit_url),
TALER_TESTING_MAKE_TRAIT_ROW_ID (&fts->serial_id), TALER_TESTING_make_trait_bank_row (&fts->serial_id),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT,
fts->payto_credit_account), fts->payto_credit_account),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT,

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 under the terms of the GNU General Public License as published
@ -16,7 +16,6 @@
License along with TALER; see the file COPYING. If not, see License along with TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/> <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file exchange-lib/testing_api_trait_number.c * @file exchange-lib/testing_api_trait_number.c
* @brief traits to offer numbers * @brief traits to offer numbers
@ -31,6 +30,8 @@
#define TALER_TESTING_TRAIT_UINT "uint" #define TALER_TESTING_TRAIT_UINT "uint"
#define TALER_TESTING_TRAIT_UINT64 "uint-64" #define TALER_TESTING_TRAIT_UINT64 "uint-64"
#define TALER_TESTING_TRAIT_BANK_ROW "bank-transaction-row"
/** /**
* Obtain a number from @a cmd. * Obtain a number from @a cmd.
@ -41,8 +42,7 @@
* @return #GNUNET_OK on success. * @return #GNUNET_OK on success.
*/ */
int int
TALER_TESTING_get_trait_uint TALER_TESTING_get_trait_uint (const struct TALER_TESTING_Command *cmd,
(const struct TALER_TESTING_Command *cmd,
unsigned int index, unsigned int index,
const unsigned int **n) const unsigned int **n)
{ {
@ -61,8 +61,7 @@ TALER_TESTING_get_trait_uint
* @return #GNUNET_OK on success. * @return #GNUNET_OK on success.
*/ */
struct TALER_TESTING_Trait struct TALER_TESTING_Trait
TALER_TESTING_make_trait_uint TALER_TESTING_make_trait_uint (unsigned int index,
(unsigned int index,
const unsigned int *n) const unsigned int *n)
{ {
struct TALER_TESTING_Trait ret = { struct TALER_TESTING_Trait ret = {
@ -84,8 +83,7 @@ TALER_TESTING_make_trait_uint
* @return #GNUNET_OK on success. * @return #GNUNET_OK on success.
*/ */
int int
TALER_TESTING_get_trait_uint64 TALER_TESTING_get_trait_uint64 (const struct TALER_TESTING_Command *cmd,
(const struct TALER_TESTING_Command *cmd,
unsigned int index, unsigned int index,
const uint64_t **n) const uint64_t **n)
{ {
@ -103,8 +101,7 @@ TALER_TESTING_get_trait_uint64
* @param n number to offer. * @param n number to offer.
*/ */
struct TALER_TESTING_Trait struct TALER_TESTING_Trait
TALER_TESTING_make_trait_uint64 TALER_TESTING_make_trait_uint64 (unsigned int index,
(unsigned int index,
const uint64_t *n) const uint64_t *n)
{ {
struct TALER_TESTING_Trait ret = { struct TALER_TESTING_Trait ret = {
@ -116,4 +113,39 @@ TALER_TESTING_make_trait_uint64
} }
/**
* Obtain a bank transaction row value from @a cmd.
*
* @param cmd command to extract the number from.
* @param row[out] set to the number coming from @a cmd.
* @return #GNUNET_OK on success.
*/
int
TALER_TESTING_get_trait_bank_row (const struct TALER_TESTING_Command *cmd,
const uint64_t **row)
{
return cmd->traits (cmd->cls,
(const void **) row,
TALER_TESTING_TRAIT_BANK_ROW,
0);
}
/**
* Offer bank transaction row trait.
*
* @param row number to offer.
*/
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_bank_row (const uint64_t *row)
{
struct TALER_TESTING_Trait ret = {
.index = 0,
.trait_name = TALER_TESTING_TRAIT_BANK_ROW,
.ptr = (const void *) row
};
return ret;
}
/* end of testing_api_trait_number.c */ /* end of testing_api_trait_number.c */