aboutsummaryrefslogtreecommitdiff
path: root/src/lib/test_taler_exchange_wirewatch.c
blob: 39a222ae4689d8e667de898b4b2b2bc234b5f5e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
  This file is part of TALER
  (C) 2016, 2017, 2018 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/

/**
 * @file exchange/test_taler_exchange_wirewatch.c
 * @brief Tests for taler-exchange-wirewatch and taler-exchange-aggregator logic;
 *        Performs an invalid wire transfer to the exchange, and then checks that
 *        wirewatch immediately sends the money back.
 *        Then performs a valid wire transfer, waits for the reserve to expire,
 *        and then checks that the aggregator sends the money back.
 * @author Christian Grothoff <christian@grothoff.org>
 */
#include "platform.h"
#include "taler_util.h"
#include <gnunet/gnunet_json_lib.h>
#include <gnunet/gnunet_pq_lib.h>
#include "taler_json_lib.h"
#include <microhttpd.h>
#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"


/**
 * Bank configuration data.
 */
static struct TALER_TESTING_BankConfiguration bc;

/**
 * Helper structure to keep exchange configuration values.
 */
static struct TALER_TESTING_ExchangeConfiguration ec;

/**
 * Name of the configuration file to use.
 */
static char *config_filename;

static struct TALER_TESTING_Command
transfer_to_exchange (const char *label,
		      const char *amount)
{
  return TALER_TESTING_cmd_admin_add_incoming (label,
                                               amount,
                                               bc.exchange_account_url,
                                               &bc.exchange_auth,
                                               bc.user42_payto);
}

/**
 * Main function that will tell the interpreter what commands to
 * run.
 *
 * @param cls closure
 */
static void
run (void *cls,
     struct TALER_TESTING_Interpreter *is)
{
  struct TALER_TESTING_Command all[] = {
    TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
    TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-empty",
		                       config_filename),
    TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty",
		                      config_filename),
    TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"),

    transfer_to_exchange ("run-transfer-good-to-exchange",
		          "EUR:5"),
    TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-good-transfer",
		                      config_filename),

    TALER_TESTING_cmd_check_bank_admin_transfer ("clear-good-transfer-to-the-exchange",
                                                 "EUR:5",
                                                 bc.user42_payto, // debit
                                                 bc.exchange_payto, // credit
                                                 "run-transfer-good-to-exchange"),

    TALER_TESTING_cmd_exec_aggregator ("run-aggregator-non-expired-reserve",
		                       config_filename),

    TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"),
    TALER_TESTING_cmd_sleep ("wait (5s)",
		             5),
    TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-expired-reserve",
		                       config_filename),
    TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
		                           ec.exchange_url,
					   "EUR:4.99",
					   bc.exchange_payto,
					   bc.user42_payto),
    TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"),
    TALER_TESTING_cmd_end ()  
  };

  TALER_TESTING_run_with_fakebank (is,
                                   all,
                                   bc.bank_url);
}

int
main (int argc,
      char *const argv[])
{
  const char *plugin_name;
  char *testname;
  struct GNUNET_OS_Process *proc;
  struct GNUNET_CONFIGURATION_Handle *cfg;
  struct GNUNET_SIGNAL_Context *shc_chld;

  /* these might get in the way */
  unsetenv ("XDG_DATA_HOME");
  unsetenv ("XDG_CONFIG_HOME");
  GNUNET_log_setup ("test_taler_exchange_wirewatch",
                    "DEBUG",
                    NULL);

  if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
  {
    GNUNET_break (0);
    return -1;
  }
  plugin_name++;
  (void) GNUNET_asprintf (&testname,
                          "test-taler-exchange-wirewatch-%s",
                          plugin_name);
  (void) GNUNET_asprintf (&config_filename,
                          "%s.conf",
                          testname);

  /* check database is working */
  {
    struct GNUNET_PQ_Context *conn;
    struct GNUNET_PQ_ExecuteStatement es[] = {
      GNUNET_PQ_EXECUTE_STATEMENT_END
    };

    conn = GNUNET_PQ_connect ("postgres:///talercheck",
                              es,
                              NULL);
    if (NULL == conn)
      return 77;
    GNUNET_PQ_disconnect (conn);
  }

  TALER_TESTING_cleanup_files (config_filename);
  if (GNUNET_OK != TALER_TESTING_prepare_exchange (config_filename,
		                                   &ec))
  {
    TALER_LOG_INFO ("Could not prepare the exchange\n");
    return 77;
  }

  if (GNUNET_OK !=
      TALER_TESTING_prepare_fakebank (config_filename,
                                      "account-1",
                                      &bc))
    return 77;

  return
    (GNUNET_OK == TALER_TESTING_setup_with_exchange (&run,
                                                     NULL,
                                                     config_filename)) ? 0 : 1;
}

/* end of test_taler_exchange_wirewatch.c */