summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bank-lib/Makefile.am10
-rw-r--r--src/bank-lib/bank_api_admin.c15
-rw-r--r--src/bank-lib/fakebank.c26
-rw-r--r--src/bank-lib/taler-exchange-wire-gateway-client.c13
-rw-r--r--src/bank-lib/test_bank.conf10
-rwxr-xr-xsrc/bank-lib/test_bank.sh74
-rw-r--r--src/include/taler_bank_service.h8
7 files changed, 143 insertions, 13 deletions
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 78349dc8d..ef15a42d8 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 56828efa9..2a8559b2f 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 7dbbd531c..0e726e77c 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 6d91d51bd..436d416d5 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 000000000..317bc05ad
--- /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 000000000..694fb82f3
--- /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 c5d0e5cac..32a730b8e 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,