summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/Makefile.am23
-rw-r--r--src/exchange/taler-exchange-aggregator.c13
-rw-r--r--src/exchange/test-exchange-home/config/exchange-common.conf33
-rw-r--r--src/exchange/test-taler-exchange-aggregator-postgres.conf8
-rw-r--r--src/exchange/test_taler_exchange_aggregator.c142
5 files changed, 216 insertions, 3 deletions
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
index e29a51bbb..18a7c1b54 100644
--- a/src/exchange/Makefile.am
+++ b/src/exchange/Makefile.am
@@ -59,4 +59,25 @@ check_SCRIPTS += \
test_taler_exchange_httpd_afl.sh
endif
-TESTS = $(check_SCRIPTS)
+test_taler_exchange_aggregator_postgres_SOURCES = \
+ test_taler_exchange_aggregator.c
+test_taler_exchange_aggregator_postgres_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lmicrohttpd \
+ -lgnunetutil \
+ -lgnunetjson \
+ -ljansson \
+ -lpthread
+
+check_PROGRAMS = \
+ test_taler_exchange_aggregator-postgres
+
+TESTS = \
+ $(check_SCRIPTS) \
+ $(check_PROGRAMS)
+
+
+EXTRA_DIST = \
+ test-taler-exchange-aggregator-postgres.conf
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index e399a422e..4699ff4bc 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -68,6 +68,11 @@ static struct TALER_WIRE_Plugin *wire_plugin;
static struct GNUNET_SCHEDULER_Task *task;
/**
+ * #GNUNET_YES if we are in test mode and are using temporary tables.
+ */
+static int test_mode;
+
+/**
* Limit on the number of transactions we aggregate at once. Note
* that the limit must be big enough to ensure that when transactions
* of the smallest possible unit are aggregated, they do surpass the
@@ -448,7 +453,7 @@ run_aggregation (void *cls,
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
if (NULL == (session = db_plugin->get_session (db_plugin->cls,
- GNUNET_NO)))
+ test_mode)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n");
@@ -813,7 +818,7 @@ run_transfers (void *cls,
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
if (NULL == (session = db_plugin->get_session (db_plugin->cls,
- GNUNET_NO)))
+ test_mode)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n");
@@ -879,6 +884,10 @@ main (int argc,
"wireformat to use, overrides WIREFORMAT option in [exchange] section", 1,
&GNUNET_GETOPT_set_filename, &exchange_wireformat},
TALER_GETOPT_OPTION_HELP ("background process that aggregates and executes wire transfers to merchants"),
+ {'t', "test", NULL,
+ "run in test mode with temporary tables", 0,
+ &GNUNET_GETOPT_set_one, &test_mode},
+ TALER_GETOPT_OPTION_HELP ("background process that aggregates and executes wire transfers to merchants"),
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/exchange/test-exchange-home/config/exchange-common.conf b/src/exchange/test-exchange-home/config/exchange-common.conf
new file mode 100644
index 000000000..e4ff2a4d6
--- /dev/null
+++ b/src/exchange/test-exchange-home/config/exchange-common.conf
@@ -0,0 +1,33 @@
+[exchange]
+# Currency supported by the exchange (can only be one)
+CURRENCY = EUR
+
+# Wire format supported by the exchange
+# We use 'test' for testing of the actual
+# coin operations.
+WIREFORMAT = test
+
+# HTTP port the exchange listens to
+PORT = 8081
+
+# Master public key used to sign the exchange's various keys
+MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+
+# How to access our database
+DB = postgres
+
+# Is this is a testcase, use transient DB actions?
+TESTRUN = YES
+
+[exchangedb-postgres]
+DB_CONN_STR = "postgres:///talercheck"
+
+[wire-test]
+# What is the main website of the bank?
+BANK_URI = "http://localhost:8082/"
+# Into which account at the 'bank' should incoming
+# wire transfers be made?
+BANK_ACCOUNT_NO_INCOMING = 2
+# From which account at the 'bank' should outgoing
+# wire transfers be made?
+BANK_ACCOUNT_NO_OUTGOING = 3
diff --git a/src/exchange/test-taler-exchange-aggregator-postgres.conf b/src/exchange/test-taler-exchange-aggregator-postgres.conf
new file mode 100644
index 000000000..0822bab44
--- /dev/null
+++ b/src/exchange/test-taler-exchange-aggregator-postgres.conf
@@ -0,0 +1,8 @@
+[exchange]
+#The DB plugin to use
+DB = postgres
+
+[exchangedb-postgres]
+
+#The connection string the plugin has to use for connecting to the database
+DB_CONN_STR = postgres:///talercheck
diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c
new file mode 100644
index 000000000..a36fcdec4
--- /dev/null
+++ b/src/exchange/test_taler_exchange_aggregator.c
@@ -0,0 +1,142 @@
+/*
+ This file is part of TALER
+ (C) 2016 GNUnet e.V.
+
+ 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, If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file exchange/test_taler_exchange_aggregator.c
+ * @brief Tests for taler-exchange-aggregator logic
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Return value from main().
+ */
+static int result;
+
+/**
+ * Name of the configuration file to use.
+ */
+static char *config_filename;
+
+
+/**
+ * Runs the aggregator process.
+ */
+static void
+run_aggregator ()
+{
+ struct GNUNET_OS_Process *proc;
+
+ proc = GNUNET_OS_start_process (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-aggregator",
+ "taler-exchange-aggregator",
+ /* "-c", config_filename, */
+ "-d", "test-exchange-home",
+ "-t", /* enable temporary tables */
+ NULL);
+ GNUNET_OS_process_wait (proc);
+ GNUNET_OS_process_destroy (proc);
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct TALER_EXCHANGEDB_Plugin *plugin;
+ struct TALER_EXCHANGEDB_Session *session;
+
+ plugin = TALER_EXCHANGEDB_plugin_load (cfg);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ GNUNET_YES))
+ {
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ result = 77;
+ return;
+ }
+ session = plugin->get_session (plugin->cls,
+ GNUNET_YES);
+ /* FIXME: prime DB */
+ /* FIXME: launch bank on 8082! */
+ run_aggregator ();
+ /* FIXME: check DB and bank */
+
+ plugin->drop_temporary (plugin->cls,
+ session);
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ result = 77; /* skip: not finished */
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ char *argv2[] = {
+ "test-taler-exchange-aggregator-<plugin_name>", /* will be replaced later */
+ "-c", "test-taler-exchange-aggregator-<plugin_name>.conf", /* will be replaced later */
+ NULL,
+ };
+ const char *plugin_name;
+ char *testname;
+
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-taler-exchange-aggregator-%s", plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf", testname);
+ argv2[0] = argv[0];
+ argv2[2] = config_filename;
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run ((sizeof (argv2)/sizeof (char *)) - 1, argv2,
+ testname,
+ "Test cases for exchange aggregator.",
+ options, &run, NULL))
+ {
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 3;
+ }
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
+
+/* end of test_taler_exchange_aggregator.c */