LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_global_fees.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 39 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) 2022 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_global_fees.c
      22             :  * @brief run the taler-exchange-offline command to download, sign and upload global 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 history fee to sign.
      51             :    */
      52             :   const char *history_fee_s;
      53             : 
      54             :   /**
      55             :    * The KYC fee to sign.
      56             :    */
      57             :   const char *kyc_fee_s;
      58             : 
      59             :   /**
      60             :    * The account fee to sign.
      61             :    */
      62             :   const char *account_fee_s;
      63             : 
      64             :   /**
      65             :    * The purse fee to sign.
      66             :    */
      67             :   const char *purse_fee_s;
      68             : 
      69             :   /**
      70             :    * When MUST purses time out?
      71             :    */
      72             :   struct GNUNET_TIME_Relative purse_timeout;
      73             : 
      74             :   /**
      75             :    * How long does a user have to complete the KYC?
      76             :    */
      77             :   struct GNUNET_TIME_Relative kyc_timeout;
      78             : 
      79             :   /**
      80             :    * How long do we keep the history?
      81             :    */
      82             :   struct GNUNET_TIME_Relative history_expiration;
      83             : 
      84             :   /**
      85             :    * Number of (free) purses per account.
      86             :    */
      87             :   unsigned int num_purses;
      88             : };
      89             : 
      90             : 
      91             : /**
      92             :  * Run the command; calls the `taler-exchange-offline' program.
      93             :  *
      94             :  * @param cls closure.
      95             :  * @param cmd the commaind being run.
      96             :  * @param is interpreter state.
      97             :  */
      98             : static void
      99           0 : offlinesign_run (void *cls,
     100             :                  const struct TALER_TESTING_Command *cmd,
     101             :                  struct TALER_TESTING_Interpreter *is)
     102             : {
     103           0 :   struct OfflineSignState *ks = cls;
     104             :   char num_purses[12];
     105             :   char history_expiration[32];
     106             :   char purse_timeout[32];
     107             :   char kyc_timeout[32];
     108             : 
     109           0 :   GNUNET_snprintf (num_purses,
     110             :                    sizeof (num_purses),
     111             :                    "%u",
     112             :                    ks->num_purses);
     113           0 :   GNUNET_snprintf (history_expiration,
     114             :                    sizeof (history_expiration),
     115             :                    "%s",
     116             :                    GNUNET_TIME_relative2s (ks->history_expiration,
     117             :                                            false));
     118           0 :   GNUNET_snprintf (purse_timeout,
     119             :                    sizeof (purse_timeout),
     120             :                    "%s",
     121             :                    GNUNET_TIME_relative2s (ks->purse_timeout,
     122             :                                            false));
     123           0 :   GNUNET_snprintf (kyc_timeout,
     124             :                    sizeof (kyc_timeout),
     125             :                    "%s",
     126             :                    GNUNET_TIME_relative2s (ks->kyc_timeout,
     127             :                                            false));
     128             :   ks->offlinesign_proc
     129           0 :     = GNUNET_OS_start_process (
     130             :         GNUNET_OS_INHERIT_STD_ALL,
     131             :         NULL, NULL, NULL,
     132             :         "taler-exchange-offline",
     133             :         "taler-exchange-offline",
     134             :         "-c", ks->config_filename,
     135             :         "-L", "INFO",
     136             :         "global-fee",
     137             :         "now",
     138             :         ks->history_fee_s,
     139             :         ks->kyc_fee_s,
     140             :         ks->account_fee_s,
     141             :         ks->purse_fee_s,
     142             :         purse_timeout,
     143             :         kyc_timeout,
     144             :         history_expiration,
     145             :         num_purses,
     146             :         "upload",
     147             :         NULL);
     148           0 :   if (NULL == ks->offlinesign_proc)
     149             :   {
     150           0 :     GNUNET_break (0);
     151           0 :     TALER_TESTING_interpreter_fail (is);
     152           0 :     return;
     153             :   }
     154           0 :   TALER_TESTING_wait_for_sigchld (is);
     155             : }
     156             : 
     157             : 
     158             : /**
     159             :  * Free the state of a "offlinesign" CMD, and possibly kills its
     160             :  * process if it did not terminate correctly.
     161             :  *
     162             :  * @param cls closure.
     163             :  * @param cmd the command being freed.
     164             :  */
     165             : static void
     166           0 : offlinesign_cleanup (void *cls,
     167             :                      const struct TALER_TESTING_Command *cmd)
     168             : {
     169           0 :   struct OfflineSignState *ks = cls;
     170             : 
     171             :   (void) cmd;
     172           0 :   if (NULL != ks->offlinesign_proc)
     173             :   {
     174           0 :     GNUNET_break (0 ==
     175             :                   GNUNET_OS_process_kill (ks->offlinesign_proc,
     176             :                                           SIGKILL));
     177           0 :     GNUNET_OS_process_wait (ks->offlinesign_proc);
     178           0 :     GNUNET_OS_process_destroy (ks->offlinesign_proc);
     179           0 :     ks->offlinesign_proc = NULL;
     180             :   }
     181           0 :   GNUNET_free (ks);
     182           0 : }
     183             : 
     184             : 
     185             : /**
     186             :  * Offer "offlinesign" CMD internal data to other commands.
     187             :  *
     188             :  * @param cls closure.
     189             :  * @param[out] ret result
     190             :  * @param trait name of the trait.
     191             :  * @param index index number of the object to offer.
     192             :  * @return #GNUNET_OK on success.
     193             :  */
     194             : static enum GNUNET_GenericReturnValue
     195           0 : offlinesign_traits (void *cls,
     196             :                     const void **ret,
     197             :                     const char *trait,
     198             :                     unsigned int index)
     199             : {
     200           0 :   struct OfflineSignState *ks = cls;
     201             :   struct TALER_TESTING_Trait traits[] = {
     202           0 :     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
     203           0 :     TALER_TESTING_trait_end ()
     204             :   };
     205             : 
     206           0 :   return TALER_TESTING_get_trait (traits,
     207             :                                   ret,
     208             :                                   trait,
     209             :                                   index);
     210             : }
     211             : 
     212             : 
     213             : struct TALER_TESTING_Command
     214           0 : TALER_TESTING_cmd_exec_offline_sign_global_fees (
     215             :   const char *label,
     216             :   const char *config_filename,
     217             :   const char *history_fee,
     218             :   const char *kyc_fee,
     219             :   const char *account_fee,
     220             :   const char *purse_fee,
     221             :   struct GNUNET_TIME_Relative purse_timeout,
     222             :   struct GNUNET_TIME_Relative kyc_timeout,
     223             :   struct GNUNET_TIME_Relative history_expiration,
     224             :   unsigned int num_purses)
     225             : {
     226             :   struct OfflineSignState *ks;
     227             : 
     228           0 :   ks = GNUNET_new (struct OfflineSignState);
     229           0 :   ks->config_filename = config_filename;
     230           0 :   ks->history_fee_s = history_fee;
     231           0 :   ks->kyc_fee_s = kyc_fee;
     232           0 :   ks->account_fee_s = account_fee;
     233           0 :   ks->purse_fee_s = purse_fee;
     234           0 :   ks->purse_timeout = purse_timeout;
     235           0 :   ks->kyc_timeout = kyc_timeout;
     236           0 :   ks->history_expiration = history_expiration;
     237           0 :   ks->num_purses = num_purses;
     238             :   {
     239           0 :     struct TALER_TESTING_Command cmd = {
     240             :       .cls = ks,
     241             :       .label = label,
     242             :       .run = &offlinesign_run,
     243             :       .cleanup = &offlinesign_cleanup,
     244             :       .traits = &offlinesign_traits
     245             :     };
     246             : 
     247           0 :     return cmd;
     248             :   }
     249             : }
     250             : 
     251             : 
     252             : /* end of testing_api_cmd_exec_offline_sign_global_fees.c */

Generated by: LCOV version 1.14