summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-05-03 13:55:40 +0200
committerChristian Grothoff <christian@grothoff.org>2016-05-03 13:55:40 +0200
commitdc2d0a186c5cf90ec8b0822ad2de114db3b1dc67 (patch)
tree460e81292bcdfcc31fca13d43b55fe007b393f84
parent79c316f0d55ef404fbb2c2eea6182eb31e865c79 (diff)
downloadexchange-dc2d0a186c5cf90ec8b0822ad2de114db3b1dc67.tar.gz
exchange-dc2d0a186c5cf90ec8b0822ad2de114db3b1dc67.tar.bz2
exchange-dc2d0a186c5cf90ec8b0822ad2de114db3b1dc67.zip
towards fixing #4399
-rw-r--r--src/exchange-lib/Makefile.am3
-rw-r--r--src/exchange-lib/test_exchange_api.c139
2 files changed, 124 insertions, 18 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index ea53623fb..5fd506562 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -1,5 +1,5 @@
# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/bank-lib
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
@@ -55,6 +55,7 @@ test_exchange_api_SOURCES = \
test_exchange_api_LDADD = \
libtalerexchange.la \
$(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/bank-lib/libfakebank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetcurl \
diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c
index addb4d741..b20f77067 100644
--- a/src/exchange-lib/test_exchange_api.c
+++ b/src/exchange-lib/test_exchange_api.c
@@ -26,6 +26,8 @@
#include "taler_json_lib.h"
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
+#include "fakebank.h"
+
/**
* Is the configuration file is set to include wire format 'test'?
@@ -58,6 +60,11 @@ static struct GNUNET_CURL_RescheduleContext *rc;
static struct GNUNET_SCHEDULER_Task *timeout_task;
/**
+ * Handle to our fakebank.
+ */
+static struct FAKEBANK_Handle *fakebank;
+
+/**
* Result of the testcases, #GNUNET_OK on success
*/
static int result;
@@ -127,7 +134,17 @@ enum OpCode
/**
* Run the aggregator to execute deposits.
*/
- OC_RUN_AGGREGATOR
+ OC_RUN_AGGREGATOR,
+
+ /**
+ * Check that the fakebank has received a certain transaction.
+ */
+ OC_CHECK_BANK_DEPOSIT,
+
+ /**
+ * Check that the fakebank has not received any other transactions.
+ */
+ OC_CHECK_BANK_DEPOSITS_EMPTY
};
@@ -549,6 +566,30 @@ struct Command
} run_aggregator;
+ struct {
+
+ /**
+ * Which amount do we expect to see transferred?
+ */
+ const char *amount;
+
+ /**
+ * Which account do we expect to be debited?
+ */
+ uint64_t account_debit;
+
+ /**
+ * Which account do we expect to be credited?
+ */
+ uint64_t account_credit;
+
+ /**
+ * Set (!) to the wire transfer identifier observed.
+ */
+ struct TALER_WireTransferIdentifierRawP wtid;
+
+ } check_bank_deposit;
+
} details;
};
@@ -1685,20 +1726,20 @@ interpreter_run (void *cls)
}
cmd->details.deposit.dh
= TALER_EXCHANGE_deposit (exchange,
- &amount,
- wire_deadline,
- wire,
- &h_contract,
- &coin_pub,
- coin_pk_sig,
- &coin_pk->key,
- timestamp,
- cmd->details.deposit.transaction_id,
- &merchant_pub,
- refund_deadline,
- &coin_sig,
- &deposit_cb,
- is);
+ &amount,
+ wire_deadline,
+ wire,
+ &h_contract,
+ &coin_pub,
+ coin_pk_sig,
+ &coin_pk->key,
+ timestamp,
+ cmd->details.deposit.transaction_id,
+ &merchant_pub,
+ refund_deadline,
+ &coin_sig,
+ &deposit_cb,
+ is);
if (NULL == cmd->details.deposit.dh)
{
GNUNET_break (0);
@@ -1873,7 +1914,19 @@ interpreter_run (void *cls)
ref = find_command (is,
cmd->details.wire_deposits.wtid_ref);
GNUNET_assert (NULL != ref);
- cmd->details.wire_deposits.wtid = ref->details.deposit_wtid.wtid;
+ switch (ref->oc)
+ {
+ case OC_DEPOSIT_WTID:
+ cmd->details.wire_deposits.wtid = ref->details.deposit_wtid.wtid;
+ break;
+ case OC_CHECK_BANK_DEPOSIT:
+ cmd->details.wire_deposits.wtid = ref->details.check_bank_deposit.wtid;
+ break;
+ default:
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
}
cmd->details.wire_deposits.wdh
= TALER_EXCHANGE_wire_deposits (exchange,
@@ -1967,6 +2020,45 @@ interpreter_run (void *cls)
next_command (is);
return;
}
+ case OC_CHECK_BANK_DEPOSIT:
+ {
+ if (GNUNET_OK !=
+ TALER_string_to_amount (cmd->details.check_bank_deposit.amount,
+ &amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %u\n",
+ cmd->details.reserve_withdraw.amount,
+ is->ip);
+ fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ FAKEBANK_check (fakebank,
+ &amount,
+ cmd->details.check_bank_deposit.account_debit,
+ cmd->details.check_bank_deposit.account_credit,
+ &cmd->details.check_bank_deposit.wtid))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ next_command (is);
+ return;
+ }
+ case OC_CHECK_BANK_DEPOSITS_EMPTY:
+ {
+ if (GNUNET_OK !=
+ FAKEBANK_check_empty (fakebank))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ next_command (is);
+ return;
+ }
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",
@@ -2159,6 +2251,10 @@ do_shutdown (void *cls)
cmd->details.run_aggregator.aggregator_proc = NULL;
}
break;
+ case OC_CHECK_BANK_DEPOSIT:
+ break;
+ case OC_CHECK_BANK_DEPOSITS_EMPTY:
+ break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",
@@ -2174,6 +2270,11 @@ do_shutdown (void *cls)
is->task = NULL;
}
GNUNET_free (is);
+ if (NULL != fakebank)
+ {
+ FAKEBANK_stop (fakebank);
+ fakebank = NULL;
+ }
if (NULL != exchange)
{
TALER_EXCHANGE_disconnect (exchange);
@@ -2465,6 +2566,9 @@ run (void *cls)
{ .oc = OC_RUN_AGGREGATOR,
.label = "run-aggregator" },
+ { .oc = OC_CHECK_BANK_DEPOSITS_EMPTY,
+ .label = "check_bank_empty" },
+
/* TODO: trigger aggregation logic and then check the
cases where tracking succeeds! */
@@ -2481,8 +2585,9 @@ run (void *cls)
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
&rc);
- rc = GNUNET_CURL_gnunet_rc_create (ctx);
GNUNET_assert (NULL != ctx);
+ rc = GNUNET_CURL_gnunet_rc_create (ctx);
+ fakebank = FAKEBANK_start (8082);
exchange = TALER_EXCHANGE_connect (ctx,
"http://localhost:8081",
&cert_cb, is,