summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-10-12 22:10:00 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-10-12 22:10:00 +0200
commit0cd18a0f8f2545eb1212c504683a8a70007caa48 (patch)
treeb0b484085308961f44622c319209792589c21543 /src
parent5b1fc2a9765465cf374b2feb7419a0e5200e4411 (diff)
downloadexchange-0cd18a0f8f2545eb1212c504683a8a70007caa48.tar.gz
exchange-0cd18a0f8f2545eb1212c504683a8a70007caa48.tar.bz2
exchange-0cd18a0f8f2545eb1212c504683a8a70007caa48.zip
clean up bank API, get test_bank_api_with_nexus to finally pass
Diffstat (limited to 'src')
-rw-r--r--src/bank-lib/bank_api_credit.c4
-rw-r--r--src/bank-lib/bank_api_debit.c4
-rw-r--r--src/bank-lib/taler-exchange-wire-gateway-client.c8
-rw-r--r--src/include/taler_bank_service.h19
-rw-r--r--src/include/taler_testing_lib.h18
-rw-r--r--src/testing/Makefile.am1
-rwxr-xr-xsrc/testing/taler-unified-setup.sh1
-rw-r--r--src/testing/test_bank_api.c23
-rw-r--r--src/testing/test_bank_api_nexus.conf14
-rw-r--r--src/testing/testing_api_cmd_bank_history_credit.c1
-rw-r--r--src/testing/testing_api_cmd_bank_history_debit.c90
-rw-r--r--src/testing/testing_api_cmd_nexus_fetch_transactions.c188
12 files changed, 127 insertions, 244 deletions
diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c
index 9ed8a2314..124415b80 100644
--- a/src/bank-lib/bank_api_credit.c
+++ b/src/bank-lib/bank_api_credit.c
@@ -83,12 +83,11 @@ parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh,
.response = history
};
const json_t *history_array;
- const char *credit_account_uri;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_array_const ("incoming_transactions",
&history_array),
GNUNET_JSON_spec_string ("credit_account",
- &credit_account_uri),
+ &chr.details.ok.credit_account_uri),
GNUNET_JSON_spec_end ()
};
@@ -134,7 +133,6 @@ parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- td->credit_account_uri = credit_account_uri;
}
chr.details.ok.details_length = len;
chr.details.ok.details = cd;
diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c
index f3c69ce3a..58dc0a736 100644
--- a/src/bank-lib/bank_api_debit.c
+++ b/src/bank-lib/bank_api_debit.c
@@ -82,13 +82,12 @@ parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh,
.ec = TALER_EC_NONE,
.response = history
};
- const char *debit_account_uri;
const json_t *history_array;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_array_const ("outgoing_transactions",
&history_array),
GNUNET_JSON_spec_string ("debit_account",
- &debit_account_uri),
+ &dhr.details.ok.debit_account_uri),
GNUNET_JSON_spec_end ()
};
@@ -136,7 +135,6 @@ parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- td->debit_account_uri = debit_account_uri;
}
dhr.details.ok.details_length = len;
dhr.details.ok.details = dd;
diff --git a/src/bank-lib/taler-exchange-wire-gateway-client.c b/src/bank-lib/taler-exchange-wire-gateway-client.c
index b20a5fd32..b0d387b71 100644
--- a/src/bank-lib/taler-exchange-wire-gateway-client.c
+++ b/src/bank-lib/taler-exchange-wire-gateway-client.c
@@ -187,7 +187,7 @@ credit_history_cb (void *cls,
/* If credit/debit accounts were specified, use as a filter */
if ( (NULL != credit_account) &&
(0 != strcasecmp (credit_account,
- cd->credit_account_uri) ) )
+ reply->details.ok.credit_account_uri) ) )
continue;
if ( (NULL != debit_account) &&
(0 != strcasecmp (debit_account,
@@ -197,7 +197,7 @@ credit_history_cb (void *cls,
"%llu: %s->%s (%s) over %s at %s\n",
(unsigned long long) cd->serial_id,
cd->debit_account_uri,
- cd->credit_account_uri,
+ reply->details.ok.credit_account_uri,
TALER_B2S (&cd->reserve_pub),
TALER_amount2s (&cd->amount),
GNUNET_TIME_timestamp2s (cd->execution_date));
@@ -291,12 +291,12 @@ debit_history_cb (void *cls,
continue;
if ( (NULL != debit_account) &&
(0 != strcasecmp (debit_account,
- dd->debit_account_uri) ) )
+ reply->details.ok.debit_account_uri) ) )
continue;
fprintf (stdout,
"%llu: %s->%s (%s) over %s at %s\n",
(unsigned long long) dd->serial_id,
- dd->debit_account_uri,
+ reply->details.ok.debit_account_uri,
dd->credit_account_uri,
TALER_B2S (&dd->wtid),
TALER_amount2s (&dd->amount),
diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h
index e0970cb12..e8e32947b 100644
--- a/src/include/taler_bank_service.h
+++ b/src/include/taler_bank_service.h
@@ -367,10 +367,6 @@ struct TALER_BANK_CreditDetails
*/
const char *debit_account_uri;
- /**
- * payto://-URL of the target account that received the funds.
- */
- const char *credit_account_uri;
};
@@ -410,6 +406,11 @@ struct TALER_BANK_CreditHistoryResponse
{
/**
+ * payto://-URL of the target account that received the funds.
+ */
+ const char *credit_account_uri;
+
+ /**
* Array of transactions received.
*/
const struct TALER_BANK_CreditDetails *details;
@@ -518,11 +519,6 @@ struct TALER_BANK_DebitDetails
const char *exchange_base_url;
/**
- * payto://-URI of the source account that send the funds.
- */
- const char *debit_account_uri;
-
- /**
* payto://-URI of the target account that received the funds.
*/
const char *credit_account_uri;
@@ -566,6 +562,11 @@ struct TALER_BANK_DebitHistoryResponse
{
/**
+ * payto://-URI of the source account that send the funds.
+ */
+ const char *debit_account_uri;
+
+ /**
* Array of transactions initiated.
*/
const struct TALER_BANK_DebitDetails *details;
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 4fedb93c7..72d70d00a 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -968,24 +968,6 @@ TALER_TESTING_cmd_exec_wget (const char *label,
/**
- * Request fetch-transactions via "wget".
- *
- * @param label command label.
- * @param username username to use
- * @param password password to use
- * @param bank_base_url base URL of the nexus
- * @param account_id account to fetch transactions for
- * @return the command.
- */
-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);
-
-
-/**
* Make a "expire" CMD.
*
* @param label command label.
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 */