LCOV - code coverage report
Current view: top level - testing - test_taler_exchange_wirewatch.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.4 % 36 34
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2016-2020 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it under the
       6              :   terms of the GNU General Public License as published by the Free Software
       7              :   Foundation; either version 3, or (at your option) any later version.
       8              : 
       9              :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10              :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11              :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU General Public License along with
      14              :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15              : */
      16              : 
      17              : /**
      18              :  * @file testing/test_taler_exchange_wirewatch.c
      19              :  * @brief Tests for taler-exchange-wirewatch and taler-exchange-aggregator logic;
      20              :  *        Performs an invalid wire transfer to the exchange, and then checks that
      21              :  *        wirewatch immediately sends the money back.
      22              :  *        Then performs a valid wire transfer, waits for the reserve to expire,
      23              :  *        and then checks that the aggregator sends the money back.
      24              :  * @author Christian Grothoff <christian@grothoff.org>
      25              :  */
      26              : #include "taler/taler_util.h"
      27              : #include <gnunet/gnunet_json_lib.h>
      28              : #include <gnunet/gnunet_pq_lib.h>
      29              : #include "taler/taler_json_lib.h"
      30              : #include <microhttpd.h>
      31              : #include "taler/taler_testing_lib.h"
      32              : 
      33              : 
      34              : /**
      35              :  * Our credentials.
      36              :  */
      37              : static struct TALER_TESTING_Credentials cred;
      38              : 
      39              : /**
      40              :  * Name of the configuration file to use.
      41              :  */
      42              : static char *config_filename;
      43              : 
      44              : 
      45              : /**
      46              :  * Execute the taler-exchange-aggregator, closer and transfer commands with
      47              :  * our configuration file.
      48              :  *
      49              :  * @param label label to use for the command.
      50              :  */
      51              : #define CMD_EXEC_AGGREGATOR(label) \
      52              :         TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_filename) \
      53              :         , \
      54              :         TALER_TESTING_cmd_exec_transfer (label "-transfer", config_filename)
      55              : 
      56              : 
      57              : static struct TALER_TESTING_Command
      58            1 : transfer_to_exchange (const char *label,
      59              :                       const char *amount)
      60              : {
      61            1 :   return TALER_TESTING_cmd_admin_add_incoming (label,
      62              :                                                amount,
      63              :                                                &cred.ba,
      64              :                                                cred.user42_payto);
      65              : }
      66              : 
      67              : 
      68              : /**
      69              :  * Main function that will tell the interpreter what commands to
      70              :  * run.
      71              :  *
      72              :  * @param cls closure
      73              :  */
      74              : static void
      75            1 : run (void *cls,
      76              :      struct TALER_TESTING_Interpreter *is)
      77              : {
      78              :   struct TALER_TESTING_Command all[] = {
      79            1 :     TALER_TESTING_cmd_run_fakebank ("run-fakebank",
      80            1 :                                     cred.cfg,
      81              :                                     "exchange-account-1"),
      82            1 :     TALER_TESTING_cmd_system_start ("start-taler",
      83              :                                     config_filename,
      84              :                                     "-e",
      85              :                                     "-u", "exchange-account-1",
      86              :                                     NULL),
      87            1 :     TALER_TESTING_cmd_get_exchange ("get-exchange",
      88            1 :                                     cred.cfg,
      89              :                                     NULL,
      90              :                                     true,
      91              :                                     true),
      92            1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
      93            1 :     CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty"),
      94            1 :     TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty",
      95              :                                       config_filename),
      96            1 :     TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"),
      97              : 
      98            1 :     transfer_to_exchange ("run-transfer-good-to-exchange",
      99              :                           "EUR:5"),
     100            1 :     TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-good-transfer",
     101              :                                       config_filename),
     102              : 
     103            1 :     TALER_TESTING_cmd_check_bank_admin_transfer (
     104              :       "clear-good-transfer-to-the-exchange",
     105              :       "EUR:5",
     106              :       cred.user42_payto,                                            // debit
     107              :       cred.exchange_payto,                                            // credit
     108              :       "run-transfer-good-to-exchange"),
     109              : 
     110            1 :     TALER_TESTING_cmd_exec_closer ("run-closer-non-expired-reserve",
     111              :                                    config_filename,
     112              :                                    NULL,
     113              :                                    NULL,
     114              :                                    NULL),
     115            1 :     TALER_TESTING_cmd_exec_transfer ("do-idle-transfer", config_filename),
     116              : 
     117            1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"),
     118            1 :     TALER_TESTING_cmd_sleep ("wait (5s)",
     119              :                              5),
     120            1 :     TALER_TESTING_cmd_exec_closer ("run-closer-expired-reserve",
     121              :                                    config_filename,
     122              :                                    "EUR:4.99",
     123              :                                    "EUR:0.01",
     124              :                                    "run-transfer-good-to-exchange"),
     125            1 :     TALER_TESTING_cmd_exec_transfer ("do-closing-transfer",
     126              :                                      config_filename),
     127              : 
     128            1 :     CMD_EXEC_AGGREGATOR ("run-closer-on-expired-reserve"),
     129            1 :     TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
     130            1 :                                            cred.exchange_url,
     131              :                                            "EUR:4.99",
     132              :                                            cred.exchange_payto,
     133              :                                            cred.user42_payto),
     134            1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"),
     135            1 :     TALER_TESTING_cmd_end ()
     136              :   };
     137              : 
     138              :   (void) cls;
     139            1 :   TALER_TESTING_run (is,
     140              :                      all);
     141            1 : }
     142              : 
     143              : 
     144              : int
     145            1 : main (int argc,
     146              :       char *const argv[])
     147              : {
     148              :   (void) argc;
     149              :   {
     150              :     const char *plugin_name;
     151              : 
     152            1 :     plugin_name = strrchr (argv[0], (int) '-');
     153            1 :     if (NULL == plugin_name)
     154              :     {
     155            0 :       GNUNET_break (0);
     156            0 :       return -1;
     157              :     }
     158            1 :     plugin_name++;
     159            1 :     GNUNET_asprintf (&config_filename,
     160              :                      "test-taler-exchange-wirewatch-%s.conf",
     161              :                      plugin_name);
     162              :   }
     163            1 :   return TALER_TESTING_main (argv,
     164              :                              "INFO",
     165              :                              config_filename,
     166              :                              "exchange-account-1",
     167              :                              TALER_TESTING_BS_FAKEBANK,
     168              :                              &cred,
     169              :                              &run,
     170              :                              NULL);
     171              : }
     172              : 
     173              : 
     174              : /* end of test_taler_exchange_wirewatch.c */
        

Generated by: LCOV version 2.0-1