merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

test_reconciliation.c (12922B)


      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 src/testing/test_reconciliation.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/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  * Password of the merchant instances the test creates.
     70  */
     71 #define INSTANCE_PASSWORD "instance-password"
     72 
     73 /**
     74  * Payto URI of the customer (payer).
     75  */
     76 static struct TALER_FullPayto payer_payto;
     77 
     78 /**
     79  * Payto URI of the exchange (escrow account).
     80  */
     81 static struct TALER_FullPayto exchange_payto;
     82 
     83 /**
     84  * Payto URI of the merchant (receiver).
     85  */
     86 static struct TALER_FullPayto merchant_payto;
     87 
     88 /**
     89  * Credentials for the test.
     90  */
     91 static struct TALER_TESTING_Credentials cred;
     92 
     93 /**
     94  * Merchant base URL.
     95  */
     96 static const char *merchant_url;
     97 
     98 /**
     99  * Merchant instance "i1a" base URL.
    100  */
    101 static char *merchant_url_i1a;
    102 
    103 /**
    104  * Account number of the exchange at the bank.
    105  */
    106 #define EXCHANGE_ACCOUNT_NAME "2"
    107 
    108 /**
    109  * Account number of some user.
    110  */
    111 #define USER_ACCOUNT_NAME "62"
    112 
    113 /**
    114  * Account number of some other user.
    115  */
    116 #define USER_ACCOUNT_NAME2 "63"
    117 
    118 /**
    119  * Account number used by the merchant
    120  */
    121 #define MERCHANT_ACCOUNT_NAME "3"
    122 
    123 static const char *order_1_transfers[] = {
    124   "post-transfer-1",
    125   NULL
    126 };
    127 
    128 
    129 /**
    130  * Run wire transfer of funds from some user's account to the
    131  * exchange.
    132  *
    133  * @param label label to use for the command.
    134  * @param amount amount to transfer, i.e. "EUR:1"
    135  * @param url exchange_url
    136  */
    137 static struct TALER_TESTING_Command
    138 cmd_transfer_to_exchange (const char *label,
    139                           const char *amount)
    140 {
    141   return TALER_TESTING_cmd_admin_add_incoming (label,
    142                                                amount,
    143                                                &cred.ba,
    144                                                payer_payto);
    145 }
    146 
    147 
    148 /**
    149  * Main function that will tell the interpreter what commands to
    150  * run.
    151  *
    152  * @param cls closure
    153  */
    154 static void
    155 run (void *cls,
    156      struct TALER_TESTING_Interpreter *is)
    157 {
    158   struct TALER_TESTING_Command pay[] = {
    159     /**
    160      * Move money to the exchange's bank account.
    161      */
    162     cmd_transfer_to_exchange ("create-reserve-1",
    163                               "EUR:5.01"),
    164     /**
    165      * Make a reserve exist, according to the previous transfer.
    166      */
    167     TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
    168                                       config_file),
    169     TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2",
    170                                                  "EUR:5.01",
    171                                                  payer_payto,
    172                                                  exchange_payto,
    173                                                  "create-reserve-1"),
    174     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
    175                                        "create-reserve-1",
    176                                        "EUR:5",
    177                                        0,
    178                                        MHD_HTTP_OK),
    179     /**
    180      * Check the reserve is depleted.
    181      */
    182     TALER_TESTING_cmd_status ("withdraw-status-1",
    183                               "create-reserve-1",
    184                               "EUR:0",
    185                               MHD_HTTP_OK),
    186     TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1",
    187                                              cred.cfg,
    188                                              merchant_url,
    189                                              MHD_HTTP_OK,
    190                                              "1",
    191                                              GNUNET_TIME_UNIT_ZERO_TS, /* refund deadline */
    192                                              GNUNET_TIME_UNIT_FOREVER_TS, /* pay deadline */
    193                                              true, /* use claim token */
    194                                              "EUR:5.0",
    195                                              "x-taler-bank",
    196                                              "",
    197                                              "",
    198                                              NULL),
    199     TALER_TESTING_cmd_merchant_claim_order ("reclaim-1",
    200                                             merchant_url,
    201                                             MHD_HTTP_OK,
    202                                             "create-proposal-1",
    203                                             NULL),
    204     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1",
    205                                         merchant_url,
    206                                         "create-proposal-1",
    207                                         false,
    208                                         false,
    209                                         false,
    210                                         MHD_HTTP_PAYMENT_REQUIRED),
    211     TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1",
    212                                           merchant_url,
    213                                           "create-proposal-1",
    214                                           TALER_MERCHANT_OSC_CLAIMED,
    215                                           false,
    216                                           MHD_HTTP_OK,
    217                                           NULL),
    218     TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
    219                                           merchant_url,
    220                                           MHD_HTTP_OK,
    221                                           "create-proposal-1",
    222                                           "withdraw-coin-1",
    223                                           "EUR:5",
    224                                           "EUR:4.99",
    225                                           "session-0"),
    226     TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2a",
    227                                           merchant_url,
    228                                           "create-proposal-1",
    229                                           TALER_MERCHANT_OSC_PAID,
    230                                           false,
    231                                           MHD_HTTP_OK,
    232                                           NULL),
    233     TALER_TESTING_cmd_sleep (
    234       "Wait for wire transfer deadline",
    235       3),
    236     TALER_TESTING_cmd_exec_aggregator ("run-aggregator",
    237                                        config_file),
    238     TALER_TESTING_cmd_exec_transfer ("run-transfer",
    239                                      config_file),
    240     TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-498c",
    241                                            EXCHANGE_URL,
    242                                            "EUR:4.98",
    243                                            exchange_payto,
    244                                            merchant_payto),
    245     // FIXME: replace by taler-merchant-wirewatch!
    246     TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1",
    247                                               &cred.ba,
    248                                               merchant_payto,
    249                                               merchant_url,
    250                                               "EUR:4.98",
    251                                               MHD_HTTP_NO_CONTENT,
    252                                               "deposit-simple",
    253                                               NULL),
    254     TALER_TESTING_cmd_depositcheck ("run-depositcheck",
    255                                     config_file),
    256     TALER_TESTING_cmd_run_tme ("run taler-merchant-reconciliation-1",
    257                                config_file),
    258     TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-2b",
    259                                            merchant_url,
    260                                            "create-proposal-1",
    261                                            // FIXME: we won't want paid, we want settled!
    262                                            TALER_MERCHANT_OSC_PAID,
    263                                            true, /* wired */
    264                                            order_1_transfers, /* "post-transfer-1" */
    265                                            false, /* refunded */
    266                                            NULL,
    267                                            NULL,
    268                                            MHD_HTTP_OK),
    269     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-2"),
    270     TALER_TESTING_cmd_end ()
    271   };
    272 
    273   struct TALER_TESTING_Command commands[] = {
    274     /* general setup */
    275     TALER_TESTING_cmd_run_fakebank (
    276       "run-fakebank",
    277       cred.cfg,
    278       "exchange-account-exchange"),
    279     TALER_TESTING_cmd_system_start (
    280       "start-taler",
    281       config_file,
    282       "-em",
    283       "-u", "exchange-account-exchange",
    284       "-r", "merchant-exchange-test",
    285       NULL),
    286     TALER_TESTING_cmd_get_exchange (
    287       "get-exchange",
    288       cred.cfg,
    289       NULL,
    290       true,
    291       true),
    292     TALER_TESTING_cmd_config (
    293       "config",
    294       merchant_url,
    295       MHD_HTTP_OK),
    296     TALER_TESTING_cmd_merchant_get_instances (
    297       "instances-empty",
    298       merchant_url,
    299       MHD_HTTP_OK,
    300       NULL),
    301     TALER_TESTING_cmd_merchant_post_instances_with_password (
    302       "instance-create-default-setup",
    303       merchant_url,
    304       "admin",
    305       INSTANCE_PASSWORD,
    306       MHD_HTTP_NO_CONTENT),
    307     TALER_TESTING_cmd_merchant_login (
    308       "login-admin",
    309       merchant_url,
    310       "admin",
    311       INSTANCE_PASSWORD),
    312     // FIXME: setup full account for taler-merchant-wirewatch
    313     TALER_TESTING_cmd_merchant_post_account (
    314       "instance-create-default-account",
    315       merchant_url,
    316       merchant_payto,
    317       NULL, NULL,
    318       MHD_HTTP_OK),
    319     TALER_TESTING_cmd_merchant_post_instances_with_password (
    320       "instance-create-i1",
    321       merchant_url,
    322       "i1",
    323       INSTANCE_PASSWORD,
    324       MHD_HTTP_NO_CONTENT),
    325     TALER_TESTING_cmd_batch ("pay",
    326                              pay),
    327     /**
    328      * End the suite.
    329      */
    330     TALER_TESTING_cmd_end ()
    331   };
    332 
    333   TALER_TESTING_run (is,
    334                      commands);
    335 }
    336 
    337 
    338 int
    339 main (int argc,
    340       char *const *argv)
    341 {
    342   {
    343     char *cipher;
    344 
    345     cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
    346     GNUNET_assert (NULL != cipher);
    347     GNUNET_asprintf (&config_file,
    348                      "test_merchant_api-%s.conf",
    349                      cipher);
    350     GNUNET_free (cipher);
    351   }
    352   payer_payto.full_payto =
    353     (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
    354     "?receiver-name=" USER_ACCOUNT_NAME;
    355   exchange_payto.full_payto =
    356     (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
    357     "?receiver-name="
    358     EXCHANGE_ACCOUNT_NAME;
    359   merchant_payto.full_payto =
    360     (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
    361     "?receiver-name=" MERCHANT_ACCOUNT_NAME;
    362   merchant_url = "http://localhost:8080/";
    363   GNUNET_asprintf (&merchant_url_i1a,
    364                    "%sinstances/i1a/",
    365                    merchant_url);
    366   return TALER_TESTING_main (argv,
    367                              "INFO",
    368                              config_file,
    369                              "exchange-account-exchange",
    370                              TALER_TESTING_BS_FAKEBANK,
    371                              &cred,
    372                              &run,
    373                              NULL);
    374 }
    375 
    376 
    377 /* end of test_merchant_api.c */