LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_bank_admin_check.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 34 49 69.4 %
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) 2018-2020 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 "platform.h"
      26             : #include "taler_json_lib.h"
      27             : #include <gnunet/gnunet_curl_lib.h>
      28             : #include "taler_testing_lib.h"
      29             : #include "taler_fakebank_lib.h"
      30             : 
      31             : 
      32             : /**
      33             :  * State for a "bank check" CMD.
      34             :  */
      35             : struct BankAdminCheckState
      36             : {
      37             : 
      38             :   /**
      39             :    * Expected transferred amount.
      40             :    */
      41             :   const char *amount;
      42             : 
      43             :   /**
      44             :    * Expected debit bank account.
      45             :    */
      46             :   const char *debit_payto;
      47             : 
      48             :   /**
      49             :    * Expected credit bank account.
      50             :    */
      51             :   const char *credit_payto;
      52             : 
      53             :   /**
      54             :    * Command providing the reserve public key trait to use.
      55             :    */
      56             :   const char *reserve_pub_ref;
      57             : 
      58             :   /**
      59             :    * Interpreter state.
      60             :    */
      61             :   struct TALER_TESTING_Interpreter *is;
      62             : 
      63             : };
      64             : 
      65             : /**
      66             :  * Run the command.
      67             :  *
      68             :  * @param cls closure.
      69             :  * @param cmd the command to execute.
      70             :  * @param is the interpreter state.
      71             :  */
      72             : static void
      73          16 : check_bank_admin_transfer_run (void *cls,
      74             :                                const struct TALER_TESTING_Command *cmd,
      75             :                                struct TALER_TESTING_Interpreter *is)
      76             : {
      77          16 :   struct BankAdminCheckState *bcs = cls;
      78             :   struct TALER_Amount amount;
      79             :   char *debit_account;
      80             :   char *credit_account;
      81             :   const char *debit_payto;
      82             :   const char *credit_payto;
      83             :   const struct TALER_ReservePublicKeyP *reserve_pub;
      84             :   const struct TALER_TESTING_Command *cmd_ref;
      85             : 
      86             :   (void) cmd;
      87             :   cmd_ref
      88          16 :     = TALER_TESTING_interpreter_lookup_command (is,
      89             :                                                 bcs->reserve_pub_ref);
      90          16 :   if (NULL == cmd_ref)
      91             :   {
      92           0 :     GNUNET_break (0);
      93           0 :     TALER_TESTING_interpreter_fail (is);
      94           0 :     return;
      95             :   }
      96          16 :   if (GNUNET_OK !=
      97          16 :       TALER_TESTING_get_trait_reserve_pub (cmd_ref,
      98             :                                            0,
      99             :                                            &reserve_pub))
     100             :   {
     101           0 :     GNUNET_break (0);
     102           0 :     TALER_LOG_ERROR ("Command reference fails to provide reserve public key\n");
     103           0 :     TALER_TESTING_interpreter_fail (is);
     104           0 :     return;
     105             :   }
     106          16 :   TALER_LOG_INFO ("Deposit reference NOT given\n");
     107          16 :   debit_payto = bcs->debit_payto;
     108          16 :   credit_payto = bcs->credit_payto;
     109          16 :   if (GNUNET_OK !=
     110          16 :       TALER_string_to_amount (bcs->amount,
     111             :                               &amount))
     112             :   {
     113           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     114             :                 "Failed to parse amount `%s' at %u\n",
     115             :                 bcs->amount,
     116             :                 is->ip);
     117           0 :     TALER_TESTING_interpreter_fail (is);
     118           0 :     return;
     119             :   }
     120          16 :   debit_account = TALER_xtalerbank_account_from_payto (debit_payto);
     121          16 :   credit_account = TALER_xtalerbank_account_from_payto (credit_payto);
     122          16 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     123             :               "converted debit_payto (%s) to debit_account (%s)\n",
     124             :               debit_payto,
     125             :               debit_account);
     126          16 :   if (GNUNET_OK !=
     127          16 :       TALER_FAKEBANK_check_credit (is->fakebank,
     128             :                                    &amount,
     129             :                                    debit_account,
     130             :                                    credit_account,
     131             :                                    reserve_pub))
     132             :   {
     133           0 :     GNUNET_break (0);
     134           0 :     GNUNET_free (credit_account);
     135           0 :     GNUNET_free (debit_account);
     136           0 :     TALER_TESTING_interpreter_fail (is);
     137           0 :     return;
     138             :   }
     139          16 :   GNUNET_free (credit_account);
     140          16 :   GNUNET_free (debit_account);
     141          16 :   TALER_TESTING_interpreter_next (is);
     142             : }
     143             : 
     144             : 
     145             : /**
     146             :  * Free the state of a "bank check" CMD.
     147             :  *
     148             :  * @param cls closure.
     149             :  * @param cmd the command which is being cleaned up.
     150             :  */
     151             : static void
     152          16 : check_bank_admin_transfer_cleanup (void *cls,
     153             :                                    const struct TALER_TESTING_Command *cmd)
     154             : {
     155          16 :   struct BankAdminCheckState *bcs = cls;
     156             : 
     157             :   (void) cmd;
     158          16 :   GNUNET_free (bcs);
     159          16 : }
     160             : 
     161             : 
     162             : /**
     163             :  * Offer internal data from a "bank admin check" CMD state.
     164             :  *
     165             :  * @param cls closure.
     166             :  * @param[out] ret result.
     167             :  * @param trait name of the trait.
     168             :  * @param index index number of the object to offer.
     169             :  * @return #GNUNET_OK on success.
     170             :  */
     171             : static int
     172          54 : check_bank_admin_transfer_traits (void *cls,
     173             :                                   const void **ret,
     174             :                                   const char *trait,
     175             :                                   unsigned int index)
     176             : {
     177             :   struct TALER_TESTING_Trait traits[] = {
     178          54 :     TALER_TESTING_trait_end ()
     179             :   };
     180             : 
     181             :   (void) cls;
     182          54 :   return TALER_TESTING_get_trait (traits,
     183             :                                   ret,
     184             :                                   trait,
     185             :                                   index);
     186             : }
     187             : 
     188             : 
     189             : /**
     190             :  * Make a "bank check" CMD.  It checks whether a particular wire transfer to
     191             :  * the exchange (credit) has been made or not.
     192             :  *
     193             :  * @param label the command label.
     194             :  * @param amount the amount expected to be transferred.
     195             :  * @param debit_payto the account that gave money.
     196             :  * @param credit_payto the account that received money.
     197             :  * @param reserve_pub_ref command that provides the reserve public key to expect
     198             :  * @return the command
     199             :  */
     200             : struct TALER_TESTING_Command
     201          16 : TALER_TESTING_cmd_check_bank_admin_transfer
     202             :   (const char *label,
     203             :   const char *amount,
     204             :   const char *debit_payto,
     205             :   const char *credit_payto,
     206             :   const char *reserve_pub_ref)
     207             : {
     208             :   struct BankAdminCheckState *bcs;
     209             : 
     210          16 :   bcs = GNUNET_new (struct BankAdminCheckState);
     211          16 :   bcs->amount = amount;
     212          16 :   bcs->debit_payto = debit_payto;
     213          16 :   bcs->credit_payto = credit_payto;
     214          16 :   bcs->reserve_pub_ref = reserve_pub_ref;
     215             :   {
     216          16 :     struct TALER_TESTING_Command cmd = {
     217             :       .label = label,
     218             :       .cls = bcs,
     219             :       .run = &check_bank_admin_transfer_run,
     220             :       .cleanup = &check_bank_admin_transfer_cleanup,
     221             :       .traits = &check_bank_admin_transfer_traits
     222             :     };
     223             : 
     224          16 :     return cmd;
     225             :   }
     226             : }

Generated by: LCOV version 1.14