commit e1f4a4530a68603b88db028a23606c64cfca0f6c
parent a88bdd41cb92b8bccf6cfacb9c4c06a7572a9958
Author: Özgür Kesim <oec@codeblau.de>
Date: Sat, 21 Nov 2026 11:36:10 +0100
testing: backdated merges and the MERGE limit (#12276)
test_exchange_api_merge_backdated, with a MERGE rule (EUR:1.5 a day):
two push purses of EUR:0.99 merged into one reserve, the first merge
dated two days back by the client; expected 451 for the second merge,
as without the backdating (control), gets 200. New command
TALER_TESTING_cmd_purse_merge_backdated.
Fails on master at merge-d.
Issue: https://bugs.gnunet.org/view?id=12276
Diffstat:
5 files changed, 273 insertions(+), 1 deletion(-)
diff --git a/src/include/taler/taler_testing_lib.h b/src/include/taler/taler_testing_lib.h
@@ -2575,6 +2575,26 @@ TALER_TESTING_cmd_purse_merge (
/**
+ * Like #TALER_TESTING_cmd_purse_merge(), but the client dates the merge
+ * (the signed merge_timestamp) @a backdate into the past.
+ *
+ * @param label command label
+ * @param expected_http_status what status do we expect to get returned
+ * @param merge_ref reference to a command providing the merge key
+ * @param reserve_ref reference to the reserve to merge into
+ * @param backdate how far back the merge is dated
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_purse_merge_backdated (
+ const char *label,
+ unsigned int expected_http_status,
+ const char *merge_ref,
+ const char *reserve_ref,
+ struct GNUNET_TIME_Relative backdate);
+
+
+/**
* Retrieve purse state.
*
* @param label command label
diff --git a/src/testing/meson.build b/src/testing/meson.build
@@ -962,7 +962,38 @@ test(
is_parallel: false,
)
+test_exchange_api_merge_backdated = executable(
+ 'test_exchange_api_merge_backdated',
+ ['test_exchange_api_merge_backdated.c'],
+ dependencies: [
+ libtalertesting_dep,
+ libtalerauditor_dep,
+ libtalerfakebank_dep,
+ libtalerbank_dep,
+ libtalerjson_dep,
+ libtalerexchange_dep,
+ libtalerexchangedb_dep,
+ libtalerutil_dep,
+ twister_dep,
+ gnunetutil_dep,
+ gnunetcurl_dep,
+ json_dep,
+ gcrypt_dep,
+ ],
+ include_directories: [incdir, configuration_inc],
+ build_by_default: false,
+ install: false,
+)
+test(
+ 'test_exchange_api_merge_backdated',
+ test_exchange_api_merge_backdated,
+ workdir: meson.current_build_dir(),
+ suite: ['testing', 'integrationtests'],
+ is_parallel: false,
+)
+
EXTRA_DIST = [
+ 'test_exchange_api_merge_backdated.conf',
'test_exchange_api_cs_nonce-cs.conf',
'valgrind.h',
'setup.sh',
diff --git a/src/testing/test_exchange_api_merge_backdated.c b/src/testing/test_exchange_api_merge_backdated.c
@@ -0,0 +1,179 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2026 Taler Systems SA
+
+ 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, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file testing/test_exchange_api_merge_backdated.c
+ * @brief merges dated back by the client must still count towards the
+ * MERGE limit of the receiving account (kyc.md (K2), KY1, KY2)
+ */
+#include "platform.h"
+#include "taler/taler_util.h"
+#include "taler/taler_json_lib.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler/taler_bank_service.h"
+#include "taler/taler_testing_lib.h"
+
+#define CONFIG_FILE "test_exchange_api_merge_backdated.conf"
+
+static struct TALER_TESTING_Credentials cred;
+
+
+static void
+run (void *cls,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct TALER_TESTING_Command commands[] = {
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ CONFIG_FILE,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve",
+ "EUR:5.01",
+ &cred.ba,
+ cred.user42_payto),
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve-payee-1",
+ "EUR:1.01",
+ &cred.ba,
+ cred.user43_payto),
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve-payee-2",
+ "EUR:1.01",
+ &cred.ba,
+ cred.user43_payto),
+ TALER_TESTING_cmd_exec_wirewatch2 ("wirewatch",
+ CONFIG_FILE,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin",
+ "create-reserve",
+ "EUR:5",
+ 0,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-a",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"purse a\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_HOURS,
+ "withdraw-coin",
+ "EUR:1.00",
+ NULL),
+ TALER_TESTING_cmd_contract_get ("get-contract-a",
+ MHD_HTTP_OK,
+ true, /* for merge */
+ "purse-a"),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-b",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"purse b\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_HOURS,
+ "withdraw-coin",
+ "EUR:1.00",
+ NULL),
+ TALER_TESTING_cmd_contract_get ("get-contract-b",
+ MHD_HTTP_OK,
+ true, /* for merge */
+ "purse-b"),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-c",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"purse c\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_HOURS,
+ "withdraw-coin",
+ "EUR:1.00",
+ NULL),
+ TALER_TESTING_cmd_contract_get ("get-contract-c",
+ MHD_HTTP_OK,
+ true, /* for merge */
+ "purse-c"),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-d",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"purse d\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_HOURS,
+ "withdraw-coin",
+ "EUR:1.00",
+ NULL),
+ TALER_TESTING_cmd_contract_get ("get-contract-d",
+ MHD_HTTP_OK,
+ true, /* for merge */
+ "purse-d"),
+ /* The receiving accounts may get EUR:1.5 a day by merges without KYC.
+ Control: two merges of EUR:0.99 into payee 1; the second one
+ exceeds the limit. */
+ TALER_TESTING_cmd_purse_merge ("merge-a",
+ MHD_HTTP_OK,
+ "get-contract-a",
+ "create-reserve-payee-1"),
+ TALER_TESTING_cmd_purse_merge ("merge-b",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ "get-contract-b",
+ "create-reserve-payee-1"),
+ /* The same into payee 2, but the client dates the first merge two days
+ back (the merge timestamp is the client's, signed, and not checked).
+ By kyc.md (K2) the operations of the last day count, and both merges
+ happen now: the second must exceed the limit as well. The current
+ exchange counts merges by their merge timestamp and lets it pass. */
+ TALER_TESTING_cmd_purse_merge_backdated ("merge-c",
+ MHD_HTTP_OK,
+ "get-contract-c",
+ "create-reserve-payee-2",
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_DAYS,
+ 2)),
+ TALER_TESTING_cmd_purse_merge ("merge-d",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ "get-contract-d",
+ "create-reserve-payee-2"),
+ TALER_TESTING_cmd_end ()
+ };
+
+ (void) cls;
+ TALER_TESTING_run (is,
+ commands);
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ (void) argc;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ CONFIG_FILE,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
+}
+
+
+/* end of test_exchange_api_merge_backdated.c */
diff --git a/src/testing/test_exchange_api_merge_backdated.conf b/src/testing/test_exchange_api_merge_backdated.conf
@@ -0,0 +1,14 @@
+# This file is in the public domain.
+#
+@INLINE@ coins-rsa.conf
+@INLINE@ test_exchange_api.conf
+
+# Merges into a reserve account: EUR:1.5 a day without KYC.
+[kyc-rule-merge]
+ENABLED = YES
+EXPOSED = YES
+IS_AND_COMBINATOR = YES
+OPERATION_TYPE = MERGE
+THRESHOLD = EUR:1.5
+TIMEFRAME = 1d
+NEXT_MEASURES = run-oauth
diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c
@@ -42,6 +42,11 @@ struct PurseMergeState
struct GNUNET_TIME_Timestamp merge_timestamp;
/**
+ * How far the client dates the merge back (zero: now).
+ */
+ struct GNUNET_TIME_Relative backdate;
+
+ /**
* Reserve public key (to be merged into)
*/
struct TALER_ReservePublicKeyP reserve_pub;
@@ -320,7 +325,9 @@ merge_run (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv,
&ds->merge_pub.eddsa_pub);
- ds->merge_timestamp = GNUNET_TIME_timestamp_get ();
+ ds->merge_timestamp = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
+ ds->backdate));
ds->dh = TALER_EXCHANGE_post_purses_merge_create (
TALER_TESTING_interpreter_get_context (is),
TALER_TESTING_get_exchange_url (is),
@@ -431,4 +438,25 @@ TALER_TESTING_cmd_purse_merge (
}
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_purse_merge_backdated (
+ const char *label,
+ unsigned int expected_http_status,
+ const char *merge_ref,
+ const char *reserve_ref,
+ struct GNUNET_TIME_Relative backdate)
+{
+ struct TALER_TESTING_Command cmd;
+ struct PurseMergeState *ds;
+
+ cmd = TALER_TESTING_cmd_purse_merge (label,
+ expected_http_status,
+ merge_ref,
+ reserve_ref);
+ ds = cmd.cls;
+ ds->backdate = backdate;
+ return cmd;
+}
+
+
/* end of testing_api_cmd_purse_merge.c */