From f3d80b58f68e308a6abac304994fd040ecb91eda Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 9 Apr 2019 17:14:13 +0200 Subject: Make the API-agnostic iterator work. This allows to build local histories to be matched against the ones returned by the bank; in particular, this version builds those stories regardless of /history or /history-range being run. --- src/bank-lib/test_bank_api_new.c | 14 +++ src/bank-lib/testing_api_cmd_history.c | 165 +++++++++++++++++++++++++----- src/exchange-tools/taler-exchange-keyup.c | 1 - src/include/taler_testing_bank_lib.h | 68 ++++++++++++ src/lib/testing_api_trait_time.c | 1 - 5 files changed, 219 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index 38ac537f7..027fbffe5 100644 --- a/src/bank-lib/test_bank_api_new.c +++ b/src/bank-lib/test_bank_api_new.c @@ -76,6 +76,20 @@ run (void *cls, NULL, /* start */ 5), + #if 0 + /** + * Just a dummy call to check if the logic doesn't crash. + */ + TALER_TESTING_cmd_bank_history_range_with_dates + ("history-0-range", + bank_url, + EXCHANGE_ACCOUNT_NUMBER, + TALER_BANK_DIRECTION_BOTH, + GNUNET_NO, + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS), + #endif + TALER_TESTING_cmd_fakebank_transfer_with_subject ("deposit-1", "KUDOS:5.01", diff --git a/src/bank-lib/testing_api_cmd_history.c b/src/bank-lib/testing_api_cmd_history.c index 37e15af82..28de1ebe9 100644 --- a/src/bank-lib/testing_api_cmd_history.c +++ b/src/bank-lib/testing_api_cmd_history.c @@ -1,4 +1,4 @@ -/* + /* This file is part of TALER Copyright (C) 2018 Taler Systems SA @@ -40,19 +40,16 @@ */ struct HistoryState { - /** * Base URL of the bank offering the "history" operation. */ const char *bank_url; - /** * Account number to ask the history for. */ uint64_t account_no; - /** * Which type of records we are interested: in-transfers * / out-transfers / rejected transfers. @@ -65,7 +62,9 @@ struct HistoryState const char *start_row_reference; /** - * How many rows we want in the result. + * How many rows we want in the result, _at most_. In + * the case of /history-range, we fake this value with + * INT64_MAX. */ long long num_results; @@ -263,6 +262,45 @@ print_expected (struct History *h, } } + + +/** + * Tell if the current item is beyond the allowed limit. + * + * @param total current number of items in the built history list. + * Note, this is the list we build locally and compare with + * what the server returned. + * @param hs the history CMD state. + * @param pos current item to be evaluated or not (if the list + * has already enough elements). + * @return GNUNET_OK / GNUNET_NO. + */ +static int +build_history_hit_limit (uint64_t total, + const struct HistoryState *hs, + const struct TALER_TESTING_Command *pos) +{ + /* "/history-range" case. */ + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->start_date.abs_value_us) + { + const struct GNUNET_TIME_Absolute *timestamp; + + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_absolute_time (pos, + 0, + ×tamp)); + + GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->end_date.abs_value_us); + + return timestamp->abs_value_us >= hs->end_date.abs_value_us; + } + + return total >= hs->num_results; +} + + /** * This function constructs the list of history elements that * interest the account number of the caller. It has two main @@ -305,10 +343,10 @@ build_history (struct TALER_TESTING_Interpreter *is, if (NULL != hs->start_row_reference) { - TALER_LOG_INFO ("`%s': start row given via reference `%s'\n", - TALER_TESTING_interpreter_get_current_label - (is), - hs->start_row_reference); + TALER_LOG_INFO + ("`%s': start row given via reference `%s'\n", + TALER_TESTING_interpreter_get_current_label (is), + hs->start_row_reference); add_incoming_cmd = TALER_TESTING_interpreter_lookup_command (is, hs->start_row_reference); GNUNET_assert (NULL != add_incoming_cmd); @@ -317,7 +355,6 @@ build_history (struct TALER_TESTING_Interpreter *is, } GNUNET_assert (0 != hs->num_results); - if (0 == is->ip) { *rh = NULL; @@ -344,9 +381,9 @@ build_history (struct TALER_TESTING_Interpreter *is, if (NULL == row_id_start) ok = GNUNET_YES; - /* This loop counts how many commands in the list off _all_ - * the commands belong to the history of the caller. This - * is stored in the @var total variable. */ + /* This loop counts how many commands _later than "start"_ belong + * to the history of the caller. This is stored in the @var total + * variable. */ for (unsigned int off = start;off != end + inc; off += inc) { const struct TALER_TESTING_Command *pos = &is->commands[off]; @@ -358,11 +395,12 @@ build_history (struct TALER_TESTING_Interpreter *is, * that do not offer a "row_id" trait. Such skipped CMDs are * not interesting for building a history. */ - - if (GNUNET_OK != TALER_TESTING_get_trait_uint64 - (pos, 0, &row_id)) + if (GNUNET_OK != TALER_TESTING_get_trait_uint64 (pos, + 0, + &row_id)) continue; + /* Seek "/history" starting row. */ if (NULL != row_id_start) { if (*row_id_start == *row_id) @@ -373,12 +411,32 @@ build_history (struct TALER_TESTING_Interpreter *is, continue; } } + + /* Seek "/history-range" starting row, _if_ that's the case */ + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->start_date.abs_value_us) + { + const struct GNUNET_TIME_Absolute *timestamp; + + TALER_TESTING_get_trait_absolute_time (pos, + 0, + ×tamp); + if (hs->start_date.abs_value_us <= timestamp->abs_value_us) + { + total = 0; + ok = GNUNET_YES; + continue; + } + } + /* when 'start' was _not_ given, then ok == GNUNET_YES */ if (GNUNET_NO == ok) continue; /* skip until we find the marker */ - if (total >= hs->num_results * inc) - break; /* hit limit specified by command */ + if (build_history_hit_limit (total, + hs, + pos)) + break; cancelled = test_cancelled (is, off); @@ -435,7 +493,6 @@ build_history (struct TALER_TESTING_Interpreter *is, if (NULL == row_id_start) ok = GNUNET_YES; - /** * This loop _only_ populates the array of history elements. */ @@ -457,12 +514,32 @@ build_history (struct TALER_TESTING_Interpreter *is, if (*row_id_start == *row_id) { - /* Doesn't count, start is excluded from output. */ + /* Warning: this zeroing is superfluous, as total doesn't + * get incremented if 'start' was given and couldn't be found. + */ total = 0; ok = GNUNET_YES; continue; } } + + /* Seek "/history-range" starting row, _if_ that's the case */ + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->start_date.abs_value_us) + { + const struct GNUNET_TIME_Absolute *timestamp; + + TALER_TESTING_get_trait_absolute_time (pos, + 0, + ×tamp); + if (hs->start_date.abs_value_us <= timestamp->abs_value_us) + { + total = 0; + ok = GNUNET_YES; + continue; + } + } + if (GNUNET_NO == ok) { TALER_LOG_INFO ("Skip on `%s'\n", @@ -470,7 +547,9 @@ build_history (struct TALER_TESTING_Interpreter *is, continue; /* skip until we find the marker */ } - if (total >= hs->num_results * inc) + if (build_history_hit_limit (total, + hs, + pos)) { TALER_LOG_INFO ("hit limit specified by command\n"); break; @@ -490,6 +569,12 @@ build_history (struct TALER_TESTING_Interpreter *is, (unsigned long long) *credit_account_no, (unsigned long long) hs->account_no); + /** + * Discard transactions where the audited account played + * _both_ the credit and the debit roles, but _only if_ + * the audit goes on both directions.. This needs more + * explaination! + */ if ( ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && (hs->account_no == *credit_account_no)) && ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) && @@ -513,6 +598,10 @@ build_history (struct TALER_TESTING_Interpreter *is, GNUNET_assert (NULL != bank_hostname); bank_hostname += 3; + /* Next two blocks only put the 'direction' and 'banking' + * information. */ + + /* Asked for credit, and account got the credit. */ if ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && (hs->account_no == *credit_account_no)) { @@ -528,6 +617,8 @@ build_history (struct TALER_TESTING_Interpreter *is, bank_hostname, (unsigned long long) *debit_account_no); } + + /* Asked for debit, and account got the debit. */ if ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) && (hs->account_no == *debit_account_no)) { @@ -543,6 +634,9 @@ build_history (struct TALER_TESTING_Interpreter *is, bank_hostname, (unsigned long long) *credit_account_no); } + + /* This block _completes_ the information of the current item, + * with amount / subject / exchange URL. */ if ( ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && (hs->account_no == *credit_account_no)) || ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) && @@ -774,8 +868,9 @@ history_run (void *cls, if (NULL == history_cmd) TALER_TESTING_FAIL (is); - if (GNUNET_OK != TALER_TESTING_get_trait_uint64 - (history_cmd, 0, &row_id_ptr)) + if (GNUNET_OK != TALER_TESTING_get_trait_uint64 (history_cmd, + 0, + &row_id_ptr)) TALER_TESTING_FAIL (is); row_id = *row_id_ptr; @@ -830,10 +925,13 @@ history_range_run (void *cls, if (GNUNET_OK != TALER_TESTING_get_trait_absolute_time (history_cmd, 0, &start_date)) TALER_TESTING_FAIL (is); + hs->start_date = *start_date; } else { - GNUNET_assert (UINT64_MAX != hs->start_date.abs_value_us); + /* no trait wanted. */ + GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->start_date.abs_value_us); start_date = &hs->start_date; } @@ -851,10 +949,13 @@ history_range_run (void *cls, if (GNUNET_OK != TALER_TESTING_get_trait_absolute_time (history_cmd, 0, &end_date)) TALER_TESTING_FAIL (is); + hs->end_date = *end_date; } else { - GNUNET_assert (UINT64_MAX != hs->end_date.abs_value_us); + /* no trait wanted. */ + GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->end_date.abs_value_us); end_date = &hs->end_date; } @@ -933,6 +1034,8 @@ TALER_TESTING_cmd_bank_history hs->start_row_reference = start_row_reference; hs->num_results = num_results; hs->ascending = ascending; + hs->start_date = GNUNET_TIME_UNIT_FOREVER_ABS; + hs->end_date = GNUNET_TIME_UNIT_FOREVER_ABS; struct TALER_TESTING_Command cmd = { .label = label, @@ -962,8 +1065,11 @@ TALER_TESTING_cmd_bank_history * @param end_row_reference reference to a command that can * offer a absolute time to use as the 'end' argument * for "/history-range". - * @param num_result how many rows we want in the result. - * + * @param num_results how many results we want from the bank; NOTE, + * this value is NOT used to issue any "delta" parameter in + * the HTTP request. Rather, it is only checked against + * the results returned by the bank. + * * @return the command. */ struct TALER_TESTING_Command @@ -1016,7 +1122,10 @@ TALER_TESTING_cmd_bank_history_range * of "/history-range". * @param end_date value for the 'end' argument * of "/history-range". - * @param num_result how many rows we want in the result. + * @param num_results how many results we want from the bank; NOTE, + * this value is NOT used to issue any "delta" parameter in + * the HTTP request. Rather, it is only checked against + * the results returned by the bank. * * @return the command. */ diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c index e10911b3d..8b6d32ac8 100644 --- a/src/exchange-tools/taler-exchange-keyup.c +++ b/src/exchange-tools/taler-exchange-keyup.c @@ -1195,7 +1195,6 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - static struct GNUNET_HashCode zero; struct GNUNET_TIME_Relative lookahead_sign; struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv; diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h index a3cc741e6..6bd1026f7 100644 --- a/src/include/taler_testing_bank_lib.h +++ b/src/include/taler_testing_bank_lib.h @@ -109,6 +109,74 @@ TALER_TESTING_cmd_bank_history const char *start_row_reference, long long num_results); + +/** + * Make a "history-range" CMD, picking dates from the arguments. + * + * @param label command label. + * @param bank_url base URL of the bank offering the "history" + * operation. + * @param account_no bank account number to ask the history for. + * @param direction which direction this operation is interested. + * @param ascending if GNUNET_YES, the bank will return the rows + * in ascending (= chronological) order. + * @param start_date value for the 'start' argument + * of "/history-range". + * @param end_date value for the 'end' argument + * of "/history-range". + * @param num_results how many results we want from the bank; NOTE, + * this value is NOT used to issue any "delta" parameter in + * the HTTP request. Rather, it is only checked against + * the results returned by the bank. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_bank_history_range_with_dates + (const char *label, + const char *bank_url, + uint64_t account_no, + enum TALER_BANK_Direction direction, + unsigned int ascending, + struct GNUNET_TIME_Absolute start_date, + struct GNUNET_TIME_Absolute end_date, + long long num_results); + + +/** + * Make a "history-range" CMD, picking dates from traits. + * + * @param label command label. + * @param bank_url base URL of the bank offering the "history" + * operation. + * @param account_no bank account number to ask the history for. + * @param direction which direction this operation is interested. + * @param ascending if GNUNET_YES, the bank will return the rows + * in ascending (= chronological) order. + * @param start_row_reference reference to a command that can + * offer a absolute time to use as the 'start' argument + * for "/history-range". + * @param end_row_reference reference to a command that can + * offer a absolute time to use as the 'end' argument + * for "/history-range". + * @param num_results how many results we want from the bank; NOTE, + * this value is NOT used to issue any "delta" parameter in + * the HTTP request. Rather, it is only checked against + * the results returned by the bank. + * + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_bank_history_range + (const char *label, + const char *bank_url, + uint64_t account_no, + enum TALER_BANK_Direction direction, + unsigned int ascending, + const char *start_row_reference, + const char *end_row_reference, + long long num_results); + + /** * Create a "reject" CMD. * diff --git a/src/lib/testing_api_trait_time.c b/src/lib/testing_api_trait_time.c index 3fd07bbba..384ff807d 100644 --- a/src/lib/testing_api_trait_time.c +++ b/src/lib/testing_api_trait_time.c @@ -52,7 +52,6 @@ TALER_TESTING_get_trait_absolute_time index); } - /** * Offer a absolute time. * -- cgit v1.2.3 From 75ac6b80634be292f7b681a7b20a1faedd32b48f Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 9 Apr 2019 18:01:10 +0200 Subject: minor fixes --- src/bank-lib/bank_api_history.c | 2 +- src/bank-lib/test_bank_api_new.c | 2 +- src/bank-lib/testing_api_cmd_history.c | 41 +++++++++++++++++----------------- src/include/taler_testing_bank_lib.h | 15 ++----------- 4 files changed, 25 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c index 4b9ea3c3c..bda5863d2 100644 --- a/src/bank-lib/bank_api_history.c +++ b/src/bank-lib/bank_api_history.c @@ -419,7 +419,7 @@ TALER_BANK_history_range (struct GNUNET_CURL_Context *ctx, GNUNET_TIME_round_abs (&end_date); GNUNET_asprintf (&url, - "/history?auth=basic&account_number=%llu&start=%llu&end=%llu&direction=%s&cancelled=%s&ordering=%s", + "/history-range?auth=basic&account_number=%llu&start=%llu&end=%llu&direction=%s&cancelled=%s&ordering=%s", (unsigned long long) account_number, start_date.abs_value_us / 1000LL / 1000LL, end_date.abs_value_us / 1000LL / 1000LL, diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index 027fbffe5..bd3d92454 100644 --- a/src/bank-lib/test_bank_api_new.c +++ b/src/bank-lib/test_bank_api_new.c @@ -76,7 +76,7 @@ run (void *cls, NULL, /* start */ 5), - #if 0 + #if 1 /** * Just a dummy call to check if the logic doesn't crash. */ diff --git a/src/bank-lib/testing_api_cmd_history.c b/src/bank-lib/testing_api_cmd_history.c index 28de1ebe9..3643c5917 100644 --- a/src/bank-lib/testing_api_cmd_history.c +++ b/src/bank-lib/testing_api_cmd_history.c @@ -354,7 +354,10 @@ build_history (struct TALER_TESTING_Interpreter *is, (add_incoming_cmd, 0, &row_id_start)); } - GNUNET_assert (0 != hs->num_results); + GNUNET_assert ((0 != hs->num_results) || + (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != + hs->start_date.abs_value_us)); + if (0 == is->ip) { *rh = NULL; @@ -784,9 +787,8 @@ history_cb (void *cls, struct TALER_TESTING_Interpreter *is = cls; struct HistoryState *hs = is->commands[is->ip].cls; - /* Possibly we got the 204 status code - * as a "end of list" marker. */ - if (MHD_HTTP_OK != http_status) + /*NOTE: "204 No Content" is used to signal the end of results.*/ + if (MHD_HTTP_NO_CONTENT == http_status) { hs->hh = NULL; if ( (hs->results_obtained != compute_result_count (is)) || @@ -813,6 +815,19 @@ history_cb (void *cls, TALER_TESTING_interpreter_next (is); return; } + + if (MHD_HTTP_OK != http_status) + { + hs->hh = NULL; + GNUNET_log + (GNUNET_ERROR_TYPE_ERROR, + "Unwanted response code from /history[-range]: %u\n", + http_status); + TALER_TESTING_interpreter_fail (is); + return; + } + + /* check current element */ if (GNUNET_OK != check_result (is, hs->results_obtained, dir, @@ -1065,11 +1080,6 @@ TALER_TESTING_cmd_bank_history * @param end_row_reference reference to a command that can * offer a absolute time to use as the 'end' argument * for "/history-range". - * @param num_results how many results we want from the bank; NOTE, - * this value is NOT used to issue any "delta" parameter in - * the HTTP request. Rather, it is only checked against - * the results returned by the bank. - * * @return the command. */ struct TALER_TESTING_Command @@ -1080,8 +1090,7 @@ TALER_TESTING_cmd_bank_history_range enum TALER_BANK_Direction direction, unsigned int ascending, const char *start_row_reference, - const char *end_row_reference, - long long num_results) + const char *end_row_reference) { struct HistoryState *hs; @@ -1091,7 +1100,6 @@ TALER_TESTING_cmd_bank_history_range hs->direction = direction; hs->start_row_reference = start_row_reference; hs->end_row_reference = end_row_reference; - hs->num_results = num_results; hs->ascending = ascending; hs->start_date = GNUNET_TIME_UNIT_FOREVER_ABS; hs->end_date = GNUNET_TIME_UNIT_FOREVER_ABS; @@ -1122,11 +1130,6 @@ TALER_TESTING_cmd_bank_history_range * of "/history-range". * @param end_date value for the 'end' argument * of "/history-range". - * @param num_results how many results we want from the bank; NOTE, - * this value is NOT used to issue any "delta" parameter in - * the HTTP request. Rather, it is only checked against - * the results returned by the bank. - * * @return the command. */ struct TALER_TESTING_Command @@ -1137,8 +1140,7 @@ TALER_TESTING_cmd_bank_history_range_with_dates enum TALER_BANK_Direction direction, unsigned int ascending, struct GNUNET_TIME_Absolute start_date, - struct GNUNET_TIME_Absolute end_date, - long long num_results) + struct GNUNET_TIME_Absolute end_date) { struct HistoryState *hs; @@ -1146,7 +1148,6 @@ TALER_TESTING_cmd_bank_history_range_with_dates hs->bank_url = bank_url; hs->account_no = account_no; hs->direction = direction; - hs->num_results = num_results; hs->ascending = ascending; hs->start_date = start_date; hs->end_date = start_date; diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h index 6bd1026f7..5beaf97f6 100644 --- a/src/include/taler_testing_bank_lib.h +++ b/src/include/taler_testing_bank_lib.h @@ -124,10 +124,6 @@ TALER_TESTING_cmd_bank_history * of "/history-range". * @param end_date value for the 'end' argument * of "/history-range". - * @param num_results how many results we want from the bank; NOTE, - * this value is NOT used to issue any "delta" parameter in - * the HTTP request. Rather, it is only checked against - * the results returned by the bank. * @return the command. */ struct TALER_TESTING_Command @@ -138,8 +134,7 @@ TALER_TESTING_cmd_bank_history_range_with_dates enum TALER_BANK_Direction direction, unsigned int ascending, struct GNUNET_TIME_Absolute start_date, - struct GNUNET_TIME_Absolute end_date, - long long num_results); + struct GNUNET_TIME_Absolute end_date); /** @@ -158,11 +153,6 @@ TALER_TESTING_cmd_bank_history_range_with_dates * @param end_row_reference reference to a command that can * offer a absolute time to use as the 'end' argument * for "/history-range". - * @param num_results how many results we want from the bank; NOTE, - * this value is NOT used to issue any "delta" parameter in - * the HTTP request. Rather, it is only checked against - * the results returned by the bank. - * * @return the command. */ struct TALER_TESTING_Command @@ -173,8 +163,7 @@ TALER_TESTING_cmd_bank_history_range enum TALER_BANK_Direction direction, unsigned int ascending, const char *start_row_reference, - const char *end_row_reference, - long long num_results); + const char *end_row_reference); /** -- cgit v1.2.3 From 814522d21c320d823ccb8b8dda1acbb7ae5538a9 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 9 Apr 2019 18:12:11 +0200 Subject: Time math macros. --- src/bank-lib/test_bank_api_new.c | 35 ++++++++++++++++++++++++++-------- src/bank-lib/testing_api_cmd_history.c | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index bd3d92454..c35bb13bc 100644 --- a/src/bank-lib/test_bank_api_new.c +++ b/src/bank-lib/test_bank_api_new.c @@ -39,6 +39,29 @@ #define CONFIG_FILE "bank.conf" +/** + * Adds to the current time. + * + * @param relative number of _seconds_ to add to the current time. + * @return a new absolute time, modified according to @e relative. + */ +#define NOWPLUSSECS(secs) \ + GNUNET_TIME_absolute_add \ + (now, \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + secs)) + +/** + * Subtracts from the current time. + * + * @param relative number of _seconds_ to add to the current time. + * @return a new absolute time, modified according to @e relative. + */ +#define NOWMINUSSECS(secs) \ + GNUNET_TIME_absolute_subtract \ + (now, \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + secs)) /** * Bank process. */ @@ -61,11 +84,12 @@ run (void *cls, { extern struct TALER_BANK_AuthenticationData AUTHS[]; + struct GNUNET_TIME_Absolute now; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bank serves at `%s'\n", bank_url); - + now = GNUNET_TIME_absolute_get (); struct TALER_TESTING_Command commands[] = { TALER_TESTING_cmd_bank_history ("history-0", @@ -76,19 +100,14 @@ run (void *cls, NULL, /* start */ 5), - #if 1 - /** - * Just a dummy call to check if the logic doesn't crash. - */ TALER_TESTING_cmd_bank_history_range_with_dates ("history-0-range", bank_url, EXCHANGE_ACCOUNT_NUMBER, TALER_BANK_DIRECTION_BOTH, GNUNET_NO, - GNUNET_TIME_UNIT_ZERO_ABS, - GNUNET_TIME_UNIT_FOREVER_ABS), - #endif + NOWMINUSSECS (5), + NOWPLUSSECS (5)), TALER_TESTING_cmd_fakebank_transfer_with_subject ("deposit-1", diff --git a/src/bank-lib/testing_api_cmd_history.c b/src/bank-lib/testing_api_cmd_history.c index 3643c5917..a50fd9bab 100644 --- a/src/bank-lib/testing_api_cmd_history.c +++ b/src/bank-lib/testing_api_cmd_history.c @@ -1150,7 +1150,7 @@ TALER_TESTING_cmd_bank_history_range_with_dates hs->direction = direction; hs->ascending = ascending; hs->start_date = start_date; - hs->end_date = start_date; + hs->end_date = end_date; struct TALER_TESTING_Command cmd = { .label = label, -- cgit v1.2.3 From ca718b9f1f76cd987d38572385d67b45114d4807 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 10 Apr 2019 11:17:18 +0200 Subject: minor fixes --- src/bank-lib/bank_api_history.c | 3 ++- src/bank-lib/test_bank_api_twisted.c | 20 +++++++++----------- src/bank-lib/test_bank_api_with_fakebank_new.c | 6 ------ src/bank-lib/test_bank_api_with_fakebank_twisted.c | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c index bda5863d2..5cdac9170 100644 --- a/src/bank-lib/bank_api_history.c +++ b/src/bank-lib/bank_api_history.c @@ -498,7 +498,8 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx, /* Locate and "cut" the 'start' argument, * if the user didn't provide one. */ if (UINT64_MAX == start_row) - *strstr (url, "&start=") = '\0'; + *strstr (url, + "&start=") = '\0'; hh = put_history_job (ctx, bank_base_url, diff --git a/src/bank-lib/test_bank_api_twisted.c b/src/bank-lib/test_bank_api_twisted.c index f9aaf5a1f..6d551eb61 100644 --- a/src/bank-lib/test_bank_api_twisted.c +++ b/src/bank-lib/test_bank_api_twisted.c @@ -81,24 +81,19 @@ static void run (void *cls, struct TALER_TESTING_Interpreter *is) { - struct TALER_TESTING_Command commands[] = { - TALER_TESTING_cmd_bank_history ("history-0", - twister_url, + TWISTED_BANK_URL, EXCHANGE_ACCOUNT_NUMBER, TALER_BANK_DIRECTION_BOTH, GNUNET_NO, NULL, 5), - /** - * End the suite. Fixme: better to have a label for this - * too, as it shows a "(null)" token on logs. - */ TALER_TESTING_cmd_end () }; - TALER_TESTING_run (is, commands); + TALER_TESTING_run (is, + commands); } /** @@ -109,7 +104,8 @@ run (void *cls, static void purge_process (struct GNUNET_OS_Process *process) { - GNUNET_OS_process_kill (process, SIGINT); + GNUNET_OS_process_kill (process, + SIGINT); GNUNET_OS_process_wait (process); GNUNET_OS_process_destroy (process); } @@ -124,14 +120,16 @@ main (int argc, unsetenv ("XDG_CONFIG_HOME"); GNUNET_log_setup ("test-bank-api-twisted", - "DEBUG", NULL); + "DEBUG", + NULL); if (NULL == (bank_url = TALER_TESTING_prepare_bank (CONFIG_FILE))) return 77; if (NULL == (bankd = TALER_TESTING_run_bank - (CONFIG_FILE, bank_url))) + (CONFIG_FILE, + bank_url))) return 77; if (NULL == (twister_url = TALER_TESTING_prepare_twister diff --git a/src/bank-lib/test_bank_api_with_fakebank_new.c b/src/bank-lib/test_bank_api_with_fakebank_new.c index b8eaabea0..8865cc403 100644 --- a/src/bank-lib/test_bank_api_with_fakebank_new.c +++ b/src/bank-lib/test_bank_api_with_fakebank_new.c @@ -63,12 +63,6 @@ run (void *cls, struct TALER_TESTING_Command commands[] = { - /** - * NOTE: this command uses internally the _fakebank_ version - * of the add-incoming command. However, this does seem to - * work fine against the Python bank too! Some renaming is - * required.. - */ TALER_TESTING_cmd_bank_history ("history-0", fakebank_url, BANK_ACCOUNT_NUMBER, diff --git a/src/bank-lib/test_bank_api_with_fakebank_twisted.c b/src/bank-lib/test_bank_api_with_fakebank_twisted.c index ca9d42f91..83838172f 100644 --- a/src/bank-lib/test_bank_api_with_fakebank_twisted.c +++ b/src/bank-lib/test_bank_api_with_fakebank_twisted.c @@ -77,7 +77,7 @@ run (void *cls, { struct TALER_TESTING_Command commands[] = { TALER_TESTING_cmd_bank_history ("history-0", - fakebank_url, + twister_url, EXCHANGE_ACCOUNT_NUMBER, TALER_BANK_DIRECTION_BOTH, GNUNET_NO, -- cgit v1.2.3 From 5c496633092de5ebccd43e7040db2cc92b72c332 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 10 Apr 2019 17:03:24 +0200 Subject: Fixing twisted tests. It has been observed that when a "twisted" test has "very little" commands in the stack, it uses to fail since the proxied service cannot be reached. This commit puts some delay before the first command gets run by the test interpreter; both in the form of a "blind" sleep, and with a more structured 'wget' loop. --- src/bank-lib/fakebank.c | 56 ++++++++-- src/bank-lib/test_bank_api_twisted.c | 4 + src/bank-lib/test_bank_api_with_fakebank_twisted.c | 20 ++-- src/include/taler_testing_lib.h | 13 +++ src/lib/test_exchange_api_twisted.c | 2 - src/lib/testing_api_cmd_sleep.c | 119 ++++++++++++++++++++- 6 files changed, 198 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index 9915516cd..1220fa057 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -587,6 +587,7 @@ handle_reject (struct TALER_FAKEBANK_Handle *h, return ret; } + /** * Handle incoming HTTP request for /history * @@ -596,9 +597,40 @@ handle_reject (struct TALER_FAKEBANK_Handle *h, * @return MHD result code */ static int -handle_history_new (struct TALER_FAKEBANK_Handle *h, - struct MHD_Connection *connection, - void **con_cls) +handle_home_page (struct TALER_FAKEBANK_Handle *h, + struct MHD_Connection *connection, + void **con_cls) +{ + int ret; + struct MHD_Response *resp; +#define HELLOMSG "Hello, Fakebank!" + + resp = MHD_create_response_from_buffer + (strlen (HELLOMSG), + HELLOMSG, + MHD_RESPMEM_MUST_COPY); + + ret = MHD_queue_response (connection, + MHD_HTTP_OK, + resp); + + MHD_destroy_response (resp); + return ret; +} + + +/** + * Handle incoming HTTP request for /history + * + * @param h the fakebank handle + * @param connection the connection + * @param con_cls place to store state, not used + * @return MHD result code + */ +static int +handle_history (struct TALER_FAKEBANK_Handle *h, + struct MHD_Connection *connection, + void **con_cls) { struct HistoryArgs ha; struct HistoryRangeIds hri; @@ -763,6 +795,18 @@ handle_mhd_request (void *cls, { struct TALER_FAKEBANK_Handle *h = cls; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fakebank, serving: %s\n", + url); + + + if ( (0 == strcasecmp (url, + "/")) && + (0 == strcasecmp (method, + MHD_HTTP_METHOD_GET)) ) + return handle_home_page (h, + connection, + con_cls); if ( (0 == strcasecmp (url, "/admin/add/incoming")) && (0 == strcasecmp (method, @@ -792,9 +836,9 @@ handle_mhd_request (void *cls, "/history")) && (0 == strcasecmp (method, MHD_HTTP_METHOD_GET)) ) - return handle_history_new (h, - connection, - con_cls); + return handle_history (h, + connection, + con_cls); /* Unexpected URL path, just close the connection. */ /* we're rather impolite here, but it's a testcase. */ diff --git a/src/bank-lib/test_bank_api_twisted.c b/src/bank-lib/test_bank_api_twisted.c index 6d551eb61..d01dbad94 100644 --- a/src/bank-lib/test_bank_api_twisted.c +++ b/src/bank-lib/test_bank_api_twisted.c @@ -82,6 +82,10 @@ run (void *cls, struct TALER_TESTING_Interpreter *is) { struct TALER_TESTING_Command commands[] = { + + TALER_TESTING_cmd_wait_service ("wait-service", + "http://localhost:8888/"), + TALER_TESTING_cmd_bank_history ("history-0", TWISTED_BANK_URL, EXCHANGE_ACCOUNT_NUMBER, diff --git a/src/bank-lib/test_bank_api_with_fakebank_twisted.c b/src/bank-lib/test_bank_api_with_fakebank_twisted.c index 83838172f..4cf500fbe 100644 --- a/src/bank-lib/test_bank_api_with_fakebank_twisted.c +++ b/src/bank-lib/test_bank_api_with_fakebank_twisted.c @@ -75,18 +75,23 @@ static void run (void *cls, struct TALER_TESTING_Interpreter *is) { + struct TALER_TESTING_Command commands[] = { + + /** + * Can't use the "wait service" CMD here because the + * fakebank runs inside the same process of the test. + */ + TALER_TESTING_cmd_sleep ("wait interface", + 2), + TALER_TESTING_cmd_bank_history ("history-0", - twister_url, + TWISTED_BANK_URL, EXCHANGE_ACCOUNT_NUMBER, TALER_BANK_DIRECTION_BOTH, GNUNET_NO, NULL, 5), - /** - * End the suite. Fixme: better to have a label for this - * too, as it shows a "(null)" token on logs. - */ TALER_TESTING_cmd_end () }; @@ -120,8 +125,9 @@ main (int argc, unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); - GNUNET_log_setup ("test-bank-api-twisted", - "DEBUG", NULL); + GNUNET_log_setup ("test-bank-api-with-fakebank-twisted", + "DEBUG", + NULL); if (NULL == (fakebank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE, diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 31180c308..99be529b3 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -1441,6 +1441,19 @@ TALER_TESTING_cmd_sleep (const char *label, unsigned int duration_s); +/** + * This CMD simply tries to connect via HTTP to the + * service addressed by @a url. It attemps 10 times + * before giving up and make the test fail. + * + * @param label label for the command. + * @param url complete URL to connect to. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_wait_service (const char *label, + const char *url); + + /** * Make a "check keys" command. This type of command * checks whether the number of denomination keys from diff --git a/src/lib/test_exchange_api_twisted.c b/src/lib/test_exchange_api_twisted.c index 7cc63c2c4..74d848206 100644 --- a/src/lib/test_exchange_api_twisted.c +++ b/src/lib/test_exchange_api_twisted.c @@ -144,8 +144,6 @@ static void run (void *cls, struct TALER_TESTING_Interpreter *is) { - - /** * This batch aims to trigger the 409 Conflict * response from a refresh-reveal operation. diff --git a/src/lib/testing_api_cmd_sleep.c b/src/lib/testing_api_cmd_sleep.c index 165d0aae4..188671bee 100644 --- a/src/lib/testing_api_cmd_sleep.c +++ b/src/lib/testing_api_cmd_sleep.c @@ -40,6 +40,25 @@ struct SleepState unsigned int duration; }; +/** + * No traits to offer, just provide a stub to be called when + * some CMDs iterates through the list of all the commands. + * + * @param cls closure. + * @param ret[out] result. + * @param trait name of the trait. + * @param index index number of the trait to return. + * + * @return #GNUNET_OK on success. + */ +static int +sleep_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_NO; +} /** * Run the command. @@ -97,8 +116,106 @@ TALER_TESTING_cmd_sleep (const char *label, .cls = ss, .label = label, .run = &sleep_run, - .cleanup = &sleep_cleanup + .cleanup = &sleep_cleanup, + .traits = &sleep_traits }; return cmd; } + +/** + * Cleanup the state from a "wait service" CMD. + * + * @param cls closure. + * @param cmd the command which is being cleaned up. + */ +static void +wait_service_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + /* nothing to clean. */ + return; +} + +/** + * No traits to offer, just provide a stub to be called when + * some CMDs iterates through the list of all the commands. + * + * @param cls closure. + * @param ret[out] result. + * @param trait name of the trait. + * @param index index number of the trait to return. + * + * @return #GNUNET_OK on success. + */ +static int +wait_service_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_NO; +} + +/** + * Run a "wait service" CMD. + * + * @param cls closure. + * @param cmd the command being run. + * @param is the interpreter state. + */ +static void +wait_service_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + unsigned int iter = 0; + const char *url = cmd->cls; + char *wget_cmd; + + GNUNET_asprintf (&wget_cmd, + "wget -q -t 1 -T 1 %s\n", + url); + do + { + fprintf (stderr, "."); + + if (10 == iter++) + { + TALER_LOG_ERROR ("Could not reach the proxied service\n"); + TALER_TESTING_interpreter_fail (is); + GNUNET_free (wget_cmd); + return; + } + } + while (0 != system (wget_cmd)); + + GNUNET_free (wget_cmd); + TALER_TESTING_interpreter_next (is); +} + + +/** + * This CMD simply tries to connect via HTTP to the + * service addressed by @a url. It attemps 10 times + * before giving up and make the test fail. + * + * @param label label for the command. + * @param url complete URL to connect to. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_wait_service (const char *label, + const char *url) +{ + struct TALER_TESTING_Command cmd = { + .label = label, + .run = wait_service_run, + .cleanup = wait_service_cleanup, + .traits = wait_service_traits, + .cls = (void *) url + }; + + return cmd; +} + +/* end of testing_api_cmd_sleep.c */ -- cgit v1.2.3 From 66425084c1c57c1fa1ddec3fb4ae6ca8c38e1070 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 10 Apr 2019 17:34:27 +0200 Subject: Test /history-range after transactions happened. --- src/bank-lib/test_bank_api_new.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index c35bb13bc..5031a3089 100644 --- a/src/bank-lib/test_bank_api_new.c +++ b/src/bank-lib/test_bank_api_new.c @@ -164,6 +164,18 @@ run (void *cls, "deposit-1", 5), + /** + * Just check that the two transactions show up. + */ + TALER_TESTING_cmd_bank_history_range_with_dates + ("history-2-range", + bank_url, + EXCHANGE_ACCOUNT_NUMBER, + TALER_BANK_DIRECTION_BOTH, + GNUNET_NO, + NOWMINUSSECS (5), + NOWPLUSSECS (5)), + TALER_TESTING_cmd_bank_reject ("reject-1", bank_url, "deposit-1"), -- cgit v1.2.3