[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-exchange] branch master updated: -fix fakebank/tewgc logic and ad
From: |
gnunet |
Subject: |
[taler-exchange] branch master updated: -fix fakebank/tewgc logic and add test case |
Date: |
Sat, 07 Aug 2021 17:50:55 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository exchange.
The following commit(s) were added to refs/heads/master by this push:
new 8a60e6b6 -fix fakebank/tewgc logic and add test case
8a60e6b6 is described below
commit 8a60e6b62f173c1148686572e72ad552c3808325
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Aug 7 17:50:53 2021 +0200
-fix fakebank/tewgc logic and add test case
---
src/bank-lib/Makefile.am | 10 +++
src/bank-lib/bank_api_admin.c | 15 +++++
src/bank-lib/fakebank.c | 26 +++++++-
src/bank-lib/taler-exchange-wire-gateway-client.c | 13 ++--
src/bank-lib/test_bank.conf | 10 +++
src/bank-lib/test_bank.sh | 74 +++++++++++++++++++++++
src/include/taler_bank_service.h | 8 +--
7 files changed, 143 insertions(+), 13 deletions(-)
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 78349dc8..ef15a42d 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -69,3 +69,13 @@ libtalerfakebank_la_LIBADD = \
-lmicrohttpd \
-lpthread \
$(XLIB)
+
+check_SCRIPTS = \
+ test_bank.sh
+
+TESTS = \
+ $(check_SCRIPTS)
+
+EXTRA_DIST = \
+ $(check_SCRIPTS) \
+ test_bank.conf
diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c
index 56828efa..2a8559b2 100644
--- a/src/bank-lib/bank_api_admin.c
+++ b/src/bank-lib/bank_api_admin.c
@@ -184,6 +184,21 @@ TALER_BANK_admin_add_incoming (
json_t *admin_obj;
CURL *eh;
+ if (NULL == debit_account)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (NULL == reserve_pub)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (NULL == amount)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
admin_obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("reserve_pub",
reserve_pub),
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 7dbbd531..0e726e77 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -1487,7 +1487,18 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
json_t *trans;
char *credit_payto;
- GNUNET_assert (T_DEBIT == pos->type);
+ if (T_DEBIT != pos->type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected CREDIT transaction #%llu for account `%s'\n",
+ (unsigned long long) pos->row_id,
+ account);
+ if (0 > ha.delta)
+ pos = pos->prev_in;
+ if (0 < ha.delta)
+ pos = pos->next_in;
+ continue;
+ }
GNUNET_asprintf (&credit_payto,
"payto://x-taler-bank/localhost/%s",
pos->credit_account->account_name);
@@ -1635,7 +1646,18 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h,
json_t *trans;
char *debit_payto;
- GNUNET_assert (T_CREDIT == pos->type);
+ if (T_CREDIT != pos->type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected DEBIT transaction #%llu for account `%s'\n",
+ (unsigned long long) pos->row_id,
+ account);
+ if (0 > ha.delta)
+ pos = pos->prev_in;
+ if (0 < ha.delta)
+ pos = pos->next_in;
+ continue;
+ }
GNUNET_asprintf (&debit_payto,
"payto://x-taler-bank/localhost/%s",
pos->debit_account->account_name);
diff --git a/src/bank-lib/taler-exchange-wire-gateway-client.c
b/src/bank-lib/taler-exchange-wire-gateway-client.c
index 6d91d51b..436d416d 100644
--- a/src/bank-lib/taler-exchange-wire-gateway-client.c
+++ b/src/bank-lib/taler-exchange-wire-gateway-client.c
@@ -64,7 +64,7 @@ static char *account_section;
/**
* Starting row.
*/
-static unsigned long long start_row;
+static unsigned long long start_row = UINT64_MAX;
/**
* Authentication data.
@@ -165,7 +165,7 @@ do_shutdown (void *cls)
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to
* abort iteration
*/
-static int
+static enum GNUNET_GenericReturnValue
credit_history_cb (void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
@@ -279,7 +279,7 @@ execute_credit_history (void)
* @param json detailed response from the HTTPD, or NULL if reply was not in
JSON
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
-static int
+static enum GNUNET_GenericReturnValue
debit_history_cb (void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
@@ -435,7 +435,7 @@ execute_wire_transfer (void)
return;
}
- // See if subject was given as a payto-parameter.
+ /* See if subject was given as a payto-parameter. */
if (NULL == subject)
subject = TALER_payto_get_subject (credit_account);
if (NULL != subject)
@@ -448,10 +448,9 @@ execute_wire_transfer (void)
{
fprintf (stderr,
"Error: wire transfer subject must be a WTID\n");
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_shutdown ();
- return;
}
else
{
@@ -563,7 +562,7 @@ execute_admin_transfer (void)
&auth,
&reserve_pub,
&amount,
- credit_account,
+ debit_account,
&res_cb,
NULL);
if (NULL == op)
diff --git a/src/bank-lib/test_bank.conf b/src/bank-lib/test_bank.conf
new file mode 100644
index 00000000..317bc05a
--- /dev/null
+++ b/src/bank-lib/test_bank.conf
@@ -0,0 +1,10 @@
+[taler]
+CURRENCY = TESTKUDOS
+
+[bank]
+serve = http
+HTTP_PORT = 8899
+MAX_DEBT_BANK = TESTKUDOS:0.0
+MAX_DEBT = TESTKUDOS:50.0
+
+RAM_LIMIT = 32
diff --git a/src/bank-lib/test_bank.sh b/src/bank-lib/test_bank.sh
new file mode 100755
index 00000000..694fb82f
--- /dev/null
+++ b/src/bank-lib/test_bank.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+set -eu
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+ for n in `jobs -p`
+ do
+ kill $n 2> /dev/null || true
+ done
+ wait
+}
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+
+echo -n "Launching bank..."
+
+taler-fakebank-run -c test_bank.conf -L DEBUG &> bank.log &
+
+# Wait for bank to be available (usually the slowest)
+for n in `seq 1 50`
+do
+ echo -n "."
+ sleep 0.2
+ OK=0
+ # bank
+ wget --tries=1 --timeout=1 http://localhost:8899/ -o /dev/null -O
/dev/null >/dev/null || continue
+ OK=1
+ break
+done
+
+if [ 1 != $OK ]
+then
+ exit_skip "Failed to launch services (bank)"
+fi
+
+echo "OK"
+
+echo -n "Making wire transfer to exchange ..."
+
+taler-exchange-wire-gateway-client \
+ -b http://localhost:8899/exchange/ \
+ -S 0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00 \
+ -D payto://x-taler-bank/localhost:8899/user \
+ -a TESTKUDOS:4 > /dev/null
+echo " OK"
+
+echo -n "Requesting exchange incoming transaction list ..."
+
+./taler-exchange-wire-gateway-client -b http://localhost:8899/exchange/ -i |
grep TESTKUDOS:4 > /dev/null
+
+echo " OK"
+
+echo -n "Making wire transfer from exchange..."
+
+./taler-exchange-wire-gateway-client \
+ -b http://localhost:8899/exchange/ \
+ -S 0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00 \
+ -C payto://x-taler-bank/localhost:8899/merchant \
+ -a TESTKUDOS:2 > /dev/null
+echo " OK"
+
+
+echo -n "Requesting exchange's outgoing transaction list..."
+
+./taler-exchange-wire-gateway-client -b http://localhost:8899/exchange/ -o |
grep TESTKUDOS:2 > /dev/null
+
+echo " OK"
+
+echo "All tests passed"
+
+exit 0
diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h
index c5d0e5ca..32a730b8 100644
--- a/src/include/taler_bank_service.h
+++ b/src/include/taler_bank_service.h
@@ -304,8 +304,8 @@ struct TALER_BANK_CreditDetails
* @param json detailed response from the HTTPD, or NULL if reply was not in
JSON
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
-typedef int
-(*TALER_BANK_CreditHistoryCallback) (
+typedef enum GNUNET_GenericReturnValue
+(*TALER_BANK_CreditHistoryCallback)(
void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
@@ -414,8 +414,8 @@ struct TALER_BANK_DebitDetails
* @param json detailed response from the HTTPD, or NULL if reply was not in
JSON
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
-typedef int
-(*TALER_BANK_DebitHistoryCallback) (
+typedef enum GNUNET_GenericReturnValue
+(*TALER_BANK_DebitHistoryCallback)(
void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-exchange] branch master updated: -fix fakebank/tewgc logic and add test case,
gnunet <=