exchange

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

test_exchange_api.c (46789B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014--2022 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_exchange_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 "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 <gnunet/gnunet_testing_lib.h>
     31 #include <microhttpd.h>
     32 #include "taler/taler_bank_service.h"
     33 #include "taler/taler_testing_lib.h"
     34 
     35 /**
     36  * Configuration file we use.  One (big) configuration is used
     37  * for the various components for this test.
     38  */
     39 static char *config_file;
     40 
     41 /**
     42  * Special configuration file to use when we want reserves
     43  * to expire 'immediately'.
     44  */
     45 static char *config_file_expire_reserve_now;
     46 
     47 /**
     48  * Our credentials.
     49  */
     50 static struct TALER_TESTING_Credentials cred;
     51 
     52 /**
     53  * Some tests behave differently when using CS as we cannot
     54  * reuse the coin private key for different denominations
     55  * due to the derivation of it with the /csr values. Hence
     56  * some tests behave differently in CS mode, hence this
     57  * flag.
     58  */
     59 static bool uses_cs;
     60 
     61 /**
     62  * Execute the taler-exchange-wirewatch command with
     63  * our configuration file.
     64  *
     65  * @param label label to use for the command.
     66  */
     67 #define CMD_EXEC_WIREWATCH(label) \
     68         TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, \
     69                                            "exchange-account-2")
     70 
     71 /**
     72  * Execute the taler-exchange-aggregator, closer and transfer commands with
     73  * our configuration file.
     74  *
     75  * @param label label to use for the command.
     76  */
     77 #define CMD_EXEC_AGGREGATOR(label) \
     78         TALER_TESTING_cmd_sleep ("sleep-before-aggregator", 2), \
     79         TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_file), \
     80         TALER_TESTING_cmd_exec_transfer (label "-transfer", config_file)
     81 
     82 
     83 /**
     84  * Run wire transfer of funds from some user's account to the
     85  * exchange.
     86  *
     87  * @param label label to use for the command.
     88  * @param amount amount to transfer, i.e. "EUR:1"
     89  */
     90 #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
     91         TALER_TESTING_cmd_admin_add_incoming (label, amount, \
     92                                               &cred.ba,                \
     93                                               cred.user42_payto)
     94 
     95 /**
     96  * Main function that will tell the interpreter what commands to
     97  * run.
     98  *
     99  * @param cls closure
    100  * @param is interpreter we use to run commands
    101  */
    102 static void
    103 run (void *cls,
    104      struct TALER_TESTING_Interpreter *is)
    105 {
    106   /**
    107    * Test withdrawal plus spending.
    108    */
    109   struct TALER_TESTING_Command withdraw[] = {
    110     /**
    111      * Move money to the exchange's bank account.
    112      */
    113     CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
    114                               "EUR:6.02"),
    115     TALER_TESTING_cmd_reserve_poll ("poll-reserve-1",
    116                                     "create-reserve-1",
    117                                     "EUR:6.02",
    118                                     GNUNET_TIME_UNIT_MINUTES,
    119                                     MHD_HTTP_OK),
    120     TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
    121                                                  "EUR:6.02",
    122                                                  cred.user42_payto,
    123                                                  cred.exchange_payto,
    124                                                  "create-reserve-1"),
    125     /**
    126      * Make a reserve exist, according to the previous
    127      * transfer.
    128      */
    129     CMD_EXEC_WIREWATCH ("wirewatch-1"),
    130     TALER_TESTING_cmd_reserve_poll_finish ("finish-poll-reserve-1",
    131                                            GNUNET_TIME_relative_multiply (
    132                                              GNUNET_TIME_UNIT_SECONDS,
    133                                              2),
    134                                            "poll-reserve-1"),
    135     /**
    136      * Withdraw EUR:5.
    137      */
    138     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
    139                                        "create-reserve-1",
    140                                        "EUR:5",
    141                                        0, /* age restriction off */
    142                                        MHD_HTTP_OK),
    143     /**
    144      * Idempotent withdrawal.  Note that in the case of CS, this is _not_
    145      * idempotent because the blinding nonces still differ, so instead,
    146      * it is an overcharging of the reserve.
    147      */
    148     TALER_TESTING_cmd_withdraw_amount_reuse_key ("withdraw-coin-1-idem",
    149                                                  "create-reserve-1",
    150                                                  "EUR:5",
    151                                                  0, /* age restriction off */
    152                                                  "withdraw-coin-1",
    153                                                  (uses_cs)
    154                                                  ? MHD_HTTP_CONFLICT
    155                                                  : MHD_HTTP_OK),
    156     /**
    157     * Withdraw EUR:1 using the SAME private coin key as for the previous coin
    158     * (in violation of the specification, to be detected on spending!).
    159     * However, note that this does NOT work with 'CS', as for a different
    160     * denomination we get different R0/R1 values from the exchange, and
    161     * thus will generate a different coin private key as R0/R1 are hashed
    162     * into the coin priv. So here, we fail to 'reuse' the key due to the
    163     * cryptographic construction!
    164     */
    165     TALER_TESTING_cmd_withdraw_amount_reuse_key ("withdraw-coin-1x",
    166                                                  "create-reserve-1",
    167                                                  "EUR:1",
    168                                                  0, /* age restriction off */
    169                                                  "withdraw-coin-1",
    170                                                  MHD_HTTP_OK),
    171     /**
    172      * Check the reserve is depleted.
    173      */
    174     TALER_TESTING_cmd_status ("status-1",
    175                               "create-reserve-1",
    176                               "EUR:0",
    177                               MHD_HTTP_OK),
    178     /*
    179      * Try to overdraw.
    180      */
    181     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
    182                                        "create-reserve-1",
    183                                        "EUR:5",
    184                                        0, /* age restriction off */
    185                                        MHD_HTTP_CONFLICT),
    186     TALER_TESTING_cmd_end ()
    187   };
    188 
    189   struct TALER_TESTING_Command spend[] = {
    190     /**
    191      * Spend the coin.
    192      */
    193     TALER_TESTING_cmd_set_var (
    194       "account-priv",
    195       TALER_TESTING_cmd_deposit (
    196         "deposit-simple-fail-kyc",
    197         "withdraw-coin-1",
    198         0,
    199         cred.user42_payto,
    200         "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
    201         GNUNET_TIME_UNIT_ZERO,
    202         "EUR:5",
    203         MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS)),
    204     TALER_TESTING_cmd_admin_add_kycauth (
    205       "kyc-auth-transfer",
    206       "EUR:0.01",
    207       &cred.ba,
    208       cred.user42_payto,
    209       "deposit-simple-fail-kyc"),
    210     CMD_EXEC_WIREWATCH (
    211       "import-kyc-account-withdraw"),
    212     TALER_TESTING_cmd_deposit_replay (
    213       "deposit-simple",
    214       "deposit-simple-fail-kyc",
    215       MHD_HTTP_OK),
    216     TALER_TESTING_cmd_deposit_replay (
    217       "deposit-simple-replay-1",
    218       "deposit-simple",
    219       MHD_HTTP_OK),
    220     TALER_TESTING_cmd_sleep (
    221       "sleep-before-deposit-replay",
    222       1),
    223     TALER_TESTING_cmd_deposit_replay (
    224       "deposit-simple-replay-2",
    225       "deposit-simple",
    226       MHD_HTTP_OK),
    227     /* This creates a conflict, as we have the same coin public key (reuse!),
    228        but different denomination public keys (which is not allowed).
    229        However, note that this does NOT work with 'CS', as for a different
    230        denomination we get different R0/R1 values from the exchange, and
    231        thus will generate a different coin private key as R0/R1 are hashed
    232        into the coin priv. So here, we fail to 'reuse' the key due to the
    233        cryptographic construction! */
    234     TALER_TESTING_cmd_deposit (
    235       "deposit-reused-coin-key-failure",
    236       "withdraw-coin-1x",
    237       0,
    238       cred.user42_payto,
    239       "{\"items\":[{\"name\":\"conflicting ice cream\",\"value\":1}]}",
    240       GNUNET_TIME_UNIT_ZERO,
    241       "EUR:1",
    242       uses_cs
    243       ? MHD_HTTP_OK
    244       : MHD_HTTP_CONFLICT),
    245     /**
    246      * Try to double spend using different wire details.
    247      */
    248     TALER_TESTING_cmd_admin_add_kycauth (
    249       "kyc-auth-transfer-2",
    250       "EUR:0.01",
    251       &cred.ba,
    252       cred.user43_payto,
    253       "deposit-simple-fail-kyc"),
    254     CMD_EXEC_WIREWATCH (
    255       "import-kyc-account-1"),
    256     TALER_TESTING_cmd_deposit (
    257       "deposit-double-1",
    258       "withdraw-coin-1",
    259       0,
    260       cred.user43_payto,
    261       "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
    262       GNUNET_TIME_UNIT_ZERO,
    263       "EUR:5",
    264       MHD_HTTP_CONFLICT),
    265     /* Try to double spend using a different transaction id.
    266      * The test needs the contract terms to differ. This
    267      * is currently the case because of the "timestamp" field,
    268      * which is set automatically by #TALER_TESTING_cmd_deposit().
    269      * This could theoretically fail if at some point a deposit
    270      * command executes in less than 1 ms. */
    271     TALER_TESTING_cmd_deposit (
    272       "deposit-double-1",
    273       "withdraw-coin-1",
    274       0,
    275       cred.user43_payto,
    276       "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
    277       GNUNET_TIME_UNIT_ZERO,
    278       "EUR:5",
    279       MHD_HTTP_CONFLICT),
    280     /**
    281      * Try to double spend with different proposal.
    282      */
    283     TALER_TESTING_cmd_deposit (
    284       "deposit-double-2",
    285       "withdraw-coin-1",
    286       0,
    287       cred.user43_payto,
    288       "{\"items\":[{\"name\":\"ice cream\",\"value\":2}]}",
    289       GNUNET_TIME_UNIT_ZERO,
    290       "EUR:5",
    291       MHD_HTTP_CONFLICT),
    292     TALER_TESTING_cmd_end ()
    293   };
    294 
    295   struct TALER_TESTING_Command refresh[] = {
    296     /**
    297      * Try to melt the coin that shared the private key with another
    298      * coin (should fail). Note that in the CS-case, we fail also
    299      * with MHD_HTTP_CONFLICT, but for a different reason: here it
    300      * is not a denomination conflict, but a double-spending conflict.
    301      */
    302     TALER_TESTING_cmd_melt (
    303       "refresh-melt-reused-coin-key-failure",
    304       "withdraw-coin-1x",
    305       MHD_HTTP_CONFLICT,
    306       NULL),
    307 
    308     /* Fill reserve with EUR:5, 1ct is for fees. */
    309     CMD_TRANSFER_TO_EXCHANGE (
    310       "refresh-create-reserve-1",
    311       "EUR:5.01"),
    312     TALER_TESTING_cmd_check_bank_admin_transfer (
    313       "ck-refresh-create-reserve-1",
    314       "EUR:5.01",
    315       cred.user42_payto,
    316       cred.exchange_payto,
    317       "refresh-create-reserve-1"),
    318     /**
    319      * Make previous command effective.
    320      */
    321     CMD_EXEC_WIREWATCH ("wirewatch-2"),
    322     /**
    323      * Withdraw EUR:5.
    324      */
    325     TALER_TESTING_cmd_withdraw_amount (
    326       "refresh-withdraw-coin-1",
    327       "refresh-create-reserve-1",
    328       "EUR:5",
    329       0,                                  /* age restriction off */
    330       MHD_HTTP_OK),
    331     /* Try to partially spend (deposit) 1 EUR of the 5 EUR coin
    332      * (in full) (merchant would receive EUR:0.99 due to 1 ct
    333      * deposit fee)
    334      */
    335     TALER_TESTING_cmd_deposit (
    336       "refresh-deposit-partial",
    337       "refresh-withdraw-coin-1",
    338       0,
    339       cred.user42_payto,
    340       "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
    341       GNUNET_TIME_UNIT_ZERO,
    342       "EUR:1",
    343       MHD_HTTP_OK),
    344     /**
    345      * Melt the rest of the coin's value
    346      * (EUR:4.00 = 3x EUR:1.03 + 7x EUR:0.13) */
    347     TALER_TESTING_cmd_melt_double (
    348       "refresh-melt-1",
    349       "refresh-withdraw-coin-1",
    350       MHD_HTTP_OK,
    351       NULL),
    352     /**
    353      * Complete (successful) melt operation, and
    354      * withdraw the coins
    355      */
    356     TALER_TESTING_cmd_melt_reveal (
    357       "refresh-reveal-1",
    358       "refresh-melt-1",
    359       MHD_HTTP_OK),
    360     /**
    361      * Do it again to check idempotency
    362      */
    363     TALER_TESTING_cmd_melt_reveal (
    364       "refresh-reveal-1-idempotency",
    365       "refresh-melt-1",
    366       MHD_HTTP_OK),
    367     /**
    368      * Try to spend a refreshed EUR:1 coin
    369      */
    370     TALER_TESTING_cmd_deposit (
    371       "refresh-deposit-refreshed-1a",
    372       "refresh-reveal-1-idempotency",
    373       0,
    374       cred.user42_payto,
    375       "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
    376       GNUNET_TIME_UNIT_ZERO,
    377       "EUR:1",
    378       MHD_HTTP_OK),
    379     /**
    380      * Try to spend a refreshed EUR:0.1 coin
    381      */
    382     TALER_TESTING_cmd_deposit (
    383       "refresh-deposit-refreshed-1b",
    384       "refresh-reveal-1",
    385       3,
    386       cred.user43_payto,
    387       "{\"items\":[{\"name\":\"cheap ice cream\",\"value\":3}]}",
    388       GNUNET_TIME_UNIT_ZERO,
    389       "EUR:0.1",
    390       MHD_HTTP_OK),
    391     /* Test running a failing melt operation (same operation
    392      * again must fail) */
    393     TALER_TESTING_cmd_melt (
    394       "refresh-melt-failing",
    395       "refresh-withdraw-coin-1",
    396       MHD_HTTP_CONFLICT,
    397       NULL),
    398     /* Test running a failing melt operation (on a coin that
    399        was itself revealed and subsequently deposited) */
    400     TALER_TESTING_cmd_melt (
    401       "refresh-melt-failing-2",
    402       "refresh-reveal-1",
    403       MHD_HTTP_CONFLICT,
    404       NULL),
    405     /* revealed melt: transfer_pubs and ev_sigs in the history;
    406        5 - 1 (deposit) - 3.17 (melt: 3 * 1.01 + 0.11 + 0.03 fee) */
    407     TALER_TESTING_cmd_coin_history (
    408       "coin-history-melted",
    409       "refresh-withdraw-coin-1",
    410       "EUR:0.83",
    411       MHD_HTTP_OK),
    412 
    413     /**
    414      * Refresh like a client that does not yet include the transfer
    415      * public keys in the refresh commitment (#11862), which the
    416      * exchange must still accept and reveal.
    417      */
    418     CMD_TRANSFER_TO_EXCHANGE (
    419       "refresh-create-reserve-legacy",
    420       "EUR:5.01"),
    421     TALER_TESTING_cmd_check_bank_admin_transfer (
    422       "ck-refresh-create-reserve-legacy",
    423       "EUR:5.01",
    424       cred.user42_payto,
    425       cred.exchange_payto,
    426       "refresh-create-reserve-legacy"),
    427     CMD_EXEC_WIREWATCH ("wirewatch-refresh-legacy"),
    428     TALER_TESTING_cmd_withdraw_amount (
    429       "refresh-withdraw-coin-legacy",
    430       "refresh-create-reserve-legacy",
    431       "EUR:5",
    432       0,                                  /* age restriction off */
    433       MHD_HTTP_OK),
    434     TALER_TESTING_cmd_melt_with_legacy_commitment (
    435       TALER_TESTING_cmd_melt_double (
    436         "refresh-melt-legacy",
    437         "refresh-withdraw-coin-legacy",
    438         MHD_HTTP_OK,
    439         NULL)),
    440     TALER_TESTING_cmd_melt_reveal (
    441       "refresh-reveal-legacy",
    442       "refresh-melt-legacy",
    443       MHD_HTTP_OK),
    444     TALER_TESTING_cmd_melt_reveal (
    445       "refresh-reveal-legacy-idempotency",
    446       "refresh-melt-legacy",
    447       MHD_HTTP_OK),
    448     TALER_TESTING_cmd_coin_history (
    449       "coin-history-melted-legacy",
    450       "refresh-withdraw-coin-legacy",
    451       "EUR:1.83",
    452       MHD_HTTP_OK),
    453 
    454     TALER_TESTING_cmd_end ()
    455   };
    456 
    457   /**
    458    * Test withdrawal with age restriction.  Success is expected, so it MUST be
    459    * called _after_ TALER_TESTING_cmd_exec_offline_sign_extensions is called,
    460    * i. e. age restriction is activated in the exchange!
    461    *
    462    * FIXME[oec]: create a test that tries to withdraw coins with age restriction but
    463    * (expectedly) fails because the exchange doesn't support age restriction
    464    * yet.
    465    */
    466   struct TALER_TESTING_Command withdraw_age[] = {
    467     /**
    468      * Move money to the exchange's bank account.
    469      */
    470     CMD_TRANSFER_TO_EXCHANGE (
    471       "create-reserve-age",
    472       "EUR:6.01"),
    473     TALER_TESTING_cmd_check_bank_admin_transfer (
    474       "check-create-reserve-age",
    475       "EUR:6.01",
    476       cred.user42_payto,
    477       cred.exchange_payto,
    478       "create-reserve-age"),
    479     /**
    480      * Make a reserve exist, according to the previous
    481      * transfer.
    482      */
    483     CMD_EXEC_WIREWATCH ("wirewatch-age"),
    484     /**
    485      * Withdraw EUR:5.
    486      */
    487     TALER_TESTING_cmd_withdraw_amount (
    488       "withdraw-coin-age-1",
    489       "create-reserve-age",
    490       "EUR:5",
    491       13,
    492       MHD_HTTP_OK),
    493 
    494     TALER_TESTING_cmd_end ()
    495   };
    496 
    497   struct TALER_TESTING_Command spend_age[] = {
    498     /**
    499      * Spend the coin.
    500      */
    501     TALER_TESTING_cmd_deposit (
    502       "deposit-simple-age",
    503       "withdraw-coin-age-1",
    504       0,
    505       cred.user42_payto,
    506       "{\"items\":[{\"name\":\"unique ice cream\",\"value\":1}]}",
    507       GNUNET_TIME_UNIT_ZERO,
    508       "EUR:4.99",
    509       MHD_HTTP_OK),
    510     TALER_TESTING_cmd_deposit_replay (
    511       "deposit-simple-replay-age",
    512       "deposit-simple-age",
    513       MHD_HTTP_OK),
    514     TALER_TESTING_cmd_deposit_replay (
    515       "deposit-simple-replay-age-1",
    516       "deposit-simple-age",
    517       MHD_HTTP_OK),
    518     TALER_TESTING_cmd_sleep (
    519       "sleep-before-age-deposit-replay",
    520       1),
    521     TALER_TESTING_cmd_deposit_replay (
    522       "deposit-simple-replay-age-2",
    523       "deposit-simple-age",
    524       MHD_HTTP_OK),
    525     TALER_TESTING_cmd_end ()
    526   };
    527 
    528   struct TALER_TESTING_Command track[] = {
    529     /* Try resolving a deposit's WTID, as we never triggered
    530      * execution of transactions, the answer should be that
    531      * the exchange knows about the deposit, but has no WTID yet.
    532      */
    533     TALER_TESTING_cmd_deposits_get (
    534       "deposit-wtid-found",
    535       "deposit-simple",
    536       0,
    537       MHD_HTTP_ACCEPTED,
    538       NULL),
    539     /* Try resolving a deposit's WTID for a failed deposit.
    540      * As the deposit failed, the answer should be that the
    541      * exchange does NOT know about the deposit.
    542      */
    543     TALER_TESTING_cmd_deposits_get (
    544       "deposit-wtid-failing",
    545       "deposit-double-2",
    546       0,
    547       MHD_HTTP_NOT_FOUND,
    548       NULL),
    549     /* Try resolving an undefined (all zeros) WTID; this
    550      * should fail as obviously the exchange didn't use that
    551      * WTID value for any transaction.
    552      */
    553     TALER_TESTING_cmd_track_transfer_empty (
    554       "wire-deposit-failing",
    555       NULL,
    556       MHD_HTTP_NOT_FOUND),
    557     /* Run transfers. */
    558     CMD_EXEC_AGGREGATOR ("run-aggregator"),
    559     /**
    560      * Check all the transfers took place.
    561      */
    562     TALER_TESTING_cmd_check_bank_transfer (
    563       "check_bank_transfer-42-aggregate",
    564       cred.exchange_url,
    565       /* In case of CS, one transaction above succeeded that
    566          failed for RSA, hence we get a larger amount here */
    567       uses_cs ? "EUR:14.91" : "EUR:13.92",
    568       cred.exchange_payto,
    569       cred.user42_payto),
    570     TALER_TESTING_cmd_check_bank_transfer (
    571       "check_bank_transfer-43-aggregate",
    572       cred.exchange_url,
    573       "EUR:0.17",
    574       cred.exchange_payto,
    575       cred.user43_payto),
    576     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"),
    577     TALER_TESTING_cmd_deposits_get (
    578       "deposit-wtid-ok",
    579       "deposit-simple",
    580       0,
    581       MHD_HTTP_OK,
    582       "check_bank_transfer-42-aggregate"),
    583     TALER_TESTING_cmd_track_transfer (
    584       "wire-deposit-success-bank",
    585       "check_bank_transfer-42-aggregate",
    586       MHD_HTTP_OK,
    587       uses_cs ? "EUR:14.91" : "EUR:13.92",
    588       "EUR:0.01"),
    589     TALER_TESTING_cmd_track_transfer (
    590       "wire-deposits-success-wtid",
    591       "check_bank_transfer-43-aggregate",
    592       MHD_HTTP_OK,
    593       "EUR:0.17",
    594       "EUR:0.01"),
    595     TALER_TESTING_cmd_end ()
    596   };
    597 
    598   /**
    599    * This block checks whether a wire deadline
    600    * very far in the future does NOT get aggregated now.
    601    */
    602   struct TALER_TESTING_Command unaggregation[] = {
    603     TALER_TESTING_cmd_check_bank_empty ("far-future-aggregation-a"),
    604     CMD_TRANSFER_TO_EXCHANGE (
    605       "create-reserve-unaggregated",
    606       "EUR:5.01"),
    607     /* "consume" reserve creation transfer.  */
    608     TALER_TESTING_cmd_check_bank_admin_transfer (
    609       "check-create-reserve-unaggregated",
    610       "EUR:5.01",
    611       cred.user42_payto,
    612       cred.exchange_payto,
    613       "create-reserve-unaggregated"),
    614     CMD_EXEC_WIREWATCH ("wirewatch-unaggregated"),
    615     TALER_TESTING_cmd_withdraw_amount (
    616       "withdraw-coin-unaggregated",
    617       "create-reserve-unaggregated",
    618       "EUR:5",
    619       0,                                  /* age restriction off */
    620       MHD_HTTP_OK),
    621     TALER_TESTING_cmd_deposit (
    622       "deposit-unaggregated",
    623       "withdraw-coin-unaggregated",
    624       0,
    625       cred.user43_payto,
    626       "{\"items\":[{\"name\":\"different ice cream\",\"value\":1}]}",
    627       GNUNET_TIME_relative_multiply (
    628         GNUNET_TIME_UNIT_YEARS,
    629         3000),
    630       "EUR:5",
    631       MHD_HTTP_OK),
    632     CMD_EXEC_AGGREGATOR ("aggregation-attempt"),
    633 
    634     TALER_TESTING_cmd_check_bank_empty (
    635       "far-future-aggregation-b"),
    636 
    637     TALER_TESTING_cmd_end ()
    638   };
    639 
    640   struct TALER_TESTING_Command refresh_age[] = {
    641     /* Fill reserve with EUR:5, 1ct is for fees. */
    642     CMD_TRANSFER_TO_EXCHANGE (
    643       "refresh-create-reserve-age-1",
    644       "EUR:6.01"),
    645     TALER_TESTING_cmd_check_bank_admin_transfer (
    646       "ck-refresh-create-reserve-age-1",
    647       "EUR:6.01",
    648       cred.user42_payto,
    649       cred.exchange_payto,
    650       "refresh-create-reserve-age-1"),
    651     /**
    652      * Make previous command effective.
    653      */
    654     CMD_EXEC_WIREWATCH ("wirewatch-age-2"),
    655     /**
    656      * Withdraw EUR:7 with age restriction for age 13.
    657      */
    658     TALER_TESTING_cmd_withdraw_amount (
    659       "refresh-withdraw-coin-age-1",
    660       "refresh-create-reserve-age-1",
    661       "EUR:5",
    662       13,
    663       MHD_HTTP_OK),
    664     /* Try to partially spend (deposit) 1 EUR of the 5 EUR coin
    665      * (in full) (merchant would receive EUR:0.99 due to 1 ct
    666      * deposit fee)
    667      */
    668     TALER_TESTING_cmd_deposit (
    669       "refresh-deposit-partial-age",
    670       "refresh-withdraw-coin-age-1",
    671       0,
    672       cred.user42_payto,
    673       "{\"items\":[{\"name\":\"special ice cream\",\"value\":\"EUR:1\"}]}",
    674       GNUNET_TIME_UNIT_ZERO,
    675       "EUR:1",
    676       MHD_HTTP_OK),
    677     /**
    678      * Melt the rest of the coin's value
    679      * (EUR:4.00 = 3x EUR:1.03 + 7x EUR:0.13) */
    680     TALER_TESTING_cmd_melt_double (
    681       "refresh-melt-age-1",
    682       "refresh-withdraw-coin-age-1",
    683       MHD_HTTP_OK,
    684       NULL),
    685     /**
    686      * Complete (successful) melt operation, and
    687      * withdraw the coins
    688      */
    689     TALER_TESTING_cmd_melt_reveal (
    690       "refresh-reveal-age-1",
    691       "refresh-melt-age-1",
    692       MHD_HTTP_OK),
    693     /**
    694      * Do it again to check idempotency
    695      */
    696     TALER_TESTING_cmd_melt_reveal (
    697       "refresh-reveal-age-1-idempotency",
    698       "refresh-melt-age-1",
    699       MHD_HTTP_OK),
    700     /**
    701      * Try to spend a refreshed EUR:1 coin
    702      */
    703     TALER_TESTING_cmd_deposit (
    704       "refresh-deposit-refreshed-age-1a",
    705       "refresh-reveal-age-1-idempotency",
    706       0,
    707       cred.user42_payto,
    708       "{\"items\":[{\"name\":\"garlic ice cream\",\"value\":3}]}",
    709       GNUNET_TIME_UNIT_ZERO,
    710       "EUR:1",
    711       MHD_HTTP_OK),
    712     /**
    713      * Try to spend a refreshed EUR:0.1 coin
    714      */
    715     TALER_TESTING_cmd_deposit (
    716       "refresh-deposit-refreshed-age-1b",
    717       "refresh-reveal-age-1",
    718       3,
    719       cred.user43_payto,
    720       "{\"items\":[{\"name\":\"spicy ice cream\",\"value\":3}]}",
    721       GNUNET_TIME_UNIT_ZERO,
    722       "EUR:0.1",
    723       MHD_HTTP_OK),
    724     /* Test running a failing melt operation (same operation
    725      * again must fail) */
    726     TALER_TESTING_cmd_melt (
    727       "refresh-melt-failing-age",
    728       "refresh-withdraw-coin-age-1",
    729       MHD_HTTP_CONFLICT,
    730       NULL),
    731     /* Test running a failing melt operation (on a coin that
    732        was itself revealed and subsequently deposited) */
    733     TALER_TESTING_cmd_melt (
    734       "refresh-melt-failing-age-2",
    735       "refresh-reveal-age-1",
    736       MHD_HTTP_CONFLICT,
    737       NULL),
    738     TALER_TESTING_cmd_end ()
    739   };
    740 
    741   /**
    742    * This block exercises the aggretation logic by making two payments
    743    * to the same merchant.
    744    */
    745   struct TALER_TESTING_Command aggregation[] = {
    746     CMD_TRANSFER_TO_EXCHANGE ("create-reserve-aggtest",
    747                               "EUR:5.01"),
    748     /* "consume" reserve creation transfer.  */
    749     TALER_TESTING_cmd_check_bank_admin_transfer (
    750       "check-create-reserve-aggtest",
    751       "EUR:5.01",
    752       cred.user42_payto,
    753       cred.exchange_payto,
    754       "create-reserve-aggtest"),
    755     CMD_EXEC_WIREWATCH ("wirewatch-aggtest"),
    756     TALER_TESTING_cmd_withdraw_amount (
    757       "withdraw-coin-aggtest",
    758       "create-reserve-aggtest",
    759       "EUR:5",
    760       0,                                  /* age restriction off */
    761       MHD_HTTP_OK),
    762     TALER_TESTING_cmd_deposit (
    763       "deposit-aggtest-1",
    764       "withdraw-coin-aggtest",
    765       0,
    766       cred.user43_payto,
    767       "{\"items\":[{\"name\":\"cinamon ice cream\",\"value\":1}]}",
    768       GNUNET_TIME_UNIT_ZERO,
    769       "EUR:2",
    770       MHD_HTTP_OK),
    771     TALER_TESTING_cmd_deposit_with_ref (
    772       "deposit-aggtest-2",
    773       "withdraw-coin-aggtest",
    774       0,
    775       cred.user43_payto,
    776       "{\"items\":[{\"name\":\"foo bar\",\"value\":1}]}",
    777       GNUNET_TIME_UNIT_ZERO,
    778       "EUR:2",
    779       MHD_HTTP_OK,
    780       "deposit-aggtest-1"),
    781     CMD_EXEC_AGGREGATOR ("aggregation-aggtest"),
    782     TALER_TESTING_cmd_check_bank_transfer (
    783       "check-bank-transfer-aggtest",
    784       cred.exchange_url,
    785       "EUR:3.97",
    786       cred.exchange_payto,
    787       cred.user43_payto),
    788     TALER_TESTING_cmd_check_bank_empty ("check-bank-empty-aggtest"),
    789     TALER_TESTING_cmd_end ()
    790   };
    791 
    792   struct TALER_TESTING_Command refund[] = {
    793     /**
    794      * Fill reserve with EUR:5.01, as withdraw fee is 1 ct per
    795      * config.
    796      */
    797     CMD_TRANSFER_TO_EXCHANGE (
    798       "create-reserve-r1",
    799       "EUR:5.01"),
    800     TALER_TESTING_cmd_check_bank_admin_transfer (
    801       "check-create-reserve-r1",
    802       "EUR:5.01",
    803       cred.user42_payto,
    804       cred.exchange_payto,
    805       "create-reserve-r1"),
    806     /**
    807      * Run wire-watch to trigger the reserve creation.
    808      */
    809     CMD_EXEC_WIREWATCH ("wirewatch-3"),
    810     /* Withdraw a 5 EUR coin, at fee of 1 ct */
    811     TALER_TESTING_cmd_withdraw_amount (
    812       "withdraw-coin-r1",
    813       "create-reserve-r1",
    814       "EUR:5",
    815       0,                                  /* age restriction off */
    816       MHD_HTTP_OK),
    817     /**
    818      * Spend 5 EUR of the 5 EUR coin (in full) (merchant would
    819      * receive EUR:4.99 due to 1 ct deposit fee)
    820      */
    821     TALER_TESTING_cmd_deposit (
    822       "deposit-refund-1",
    823       "withdraw-coin-r1",
    824       0,
    825       cred.user42_payto,
    826       "{\"items\":[{\"name\":\"blue ice cream\",\"value\":\"EUR:5\"}]}",
    827       GNUNET_TIME_UNIT_MINUTES,
    828       "EUR:5",
    829       MHD_HTTP_OK),
    830     /**
    831      * Run transfers. Should do nothing as refund deadline blocks it
    832      */
    833     CMD_EXEC_AGGREGATOR ("run-aggregator-refund"),
    834     /* Check that aggregator didn't do anything, as expected.
    835      * Note, this operation takes two commands: one to "flush"
    836      * the preliminary transfer (used to withdraw) from the
    837      * fakebank and the second to actually check there are not
    838      * other transfers around. */
    839     TALER_TESTING_cmd_check_bank_empty ("check_bank_transfer-pre-refund"),
    840     TALER_TESTING_cmd_refund_with_id (
    841       "refund-ok",
    842       MHD_HTTP_OK,
    843       "EUR:3",
    844       "deposit-refund-1",
    845       3),
    846     TALER_TESTING_cmd_refund_with_id (
    847       "refund-ok-double",
    848       MHD_HTTP_OK,
    849       "EUR:3",
    850       "deposit-refund-1",
    851       3),
    852     /* Previous /refund(s) had id == 0.  */
    853     TALER_TESTING_cmd_refund_with_id (
    854       "refund-conflicting",
    855       MHD_HTTP_CONFLICT,
    856       "EUR:5",
    857       "deposit-refund-1",
    858       1),
    859     TALER_TESTING_cmd_deposit (
    860       "deposit-refund-insufficient-refund",
    861       "withdraw-coin-r1",
    862       0,
    863       cred.user42_payto,
    864       "{\"items\":[{\"name\":\"fruit ice cream\",\"value\":\"EUR:4\"}]}",
    865       GNUNET_TIME_UNIT_MINUTES,
    866       "EUR:4",
    867       MHD_HTTP_CONFLICT),
    868     TALER_TESTING_cmd_refund_with_id (
    869       "refund-ok-increase",
    870       MHD_HTTP_OK,
    871       "EUR:2",
    872       "deposit-refund-1",
    873       2),
    874     /**
    875      * Spend 4.99 EUR of the refunded 4.99 EUR coin (1ct gone
    876      * due to refund) (merchant would receive EUR:4.98 due to
    877      * 1 ct deposit fee) */
    878     TALER_TESTING_cmd_deposit (
    879       "deposit-refund-2",
    880       "withdraw-coin-r1",
    881       0,
    882       cred.user42_payto,
    883       "{\"items\":[{\"name\":\"more ice cream\",\"value\":\"EUR:5\"}]}",
    884       GNUNET_TIME_UNIT_ZERO,
    885       "EUR:4.99",
    886       MHD_HTTP_OK),
    887     /**
    888      * Run transfers. This will do the transfer as refund deadline
    889      * was 0
    890      */
    891     CMD_EXEC_AGGREGATOR ("run-aggregator-3"),
    892     /**
    893      * Check that deposit did run.
    894      */
    895     TALER_TESTING_cmd_check_bank_transfer (
    896       "check_bank_transfer-pre-refund",
    897       cred.exchange_url,
    898       "EUR:4.97",
    899       cred.exchange_payto,
    900       cred.user42_payto),
    901     /**
    902      * Run failing refund, as past deadline & aggregation.
    903      */
    904     TALER_TESTING_cmd_refund (
    905       "refund-fail",
    906       MHD_HTTP_GONE,
    907       "EUR:4.99",
    908       "deposit-refund-2"),
    909     TALER_TESTING_cmd_check_bank_empty ("check-empty-after-refund"),
    910     /**
    911      * Test refunded coins are never executed, even past
    912      * refund deadline
    913      */
    914     CMD_TRANSFER_TO_EXCHANGE (
    915       "create-reserve-rb",
    916       "EUR:5.01"),
    917     TALER_TESTING_cmd_check_bank_admin_transfer (
    918       "check-create-reserve-rb",
    919       "EUR:5.01",
    920       cred.user42_payto,
    921       cred.exchange_payto,
    922       "create-reserve-rb"),
    923     CMD_EXEC_WIREWATCH ("wirewatch-rb"),
    924     TALER_TESTING_cmd_withdraw_amount (
    925       "withdraw-coin-rb",
    926       "create-reserve-rb",
    927       "EUR:5",
    928       0,                                  /* age restriction off */
    929       MHD_HTTP_OK),
    930     TALER_TESTING_cmd_deposit (
    931       "deposit-refund-1b",
    932       "withdraw-coin-rb",
    933       0,
    934       cred.user42_payto,
    935       "{\"items\":[{\"name\":\"purple ice cream\",\"value\":\"EUR:5\"}]}",
    936       GNUNET_TIME_UNIT_ZERO,
    937       "EUR:5",
    938       MHD_HTTP_OK),
    939     /**
    940      * Trigger refund (before aggregator had a chance to execute
    941      * deposit, even though refund deadline was zero).
    942      */
    943     TALER_TESTING_cmd_refund (
    944       "refund-ok-fast",
    945       MHD_HTTP_OK,
    946       "EUR:5",
    947       "deposit-refund-1b"),
    948     /**
    949      * Run transfers. This will do the transfer as refund deadline
    950      * was 0, except of course because the refund succeeded, the
    951      * transfer should no longer be done.
    952      */
    953     CMD_EXEC_AGGREGATOR ("run-aggregator-3b"),
    954     /* check that aggregator didn't do anything, as expected */
    955     TALER_TESTING_cmd_check_bank_empty ("check-refund-fast-not-run"),
    956     TALER_TESTING_cmd_end ()
    957   };
    958 
    959   struct TALER_TESTING_Command recoup[] = {
    960     /**
    961      * Fill reserve with EUR:5.01, as withdraw fee is 1 ct per
    962      * config.
    963      */
    964     CMD_TRANSFER_TO_EXCHANGE (
    965       "recoup-create-reserve-1",
    966       "EUR:15.02"),
    967     TALER_TESTING_cmd_check_bank_admin_transfer (
    968       "recoup-create-reserve-1-check",
    969       "EUR:15.02",
    970       cred.user42_payto,
    971       cred.exchange_payto,
    972       "recoup-create-reserve-1"),
    973     /**
    974      * Run wire-watch to trigger the reserve creation.
    975      */
    976     CMD_EXEC_WIREWATCH ("wirewatch-4"),
    977     /* Withdraw a 5 EUR coin, at fee of 1 ct */
    978     TALER_TESTING_cmd_withdraw_amount (
    979       "recoup-withdraw-coin-1",
    980       "recoup-create-reserve-1",
    981       "EUR:5",
    982       0,                                  /* age restriction off */
    983       MHD_HTTP_OK),
    984     /* Withdraw a 10 EUR coin, at fee of 1 ct */
    985     TALER_TESTING_cmd_withdraw_amount (
    986       "recoup-withdraw-coin-1b",
    987       "recoup-create-reserve-1",
    988       "EUR:10",
    989       0,                                  /* age restriction off */
    990       MHD_HTTP_OK),
    991     /* melt 10 EUR coin to get 5 EUR refreshed coin */
    992     TALER_TESTING_cmd_melt (
    993       "recoup-melt-coin-1b",
    994       "recoup-withdraw-coin-1b",
    995       MHD_HTTP_OK,
    996       "EUR:5",
    997       NULL),
    998     TALER_TESTING_cmd_melt_reveal (
    999       "recoup-reveal-coin-1b",
   1000       "recoup-melt-coin-1b",
   1001       MHD_HTTP_OK),
   1002     /* Revoke both 5 EUR coins */
   1003     TALER_TESTING_cmd_revoke (
   1004       "revoke-0-EUR:5",
   1005       MHD_HTTP_OK,
   1006       "recoup-withdraw-coin-1",
   1007       config_file),
   1008     /* Recoup coin to reserve */
   1009     TALER_TESTING_cmd_recoup (
   1010       "recoup-1",
   1011       MHD_HTTP_OK,
   1012       "recoup-withdraw-coin-1",
   1013       "EUR:5"),
   1014     /* Check the money is back with the reserve */
   1015     TALER_TESTING_cmd_status (
   1016       "recoup-reserve-status-1",
   1017       "recoup-create-reserve-1",
   1018       "EUR:5.0",
   1019       MHD_HTTP_OK),
   1020     /* Recoup-refresh coin to 10 EUR coin */
   1021     TALER_TESTING_cmd_recoup_refresh (
   1022       "recoup-1b",
   1023       MHD_HTTP_OK,
   1024       "recoup-reveal-coin-1b",
   1025       "recoup-melt-coin-1b",
   1026       "EUR:5"),
   1027     /* melt 10 EUR coin *again* to get 1 EUR refreshed coin */
   1028     TALER_TESTING_cmd_melt (
   1029       "recoup-remelt-coin-1a",
   1030       "recoup-withdraw-coin-1b",
   1031       MHD_HTTP_OK,
   1032       "EUR:1",
   1033       NULL),
   1034     TALER_TESTING_cmd_melt_reveal (
   1035       "recoup-reveal-coin-1a",
   1036       "recoup-remelt-coin-1a",
   1037       MHD_HTTP_OK),
   1038     /* Try melting for more than the residual value to provoke an error */
   1039     TALER_TESTING_cmd_melt (
   1040       "recoup-remelt-coin-1b",
   1041       "recoup-withdraw-coin-1b",
   1042       MHD_HTTP_OK,
   1043       "EUR:1",
   1044       NULL),
   1045     TALER_TESTING_cmd_melt (
   1046       "recoup-remelt-coin-1c",
   1047       "recoup-withdraw-coin-1b",
   1048       MHD_HTTP_OK,
   1049       "EUR:1",
   1050       NULL),
   1051     TALER_TESTING_cmd_melt (
   1052       "recoup-remelt-coin-1d",
   1053       "recoup-withdraw-coin-1b",
   1054       MHD_HTTP_OK,
   1055       "EUR:1",
   1056       NULL),
   1057     TALER_TESTING_cmd_melt (
   1058       "recoup-remelt-coin-1e",
   1059       "recoup-withdraw-coin-1b",
   1060       MHD_HTTP_OK,
   1061       "EUR:1",
   1062       NULL),
   1063     TALER_TESTING_cmd_melt (
   1064       "recoup-remelt-coin-1f",
   1065       "recoup-withdraw-coin-1b",
   1066       MHD_HTTP_OK,
   1067       "EUR:1",
   1068       NULL),
   1069     TALER_TESTING_cmd_melt (
   1070       "recoup-remelt-coin-1g",
   1071       "recoup-withdraw-coin-1b",
   1072       MHD_HTTP_OK,
   1073       "EUR:1",
   1074       NULL),
   1075     TALER_TESTING_cmd_melt (
   1076       "recoup-remelt-coin-1h",
   1077       "recoup-withdraw-coin-1b",
   1078       MHD_HTTP_OK,
   1079       "EUR:1",
   1080       NULL),
   1081     TALER_TESTING_cmd_melt (
   1082       "recoup-remelt-coin-1i",
   1083       "recoup-withdraw-coin-1b",
   1084       MHD_HTTP_OK,
   1085       "EUR:1",
   1086       NULL),
   1087     TALER_TESTING_cmd_melt (
   1088       "recoup-remelt-coin-1b-failing",
   1089       "recoup-withdraw-coin-1b",
   1090       MHD_HTTP_CONFLICT,
   1091       "EUR:1",
   1092       NULL),
   1093     /* Re-withdraw from this reserve */
   1094     TALER_TESTING_cmd_withdraw_amount (
   1095       "recoup-withdraw-coin-2",
   1096       "recoup-create-reserve-1",
   1097       "EUR:1",
   1098       0,                                  /* age restriction off */
   1099       MHD_HTTP_OK),
   1100     /**
   1101      * This withdrawal will test the logic to create a "recoup"
   1102      * element to insert into the reserve's history.
   1103      */
   1104     TALER_TESTING_cmd_withdraw_amount (
   1105       "recoup-withdraw-coin-2-over",
   1106       "recoup-create-reserve-1",
   1107       "EUR:10",
   1108       0,                                  /* age restriction off */
   1109       MHD_HTTP_CONFLICT),
   1110     TALER_TESTING_cmd_status (
   1111       "recoup-reserve-status-2",
   1112       "recoup-create-reserve-1",
   1113       "EUR:3.99",
   1114       MHD_HTTP_OK),
   1115     /* These commands should close the reserve because
   1116      * the aggregator is given a config file that overrides
   1117      * the reserve expiration time (making it now-ish) */
   1118     CMD_TRANSFER_TO_EXCHANGE ("short-lived-reserve",
   1119                               "EUR:5.01"),
   1120     TALER_TESTING_cmd_check_bank_admin_transfer (
   1121       "check-short-lived-reserve",
   1122       "EUR:5.01",
   1123       cred.user42_payto,
   1124       cred.exchange_payto,
   1125       "short-lived-reserve"),
   1126     TALER_TESTING_cmd_exec_wirewatch2 (
   1127       "short-lived-aggregation",
   1128       config_file_expire_reserve_now,
   1129       "exchange-account-2"),
   1130     TALER_TESTING_cmd_exec_closer (
   1131       "close-reserves",
   1132       config_file_expire_reserve_now,
   1133       "EUR:5",
   1134       "EUR:0.01",
   1135       "short-lived-reserve"),
   1136     TALER_TESTING_cmd_exec_transfer (
   1137       "close-reserves-transfer",
   1138       config_file_expire_reserve_now),
   1139 
   1140     TALER_TESTING_cmd_status (
   1141       "short-lived-status",
   1142       "short-lived-reserve",
   1143       "EUR:0",
   1144       MHD_HTTP_OK),
   1145     TALER_TESTING_cmd_withdraw_amount (
   1146       "expired-withdraw",
   1147       "short-lived-reserve",
   1148       "EUR:1",
   1149       0,                                  /* age restriction off */
   1150       MHD_HTTP_CONFLICT),
   1151     TALER_TESTING_cmd_check_bank_transfer (
   1152       "check_bank_short-lived_reimburse",
   1153       cred.exchange_url,
   1154       "EUR:5",
   1155       cred.exchange_payto,
   1156       cred.user42_payto),
   1157     /* Fill reserve with EUR:2.02, as withdraw fee is 1 ct per
   1158      * config, then withdraw two coin, partially spend one, and
   1159      * then have the rest paid back.  Check deposit of other coin
   1160      * fails.  Do not use EUR:5 here as the EUR:5 coin was
   1161      * revoked and we did not bother to create a new one... */
   1162     CMD_TRANSFER_TO_EXCHANGE ("recoup-create-reserve-2",
   1163                               "EUR:2.02"),
   1164     TALER_TESTING_cmd_check_bank_admin_transfer (
   1165       "ck-recoup-create-reserve-2",
   1166       "EUR:2.02",
   1167       cred.user42_payto,
   1168       cred.exchange_payto,
   1169       "recoup-create-reserve-2"),
   1170     /* Make previous command effective. */
   1171     CMD_EXEC_WIREWATCH ("wirewatch-5"),
   1172     /* Withdraw a 1 EUR coin, at fee of 1 ct */
   1173     TALER_TESTING_cmd_withdraw_amount (
   1174       "recoup-withdraw-coin-2a",
   1175       "recoup-create-reserve-2",
   1176       "EUR:1",
   1177       0,                                  /* age restriction off */
   1178       MHD_HTTP_OK),
   1179     /* Withdraw a 1 EUR coin, at fee of 1 ct */
   1180     TALER_TESTING_cmd_withdraw_amount (
   1181       "recoup-withdraw-coin-2b",
   1182       "recoup-create-reserve-2",
   1183       "EUR:1",
   1184       0,                                  /* age restriction off */
   1185       MHD_HTTP_OK),
   1186     TALER_TESTING_cmd_deposit (
   1187       "recoup-deposit-partial",
   1188       "recoup-withdraw-coin-2a",
   1189       0,
   1190       cred.user42_payto,
   1191       "{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}",
   1192       GNUNET_TIME_UNIT_ZERO,
   1193       "EUR:0.5",
   1194       MHD_HTTP_OK),
   1195     TALER_TESTING_cmd_revoke (
   1196       "revoke-1-EUR:1",
   1197       MHD_HTTP_OK,
   1198       "recoup-withdraw-coin-2a",
   1199       config_file),
   1200     /* Check recoup is failing for the coin with the reused coin key
   1201        (fails either because of denomination conflict (RSA) or
   1202        double-spending (CS))*/
   1203     TALER_TESTING_cmd_recoup (
   1204       "recoup-2x",
   1205       MHD_HTTP_CONFLICT,
   1206       "withdraw-coin-1x",
   1207       "EUR:1"),
   1208     TALER_TESTING_cmd_recoup (
   1209       "recoup-2",
   1210       MHD_HTTP_OK,
   1211       "recoup-withdraw-coin-2a",
   1212       "EUR:0.5"),
   1213     /* Idempotency of recoup (withdrawal variant) */
   1214     TALER_TESTING_cmd_recoup (
   1215       "recoup-2b",
   1216       MHD_HTTP_OK,
   1217       "recoup-withdraw-coin-2a",
   1218       "EUR:0.5"),
   1219     TALER_TESTING_cmd_deposit (
   1220       "recoup-deposit-revoked",
   1221       "recoup-withdraw-coin-2b",
   1222       0,
   1223       cred.user42_payto,
   1224       "{\"items\":[{\"name\":\"gnu ice cream\",\"value\":1}]}",
   1225       GNUNET_TIME_UNIT_ZERO,
   1226       "EUR:1",
   1227       MHD_HTTP_GONE),
   1228     /* Test deposit fails after recoup, with proof in recoup */
   1229 
   1230     /* Note that, the exchange will never return the coin's transaction
   1231      * history with recoup data, as we get a 410 on the DK! */
   1232     TALER_TESTING_cmd_deposit (
   1233       "recoup-deposit-partial-after-recoup",
   1234       "recoup-withdraw-coin-2a",
   1235       0,
   1236       cred.user42_payto,
   1237       "{\"items\":[{\"name\":\"extra ice cream\",\"value\":1}]}",
   1238       GNUNET_TIME_UNIT_ZERO,
   1239       "EUR:0.5",
   1240       MHD_HTTP_GONE),
   1241     /* Test that revoked coins cannot be withdrawn */
   1242     CMD_TRANSFER_TO_EXCHANGE (
   1243       "recoup-create-reserve-3",
   1244       "EUR:1.01"),
   1245     TALER_TESTING_cmd_check_bank_admin_transfer (
   1246       "check-recoup-create-reserve-3",
   1247       "EUR:1.01",
   1248       cred.user42_payto,
   1249       cred.exchange_payto,
   1250       "recoup-create-reserve-3"),
   1251     CMD_EXEC_WIREWATCH ("wirewatch-6"),
   1252     TALER_TESTING_cmd_withdraw_amount (
   1253       "recoup-withdraw-coin-3-revoked",
   1254       "recoup-create-reserve-3",
   1255       "EUR:1",
   1256       0,                                  /* age restriction off */
   1257       MHD_HTTP_GONE),
   1258     /* check that we are empty before the rejection test */
   1259     TALER_TESTING_cmd_check_bank_empty ("check-empty-again"),
   1260 
   1261     TALER_TESTING_cmd_end ()
   1262   };
   1263 
   1264   /**
   1265    * Test batch withdrawal plus spending.
   1266    */
   1267   struct TALER_TESTING_Command batch_withdraw[] = {
   1268     /**
   1269      * Move money to the exchange's bank account.
   1270      */
   1271     CMD_TRANSFER_TO_EXCHANGE (
   1272       "create-batch-reserve-1",
   1273       "EUR:6.03"),
   1274     TALER_TESTING_cmd_reserve_poll (
   1275       "poll-batch-reserve-1",
   1276       "create-batch-reserve-1",
   1277       "EUR:6.03",
   1278       GNUNET_TIME_UNIT_MINUTES,
   1279       MHD_HTTP_OK),
   1280     TALER_TESTING_cmd_check_bank_admin_transfer (
   1281       "check-create-batch-reserve-1",
   1282       "EUR:6.03",
   1283       cred.user42_payto,
   1284       cred.exchange_payto,
   1285       "create-batch-reserve-1"),
   1286     /*
   1287      * Make a reserve exist, according to the previous
   1288      * transfer.
   1289      */
   1290     CMD_EXEC_WIREWATCH ("wirewatch-batch-1"),
   1291     TALER_TESTING_cmd_reserve_poll_finish (
   1292       "finish-poll-batch-reserve-1",
   1293       GNUNET_TIME_UNIT_SECONDS,
   1294       "poll-batch-reserve-1"),
   1295     /**
   1296      * Withdraw EUR:5 AND EUR:1.
   1297      */
   1298     TALER_TESTING_cmd_batch_withdraw (
   1299       "batch-withdraw-coin-1",
   1300       "create-batch-reserve-1",
   1301       MHD_HTTP_OK,
   1302       "EUR:5",
   1303       "EUR:1",
   1304       NULL),
   1305     /**
   1306      * Check the reserve is (almost) depleted.
   1307      */
   1308     TALER_TESTING_cmd_status (
   1309       "status-batch-1",
   1310       "create-batch-reserve-1",
   1311       "EUR:0.01",
   1312       MHD_HTTP_OK),
   1313     TALER_TESTING_cmd_reserve_history (
   1314       "history-batch-1",
   1315       "create-batch-reserve-1",
   1316       "EUR:0.01",
   1317       MHD_HTTP_OK),
   1318     /* the same coin twice in one batch is a malformed request */
   1319     TALER_TESTING_cmd_batch_deposit (
   1320       "batch-deposit-duplicate-coin",
   1321       cred.user42_payto,
   1322       "{\"items\":[{\"name\":\"double ice cream\",\"value\":1}]}",
   1323       GNUNET_TIME_UNIT_ZERO,
   1324       MHD_HTTP_BAD_REQUEST,
   1325       "batch-withdraw-coin-1#0",
   1326       "EUR:1",
   1327       "batch-withdraw-coin-1#0",
   1328       "EUR:1",
   1329       NULL),
   1330     /**
   1331      * Spend the coins.
   1332      */
   1333     TALER_TESTING_cmd_batch_deposit (
   1334       "batch-deposit-1",
   1335       cred.user42_payto,
   1336       "{\"items\":[{\"name\":\"final ice cream\",\"value\":5}]}",
   1337       GNUNET_TIME_UNIT_ZERO,
   1338       MHD_HTTP_OK,
   1339       "batch-withdraw-coin-1#0",
   1340       "EUR:5",
   1341       "batch-withdraw-coin-1#1",
   1342       "EUR:1",
   1343       NULL),
   1344     TALER_TESTING_cmd_coin_history (
   1345       "coin-history-batch-1",
   1346       "batch-withdraw-coin-1#0",
   1347       "EUR:0.0",
   1348       MHD_HTTP_OK),
   1349     TALER_TESTING_cmd_end ()
   1350   };
   1351 
   1352 
   1353 #define RESERVE_OPEN_CLOSE_CHUNK 4
   1354 #define RESERVE_OPEN_CLOSE_ITERATIONS 3
   1355 
   1356   struct TALER_TESTING_Command reserve_open_close[(RESERVE_OPEN_CLOSE_ITERATIONS
   1357                                                    * RESERVE_OPEN_CLOSE_CHUNK)
   1358                                                   + 1];
   1359 
   1360   (void) cls;
   1361   for (unsigned int i = 0;
   1362        i < RESERVE_OPEN_CLOSE_ITERATIONS;
   1363        i++)
   1364   {
   1365     reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 0]
   1366       = CMD_TRANSFER_TO_EXCHANGE ("reserve-open-close-key",
   1367                                   "EUR:20");
   1368     reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 1]
   1369       = TALER_TESTING_cmd_exec_wirewatch2 ("reserve-open-close-wirewatch",
   1370                                            config_file_expire_reserve_now,
   1371                                            "exchange-account-2");
   1372     reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 2]
   1373       = TALER_TESTING_cmd_exec_closer ("reserve-open-close-aggregation",
   1374                                        config_file_expire_reserve_now,
   1375                                        "EUR:19.99",
   1376                                        "EUR:0.01",
   1377                                        "reserve-open-close-key");
   1378     reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 3]
   1379       = TALER_TESTING_cmd_status ("reserve-open-close-status",
   1380                                   "reserve-open-close-key",
   1381                                   "EUR:0",
   1382                                   MHD_HTTP_OK);
   1383   }
   1384   reserve_open_close[RESERVE_OPEN_CLOSE_ITERATIONS * RESERVE_OPEN_CLOSE_CHUNK]
   1385     = TALER_TESTING_cmd_end ();
   1386 
   1387   {
   1388     struct TALER_TESTING_Command commands[] = {
   1389       TALER_TESTING_cmd_run_fakebank ("run-fakebank",
   1390                                       cred.cfg,
   1391                                       "exchange-account-2"),
   1392       TALER_TESTING_cmd_system_start ("start-taler",
   1393                                       config_file,
   1394                                       "-e",
   1395                                       NULL),
   1396       TALER_TESTING_cmd_get_exchange ("get-exchange",
   1397                                       cred.cfg,
   1398                                       NULL,
   1399                                       true,
   1400                                       true),
   1401       TALER_TESTING_cmd_batch ("withdraw",
   1402                                withdraw),
   1403       TALER_TESTING_cmd_batch ("spend",
   1404                                spend),
   1405       TALER_TESTING_cmd_batch ("refresh",
   1406                                refresh),
   1407       TALER_TESTING_cmd_batch ("withdraw-age",
   1408                                withdraw_age),
   1409       TALER_TESTING_cmd_batch ("spend-age",
   1410                                spend_age),
   1411       TALER_TESTING_cmd_batch ("refresh-age",
   1412                                refresh_age),
   1413       TALER_TESTING_cmd_batch ("track",
   1414                                track),
   1415       TALER_TESTING_cmd_batch ("unaggregation",
   1416                                unaggregation),
   1417       TALER_TESTING_cmd_batch ("aggregation",
   1418                                aggregation),
   1419       TALER_TESTING_cmd_batch ("refund",
   1420                                refund),
   1421       TALER_TESTING_cmd_batch ("batch-withdraw",
   1422                                batch_withdraw),
   1423       TALER_TESTING_cmd_batch ("recoup",
   1424                                recoup),
   1425       TALER_TESTING_cmd_batch ("reserve-open-close",
   1426                                reserve_open_close),
   1427       /* End the suite. */
   1428       TALER_TESTING_cmd_end ()
   1429     };
   1430 
   1431     TALER_TESTING_run (is,
   1432                        commands);
   1433   }
   1434 }
   1435 
   1436 
   1437 int
   1438 main (int argc,
   1439       char *const *argv)
   1440 {
   1441   (void) argc;
   1442   {
   1443     char *cipher;
   1444 
   1445     cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
   1446     GNUNET_assert (NULL != cipher);
   1447     uses_cs = (0 == strcmp (cipher,
   1448                             "cs"));
   1449     GNUNET_asprintf (&config_file,
   1450                      "test_exchange_api-%s.conf",
   1451                      cipher);
   1452     GNUNET_asprintf (&config_file_expire_reserve_now,
   1453                      "test_exchange_api_expire_reserve_now-%s.conf",
   1454                      cipher);
   1455     GNUNET_free (cipher);
   1456   }
   1457   return TALER_TESTING_main (argv,
   1458                              "INFO",
   1459                              config_file,
   1460                              "exchange-account-2",
   1461                              TALER_TESTING_BS_FAKEBANK,
   1462                              &cred,
   1463                              &run,
   1464                              NULL);
   1465 }
   1466 
   1467 
   1468 /* end of test_exchange_api.c */