exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

test_exchange_api_merge_backdated.c (7156B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU General Public License as
      7   published by the Free Software Foundation; either version 3, or
      8   (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 
     20 /**
     21  * @file testing/test_exchange_api_merge_backdated.c
     22  * @brief merges dated back by the client must still count towards the
     23  *        MERGE limit of the receiving account (kyc.md (K2), KY1, KY2)
     24  */
     25 #include "platform.h"
     26 #include "taler/taler_util.h"
     27 #include "taler/taler_json_lib.h"
     28 #include <gnunet/gnunet_util_lib.h>
     29 #include <microhttpd.h>
     30 #include "taler/taler_bank_service.h"
     31 #include "taler/taler_testing_lib.h"
     32 
     33 #define CONFIG_FILE "test_exchange_api_merge_backdated.conf"
     34 
     35 static struct TALER_TESTING_Credentials cred;
     36 
     37 
     38 static void
     39 run (void *cls,
     40      struct TALER_TESTING_Interpreter *is)
     41 {
     42   struct TALER_TESTING_Command commands[] = {
     43     TALER_TESTING_cmd_run_fakebank ("run-fakebank",
     44                                     cred.cfg,
     45                                     "exchange-account-2"),
     46     TALER_TESTING_cmd_system_start ("start-taler",
     47                                     CONFIG_FILE,
     48                                     "-e",
     49                                     NULL),
     50     TALER_TESTING_cmd_get_exchange ("get-exchange",
     51                                     cred.cfg,
     52                                     NULL,
     53                                     true,
     54                                     true),
     55     TALER_TESTING_cmd_admin_add_incoming ("create-reserve",
     56                                           "EUR:5.01",
     57                                           &cred.ba,
     58                                           cred.user42_payto),
     59     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-payee-1",
     60                                           "EUR:1.01",
     61                                           &cred.ba,
     62                                           cred.user43_payto),
     63     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-payee-2",
     64                                           "EUR:1.01",
     65                                           &cred.ba,
     66                                           cred.user43_payto),
     67     TALER_TESTING_cmd_exec_wirewatch2 ("wirewatch",
     68                                        CONFIG_FILE,
     69                                        "exchange-account-2"),
     70     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin",
     71                                        "create-reserve",
     72                                        "EUR:5",
     73                                        0,
     74                                        MHD_HTTP_OK),
     75     TALER_TESTING_cmd_purse_create_with_deposit (
     76       "purse-a",
     77       MHD_HTTP_OK,
     78       "{\"amount\":\"EUR:0.99\",\"summary\":\"purse a\"}",
     79       true, /* upload contract */
     80       GNUNET_TIME_UNIT_HOURS,
     81       "withdraw-coin",
     82       "EUR:1.00",
     83       NULL),
     84     TALER_TESTING_cmd_contract_get ("get-contract-a",
     85                                     MHD_HTTP_OK,
     86                                     true, /* for merge */
     87                                     "purse-a"),
     88     TALER_TESTING_cmd_purse_create_with_deposit (
     89       "purse-b",
     90       MHD_HTTP_OK,
     91       "{\"amount\":\"EUR:0.99\",\"summary\":\"purse b\"}",
     92       true, /* upload contract */
     93       GNUNET_TIME_UNIT_HOURS,
     94       "withdraw-coin",
     95       "EUR:1.00",
     96       NULL),
     97     TALER_TESTING_cmd_contract_get ("get-contract-b",
     98                                     MHD_HTTP_OK,
     99                                     true, /* for merge */
    100                                     "purse-b"),
    101     TALER_TESTING_cmd_purse_create_with_deposit (
    102       "purse-c",
    103       MHD_HTTP_OK,
    104       "{\"amount\":\"EUR:0.99\",\"summary\":\"purse c\"}",
    105       true, /* upload contract */
    106       GNUNET_TIME_UNIT_HOURS,
    107       "withdraw-coin",
    108       "EUR:1.00",
    109       NULL),
    110     TALER_TESTING_cmd_contract_get ("get-contract-c",
    111                                     MHD_HTTP_OK,
    112                                     true, /* for merge */
    113                                     "purse-c"),
    114     TALER_TESTING_cmd_purse_create_with_deposit (
    115       "purse-d",
    116       MHD_HTTP_OK,
    117       "{\"amount\":\"EUR:0.99\",\"summary\":\"purse d\"}",
    118       true, /* upload contract */
    119       GNUNET_TIME_UNIT_HOURS,
    120       "withdraw-coin",
    121       "EUR:1.00",
    122       NULL),
    123     TALER_TESTING_cmd_contract_get ("get-contract-d",
    124                                     MHD_HTTP_OK,
    125                                     true, /* for merge */
    126                                     "purse-d"),
    127     /* The receiving accounts may get EUR:1.5 a day by merges without KYC.
    128        Control: two merges of EUR:0.99 into payee 1; the second one
    129        exceeds the limit. */
    130     TALER_TESTING_cmd_purse_merge ("merge-a",
    131                                    MHD_HTTP_OK,
    132                                    "get-contract-a",
    133                                    "create-reserve-payee-1"),
    134     TALER_TESTING_cmd_purse_merge ("merge-b",
    135                                    MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
    136                                    "get-contract-b",
    137                                    "create-reserve-payee-1"),
    138     /* The same into payee 2, but the client dates the first merge two days
    139        back (the merge timestamp is the client's, signed, and not checked).
    140        By kyc.md (K2) the operations of the last day count, and both merges
    141        happen now: the second must exceed the limit as well.  The current
    142        exchange counts merges by their merge timestamp and lets it pass. */
    143     TALER_TESTING_cmd_purse_merge_backdated ("merge-c",
    144                                              MHD_HTTP_OK,
    145                                              "get-contract-c",
    146                                              "create-reserve-payee-2",
    147                                              GNUNET_TIME_relative_multiply (
    148                                                GNUNET_TIME_UNIT_DAYS,
    149                                                2)),
    150     TALER_TESTING_cmd_purse_merge ("merge-d",
    151                                    MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
    152                                    "get-contract-d",
    153                                    "create-reserve-payee-2"),
    154     TALER_TESTING_cmd_end ()
    155   };
    156 
    157   (void) cls;
    158   TALER_TESTING_run (is,
    159                      commands);
    160 }
    161 
    162 
    163 int
    164 main (int argc,
    165       char *const *argv)
    166 {
    167   (void) argc;
    168   return TALER_TESTING_main (argv,
    169                              "INFO",
    170                              CONFIG_FILE,
    171                              "exchange-account-2",
    172                              TALER_TESTING_BS_FAKEBANK,
    173                              &cred,
    174                              &run,
    175                              NULL);
    176 }
    177 
    178 
    179 /* end of test_exchange_api_merge_backdated.c */