exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_bank_check_empty.c (3206B)


      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_check_empty.c
     21  * @brief command to check if a particular wire transfer took
     22  *        place.
     23  * @author Marcello Stanisci
     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  * Cleanup the state, only defined to respect the API.
     33  *
     34  * @param cls closure.
     35  * @param cmd the command which is being cleaned up.
     36  */
     37 static void
     38 check_bank_empty_cleanup
     39   (void *cls,
     40   const struct TALER_TESTING_Command *cmd)
     41 {
     42   (void) cls;
     43   (void) cmd;
     44   return;
     45 }
     46 
     47 
     48 /**
     49  * Run the command.
     50  *
     51  * @param cls closure.
     52  * @param cmd the command to execute.
     53  * @param is the interpreter state.
     54  */
     55 static void
     56 check_bank_empty_run (
     57   void *cls,
     58   const struct TALER_TESTING_Command *cmd,
     59   struct TALER_TESTING_Interpreter *is)
     60 {
     61   struct TALER_FAKEBANK_Handle *fakebank;
     62 
     63   (void) cls;
     64   (void) cmd;
     65   {
     66     const struct TALER_TESTING_Command *fakebank_cmd;
     67 
     68     fakebank_cmd
     69       = TALER_TESTING_interpreter_get_command (is,
     70                                                "fakebank");
     71     if (NULL == fakebank_cmd)
     72     {
     73       GNUNET_break (0);
     74       TALER_TESTING_interpreter_fail (is);
     75       return;
     76     }
     77     if (GNUNET_OK !=
     78         TALER_TESTING_get_trait_fakebank (fakebank_cmd,
     79                                           &fakebank))
     80     {
     81       GNUNET_break (0);
     82       TALER_TESTING_interpreter_fail (is);
     83       return;
     84     }
     85   }
     86   if (GNUNET_OK !=
     87       TALER_FAKEBANK_check_empty (fakebank))
     88   {
     89     GNUNET_break (0);
     90     TALER_TESTING_interpreter_fail (is);
     91     return;
     92   }
     93   TALER_TESTING_interpreter_next (is);
     94 }
     95 
     96 
     97 /**
     98  * Some commands (notably "bank history") could randomly
     99  * look for traits; this way makes sure we don't segfault.
    100  */
    101 static enum GNUNET_GenericReturnValue
    102 check_bank_empty_traits (void *cls,
    103                          const void **ret,
    104                          const char *trait,
    105                          unsigned int index)
    106 {
    107   (void) cls;
    108   (void) ret;
    109   (void) trait;
    110   (void) index;
    111   return GNUNET_SYSERR;
    112 }
    113 
    114 
    115 /**
    116  * Checks whether all the wire transfers got "checked"
    117  * by the "bank check" CMD.
    118  *
    119  * @param label command label.
    120  *
    121  * @return the command
    122  */
    123 struct TALER_TESTING_Command
    124 TALER_TESTING_cmd_check_bank_empty (const char *label)
    125 {
    126   struct TALER_TESTING_Command cmd = {
    127     .label = label,
    128     .run = &check_bank_empty_run,
    129     .cleanup = &check_bank_empty_cleanup,
    130     .traits = &check_bank_empty_traits
    131   };
    132 
    133   return cmd;
    134 }