LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_wire_fees.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 29 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2020 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it
       6             :   under the terms of the GNU General Public License as published
       7             :   by the Free Software Foundation; either version 3, or (at your
       8             :   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,
      17             :   see <http://www.gnu.org/licenses/>
      18             : */
      19             : 
      20             : /**
      21             :  * @file testing/testing_api_cmd_offline_sign_wire_fees.c
      22             :  * @brief run the taler-exchange-offline command to download, sign and upload wire fees
      23             :  * @author Marcello Stanisci
      24             :  * @author Christian Grothoff
      25             :  */
      26             : #include "platform.h"
      27             : #include "taler_json_lib.h"
      28             : #include <gnunet/gnunet_curl_lib.h>
      29             : #include "taler_signatures.h"
      30             : #include "taler_testing_lib.h"
      31             : 
      32             : 
      33             : /**
      34             :  * State for a "offlinesign" CMD.
      35             :  */
      36             : struct OfflineSignState
      37             : {
      38             : 
      39             :   /**
      40             :    * Process for the "offlinesign" command.
      41             :    */
      42             :   struct GNUNET_OS_Process *offlinesign_proc;
      43             : 
      44             :   /**
      45             :    * Configuration file used by the command.
      46             :    */
      47             :   const char *config_filename;
      48             : 
      49             :   /**
      50             :    * The wire fee to sign.
      51             :    */
      52             :   const char *wire_fee_s;
      53             : 
      54             :   /**
      55             :    * The closing fee to sign.
      56             :    */
      57             :   const char *closing_fee_s;
      58             : 
      59             : };
      60             : 
      61             : 
      62             : /**
      63             :  * Run the command; calls the `taler-exchange-offline' program.
      64             :  *
      65             :  * @param cls closure.
      66             :  * @param cmd the commaind being run.
      67             :  * @param is interpreter state.
      68             :  */
      69             : static void
      70           0 : offlinesign_run (void *cls,
      71             :                  const struct TALER_TESTING_Command *cmd,
      72             :                  struct TALER_TESTING_Interpreter *is)
      73             : {
      74           0 :   struct OfflineSignState *ks = cls;
      75             : 
      76             :   ks->offlinesign_proc
      77           0 :     = GNUNET_OS_start_process (
      78             :         GNUNET_OS_INHERIT_STD_ALL,
      79             :         NULL, NULL, NULL,
      80             :         "taler-exchange-offline",
      81             :         "taler-exchange-offline",
      82             :         "-c", ks->config_filename,
      83             :         "-L", "INFO",
      84             :         "wire-fee",
      85             :         "now",
      86             :         "x-taler-bank",
      87             :         ks->wire_fee_s,
      88             :         ks->closing_fee_s,
      89             :         "upload",
      90             :         NULL);
      91           0 :   if (NULL == ks->offlinesign_proc)
      92             :   {
      93           0 :     GNUNET_break (0);
      94           0 :     TALER_TESTING_interpreter_fail (is);
      95           0 :     return;
      96             :   }
      97           0 :   TALER_TESTING_wait_for_sigchld (is);
      98             : }
      99             : 
     100             : 
     101             : /**
     102             :  * Free the state of a "offlinesign" CMD, and possibly kills its
     103             :  * process if it did not terminate correctly.
     104             :  *
     105             :  * @param cls closure.
     106             :  * @param cmd the command being freed.
     107             :  */
     108             : static void
     109           0 : offlinesign_cleanup (void *cls,
     110             :                      const struct TALER_TESTING_Command *cmd)
     111             : {
     112           0 :   struct OfflineSignState *ks = cls;
     113             : 
     114             :   (void) cmd;
     115           0 :   if (NULL != ks->offlinesign_proc)
     116             :   {
     117           0 :     GNUNET_break (0 ==
     118             :                   GNUNET_OS_process_kill (ks->offlinesign_proc,
     119             :                                           SIGKILL));
     120           0 :     GNUNET_OS_process_wait (ks->offlinesign_proc);
     121           0 :     GNUNET_OS_process_destroy (ks->offlinesign_proc);
     122           0 :     ks->offlinesign_proc = NULL;
     123             :   }
     124           0 :   GNUNET_free (ks);
     125           0 : }
     126             : 
     127             : 
     128             : /**
     129             :  * Offer "offlinesign" CMD internal data to other commands.
     130             :  *
     131             :  * @param cls closure.
     132             :  * @param[out] ret result
     133             :  * @param trait name of the trait.
     134             :  * @param index index number of the object to offer.
     135             :  * @return #GNUNET_OK on success.
     136             :  */
     137             : static enum GNUNET_GenericReturnValue
     138           0 : offlinesign_traits (void *cls,
     139             :                     const void **ret,
     140             :                     const char *trait,
     141             :                     unsigned int index)
     142             : {
     143           0 :   struct OfflineSignState *ks = cls;
     144             :   struct TALER_TESTING_Trait traits[] = {
     145           0 :     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
     146           0 :     TALER_TESTING_trait_end ()
     147             :   };
     148             : 
     149           0 :   return TALER_TESTING_get_trait (traits,
     150             :                                   ret,
     151             :                                   trait,
     152             :                                   index);
     153             : }
     154             : 
     155             : 
     156             : struct TALER_TESTING_Command
     157           0 : TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
     158             :                                           const char *config_filename,
     159             :                                           const char *wire_fee,
     160             :                                           const char *closing_fee)
     161             : {
     162             :   struct OfflineSignState *ks;
     163             : 
     164           0 :   ks = GNUNET_new (struct OfflineSignState);
     165           0 :   ks->config_filename = config_filename;
     166           0 :   ks->wire_fee_s = wire_fee;
     167           0 :   ks->closing_fee_s = closing_fee;
     168             :   {
     169           0 :     struct TALER_TESTING_Command cmd = {
     170             :       .cls = ks,
     171             :       .label = label,
     172             :       .run = &offlinesign_run,
     173             :       .cleanup = &offlinesign_cleanup,
     174             :       .traits = &offlinesign_traits
     175             :     };
     176             : 
     177           0 :     return cmd;
     178             :   }
     179             : }
     180             : 
     181             : 
     182             : /* end of testing_api_cmd_exec_offline_sign_fees.c */

Generated by: LCOV version 1.16