LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_wire_fees.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 30 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          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 wad fee to sign.
      56             :    */
      57             :   const char *wad_fee_s;
      58             : 
      59             :   /**
      60             :    * The closing fee to sign.
      61             :    */
      62             :   const char *closing_fee_s;
      63             : 
      64             : };
      65             : 
      66             : 
      67             : /**
      68             :  * Run the command; calls the `taler-exchange-offline' program.
      69             :  *
      70             :  * @param cls closure.
      71             :  * @param cmd the commaind being run.
      72             :  * @param is interpreter state.
      73             :  */
      74             : static void
      75           0 : offlinesign_run (void *cls,
      76             :                  const struct TALER_TESTING_Command *cmd,
      77             :                  struct TALER_TESTING_Interpreter *is)
      78             : {
      79           0 :   struct OfflineSignState *ks = cls;
      80             : 
      81             :   ks->offlinesign_proc
      82           0 :     = GNUNET_OS_start_process (
      83             :         GNUNET_OS_INHERIT_STD_ALL,
      84             :         NULL, NULL, NULL,
      85             :         "taler-exchange-offline",
      86             :         "taler-exchange-offline",
      87             :         "-c", ks->config_filename,
      88             :         "-L", "INFO",
      89             :         "wire-fee",
      90             :         "now",
      91             :         "x-taler-bank",
      92             :         ks->wire_fee_s,
      93             :         ks->closing_fee_s,
      94             :         ks->wad_fee_s,
      95             :         "upload",
      96             :         NULL);
      97           0 :   if (NULL == ks->offlinesign_proc)
      98             :   {
      99           0 :     GNUNET_break (0);
     100           0 :     TALER_TESTING_interpreter_fail (is);
     101           0 :     return;
     102             :   }
     103           0 :   TALER_TESTING_wait_for_sigchld (is);
     104             : }
     105             : 
     106             : 
     107             : /**
     108             :  * Free the state of a "offlinesign" CMD, and possibly kills its
     109             :  * process if it did not terminate correctly.
     110             :  *
     111             :  * @param cls closure.
     112             :  * @param cmd the command being freed.
     113             :  */
     114             : static void
     115           0 : offlinesign_cleanup (void *cls,
     116             :                      const struct TALER_TESTING_Command *cmd)
     117             : {
     118           0 :   struct OfflineSignState *ks = cls;
     119             : 
     120             :   (void) cmd;
     121           0 :   if (NULL != ks->offlinesign_proc)
     122             :   {
     123           0 :     GNUNET_break (0 ==
     124             :                   GNUNET_OS_process_kill (ks->offlinesign_proc,
     125             :                                           SIGKILL));
     126           0 :     GNUNET_OS_process_wait (ks->offlinesign_proc);
     127           0 :     GNUNET_OS_process_destroy (ks->offlinesign_proc);
     128           0 :     ks->offlinesign_proc = NULL;
     129             :   }
     130           0 :   GNUNET_free (ks);
     131           0 : }
     132             : 
     133             : 
     134             : /**
     135             :  * Offer "offlinesign" CMD internal data to other commands.
     136             :  *
     137             :  * @param cls closure.
     138             :  * @param[out] ret result
     139             :  * @param trait name of the trait.
     140             :  * @param index index number of the object to offer.
     141             :  * @return #GNUNET_OK on success.
     142             :  */
     143             : static enum GNUNET_GenericReturnValue
     144           0 : offlinesign_traits (void *cls,
     145             :                     const void **ret,
     146             :                     const char *trait,
     147             :                     unsigned int index)
     148             : {
     149           0 :   struct OfflineSignState *ks = cls;
     150             :   struct TALER_TESTING_Trait traits[] = {
     151           0 :     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
     152           0 :     TALER_TESTING_trait_end ()
     153             :   };
     154             : 
     155           0 :   return TALER_TESTING_get_trait (traits,
     156             :                                   ret,
     157             :                                   trait,
     158             :                                   index);
     159             : }
     160             : 
     161             : 
     162             : struct TALER_TESTING_Command
     163           0 : TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
     164             :                                           const char *config_filename,
     165             :                                           const char *wire_fee,
     166             :                                           const char *closing_fee,
     167             :                                           const char *wad_fee)
     168             : {
     169             :   struct OfflineSignState *ks;
     170             : 
     171           0 :   ks = GNUNET_new (struct OfflineSignState);
     172           0 :   ks->config_filename = config_filename;
     173           0 :   ks->wire_fee_s = wire_fee;
     174           0 :   ks->wad_fee_s = wad_fee;
     175           0 :   ks->closing_fee_s = closing_fee;
     176             :   {
     177           0 :     struct TALER_TESTING_Command cmd = {
     178             :       .cls = ks,
     179             :       .label = label,
     180             :       .run = &offlinesign_run,
     181             :       .cleanup = &offlinesign_cleanup,
     182             :       .traits = &offlinesign_traits
     183             :     };
     184             : 
     185           0 :     return cmd;
     186             :   }
     187             : }
     188             : 
     189             : 
     190             : /* end of testing_api_cmd_exec_offline_sign_fees.c */

Generated by: LCOV version 1.14