LCOV - code coverage report
Current view: top level - testing - test_taler_exchange_wirewatch.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 36 94.4 %
Date: 2025-06-05 21:03:14 Functions: 3 3 100.0 %

          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 "platform.h"
      27             : #include "taler_util.h"
      28             : #include <gnunet/gnunet_json_lib.h>
      29             : #include <gnunet/gnunet_pq_lib.h>
      30             : #include "taler_json_lib.h"
      31             : #include <microhttpd.h>
      32             : #include "taler_fakebank_lib.h"
      33             : #include "taler_testing_lib.h"
      34             : 
      35             : 
      36             : /**
      37             :  * Our credentials.
      38             :  */
      39             : static struct TALER_TESTING_Credentials cred;
      40             : 
      41             : /**
      42             :  * Name of the configuration file to use.
      43             :  */
      44             : static char *config_filename;
      45             : 
      46             : 
      47             : /**
      48             :  * Execute the taler-exchange-aggregator, closer and transfer commands with
      49             :  * our configuration file.
      50             :  *
      51             :  * @param label label to use for the command.
      52             :  */
      53             : #define CMD_EXEC_AGGREGATOR(label) \
      54             :   TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_filename), \
      55             :   TALER_TESTING_cmd_exec_transfer (label "-transfer", config_filename)
      56             : 
      57             : 
      58             : static struct TALER_TESTING_Command
      59           1 : transfer_to_exchange (const char *label,
      60             :                       const char *amount)
      61             : {
      62           1 :   return TALER_TESTING_cmd_admin_add_incoming (label,
      63             :                                                amount,
      64             :                                                &cred.ba,
      65             :                                                cred.user42_payto);
      66             : }
      67             : 
      68             : 
      69             : /**
      70             :  * Main function that will tell the interpreter what commands to
      71             :  * run.
      72             :  *
      73             :  * @param cls closure
      74             :  */
      75             : static void
      76           1 : run (void *cls,
      77             :      struct TALER_TESTING_Interpreter *is)
      78             : {
      79             :   struct TALER_TESTING_Command all[] = {
      80           1 :     TALER_TESTING_cmd_run_fakebank ("run-fakebank",
      81           1 :                                     cred.cfg,
      82             :                                     "exchange-account-1"),
      83           1 :     TALER_TESTING_cmd_system_start ("start-taler",
      84             :                                     config_filename,
      85             :                                     "-e",
      86             :                                     "-u", "exchange-account-1",
      87             :                                     NULL),
      88           1 :     TALER_TESTING_cmd_get_exchange ("get-exchange",
      89           1 :                                     cred.cfg,
      90             :                                     NULL,
      91             :                                     true,
      92             :                                     true),
      93           1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
      94           1 :     CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty"),
      95           1 :     TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty",
      96             :                                       config_filename),
      97           1 :     TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"),
      98             : 
      99           1 :     transfer_to_exchange ("run-transfer-good-to-exchange",
     100             :                           "EUR:5"),
     101           1 :     TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-good-transfer",
     102             :                                       config_filename),
     103             : 
     104           1 :     TALER_TESTING_cmd_check_bank_admin_transfer (
     105             :       "clear-good-transfer-to-the-exchange",
     106             :       "EUR:5",
     107             :       cred.user42_payto,                                            // debit
     108             :       cred.exchange_payto,                                            // credit
     109             :       "run-transfer-good-to-exchange"),
     110             : 
     111           1 :     TALER_TESTING_cmd_exec_closer ("run-closer-non-expired-reserve",
     112             :                                    config_filename,
     113             :                                    NULL,
     114             :                                    NULL,
     115             :                                    NULL),
     116           1 :     TALER_TESTING_cmd_exec_transfer ("do-idle-transfer", config_filename),
     117             : 
     118           1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"),
     119           1 :     TALER_TESTING_cmd_sleep ("wait (5s)",
     120             :                              5),
     121           1 :     TALER_TESTING_cmd_exec_closer ("run-closer-expired-reserve",
     122             :                                    config_filename,
     123             :                                    "EUR:4.99",
     124             :                                    "EUR:0.01",
     125             :                                    "run-transfer-good-to-exchange"),
     126           1 :     TALER_TESTING_cmd_exec_transfer ("do-closing-transfer",
     127             :                                      config_filename),
     128             : 
     129           1 :     CMD_EXEC_AGGREGATOR ("run-closer-on-expired-reserve"),
     130           1 :     TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
     131           1 :                                            cred.exchange_url,
     132             :                                            "EUR:4.99",
     133             :                                            cred.exchange_payto,
     134             :                                            cred.user42_payto),
     135           1 :     TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"),
     136           1 :     TALER_TESTING_cmd_end ()
     137             :   };
     138             : 
     139             :   (void) cls;
     140           1 :   TALER_TESTING_run (is,
     141             :                      all);
     142           1 : }
     143             : 
     144             : 
     145             : int
     146           1 : main (int argc,
     147             :       char *const argv[])
     148             : {
     149             :   (void) argc;
     150             :   {
     151             :     const char *plugin_name;
     152             : 
     153           1 :     plugin_name = strrchr (argv[0], (int) '-');
     154           1 :     if (NULL == plugin_name)
     155             :     {
     156           0 :       GNUNET_break (0);
     157           0 :       return -1;
     158             :     }
     159           1 :     plugin_name++;
     160           1 :     GNUNET_asprintf (&config_filename,
     161             :                      "test-taler-exchange-wirewatch-%s.conf",
     162             :                      plugin_name);
     163             :   }
     164           1 :   return TALER_TESTING_main (argv,
     165             :                              "INFO",
     166             :                              config_filename,
     167             :                              "exchange-account-1",
     168             :                              TALER_TESTING_BS_FAKEBANK,
     169             :                              &cred,
     170             :                              &run,
     171             :                              NULL);
     172             : }
     173             : 
     174             : 
     175             : /* end of test_taler_exchange_wirewatch.c */

Generated by: LCOV version 1.16