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 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/bank-lib/test_bank_api_new.c') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index 38ac537f..027fbffe 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", -- 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/bank-lib/test_bank_api_new.c') diff --git a/src/bank-lib/bank_api_history.c b/src/bank-lib/bank_api_history.c index 4b9ea3c3..bda5863d 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 027fbffe..bd3d9245 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 28de1ebe..3643c591 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 6bd1026f..5beaf97f 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/bank-lib/test_bank_api_new.c') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index bd3d9245..c35bb13b 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 3643c591..a50fd9ba 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 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/bank-lib/test_bank_api_new.c') diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index c35bb13b..5031a308 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