From 061eaac70f9548f23a895b3cf8dec4d51ca4fe8f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 12 Jan 2020 19:45:45 +0100 Subject: [PATCH] split of check_empty logic --- src/include/taler_testing_lib.h | 2 - src/lib/Makefile.am | 1 + src/lib/test_exchange_api.c | 53 +++-------- src/lib/testing_api_cmd_bank_check.c | 78 ---------------- src/lib/testing_api_cmd_bank_check_empty.c | 103 +++++++++++++++++++++ 5 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 src/lib/testing_api_cmd_bank_check_empty.c diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index af122abde..bb5270042 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -1081,7 +1081,6 @@ TALER_TESTING_cmd_track_transfer_empty (const char *label, * @param expected_amount how much money we expect being moved * with this wire-transfer. * @param expected_wire_fee expected wire fee. - * * @return the command */ struct TALER_TESTING_Command @@ -1102,7 +1101,6 @@ TALER_TESTING_cmd_track_transfer (const char *label, * @param amount the amount expected to be transferred. * @param debit_account the account that gave money. * @param credit_account the account that received money. - * * @return the command */ struct TALER_TESTING_Command diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 729d54ba5..003713133 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -85,6 +85,7 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_refresh.c \ testing_api_cmd_track.c \ testing_api_cmd_bank_check.c \ + testing_api_cmd_bank_check_empty.c \ testing_api_cmd_payback.c \ testing_api_cmd_signal.c \ testing_api_cmd_check_keys.c \ diff --git a/src/lib/test_exchange_api.c b/src/lib/test_exchange_api.c index b95b060f5..0605ab252 100644 --- a/src/lib/test_exchange_api.c +++ b/src/lib/test_exchange_api.c @@ -35,6 +35,7 @@ #include "taler_bank_service.h" #include "taler_fakebank_lib.h" #include "taler_testing_lib.h" +#include "taler_testing_bank_lib.h" /** * Configuration file we use. One (big) configuration is used @@ -65,25 +66,27 @@ static char *exchange_url; */ static char *auditor_url; +/** + * URL of the exchange's account at the bank. Obtained from CONFIG_FILE's + * "exchange-wire-test:BANK_URI" option plus the exchange account. + */ +static char *exchange_account_url; // FIXME: initialize! + /** * Account number of the exchange at the bank. */ -#define EXCHANGE_ACCOUNT_NO 2 +#define EXCHANGE_ACCOUNT_NO "2" // FIXME: used? /** - * Account number of some user. + * Payto URL of the user's account. */ -#define USER_ACCOUNT_NO 42 +static char *user_account_payto; // FIXME: initialize! /** - * User name. Never checked by fakebank. + * Credentials for talking to the bank. */ -#define USER_LOGIN_NAME "user42" +static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize! -/** - * User password. Never checked by fakebank. - */ -#define USER_LOGIN_PASS "pass42" /** * Execute the taler-exchange-wirewatch command with @@ -112,23 +115,9 @@ static char *auditor_url; */ #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \ TALER_TESTING_cmd_admin_add_incoming (label, amount, \ - fakebank_url, USER_ACCOUNT_NO, \ - EXCHANGE_ACCOUNT_NO, \ - USER_LOGIN_NAME, USER_LOGIN_PASS, \ - exchange_url) - -/** - * Run wire transfer of funds from some user's account to the - * exchange. - * - * @param label label to use for the command. - * @param amount amount to transfer, i.e. "EUR:1" - */ -#define CMD_TRANSFER_TO_EXCHANGE_SUBJECT(label,amount,subject) \ - TALER_TESTING_cmd_admin_add_incoming_with_subject \ - (label, amount, fakebank_url, USER_ACCOUNT_NO, \ - EXCHANGE_ACCOUNT_NO, USER_LOGIN_NAME, USER_LOGIN_PASS, \ - subject, exchange_url) + exchange_account_url, \ + &auth, \ + user_account_payto) /** * Main function that will tell the interpreter what commands to @@ -832,21 +821,9 @@ run (void *cls, TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-pr3", exchange_url, "EUR:1.01", 42, 2), - TALER_TESTING_cmd_check_bank_empty ("check-empty-again"), - /* Test rejection of bogus wire transfers */ - CMD_TRANSFER_TO_EXCHANGE_SUBJECT - ("bogus-subject", - "EUR:1.01", - "not a reserve public key"), - - CMD_EXEC_WIREWATCH ("wirewatch-7"), - - TALER_TESTING_cmd_check_bank_empty - ("check-empty-from-reject"), - TALER_TESTING_cmd_end () }; diff --git a/src/lib/testing_api_cmd_bank_check.c b/src/lib/testing_api_cmd_bank_check.c index ad0a14b65..a7c4341c5 100644 --- a/src/lib/testing_api_cmd_bank_check.c +++ b/src/lib/testing_api_cmd_bank_check.c @@ -16,14 +16,12 @@ License along with TALER; see the file COPYING. If not, see */ - /** * @file exchange-lib/testing_api_cmd_bank_check.c * @brief command to check if a particular wire transfer took * place. * @author Marcello Stanisci */ - #include "platform.h" #include "taler_json_lib.h" #include @@ -255,80 +253,6 @@ TALER_TESTING_cmd_check_bank_transfer } -/** - * Cleanup the state, only defined to respect the API. - * - * @param cls closure. - * @param cmd the command which is being cleaned up. - */ -static void -check_bank_empty_cleanup - (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - return; -} - - -/** - * Run the command. - * - * @param cls closure. - * @param cmd the command to execute. - * @param is the interpreter state. - */ -static void -check_bank_empty_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - - if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } - TALER_TESTING_interpreter_next (is); -} - - -/** - * Some commands (notably "bank history") could randomly - * look for traits; this way makes sure we don't segfault. - */ -static int -check_bank_empty_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_SYSERR; -} - - -/** - * Checks wheter all the wire transfers got "checked" - * by the "bank check" CMD. - * - * @param label command label. - * - * @return the command - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_check_bank_empty (const char *label) -{ - struct TALER_TESTING_Command cmd = { - .label = label, - .run = &check_bank_empty_run, - .cleanup = &check_bank_empty_cleanup, - .traits = &check_bank_empty_traits - }; - - return cmd; -} - - /** * Define a "bank check" CMD that takes the input * data from another CMD that offers it. @@ -337,7 +261,6 @@ TALER_TESTING_cmd_check_bank_empty (const char *label) * @param deposit_reference reference to a CMD that is * able to provide the "check bank transfer" operation * input data. - * * @return the command. */ struct TALER_TESTING_Command @@ -345,7 +268,6 @@ TALER_TESTING_cmd_check_bank_transfer_with_ref (const char *label, const char *deposit_reference) { - struct BankCheckState *bcs; bcs = GNUNET_new (struct BankCheckState); diff --git a/src/lib/testing_api_cmd_bank_check_empty.c b/src/lib/testing_api_cmd_bank_check_empty.c new file mode 100644 index 000000000..fddbba527 --- /dev/null +++ b/src/lib/testing_api_cmd_bank_check_empty.c @@ -0,0 +1,103 @@ +/* + This file is part of TALER + Copyright (C) 2018-2020 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, or + (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + +*/ +/** + * @file exchange-lib/testing_api_cmd_bank_check_empty.c + * @brief command to check if a particular wire transfer took + * place. + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include +#include "exchange_api_handle.h" +#include "taler_testing_lib.h" +#include "taler_fakebank_lib.h" + + +/** + * Cleanup the state, only defined to respect the API. + * + * @param cls closure. + * @param cmd the command which is being cleaned up. + */ +static void +check_bank_empty_cleanup + (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + return; +} + + +/** + * Run the command. + * + * @param cls closure. + * @param cmd the command to execute. + * @param is the interpreter state. + */ +static void +check_bank_empty_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + TALER_TESTING_interpreter_next (is); +} + + +/** + * Some commands (notably "bank history") could randomly + * look for traits; this way makes sure we don't segfault. + */ +static int +check_bank_empty_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + return GNUNET_SYSERR; +} + + +/** + * Checks wheter all the wire transfers got "checked" + * by the "bank check" CMD. + * + * @param label command label. + * + * @return the command + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_check_bank_empty (const char *label) +{ + struct TALER_TESTING_Command cmd = { + .label = label, + .run = &check_bank_empty_run, + .cleanup = &check_bank_empty_cleanup, + .traits = &check_bank_empty_traits + }; + + return cmd; +}