diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-03 20:31:29 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-03 20:31:29 +0100 |
commit | f406f96129766c144c1531dc853969664f410d8c (patch) | |
tree | 6fdbae6ed117d3057ae9101ab4f799f5e3354d59 /src/exchangedb | |
parent | 364abbaea1383bd7d8311269d596bdc3c1d4b591 (diff) | |
download | exchange-f406f96129766c144c1531dc853969664f410d8c.tar.xz |
implement #4929: add wire transfer fee to /wire (but not yet charged by aggregator)
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/Makefile.am | 14 | ||||
-rw-r--r-- | src/exchangedb/exchangedb_denomkeys.c | 9 | ||||
-rw-r--r-- | src/exchangedb/exchangedb_fees.c | 2 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb_fees.c | 104 |
4 files changed, 119 insertions, 10 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index f6754e803..2122c174c 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -44,6 +44,7 @@ lib_LTLIBRARIES = \ libtalerexchangedb_la_SOURCES = \ exchangedb_auditorkeys.c \ exchangedb_denomkeys.c \ + exchangedb_fees.c \ exchangedb_signkeys.c \ exchangedb_plugin.c @@ -60,6 +61,7 @@ libtalerexchangedb_la_LDFLAGS = \ check_PROGRAMS = \ test-exchangedb-auditors \ test-exchangedb-denomkeys \ + test-exchangedb-fees \ test-exchangedb-signkeys \ test-exchangedb-postgres \ test-perf-taler-exchangedb \ @@ -68,10 +70,11 @@ check_PROGRAMS = \ AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; TESTS = \ test-exchangedb-auditors \ + test-exchangedb-denomkeys \ + test-exchangedb-fees \ test-exchangedb-postgres \ test-exchangedb-signkeys \ - test-perf-taler-exchangedb \ - test-exchangedb-denomkeys + test-perf-taler-exchangedb test_exchangedb_auditors_SOURCES = \ test_exchangedb_auditors.c @@ -87,6 +90,13 @@ test_exchangedb_denomkeys_LDADD = \ $(top_srcdir)/src/util/libtalerutil.la \ -lgnunetutil +test_exchangedb_fees_SOURCES = \ + test_exchangedb_fees.c +test_exchangedb_fees_LDADD = \ + libtalerexchangedb.la \ + $(top_srcdir)/src/util/libtalerutil.la \ + -lgnunetutil + test_exchangedb_signkeys_SOURCES = \ test_exchangedb_signkeys.c test_exchangedb_signkeys_LDADD = \ diff --git a/src/exchangedb/exchangedb_denomkeys.c b/src/exchangedb/exchangedb_denomkeys.c index 7e7a73a32..de8dfa6f2 100644 --- a/src/exchangedb/exchangedb_denomkeys.c +++ b/src/exchangedb/exchangedb_denomkeys.c @@ -42,10 +42,11 @@ TALER_EXCHANGEDB_denomination_key_read (const char *filename, void *data; struct GNUNET_CRYPTO_RsaPrivateKey *priv; - if (GNUNET_OK != GNUNET_DISK_file_size (filename, - &size, - GNUNET_YES, - GNUNET_YES)) + if (GNUNET_OK != + GNUNET_DISK_file_size (filename, + &size, + GNUNET_YES, + GNUNET_YES)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Skipping inaccessable denomination key file `%s'\n", diff --git a/src/exchangedb/exchangedb_fees.c b/src/exchangedb/exchangedb_fees.c index 938b61c19..5adee5d41 100644 --- a/src/exchangedb/exchangedb_fees.c +++ b/src/exchangedb/exchangedb_fees.c @@ -92,7 +92,7 @@ TALER_EXCHANGEDB_fees_read (const struct GNUNET_CONFIGURATION_Handle *cfg, &wirefee_base_dir)) return NULL; GNUNET_asprintf (&fn, - "%s" DIR_SEPARATOR_STR "%s.fee", + "%s/%s.fee", wirefee_base_dir, wireplugin); GNUNET_free (wirefee_base_dir); diff --git a/src/exchangedb/test_exchangedb_fees.c b/src/exchangedb/test_exchangedb_fees.c index e23879ead..b82abc5fd 100644 --- a/src/exchangedb/test_exchangedb_fees.c +++ b/src/exchangedb/test_exchangedb_fees.c @@ -24,23 +24,121 @@ #include "taler_exchangedb_lib.h" +/** + * Sign @a af with @a priv + * + * @param[in|out] af fee structure to sign + * @param priv private key to use for signing + */ +static void +sign_af (struct TALER_EXCHANGEDB_AggregateFees *af, + const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) +{ + struct TALER_MasterWireFeePS wf; + + TALER_EXCHANGEDB_fees_2_wf (af, + &wf); + GNUNET_assert (GNUNET_OK == + GNUNET_CRYPTO_eddsa_sign (priv, + &wf.purpose, + &af->master_sig.eddsa_signature)); +} + + int main (int argc, const char *const argv[]) { struct GNUNET_CONFIGURATION_Handle *cfg; + struct TALER_EXCHANGEDB_AggregateFees *af; + struct TALER_EXCHANGEDB_AggregateFees *n; + struct TALER_MasterPublicKeyP master_pub; + struct GNUNET_CRYPTO_EddsaPrivateKey *priv; + char *tmpdir; + char *tmpfile = NULL; int ret; + unsigned int year; - ret = 1; GNUNET_log_setup ("test-exchangedb-fees", "WARNING", NULL); + tmpdir = GNUNET_DISK_mkdtemp ("test_exchangedb_fees"); + if (NULL == tmpdir) + return 77; /* skip test */ + priv = GNUNET_CRYPTO_eddsa_key_create (); + GNUNET_CRYPTO_eddsa_key_get_public (priv, + &master_pub.eddsa_pub); cfg = GNUNET_CONFIGURATION_create (); - GNUNET_CONFIGURATION_set_value_string (cfg, "exchangedb", - "AUDITOR_BASE_DIR", + "WIREFEE_BASE_DIR", tmpdir); + GNUNET_asprintf (&tmpfile, + "%s/%s.fee", + tmpdir, + "test"); ret = 0; + af = GNUNET_new (struct TALER_EXCHANGEDB_AggregateFees); + year = GNUNET_TIME_get_current_year (); + af->start_date = GNUNET_TIME_year_to_time (year); + af->end_date = GNUNET_TIME_year_to_time (year + 1); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:1.0", + &af->wire_fee)); + sign_af (af, + priv); + n = GNUNET_new (struct TALER_EXCHANGEDB_AggregateFees); + n->start_date = GNUNET_TIME_year_to_time (year + 1); + n->end_date = GNUNET_TIME_year_to_time (year + 2); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:0.1", + &n->wire_fee)); + sign_af (n, + priv); + af->next = n; + + if (GNUNET_OK != + TALER_EXCHANGEDB_fees_write (tmpfile, + af)) + { + GNUNET_break (0); + ret = 1; + } + TALER_EXCHANGEDB_fees_free (af); + GNUNET_free (tmpfile); + af = TALER_EXCHANGEDB_fees_read (cfg, + "test"); + if (NULL == af) + { + GNUNET_break (0); + ret = 1; + } + else + { + for (struct TALER_EXCHANGEDB_AggregateFees *p = af; + NULL != p; + p = p->next) + { + struct TALER_MasterWireFeePS wf; + + TALER_EXCHANGEDB_fees_2_wf (p, + &wf); + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_WIRE_FEES, + &wf.purpose, + &p->master_sig.eddsa_signature, + &master_pub.eddsa_pub)) + { + GNUNET_break (0); + ret = 1; + } + } + TALER_EXCHANGEDB_fees_free (af); + } + + (void) GNUNET_DISK_directory_remove (tmpdir); + GNUNET_free (tmpdir); + GNUNET_free (priv); + GNUNET_CONFIGURATION_destroy (cfg); return ret; } |