LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_fees.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 22 29 75.9 %
Date: 2021-08-30 06:43:37 Functions: 4 4 100.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_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           5 : offlinesign_run (void *cls,
      71             :                  const struct TALER_TESTING_Command *cmd,
      72             :                  struct TALER_TESTING_Interpreter *is)
      73             : {
      74           5 :   struct OfflineSignState *ks = cls;
      75             : 
      76             :   ks->offlinesign_proc
      77           5 :     = 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           5 :   if (NULL == ks->offlinesign_proc)
      92             :   {
      93           0 :     GNUNET_break (0);
      94           0 :     TALER_TESTING_interpreter_fail (is);
      95           0 :     return;
      96             :   }
      97           5 :   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           5 : offlinesign_cleanup (void *cls,
     110             :                      const struct TALER_TESTING_Command *cmd)
     111             : {
     112           5 :   struct OfflineSignState *ks = cls;
     113             : 
     114             :   (void) cmd;
     115           5 :   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           5 :   GNUNET_free (ks);
     125           5 : }
     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 int
     138          12 : offlinesign_traits (void *cls,
     139             :                     const void **ret,
     140             :                     const char *trait,
     141             :                     unsigned int index)
     142             : {
     143          12 :   struct OfflineSignState *ks = cls;
     144             :   struct TALER_TESTING_Trait traits[] = {
     145          12 :     TALER_TESTING_make_trait_process (0,
     146             :                                       &ks->offlinesign_proc),
     147          12 :     TALER_TESTING_trait_end ()
     148             :   };
     149             : 
     150          12 :   return TALER_TESTING_get_trait (traits,
     151             :                                   ret,
     152             :                                   trait,
     153             :                                   index);
     154             : }
     155             : 
     156             : 
     157             : /**
     158             :  * Sign a wire fee.
     159             :  *
     160             :  * @param label command label.
     161             :  * @param config_filename configuration filename.
     162             :  * @param wire_fee the wire fee to affirm (for the current year)
     163             :  * @param closing_fee the closing fee to affirm (for the current year)
     164             :  * @return the command
     165             :  */
     166             : struct TALER_TESTING_Command
     167           5 : TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
     168             :                                           const char *config_filename,
     169             :                                           const char *wire_fee,
     170             :                                           const char *closing_fee)
     171             : {
     172             :   struct OfflineSignState *ks;
     173             : 
     174           5 :   ks = GNUNET_new (struct OfflineSignState);
     175           5 :   ks->config_filename = config_filename;
     176           5 :   ks->wire_fee_s = wire_fee;
     177           5 :   ks->closing_fee_s = closing_fee;
     178             :   {
     179           5 :     struct TALER_TESTING_Command cmd = {
     180             :       .cls = ks,
     181             :       .label = label,
     182             :       .run = &offlinesign_run,
     183             :       .cleanup = &offlinesign_cleanup,
     184             :       .traits = &offlinesign_traits
     185             :     };
     186             : 
     187           5 :     return cmd;
     188             :   }
     189             : }
     190             : 
     191             : 
     192             : /* end of testing_api_cmd_exec_offline_sign_fees.c */

Generated by: LCOV version 1.14