-fix fakebank/tewgc logic and add test case

This commit is contained in:
Christian Grothoff 2021-08-07 17:50:53 +02:00
parent 26e061c212
commit 8a60e6b62f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
7 changed files with 143 additions and 13 deletions

View File

@ -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

View File

@ -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),

View File

@ -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);

View File

@ -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)

View File

@ -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

74
src/bank-lib/test_bank.sh Executable file
View File

@ -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

View File

@ -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,