exchange

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

test_bank_api_twisted.c (5574B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2023 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/test_bank_api_twisted.c
     21  * @author Marcello Stanisci
     22  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
     23  * @author Christian Grothoff
     24  */
     25 #include "platform.h"
     26 #include "taler/taler_util.h"
     27 #include "taler/taler_signatures.h"
     28 #include "taler/taler_json_lib.h"
     29 #include <gnunet/gnunet_util_lib.h>
     30 #include <microhttpd.h>
     31 #include "taler/taler_bank_service.h"
     32 #include "taler/taler_fakebank_lib.h"
     33 #include "taler/taler_testing_lib.h"
     34 #include "taler/taler_twister_testing_lib.h"
     35 #include <taler/taler_twister_service.h>
     36 
     37 /**
     38  * Configuration file we use.  One (big) configuration is used
     39  * for the various components for this test.
     40  */
     41 #define CONFIG_FILE_FAKEBANK "test_bank_api_fakebank_twisted.conf"
     42 
     43 /**
     44  * Configuration file we use.
     45  */
     46 static const char *cfgfile;
     47 
     48 /**
     49  * Our credentials.
     50  */
     51 static struct TALER_TESTING_Credentials cred;
     52 
     53 /**
     54  * Which bank is the test running against?
     55  * Set up at runtime.
     56  */
     57 static enum TALER_TESTING_BankSystem bs;
     58 
     59 /**
     60  * (real) Twister URL.  Used at startup time to check if it runs.
     61  */
     62 static char *twister_url;
     63 
     64 /**
     65  * Twister process.
     66  */
     67 static struct GNUNET_Process *twisterd;
     68 
     69 
     70 /**
     71  * Main function that will tell
     72  * the interpreter what commands to run.
     73  *
     74  * @param cls closure
     75  */
     76 static void
     77 run (void *cls,
     78      struct TALER_TESTING_Interpreter *is)
     79 {
     80   struct TALER_WireTransferIdentifierRawP wtid;
     81   /* Authentication data to route our commands through twister. */
     82   struct TALER_BANK_AuthenticationData exchange_auth_twisted;
     83   const char *systype = NULL;
     84 
     85   (void) cls;
     86   memset (&wtid,
     87           0x5a,
     88           sizeof (wtid));
     89   GNUNET_memcpy (&exchange_auth_twisted,
     90                  &cred.ba,
     91                  sizeof (struct TALER_BANK_AuthenticationData));
     92   switch (bs)
     93   {
     94   case TALER_TESTING_BS_FAKEBANK:
     95     exchange_auth_twisted.wire_gateway_url
     96       = (char *) "http://localhost:8888/accounts/2/taler-wire-gateway/";
     97     systype = "-f";
     98     break;
     99   case TALER_TESTING_BS_IBAN:
    100     exchange_auth_twisted.wire_gateway_url
    101       = (char *) "http://localhost:8888/accounts/Exchange/taler-wire-gateway/";
    102     systype = "-b";
    103     break;
    104   }
    105   GNUNET_assert (NULL != systype);
    106 
    107   {
    108     struct TALER_TESTING_Command commands[] = {
    109       TALER_TESTING_cmd_system_start ("start-taler",
    110                                       cfgfile,
    111                                       systype,
    112                                       NULL),
    113       /* Test retrying transfer after failure. */
    114       TALER_TESTING_cmd_malform_response ("malform-transfer",
    115                                           cfgfile),
    116       TALER_TESTING_cmd_transfer_retry (
    117         TALER_TESTING_cmd_transfer ("debit-1",
    118                                     "EUR:3.22",
    119                                     &exchange_auth_twisted,
    120                                     cred.exchange_payto,
    121                                     cred.user42_payto,
    122                                     &wtid,
    123                                     "http://exchange.example.com/")),
    124       TALER_TESTING_cmd_end ()
    125     };
    126 
    127     TALER_TESTING_run (is,
    128                        commands);
    129   }
    130 }
    131 
    132 
    133 /**
    134  * Kill, wait, and destroy convenience function.
    135  *
    136  * @param[in] process process to purge.
    137  */
    138 static void
    139 purge_process (struct GNUNET_Process *process)
    140 {
    141   GNUNET_break (GNUNET_OK ==
    142                 GNUNET_process_kill (process,
    143                                      SIGINT));
    144   GNUNET_break (GNUNET_OK ==
    145                 GNUNET_process_wait (process,
    146                                      true,
    147                                      NULL,
    148                                      NULL));
    149   GNUNET_process_destroy (process);
    150 }
    151 
    152 
    153 int
    154 main (int argc,
    155       char *const *argv)
    156 {
    157   int ret;
    158 
    159   (void) argc;
    160   if (TALER_TESTING_has_in_name (argv[0],
    161                                  "_with_fakebank"))
    162   {
    163     bs = TALER_TESTING_BS_FAKEBANK;
    164     cfgfile = CONFIG_FILE_FAKEBANK;
    165   }
    166   else if (TALER_TESTING_has_in_name (argv[0],
    167                                       "_with_nexus"))
    168   {
    169     GNUNET_assert (0); /* FIXME: test with nexus not yet implemented */
    170     bs = TALER_TESTING_BS_IBAN;
    171     /* cfgfile = CONFIG_FILE_NEXUS; */
    172   }
    173   else
    174   {
    175     /* no bank service was specified.  */
    176     GNUNET_break (0);
    177     return 77;
    178   }
    179 
    180   /* FIXME: introduce commands for twister! */
    181   twister_url = TALER_TWISTER_prepare_twister (cfgfile);
    182   if (NULL == twister_url)
    183     return 77;
    184   twisterd = TALER_TWISTER_run_twister (cfgfile);
    185   if (NULL == twisterd)
    186     return 77;
    187   ret = TALER_TESTING_main (argv,
    188                             "INFO",
    189                             cfgfile,
    190                             "exchange-account-2",
    191                             bs,
    192                             &cred,
    193                             &run,
    194                             NULL);
    195   purge_process (twisterd);
    196   GNUNET_free (twister_url);
    197   return ret;
    198 }
    199 
    200 
    201 /* end of test_bank_api_twisted.c */