diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-10-12 22:10:00 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-10-12 22:10:00 +0200 |
commit | 0cd18a0f8f2545eb1212c504683a8a70007caa48 (patch) | |
tree | b0b484085308961f44622c319209792589c21543 /src/testing | |
parent | 5b1fc2a9765465cf374b2feb7419a0e5200e4411 (diff) | |
download | exchange-0cd18a0f8f2545eb1212c504683a8a70007caa48.tar.xz |
clean up bank API, get test_bank_api_with_nexus to finally pass
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rwxr-xr-x | src/testing/taler-unified-setup.sh | 1 | ||||
-rw-r--r-- | src/testing/test_bank_api.c | 23 | ||||
-rw-r--r-- | src/testing/test_bank_api_nexus.conf | 14 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_bank_history_credit.c | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_bank_history_debit.c | 90 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_nexus_fetch_transactions.c | 188 |
7 files changed, 111 insertions, 207 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index c63c76475..d8e440536 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -79,7 +79,6 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_kyc_check_get.c \ testing_api_cmd_kyc_proof.c \ testing_api_cmd_kyc_wallet_get.c \ - testing_api_cmd_nexus_fetch_transactions.c \ testing_api_cmd_oauth.c \ testing_api_cmd_offline_sign_global_fees.c \ testing_api_cmd_offline_sign_wire_fees.c \ diff --git a/src/testing/taler-unified-setup.sh b/src/testing/taler-unified-setup.sh index b6624b467..9055ed29f 100755 --- a/src/testing/taler-unified-setup.sh +++ b/src/testing/taler-unified-setup.sh @@ -285,6 +285,7 @@ then echo $! > libeufin-bank.pid echo "DONE" echo -n "Waiting for Bank ..." + OK="0" for n in $(seq 1 100); do echo -n "." sleep "$DEFAULT_SLEEP" diff --git a/src/testing/test_bank_api.c b/src/testing/test_bank_api.c index 8477ef9ba..0dea6026d 100644 --- a/src/testing/test_bank_api.c +++ b/src/testing/test_bank_api.c @@ -112,8 +112,6 @@ run (void *cls, cred.user42_payto, "credit-1", -1), - TALER_TESTING_cmd_sleep ("Waiting 4s for 'credit-1' to settle", - 4), /** * Check that the incoming payment with a duplicate * reserve public key didn't make it to the exchange. @@ -137,18 +135,6 @@ run (void *cls, cred.user42_payto, &wtid, "http://exchange.example.com/"), - - TALER_TESTING_cmd_sleep ("Waiting 5s for 'debit-1' to settle", - 5), - (bs == TALER_TESTING_BS_IBAN) - ? TALER_TESTING_cmd_nexus_fetch_transactions ( - "fetch-transactions-at-nexus", - "exchange", /* from taler-nexus-prepare */ - "x", /* from taler-nexus-prepare */ - "http://localhost:8082", - "exchange-nexus") /* from taler-nexus-prepare */ - : TALER_TESTING_cmd_sleep ("nop", - 0), TALER_TESTING_cmd_bank_debits ("history-2b", &cred.ba, NULL, @@ -181,6 +167,15 @@ main (int argc, { bs = TALER_TESTING_BS_IBAN; cfgfile = CONFIG_FILE_NEXUS; + if (GNUNET_SYSERR == + GNUNET_OS_check_helper_binary ("libeufin-bank", + false, + NULL)) + { + fprintf (stderr, + "libeufin-bank not found. Skipping test.\n"); + return 77; + } } else { diff --git a/src/testing/test_bank_api_nexus.conf b/src/testing/test_bank_api_nexus.conf index 94e422a8a..6fc97ee37 100644 --- a/src/testing/test_bank_api_nexus.conf +++ b/src/testing/test_bank_api_nexus.conf @@ -12,3 +12,17 @@ PASSWORD = x [libeufin-bankdb-postgres] CONFIG="postgresql:///talercheck" + +# libeufin doesn't search our config.d/currencies.conf +# as it has a different resource path. Thus replicated +# here. +[currency-euro] +ENABLED = YES +name = "Euro" +code = "EUR" +decimal_separator = "," +fractional_input_digits = 2 +fractional_normal_digits = 2 +fractional_trailing_zero_digits = 2 +is_currency_name_leading = NO +alt_unit_names = {"0":"€"} diff --git a/src/testing/testing_api_cmd_bank_history_credit.c b/src/testing/testing_api_cmd_bank_history_credit.c index 7428a7d8d..956e6c857 100644 --- a/src/testing/testing_api_cmd_bank_history_credit.c +++ b/src/testing/testing_api_cmd_bank_history_credit.c @@ -276,7 +276,6 @@ command_cb (void *cls, ic->h[ic->pos].details.amount = *amount; ic->h[ic->pos].row_id = *row_id; ic->h[ic->pos].details.reserve_pub = *reserve_pub; - ic->h[ic->pos].details.credit_account_uri = exchange_credit_url; ic->pos++; } diff --git a/src/testing/testing_api_cmd_bank_history_debit.c b/src/testing/testing_api_cmd_bank_history_debit.c index 538538b6c..1cb7320fa 100644 --- a/src/testing/testing_api_cmd_bank_history_debit.c +++ b/src/testing/testing_api_cmd_bank_history_debit.c @@ -267,7 +267,6 @@ command_cb (void *cls, ic->h[ic->pos].c_url = GNUNET_strdup (credit_account); ic->h[ic->pos].d_url = GNUNET_strdup (debit_account); ic->h[ic->pos].details.credit_account_uri = ic->h[ic->pos].c_url; - ic->h[ic->pos].details.debit_account_uri = ic->h[ic->pos].d_url; ic->h[ic->pos].details.amount = *amount; ic->h[ic->pos].row_id = *row_id; ic->h[ic->pos].details.wtid = *wtid; @@ -336,6 +335,69 @@ build_history (struct HistoryState *hs, /** + * Normalize IBAN-based payto URI in @a in. + * + * @param in input payto://-URI to normalize + * @return normalized IBAN for the test + */ +static char * +normalize (const char *in) +{ + char *npt; + const char *q = strchr (in, + '?'); + const char *mptr; + const char *bic; + const char *iban; + + if (NULL == q) + npt = GNUNET_strdup (in); + else + npt = GNUNET_strndup (in, + q - in); + if (0 != strncasecmp (npt, + "payto://", + strlen ("payto://"))) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Invalid payto: %s\n", + npt); + GNUNET_free (npt); + return NULL; + } + mptr = npt + strlen ("payto://"); + bic = strchr (mptr, '/'); + if (NULL == bic) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Invalid payto: %s\n", + npt); + GNUNET_free (npt); + return NULL; + } + bic++; + iban = strchr (bic, '/'); + if (NULL != iban) + { + /* need to remove bic */ + char *n; + + iban++; + GNUNET_asprintf (&n, + "payto://%.*s/%s", + (int) ((bic - mptr) - 1), + mptr, + iban); + GNUNET_free (npt); + npt = n; + } + return npt; +} + + +/** * Check that the "/history/outgoing" response matches the * CMD whose offset in the list of CMDs is @a off. * @@ -352,6 +414,9 @@ check_result (struct History *h, unsigned int off, const struct TALER_BANK_DebitDetails *details) { + char *u1; + char *u2; + if (off >= total) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -364,14 +429,33 @@ check_result (struct History *h, off); return GNUNET_SYSERR; } + u1 = normalize (h[off].details.credit_account_uri); + if (NULL == u1) + return GNUNET_SYSERR; + u2 = normalize (details->credit_account_uri); + if (NULL == u2) + { + GNUNET_free (u1); + return GNUNET_SYSERR; + } if ( (0 != GNUNET_memcmp (&h[off].details.wtid, &details->wtid)) || (0 != TALER_amount_cmp (&h[off].details.amount, &details->amount)) || - (0 != strcasecmp (h[off].details.credit_account_uri, - details->credit_account_uri)) ) + (0 != strcasecmp (u1, + u2)) ) { GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "expected debit_account_uri: %s with %s for %s\n", + u1, + TALER_amount2s (&h[off].details.amount), + TALER_B2S (&h[off].details.wtid)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "actual debit_account_uri: %s with %s for %s\n", + u2, + TALER_amount2s (&details->amount), + TALER_B2S (&details->wtid)); print_expected (h, total, off); diff --git a/src/testing/testing_api_cmd_nexus_fetch_transactions.c b/src/testing/testing_api_cmd_nexus_fetch_transactions.c deleted file mode 100644 index fc59444de..000000000 --- a/src/testing/testing_api_cmd_nexus_fetch_transactions.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023 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 - <http://www.gnu.org/licenses/> -*/ -/** - * @file testing/testing_api_cmd_nexus_fetch_transactions.c - * @brief run a nft command - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_json_lib.h" -#include <gnunet/gnunet_curl_lib.h> -#include "taler_signatures.h" -#include "taler_testing_lib.h" - - -/** - * State for a "nft" CMD. - */ -struct NftState -{ - /** - * Process for the nfter. - */ - struct GNUNET_OS_Process *nft_proc; - - const char *username; - const char *password; - const char *bank_base_url; - const char *account_id; -}; - - -/** - * Run the command; use the `nft' program. - * - * @param cls closure. - * @param cmd command currently being executed. - * @param is interpreter state. - */ -static void -nft_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct NftState *ws = cls; - char *url; - char *user; - char *pass; - - (void) cmd; - GNUNET_asprintf (&url, - "%s/bank-accounts/%s/fetch-transactions", - ws->bank_base_url, - ws->account_id); - GNUNET_asprintf (&user, - "--user=%s", - ws->username); - GNUNET_asprintf (&pass, - "--password=%s", - ws->password); - ws->nft_proc - = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, - NULL, NULL, NULL, - "wget", - "wget", - "--header=Content-Type:application/json", - "--auth-no-challenge", - "--output-file=/dev/null", - "--output-document=/dev/null", - "--post-data={\"level\":\"all\",\"rangeType\":\"latest\"}", - user, - pass, - url, - NULL); - GNUNET_free (url); - GNUNET_free (user); - GNUNET_free (pass); - if (NULL == ws->nft_proc) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } - TALER_TESTING_wait_for_sigchld (is); -} - - -/** - * Free the state of a "nft" CMD, and possibly - * kills its process if it did not terminate regularly. - * - * @param cls closure. - * @param cmd the command being freed. - */ -static void -nft_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct NftState *ws = cls; - - (void) cmd; - if (NULL != ws->nft_proc) - { - GNUNET_break (0 == - GNUNET_OS_process_kill (ws->nft_proc, - SIGKILL)); - GNUNET_OS_process_wait (ws->nft_proc); - GNUNET_OS_process_destroy (ws->nft_proc); - ws->nft_proc = NULL; - } - GNUNET_free (ws); -} - - -/** - * Offer "nft" CMD internal data to other commands. - * - * @param cls closure. - * @param[out] ret result. - * @param trait name of the trait. - * @param index index number of the object to offer. - * @return #GNUNET_OK on success. - */ -static enum GNUNET_GenericReturnValue -nft_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct NftState *ws = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_process (&ws->nft_proc), - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_nexus_fetch_transactions ( - const char *label, - const char *username, - const char *password, - const char *bank_base_url, - const char *account_id) -{ - struct NftState *ws; - - ws = GNUNET_new (struct NftState); - ws->username = username; - ws->password = password; - ws->bank_base_url = bank_base_url; - ws->account_id = account_id; - - { - struct TALER_TESTING_Command cmd = { - .cls = ws, - .label = label, - .run = &nft_run, - .cleanup = &nft_cleanup, - .traits = &nft_traits - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_nexus_fetch_transactions.c */ |