LCOV - code coverage report
Current view: top level - testing - test_reconciliation.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 51 51 100.0 %
Date: 2025-08-28 06:06:54 Functions: 3 3 100.0 %

          Line data    Source code
       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 test_merchant_api.c
      21             :  * @brief testcase to test exchange's HTTP API interface
      22             :  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
      23             :  * @author Christian Grothoff
      24             :  * @author Marcello Stanisci
      25             :  */
      26             : #include "platform.h"
      27             : #include <gnunet/gnunet_time_lib.h>
      28             : #include <taler/taler_util.h>
      29             : #include <taler/taler_signatures.h>
      30             : #include <taler/taler_exchange_service.h>
      31             : #include <taler/taler_json_lib.h>
      32             : #include <gnunet/gnunet_util_lib.h>
      33             : #include <gnunet/gnunet_testing_lib.h>
      34             : #include <microhttpd.h>
      35             : #include <taler/taler_bank_service.h>
      36             : #include <taler/taler_fakebank_lib.h>
      37             : #include <taler/taler_testing_lib.h>
      38             : #include <taler/taler_error_codes.h>
      39             : #include "taler_merchant_testing_lib.h"
      40             : 
      41             : 
      42             : /**
      43             :  * The 'poll-orders-conclude-1' and other 'conclude'
      44             :  * commands should NOT wait for this timeout!
      45             :  */
      46             : #define POLL_ORDER_TIMEOUT \
      47             :         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
      48             : 
      49             : /**
      50             :  * The 'poll-orders-conclude-1x' and other 'conclude'
      51             :  * commands that should (!) wait for this timeout! Hence,
      52             :  * here we use a short value!
      53             :  */
      54             : #define POLL_ORDER_SHORT_TIMEOUT \
      55             :         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
      56             : 
      57             : /**
      58             :  * Configuration file we use.  One (big) configuration is used
      59             :  * for the various components for this test.
      60             :  */
      61             : static char *config_file;
      62             : 
      63             : /**
      64             :  * Exchange base URL.  Could also be taken from config.
      65             :  */
      66             : #define EXCHANGE_URL "http://localhost:8081/"
      67             : 
      68             : /**
      69             :  * Payto URI of the customer (payer).
      70             :  */
      71             : static struct TALER_FullPayto payer_payto;
      72             : 
      73             : /**
      74             :  * Payto URI of the exchange (escrow account).
      75             :  */
      76             : static struct TALER_FullPayto exchange_payto;
      77             : 
      78             : /**
      79             :  * Payto URI of the merchant (receiver).
      80             :  */
      81             : static struct TALER_FullPayto merchant_payto;
      82             : 
      83             : /**
      84             :  * Credentials for the test.
      85             :  */
      86             : static struct TALER_TESTING_Credentials cred;
      87             : 
      88             : /**
      89             :  * Merchant base URL.
      90             :  */
      91             : static const char *merchant_url;
      92             : 
      93             : /**
      94             :  * Merchant instance "i1a" base URL.
      95             :  */
      96             : static char *merchant_url_i1a;
      97             : 
      98             : /**
      99             :  * Account number of the exchange at the bank.
     100             :  */
     101             : #define EXCHANGE_ACCOUNT_NAME "2"
     102             : 
     103             : /**
     104             :  * Account number of some user.
     105             :  */
     106             : #define USER_ACCOUNT_NAME "62"
     107             : 
     108             : /**
     109             :  * Account number of some other user.
     110             :  */
     111             : #define USER_ACCOUNT_NAME2 "63"
     112             : 
     113             : /**
     114             :  * Account number used by the merchant
     115             :  */
     116             : #define MERCHANT_ACCOUNT_NAME "3"
     117             : 
     118             : static const char *order_1_transfers[] = {
     119             :   "post-transfer-1",
     120             :   NULL
     121             : };
     122             : 
     123             : 
     124             : /**
     125             :  * Run wire transfer of funds from some user's account to the
     126             :  * exchange.
     127             :  *
     128             :  * @param label label to use for the command.
     129             :  * @param amount amount to transfer, i.e. "EUR:1"
     130             :  * @param url exchange_url
     131             :  */
     132             : static struct TALER_TESTING_Command
     133           1 : cmd_transfer_to_exchange (const char *label,
     134             :                           const char *amount)
     135             : {
     136           1 :   return TALER_TESTING_cmd_admin_add_incoming (label,
     137             :                                                amount,
     138             :                                                &cred.ba,
     139             :                                                payer_payto);
     140             : }
     141             : 
     142             : 
     143             : /**
     144             :  * Main function that will tell the interpreter what commands to
     145             :  * run.
     146             :  *
     147             :  * @param cls closure
     148             :  */
     149             : static void
     150           1 : run (void *cls,
     151             :      struct TALER_TESTING_Interpreter *is)
     152             : {
     153             :   struct TALER_TESTING_Command pay[] = {
     154             :     /**
     155             :      * Move money to the exchange's bank account.
     156             :      */
     157           1 :     cmd_transfer_to_exchange ("create-reserve-1",
     158             :                               "EUR:5.01"),
     159             :     /**
     160             :      * Make a reserve exist, according to the previous transfer.
     161             :      */
     162           1 :     TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
     163             :                                       config_file),
     164           1 :     TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2",
     165             :                                                  "EUR:5.01",
     166             :                                                  payer_payto,
     167             :                                                  exchange_payto,
     168             :                                                  "create-reserve-1"),
     169           1 :     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
     170             :                                        "create-reserve-1",
     171             :                                        "EUR:5",
     172             :                                        0,
     173             :                                        MHD_HTTP_OK),
     174             :     /**
     175             :      * Check the reserve is depleted.
     176             :      */
     177           1 :     TALER_TESTING_cmd_status ("withdraw-status-1",
     178             :                               "create-reserve-1",
     179             :                               "EUR:0",
     180             :                               MHD_HTTP_OK),
     181           1 :     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1",
     182           1 :                                              cred.cfg,
     183             :                                              merchant_url,
     184             :                                              MHD_HTTP_OK,
     185             :                                              "1",
     186           1 :                                              GNUNET_TIME_UNIT_ZERO_TS, /* refund deadline */
     187           1 :                                              GNUNET_TIME_UNIT_FOREVER_TS, /* pay deadline */
     188             :                                              true, /* use claim token */
     189             :                                              "EUR:5.0",
     190             :                                              "x-taler-bank",
     191             :                                              "",
     192             :                                              "",
     193             :                                              NULL),
     194           1 :     TALER_TESTING_cmd_merchant_claim_order ("reclaim-1",
     195             :                                             merchant_url,
     196             :                                             MHD_HTTP_OK,
     197             :                                             "create-proposal-1",
     198             :                                             NULL),
     199           1 :     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1",
     200             :                                         merchant_url,
     201             :                                         "create-proposal-1",
     202             :                                         false,
     203             :                                         false,
     204             :                                         false,
     205             :                                         MHD_HTTP_PAYMENT_REQUIRED),
     206           1 :     TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1",
     207             :                                           merchant_url,
     208             :                                           "create-proposal-1",
     209             :                                           TALER_MERCHANT_OSC_CLAIMED,
     210             :                                           false,
     211             :                                           MHD_HTTP_OK,
     212             :                                           NULL),
     213           1 :     TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
     214             :                                           merchant_url,
     215             :                                           MHD_HTTP_OK,
     216             :                                           "create-proposal-1",
     217             :                                           "withdraw-coin-1",
     218             :                                           "EUR:5",
     219             :                                           "EUR:4.99",
     220             :                                           "session-0"),
     221           1 :     TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2a",
     222             :                                           merchant_url,
     223             :                                           "create-proposal-1",
     224             :                                           TALER_MERCHANT_OSC_PAID,
     225             :                                           false,
     226             :                                           MHD_HTTP_OK,
     227             :                                           NULL),
     228           1 :     TALER_TESTING_cmd_exec_aggregator ("run-aggregator",
     229             :                                        config_file),
     230           1 :     TALER_TESTING_cmd_exec_transfer ("run-transfer",
     231             :                                      config_file),
     232           1 :     TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-498c",
     233             :                                            EXCHANGE_URL,
     234             :                                            "EUR:4.98",
     235             :                                            exchange_payto,
     236             :                                            merchant_payto),
     237             :     // FIXME: replace by taler-merchant-wirewatch!
     238           1 :     TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1",
     239             :                                               &cred.ba,
     240             :                                               merchant_payto,
     241             :                                               merchant_url,
     242             :                                               "EUR:4.98",
     243             :                                               MHD_HTTP_NO_CONTENT,
     244             :                                               "deposit-simple",
     245             :                                               NULL),
     246           1 :     TALER_TESTING_cmd_depositcheck ("run-depositcheck",
     247             :                                     config_file),
     248           1 :     TALER_TESTING_cmd_run_tme ("run taler-merchant-reconciliation-1",
     249             :                                config_file),
     250           1 :     TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-2b",
     251             :                                            merchant_url,
     252             :                                            "create-proposal-1",
     253             :                                            // FIXME: we won't want paid, we want settled!
     254             :                                            TALER_MERCHANT_OSC_PAID,
     255             :                                            true, /* wired */
     256             :                                            order_1_transfers, /* "post-transfer-1" */
     257             :                                            false, /* refunded */
     258             :                                            NULL,
     259             :                                            NULL,
     260             :                                            MHD_HTTP_OK),
     261           1 :     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-2"),
     262           1 :     TALER_TESTING_cmd_end ()
     263             :   };
     264             : 
     265             :   struct TALER_TESTING_Command commands[] = {
     266             :     /* general setup */
     267           1 :     TALER_TESTING_cmd_run_fakebank (
     268             :       "run-fakebank",
     269           1 :       cred.cfg,
     270             :       "exchange-account-exchange"),
     271           1 :     TALER_TESTING_cmd_system_start (
     272             :       "start-taler",
     273             :       config_file,
     274             :       "-em",
     275             :       "-u", "exchange-account-exchange",
     276             :       "-r", "merchant-exchange-test",
     277             :       NULL),
     278           1 :     TALER_TESTING_cmd_get_exchange (
     279             :       "get-exchange",
     280           1 :       cred.cfg,
     281             :       NULL,
     282             :       true,
     283             :       true),
     284           1 :     TALER_TESTING_cmd_config (
     285             :       "config",
     286             :       merchant_url,
     287             :       MHD_HTTP_OK),
     288           1 :     TALER_TESTING_cmd_merchant_get_instances (
     289             :       "instances-empty",
     290             :       merchant_url,
     291             :       MHD_HTTP_OK,
     292             :       NULL),
     293           1 :     TALER_TESTING_cmd_merchant_post_instances (
     294             :       "instance-create-default-setup",
     295             :       merchant_url,
     296             :       "admin",
     297             :       MHD_HTTP_NO_CONTENT),
     298             :     // FIXME: setup full account for taler-merchant-wirewatch
     299           1 :     TALER_TESTING_cmd_merchant_post_account (
     300             :       "instance-create-default-account",
     301             :       merchant_url,
     302             :       merchant_payto,
     303             :       NULL, NULL,
     304             :       MHD_HTTP_OK),
     305           1 :     TALER_TESTING_cmd_merchant_post_instances (
     306             :       "instance-create-i1",
     307             :       merchant_url,
     308             :       "i1",
     309             :       MHD_HTTP_NO_CONTENT),
     310           1 :     TALER_TESTING_cmd_batch ("pay",
     311             :                              pay),
     312             :     /**
     313             :      * End the suite.
     314             :      */
     315           1 :     TALER_TESTING_cmd_end ()
     316             :   };
     317             : 
     318           1 :   TALER_TESTING_run (is,
     319             :                      commands);
     320           1 : }
     321             : 
     322             : 
     323             : int
     324           1 : main (int argc,
     325             :       char *const *argv)
     326             : {
     327             :   {
     328             :     char *cipher;
     329             : 
     330           1 :     cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
     331           1 :     GNUNET_assert (NULL != cipher);
     332           1 :     GNUNET_asprintf (&config_file,
     333             :                      "test_merchant_api-%s.conf",
     334             :                      cipher);
     335           1 :     GNUNET_free (cipher);
     336             :   }
     337           1 :   payer_payto.full_payto =
     338             :     (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
     339             :     "?receiver-name=" USER_ACCOUNT_NAME;
     340           1 :   exchange_payto.full_payto =
     341             :     (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
     342             :     "?receiver-name="
     343             :     EXCHANGE_ACCOUNT_NAME;
     344           1 :   merchant_payto.full_payto =
     345             :     (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
     346             :     "?receiver-name=" MERCHANT_ACCOUNT_NAME;
     347           1 :   merchant_url = "http://localhost:8080/";
     348           1 :   GNUNET_asprintf (&merchant_url_i1a,
     349             :                    "%sinstances/i1a/",
     350             :                    merchant_url);
     351           1 :   return TALER_TESTING_main (argv,
     352             :                              "INFO",
     353             :                              config_file,
     354             :                              "exchange-account-exchange",
     355             :                              TALER_TESTING_BS_FAKEBANK,
     356             :                              &cred,
     357             :                              &run,
     358             :                              NULL);
     359             : }
     360             : 
     361             : 
     362             : /* end of test_merchant_api.c */

Generated by: LCOV version 1.16