LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_bank_admin_check.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.8 % 55 34
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2018-2020, 2024 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify
       6              :   it under the terms of the GNU General Public License as
       7              :   published by the Free Software Foundation; either version 3, or
       8              :   (at your 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, see
      17              :   <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file testing/testing_api_cmd_bank_admin_check.c
      21              :  * @brief command to check if a particular admin/add-incoming transfer took
      22              :  *        place.
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "taler/taler_json_lib.h"
      26              : #include <gnunet/gnunet_curl_lib.h>
      27              : #include "taler/taler_testing_lib.h"
      28              : #include "taler/taler_fakebank_lib.h"
      29              : 
      30              : 
      31              : /**
      32              :  * State for a "bank check" CMD.
      33              :  */
      34              : struct BankAdminCheckState
      35              : {
      36              : 
      37              :   /**
      38              :    * Expected transferred amount.
      39              :    */
      40              :   const char *amount;
      41              : 
      42              :   /**
      43              :    * Expected debit bank account.
      44              :    */
      45              :   struct TALER_FullPayto debit_payto;
      46              : 
      47              :   /**
      48              :    * Expected credit bank account.
      49              :    */
      50              :   struct TALER_FullPayto credit_payto;
      51              : 
      52              :   /**
      53              :    * Command providing the reserve public key trait to use.
      54              :    */
      55              :   const char *reserve_pub_ref;
      56              : 
      57              :   /**
      58              :    * Interpreter state.
      59              :    */
      60              :   struct TALER_TESTING_Interpreter *is;
      61              : 
      62              : };
      63              : 
      64              : /**
      65              :  * Run the command.
      66              :  *
      67              :  * @param cls closure.
      68              :  * @param cmd the command to execute.
      69              :  * @param is the interpreter state.
      70              :  */
      71              : static void
      72           45 : check_bank_admin_transfer_run (void *cls,
      73              :                                const struct TALER_TESTING_Command *cmd,
      74              :                                struct TALER_TESTING_Interpreter *is)
      75              : {
      76           45 :   struct BankAdminCheckState *bcs = cls;
      77              :   struct TALER_Amount amount;
      78              :   char *debit_account;
      79              :   char *credit_account;
      80              :   struct TALER_FullPayto debit_payto;
      81              :   struct TALER_FullPayto credit_payto;
      82              :   const struct TALER_ReservePublicKeyP *reserve_pub;
      83              :   const struct TALER_TESTING_Command *cmd_ref;
      84              :   struct TALER_FAKEBANK_Handle *fakebank;
      85              : 
      86              :   (void) cmd;
      87              :   {
      88              :     const struct TALER_TESTING_Command *fakebank_cmd;
      89              : 
      90              :     fakebank_cmd
      91           45 :       = TALER_TESTING_interpreter_get_command (is,
      92              :                                                "fakebank");
      93           45 :     if (NULL == fakebank_cmd)
      94              :     {
      95            0 :       GNUNET_break (0);
      96            0 :       TALER_TESTING_interpreter_fail (is);
      97            0 :       return;
      98              :     }
      99           45 :     if (GNUNET_OK !=
     100           45 :         TALER_TESTING_get_trait_fakebank (fakebank_cmd,
     101              :                                           &fakebank))
     102              :     {
     103            0 :       GNUNET_break (0);
     104            0 :       TALER_TESTING_interpreter_fail (is);
     105            0 :       return;
     106              :     }
     107              :   }
     108              :   cmd_ref
     109           45 :     = TALER_TESTING_interpreter_lookup_command (is,
     110              :                                                 bcs->reserve_pub_ref);
     111           45 :   if (NULL == cmd_ref)
     112              :   {
     113            0 :     GNUNET_break (0);
     114            0 :     TALER_TESTING_interpreter_fail (is);
     115            0 :     return;
     116              :   }
     117           45 :   if (GNUNET_OK !=
     118           45 :       TALER_TESTING_get_trait_reserve_pub (cmd_ref,
     119              :                                            &reserve_pub))
     120              :   {
     121            0 :     GNUNET_break (0);
     122            0 :     TALER_LOG_ERROR ("Command reference fails to provide reserve public key\n");
     123            0 :     TALER_TESTING_interpreter_fail (is);
     124            0 :     return;
     125              :   }
     126           45 :   debit_payto = bcs->debit_payto;
     127           45 :   credit_payto = bcs->credit_payto;
     128           45 :   if (GNUNET_OK !=
     129           45 :       TALER_string_to_amount (bcs->amount,
     130              :                               &amount))
     131              :   {
     132            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     133              :                 "Failed to parse amount `%s' at %s\n",
     134              :                 bcs->amount,
     135              :                 TALER_TESTING_interpreter_get_current_label (is));
     136            0 :     TALER_TESTING_interpreter_fail (is);
     137            0 :     return;
     138              :   }
     139           45 :   debit_account = TALER_xtalerbank_account_from_payto (debit_payto);
     140           45 :   credit_account = TALER_xtalerbank_account_from_payto (credit_payto);
     141           45 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     142              :               "converted debit_payto (%s) to debit_account (%s)\n",
     143              :               debit_payto.full_payto,
     144              :               debit_account);
     145           45 :   if (GNUNET_OK !=
     146           45 :       TALER_FAKEBANK_check_credit (fakebank,
     147              :                                    &amount,
     148              :                                    debit_account,
     149              :                                    credit_account,
     150              :                                    reserve_pub))
     151              :   {
     152            0 :     GNUNET_break (0);
     153            0 :     GNUNET_free (credit_account);
     154            0 :     GNUNET_free (debit_account);
     155            0 :     TALER_TESTING_interpreter_fail (is);
     156            0 :     return;
     157              :   }
     158           45 :   GNUNET_free (credit_account);
     159           45 :   GNUNET_free (debit_account);
     160           45 :   TALER_TESTING_interpreter_next (is);
     161              : }
     162              : 
     163              : 
     164              : /**
     165              :  * Free the state of a "bank check" CMD.
     166              :  *
     167              :  * @param cls closure.
     168              :  * @param cmd the command which is being cleaned up.
     169              :  */
     170              : static void
     171           45 : check_bank_admin_transfer_cleanup (void *cls,
     172              :                                    const struct TALER_TESTING_Command *cmd)
     173              : {
     174           45 :   struct BankAdminCheckState *bcs = cls;
     175              : 
     176              :   (void) cmd;
     177           45 :   GNUNET_free (bcs);
     178           45 : }
     179              : 
     180              : 
     181              : /**
     182              :  * Make a "bank check" CMD.  It checks whether a particular wire transfer to
     183              :  * the exchange (credit) has been made or not.
     184              :  *
     185              :  * @param label the command label.
     186              :  * @param amount the amount expected to be transferred.
     187              :  * @param debit_payto the account that gave money.
     188              :  * @param credit_payto the account that received money.
     189              :  * @param reserve_pub_ref command that provides the reserve public key to expect
     190              :  * @return the command
     191              :  */
     192              : struct TALER_TESTING_Command
     193           45 : TALER_TESTING_cmd_check_bank_admin_transfer (
     194              :   const char *label,
     195              :   const char *amount,
     196              :   struct TALER_FullPayto debit_payto,
     197              :   struct TALER_FullPayto credit_payto,
     198              :   const char *reserve_pub_ref)
     199              : {
     200              :   struct BankAdminCheckState *bcs;
     201              : 
     202           45 :   bcs = GNUNET_new (struct BankAdminCheckState);
     203           45 :   bcs->amount = amount;
     204           45 :   bcs->debit_payto = debit_payto;
     205           45 :   bcs->credit_payto = credit_payto;
     206           45 :   bcs->reserve_pub_ref = reserve_pub_ref;
     207              :   {
     208           45 :     struct TALER_TESTING_Command cmd = {
     209              :       .label = label,
     210              :       .cls = bcs,
     211              :       .run = &check_bank_admin_transfer_run,
     212              :       .cleanup = &check_bank_admin_transfer_cleanup
     213              :     };
     214              : 
     215           45 :     return cmd;
     216              :   }
     217              : }
        

Generated by: LCOV version 2.0-1