summaryrefslogtreecommitdiff
path: root/src/merchant-tools/taler-merchant-benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/merchant-tools/taler-merchant-benchmark.c')
-rw-r--r--src/merchant-tools/taler-merchant-benchmark.c785
1 files changed, 348 insertions, 437 deletions
diff --git a/src/merchant-tools/taler-merchant-benchmark.c b/src/merchant-tools/taler-merchant-benchmark.c
index 00417a7b..f811b502 100644
--- a/src/merchant-tools/taler-merchant-benchmark.c
+++ b/src/merchant-tools/taler-merchant-benchmark.c
@@ -21,6 +21,7 @@
* @file merchant/backend/taler-merchant-benchmark.c
* @brief benchmark the backend to evaluate performance
* @author Marcello Stanisci
+ * @author Christian Grothoff
*/
#include "platform.h"
#include <taler/taler_util.h>
@@ -35,22 +36,31 @@
#include <taler/taler_error_codes.h>
#include "taler_merchant_testing_lib.h"
+/**
+ * Maximum length of an amount (value plus currency string) needed by the test.
+ * We have a 32-bit and a 64-bit value (~48 characters), plus the currency, plus
+ * some punctuation.
+ */
+#define MAX_AMOUNT_LEN (TALER_CURRENCY_LEN + 64)
-#define APIKEY_SANDBOX "Authorization: ApiKey sandbox"
+/**
+ * Maximum length of an order JSON. Generously allocated.
+ */
+#define MAX_ORDER_LEN (MAX_AMOUNT_LEN * 4 + 2048)
/* Error codes. */
enum PaymentGeneratorError
{
-
- MISSING_MERCHANT_URL = 2,
- FAILED_TO_LAUNCH_MERCHANT,
- MISSING_BANK_URL,
- FAILED_TO_LAUNCH_BANK,
- BAD_CLI_ARG,
- MISSING_CURRENCY
+ PG_SUCCESS = 0,
+ PG_NO_SUBCOMMAND,
+ PG_BAD_OPTIONS,
+ PG_FAILED_TO_LAUNCH_MERCHANT,
+ PG_FAILED_TO_LAUNCH_BANK,
+ PG_RUNTIME_FAILURE
};
+
/* Hard-coded params. Note, the bank is expected to
* have the Tor user with account number 3 and password 'x'.
*/
@@ -62,28 +72,21 @@ enum PaymentGeneratorError
#define TRACKS_INSTRUCTION 9
#define TWOCOINS_INSTRUCTION 5
+
/**
- * Help string shown if NO subcommand is given on command line.
+ * What API key should we send in the HTTP 'Authorization' header?
*/
-static int root_help;
+static char *apikey;
/**
* Witnesses if the ordinary cases payment suite should be run.
*/
-static unsigned int ordinary;
+static bool ordinary;
/**
* Witnesses if the corner cases payment suite should be run.
*/
-static unsigned int corner;
-
-/**
- * Root help string.
- */
-static const char *root_help_str = \
- "taler-merchant-benchmark\nPopulates production database"
- " with fake payments.\nMust be used with either 'ordinary'"
- " or 'corner' sub-commands.\n";
+static bool corner;
/**
* Alternative non default instance.
@@ -106,21 +109,6 @@ static unsigned int unaggregated_number = 1;
static unsigned int twocoins_number = 1;
/**
- * Exit code.
- */
-static int result;
-
-/**
- * Bank process.
- */
-static struct GNUNET_OS_Process *bankd;
-
-/**
- * Merchant process.
- */
-static struct GNUNET_OS_Process *merchantd;
-
-/**
* How many payments we want to generate.
*/
static unsigned int payments_number = 1;
@@ -130,19 +118,8 @@ static unsigned int payments_number = 1;
*/
static unsigned int tracks_number = 1;
-
-/**
- * Usually set as ~/.config/taler.net
- */
-static const char *default_config_file;
-
-/**
- * Log level used during the run.
- */
-static char *loglev;
-
/**
- * Config filename.
+ * Config filename to give to commands (like wirewatch).
*/
static char *cfg_filename;
@@ -152,11 +129,6 @@ static char *cfg_filename;
static char *bank_url;
/**
- * Log file.
- */
-static char *logfile;
-
-/**
* Merchant base URL.
*/
static char *merchant_url;
@@ -175,136 +147,6 @@ static char *exchange_payto;
static char *customer_payto;
static char *merchant_payto;
-/**
- * Convenience macros to allocate all the currency-dependant
- * strings; note that the argument list of the macro is ignored.
- * It is kept as a way to make the macro more auto-descriptive
- * where it is called.
- */
-
-// FIXME: This should not be a macro!
-#define ALLOCATE_AMOUNTS(...) \
- char *CURRENCY_10_02; \
- char *CURRENCY_10; \
- char *CURRENCY_9_98; \
- char *CURRENCY_5_01; \
- char *CURRENCY_5; \
- char *CURRENCY_4_99; \
- char *CURRENCY_0_02; \
- char *CURRENCY_0_01; \
- \
- GNUNET_asprintf (&CURRENCY_10_02, \
- "%s:10.02", \
- currency); \
- GNUNET_asprintf (&CURRENCY_10, \
- "%s:10", \
- currency); \
- GNUNET_asprintf (&CURRENCY_9_98, \
- "%s:9.98", \
- currency); \
- GNUNET_asprintf (&CURRENCY_5_01, \
- "%s:5.01", \
- currency); \
- GNUNET_asprintf (&CURRENCY_5, \
- "%s:5", \
- currency); \
- GNUNET_asprintf (&CURRENCY_4_99, \
- "%s:4.99", \
- currency); \
- GNUNET_asprintf (&CURRENCY_0_02, \
- "%s:0.02", \
- currency); \
- GNUNET_asprintf (&CURRENCY_0_01, \
- "%s:0.01", \
- currency);
-
-// FIXME: this should not be a macro
-// FIXME: the inline JSON is outdated
-// FIXME: find a better way to produce the contract terms via a helper function
-#define ALLOCATE_ORDERS(...) \
- char *order_worth_5; \
- char *order_worth_5_track; \
- char *order_worth_5_unaggregated; \
- char *order_worth_10_2coins; \
- \
- GNUNET_asprintf \
- (&order_worth_5, \
- "{\"max_fee\":\
- {\"currency\":\"%s\",\
- \"value\":0,\
- \"fraction\":50000000},\
- \"refund_deadline\":\"\\/Date(0)\\/\",\
- \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
- \"amount\":\
- {\"currency\":\"%s\",\
- \"value\":5,\
- \"fraction\":0},\
- \"summary\": \"merchant-lib testcase\",\
- \"fulfillment_url\": \"https://example.com/\",\
- \"products\": [ {\"description\":\"ice cream\",\
- \"value\":\"{%s:5}\"} ] }", \
- currency, \
- currency, \
- currency); \
- GNUNET_asprintf \
- (&order_worth_5_track, \
- "{\"max_fee\":\
- {\"currency\":\"%s\",\
- \"value\":0,\
- \"fraction\":50000000},\
- \"refund_deadline\":\"\\/Date(0)\\/\",\
- \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
- \"amount\":\
- {\"currency\":\"%s\",\
- \"value\":5,\
- \"fraction\":0},\
- \"summary\": \"ice track cream!\",\
- \"fulfillment_url\": \"https://example.com/\",\
- \"products\": [ {\"description\":\"ice track cream\",\
- \"value\":\"{%s:5}\"} ] }", \
- currency, \
- currency, \
- currency); \
- GNUNET_asprintf \
- (&order_worth_5_unaggregated, \
- "{\"max_fee\":\
- {\"currency\":\"%s\",\
- \"value\":0,\
- \"fraction\":50000000},\
- \"wire_transfer_delay\":\"\\/Delay(30000)\\/\",\
- \"refund_deadline\":\"\\/Date(22)\\/\",\
- \"pay_deadline\":\"\\/Date(1)\\/\",\
- \"amount\":\
- {\"currency\":\"%s\",\
- \"value\":5,\
- \"fraction\":0},\
- \"summary\": \"unaggregated deposit!\",\
- \"fulfillment_url\": \"https://example.com/\",\
- \"products\": [ {\"description\":\"unaggregated cream\",\
- \"value\":\"{%s:5}\"} ] }", \
- currency, \
- currency, \
- currency); \
- GNUNET_asprintf \
- (&order_worth_10_2coins, \
- "{\"max_fee\":\
- {\"currency\":\"%s\",\
- \"value\":0,\
- \"fraction\":50000000},\
- \"refund_deadline\":\"\\/Date(0)\\/\",\
- \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
- \"amount\":\
- {\"currency\":\"%s\",\
- \"value\":10,\
- \"fraction\":0},\
- \"summary\": \"2-coins payment\",\
- \"fulfillment_url\": \"https://example.com/\",\
- \"products\": [ {\"description\":\"2-coins payment\",\
- \"value\":\"{%s:10}\"} ] }", \
- currency, \
- currency, \
- currency);
-
/**
* Actual commands collection.
@@ -313,166 +155,253 @@ static void
run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
- /* Will be freed by testing-lib. */
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CURL_append_header (is->ctx,
- APIKEY_SANDBOX));
- ALLOCATE_AMOUNTS (CURRENCY_10_02,
- CURRENCY_9_98,
- CURRENCY_5_01,
- CURRENCY_5,
- CURRENCY_4_99,
- CURRENCY_0_02,
- CURRENCY_0_01);
- ALLOCATE_ORDERS (order_worth_5,
- order_worth_5_track,
- order_worth_5_unaggregated,
- order_worth_10_2coins);
- struct TALER_TESTING_Command ordinary_commands[] = {
- TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
- CURRENCY_10_02,
- &auth,
- customer_payto),
- TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
- cfg_filename),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
- "create-reserve-1",
- CURRENCY_5,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
- "create-reserve-1",
- CURRENCY_5,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1",
- merchant_url,
- MHD_HTTP_OK,
- order_worth_5),
- TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
- merchant_url,
- MHD_HTTP_OK,
- "create-proposal-1",
- "withdraw-coin-1",
- CURRENCY_5,
- CURRENCY_4_99),
- TALER_TESTING_cmd_rewind_ip ("rewind-payments",
- FIRST_INSTRUCTION,
- &payments_number),
- /* Next proposal-pay cycle will be used by /track CMDs
- * and so it will not have to be looped over, only /track
- * CMDs will have to. */
- TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2",
- merchant_url,
- MHD_HTTP_OK,
- order_worth_5_track),
- TALER_TESTING_cmd_merchant_pay_order ("deposit-simple-2",
- merchant_url,
- MHD_HTTP_OK,
- "create-proposal-2",
- "withdraw-coin-2",
- CURRENCY_5,
- CURRENCY_4_99),
- /* /track/transaction over deposit-simple-2 */
-
- TALER_TESTING_cmd_exec_aggregator ("aggregate-1",
- cfg_filename),
- TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1",
- &auth,
- bank_url,
+ char CURRENCY_10_02[MAX_AMOUNT_LEN];
+ char CURRENCY_10[MAX_AMOUNT_LEN];
+ char CURRENCY_9_98[MAX_AMOUNT_LEN];
+ char CURRENCY_5_01[MAX_AMOUNT_LEN];
+ char CURRENCY_5[MAX_AMOUNT_LEN];
+ char CURRENCY_4_99[MAX_AMOUNT_LEN];
+ char CURRENCY_0_02[MAX_AMOUNT_LEN];
+ char CURRENCY_0_01[MAX_AMOUNT_LEN];
+ char order_worth_5[MAX_ORDER_LEN];
+ char order_worth_5_track[MAX_ORDER_LEN];
+ char order_worth_5_unaggregated[MAX_ORDER_LEN];
+ char order_worth_10_2coins[MAX_ORDER_LEN];
+
+ GNUNET_snprintf (CURRENCY_10_02,
+ sizeof (CURRENCY_10_02),
+ "%s:10.02",
+ currency);
+ GNUNET_snprintf (CURRENCY_10,
+ sizeof (CURRENCY_10),
+ "%s:10",
+ currency);
+ GNUNET_snprintf (CURRENCY_9_98,
+ sizeof (CURRENCY_9_98),
+ "%s:9.98",
+ currency);
+ GNUNET_snprintf (CURRENCY_5_01,
+ sizeof (CURRENCY_5_01),
+ "%s:5.01",
+ currency);
+ GNUNET_snprintf (CURRENCY_5,
+ sizeof (CURRENCY_5),
+ "%s:5",
+ currency);
+ GNUNET_snprintf (CURRENCY_4_99,
+ sizeof (CURRENCY_4_99),
+ "%s:4.99",
+ currency);
+ GNUNET_snprintf (CURRENCY_0_02,
+ sizeof (CURRENCY_0_02),
+ "%s:0.02",
+ currency);
+ GNUNET_snprintf (CURRENCY_0_01,
+ sizeof (CURRENCY_0_01),
+ "%s:0.01",
+ currency);
+ GNUNET_snprintf (order_worth_5,
+ sizeof (order_worth_5),
+ "{\"max_fee\": {\"currency\":\"%s\", \"value\":0, \"fraction\":50000000},"
+ "\"refund_deadline\":\"\\/Date(0)\\/\","
+ "\"pay_deadline\":\"\\/Date(99999999999)\\/\","
+ "\"amount\": {\"currency\":\"%s\", \"value\":5, \"fraction\":0},"
+ "\"summary\": \"merchant-lib testcase\","
+ "\"fulfillment_url\": \"https://example.com/\","
+ "\"products\": [ {\"description\":\"ice cream\", \"value\":\"{%s:5}\"} ] }",
+ currency,
+ currency,
+ currency);
+ GNUNET_snprintf (order_worth_5_track,
+ sizeof (order_worth_5_track),
+ "{\"max_fee\": {\"currency\":\"%s\", \"value\":0, \"fraction\":50000000},"
+ "\"refund_deadline\":\"\\/Date(0)\\/\","
+ "\"pay_deadline\":\"\\/Date(99999999999)\\/\","
+ "\"amount\": {\"currency\":\"%s\", \"value\":5, \"fraction\":0},"
+ "\"summary\": \"ice track cream!\","
+ "\"fulfillment_url\": \"https://example.com/\","
+ "\"products\": [ {\"description\":\"ice track cream\", \"value\":\"{%s:5}\"} ] }",
+ currency,
+ currency,
+ currency);
+ GNUNET_snprintf (order_worth_5_unaggregated,
+ sizeof (order_worth_5_unaggregated),
+ "{\"max_fee\": {\"currency\":\"%s\", \"value\":0, \"fraction\":50000000},"
+ "\"wire_transfer_delay\":\"\\/Delay(30000)\\/\","
+ "\"refund_deadline\":\"\\/Date(22)\\/\","
+ "\"pay_deadline\":\"\\/Date(1)\\/\","
+ "\"amount\": {\"currency\":\"%s\", \"value\":5, \"fraction\":0},"
+ "\"summary\": \"unaggregated deposit!\","
+ "\"fulfillment_url\": \"https://example.com/\","
+ "\"products\": [ {\"description\":\"unaggregated cream\","
+ "\"value\":\"{%s:5}\"} ] }",
+ currency,
+ currency,
+ currency);
+ GNUNET_snprintf (order_worth_10_2coins,
+ sizeof (order_worth_10_2coins),
+ "{\"max_fee\": {\"currency\":\"%s\", \"value\":0, \"fraction\":50000000},"
+ "\"refund_deadline\":\"\\/Date(0)\\/\","
+ "\"pay_deadline\":\"\\/Date(99999999999)\\/\","
+ "\"amount\": {\"currency\":\"%s\",\"value\":10, \"fraction\":0},"
+ "\"summary\": \"2-coins payment\","
+ "\"fulfillment_url\": \"https://example.com/\","
+ "\"products\": [ {\"description\":\"2-coins payment\","
+ "\"value\":\"{%s:10}\"} ] }",
+ currency,
+ currency,
+ currency);
+ {
+ char *hdr;
+
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ apikey);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CURL_append_header (is->ctx,
+ hdr));
+ GNUNET_free (hdr);
+ }
+
+ if (ordinary)
+ {
+ struct TALER_TESTING_Command ordinary_commands[] = {
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
+ CURRENCY_10_02,
+ &auth,
+ customer_payto),
+ TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
+ cfg_filename),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
+ "create-reserve-1",
+ CURRENCY_5,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
+ "create-reserve-1",
+ CURRENCY_5,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1",
merchant_url,
- "EUR:4.98", /* FIXME: check amount! */
MHD_HTTP_OK,
- "deposit-simple-2",
- NULL),
- TALER_TESTING_cmd_merchant_get_transfers ("track-transfer-1",
+ order_worth_5),
+ TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
+ merchant_url,
+ MHD_HTTP_OK,
+ "create-proposal-1",
+ "withdraw-coin-1",
+ CURRENCY_5,
+ CURRENCY_4_99),
+ TALER_TESTING_cmd_rewind_ip ("rewind-payments",
+ FIRST_INSTRUCTION,
+ &payments_number),
+ /* Next proposal-pay cycle will be used by /track CMDs
+ * and so it will not have to be looped over, only /track
+ * CMDs will have to. */
+ TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2",
merchant_url,
- merchant_payto,
MHD_HTTP_OK,
- "post-transaction-1",
- NULL),
- TALER_TESTING_cmd_rewind_ip ("rewind-tracks",
- TRACKS_INSTRUCTION,
- &tracks_number),
- TALER_TESTING_cmd_end ()
- };
-
- struct TALER_TESTING_Command corner_commands[] = {
- TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
- CURRENCY_5_01,
- &auth,
- customer_payto),
- TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
- cfg_filename),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
- "create-reserve-1",
- CURRENCY_5,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_merchant_post_orders ("create-unaggregated-proposal",
- alt_instance_url,
- MHD_HTTP_OK,
- order_worth_5_unaggregated),
- TALER_TESTING_cmd_merchant_pay_order ("deposit-unaggregated",
- merchant_url,
- MHD_HTTP_OK,
- "create-unaggregated-proposal",
- "withdraw-coin-1",
- CURRENCY_5,
- CURRENCY_4_99),
- TALER_TESTING_cmd_rewind_ip ("rewind-unaggregated",
- FIRST_INSTRUCTION,
- &unaggregated_number),
- TALER_TESTING_cmd_admin_add_incoming ("create-reserve-2",
- CURRENCY_10_02,
- &auth,
- customer_payto),
- TALER_TESTING_cmd_exec_wirewatch ("wirewatch-2",
- cfg_filename),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
- "create-reserve-2",
- CURRENCY_5,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-3",
- "create-reserve-2",
- CURRENCY_5,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_merchant_post_orders ("create-twocoins-proposal",
+ order_worth_5_track),
+ TALER_TESTING_cmd_merchant_pay_order ("deposit-simple-2",
merchant_url,
MHD_HTTP_OK,
- order_worth_10_2coins),
- TALER_TESTING_cmd_merchant_pay_order ("deposit-twocoins",
- merchant_url,
- MHD_HTTP_OK,
- "create-twocoins-proposal",
- "withdraw-coin-2;withdraw-coin-3",
- CURRENCY_10,
- CURRENCY_9_98),
- TALER_TESTING_cmd_exec_aggregator ("aggregate-twocoins",
- cfg_filename),
- TALER_TESTING_cmd_rewind_ip ("rewind-twocoins",
- TWOCOINS_INSTRUCTION,
- &twocoins_number),
- TALER_TESTING_cmd_end ()
- };
+ "create-proposal-2",
+ "withdraw-coin-2",
+ CURRENCY_5,
+ CURRENCY_4_99),
+ /* /track/transaction over deposit-simple-2 */
+
+ TALER_TESTING_cmd_exec_aggregator ("aggregate-1",
+ cfg_filename),
+ TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1",
+ &auth,
+ bank_url,
+ merchant_url,
+ "EUR:4.98", /* FIXME: check amount! */
+ MHD_HTTP_OK,
+ "deposit-simple-2",
+ NULL),
+ TALER_TESTING_cmd_merchant_get_transfers ("track-transfer-1",
+ merchant_url,
+ merchant_payto,
+ MHD_HTTP_OK,
+ "post-transaction-1",
+ NULL),
+ TALER_TESTING_cmd_rewind_ip ("rewind-tracks",
+ TRACKS_INSTRUCTION,
+ &tracks_number),
+ TALER_TESTING_cmd_end ()
+ };
- if (GNUNET_OK == ordinary)
- {
TALER_TESTING_run (is,
ordinary_commands);
return;
}
- if (GNUNET_OK == corner)
+ if (corner) /* should never be 'false' here */
{
+ struct TALER_TESTING_Command corner_commands[] = {
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
+ CURRENCY_5_01,
+ &auth,
+ customer_payto),
+ TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
+ cfg_filename),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
+ "create-reserve-1",
+ CURRENCY_5,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders ("create-unaggregated-proposal",
+ alt_instance_url,
+ MHD_HTTP_OK,
+ order_worth_5_unaggregated),
+ TALER_TESTING_cmd_merchant_pay_order ("deposit-unaggregated",
+ merchant_url,
+ MHD_HTTP_OK,
+ "create-unaggregated-proposal",
+ "withdraw-coin-1",
+ CURRENCY_5,
+ CURRENCY_4_99),
+ TALER_TESTING_cmd_rewind_ip ("rewind-unaggregated",
+ FIRST_INSTRUCTION,
+ &unaggregated_number),
+ TALER_TESTING_cmd_admin_add_incoming ("create-reserve-2",
+ CURRENCY_10_02,
+ &auth,
+ customer_payto),
+ TALER_TESTING_cmd_exec_wirewatch ("wirewatch-2",
+ cfg_filename),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
+ "create-reserve-2",
+ CURRENCY_5,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-3",
+ "create-reserve-2",
+ CURRENCY_5,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_orders ("create-twocoins-proposal",
+ merchant_url,
+ MHD_HTTP_OK,
+ order_worth_10_2coins),
+ TALER_TESTING_cmd_merchant_pay_order ("deposit-twocoins",
+ merchant_url,
+ MHD_HTTP_OK,
+ "create-twocoins-proposal",
+ "withdraw-coin-2;withdraw-coin-3",
+ CURRENCY_10,
+ CURRENCY_9_98),
+ TALER_TESTING_cmd_exec_aggregator ("aggregate-twocoins",
+ cfg_filename),
+ TALER_TESTING_cmd_rewind_ip ("rewind-twocoins",
+ TWOCOINS_INSTRUCTION,
+ &twocoins_number),
+ TALER_TESTING_cmd_end ()
+ };
+
TALER_TESTING_run (is,
corner_commands);
return;
}
-
- /* Should never get here, as the control on subcommands
- * happens earlier at launch time. */
- fprintf (stderr,
- "None of 'ordinary' or 'corner'"
- " subcommands were given\n");
- result = 1;
}
@@ -484,7 +413,8 @@ run (void *cls,
static void
terminate_process (struct GNUNET_OS_Process *process)
{
- GNUNET_OS_process_kill (process, SIGTERM);
+ GNUNET_OS_process_kill (process,
+ SIGTERM);
GNUNET_OS_process_wait (process);
GNUNET_OS_process_destroy (process);
}
@@ -501,14 +431,16 @@ int
main (int argc,
char *const *argv)
{
+ char *loglev;
+ char *logfile;
+ struct GNUNET_OS_Process *bankd;
+ struct GNUNET_OS_Process *merchantd;
struct GNUNET_GETOPT_CommandLineOption *options;
struct GNUNET_GETOPT_CommandLineOption root_options[] = {
GNUNET_GETOPT_option_cfgfile (&cfg_filename),
GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_option_flag ('h',
- "help",
- NULL,
- &root_help),
+ GNUNET_GETOPT_option_help ("Runs benchmark logic against merchant backend. "
+ "Must be used with either 'ordinary' or 'corner' sub-commands."),
GNUNET_GETOPT_OPTION_END
};
struct GNUNET_GETOPT_CommandLineOption corner_options[] = {
@@ -531,33 +463,43 @@ main (int argc,
* Clearly, we could introduce a merchant_base_url
* value into the configuration.
*///
- GNUNET_GETOPT_option_string ('m',
- "merchant-url",
- "MU",
- "merchant base url, mandatory",
- &merchant_url),
- GNUNET_GETOPT_option_string ('k',
- "currency",
- "K",
- "Used currency, mandatory",
- &currency),
- GNUNET_GETOPT_option_string ('i',
- "alt-instance",
- "AI",
- "alternative (non default) instance,"
- " used to provide fresh wire details to"
- " make unaggregated transactions stay so."
- " Note, this instance will be given far"
- " future wire deadline, and so it should"
- " never author now-deadlined transactions,"
- " as they would get those far future ones"
- " aggregated too.",
- &alt_instance_id),
- GNUNET_GETOPT_option_string ('b',
- "bank-url",
- "BU",
- "bank base url, mandatory",
- &bank_url),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('m',
+ "merchant-url",
+ "MU",
+ "merchant base url, mandatory",
+ &merchant_url)),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('a',
+ "apikey",
+ "APIKEY",
+ "HTTP 'Authorization' header to send to the merchant, mandatory",
+ &apikey)),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('k',
+ "currency",
+ "K",
+ "Used currency, mandatory",
+ &currency)),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('i',
+ "alt-instance",
+ "AI",
+ "alternative (non default) instance,"
+ " used to provide fresh wire details to"
+ " make unaggregated transactions stay so."
+ " Note, this instance will be given far"
+ " future wire deadline, and so it should"
+ " never author now-deadlined transactions,"
+ " as they would get those far future ones"
+ " aggregated too.",
+ &alt_instance_id)),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('b',
+ "bank-url",
+ "BU",
+ "bank base url, mandatory",
+ &bank_url)),
GNUNET_GETOPT_option_string ('l',
"logfile",
"LF",
@@ -576,6 +518,12 @@ main (int argc,
"PN",
"will generate PN payments, defaults to 1",
&payments_number),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('a',
+ "apikey",
+ "APIKEY",
+ "HTTP 'Authorization' header to send to the merchant, mandatory",
+ &apikey)),
GNUNET_GETOPT_option_uint ('t',
"tracks-number",
"TN",
@@ -588,16 +536,18 @@ main (int argc,
* Clearly, we could introduce a merchant_base_url
* value into the configuration.
*///
- GNUNET_GETOPT_option_string ('m',
- "merchant-url",
- "MU",
- "merchant base url, mandatory",
- &merchant_url),
- GNUNET_GETOPT_option_string ('b',
- "bank-url",
- "BU",
- "bank base url, mandatory",
- &bank_url),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('m',
+ "merchant-url",
+ "MU",
+ "merchant base url, mandatory",
+ &merchant_url)),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string ('b',
+ "bank-url",
+ "BU",
+ "bank base url, mandatory",
+ &bank_url)),
GNUNET_GETOPT_option_string ('l',
"logfile",
"LF",
@@ -605,10 +555,9 @@ main (int argc,
&logfile),
GNUNET_GETOPT_OPTION_END
};
+ const char *default_config_file;
- default_config_file = GNUNET_OS_project_data_get
- ()->user_config_file;
-
+ default_config_file = GNUNET_OS_project_data_get ()->user_config_file;
loglev = NULL;
GNUNET_log_setup ("taler-merchant-benchmark",
loglev,
@@ -618,66 +567,37 @@ main (int argc,
{
if (0 == strcmp ("ordinary", argv[1]))
{
- ordinary = GNUNET_YES;
+ ordinary = true;
options = ordinary_options;
}
if (0 == strcmp ("corner", argv[1]))
{
- corner = GNUNET_YES;
+ corner = true;
options = corner_options;
}
}
- if (GNUNET_SYSERR !=
- (result = GNUNET_GETOPT_run
- ("taler-merchant-benchmark",
- options,
- argc,
- argv)))
{
-
- if (GNUNET_YES == root_help)
- {
- fprintf (stdout,
- "%s",
- root_help_str);
- return 0;
- }
-
- /* --help was given. */
+ int result;
+
+ result = GNUNET_GETOPT_run ("taler-merchant-benchmark",
+ options,
+ argc,
+ argv);
+ if (GNUNET_SYSERR == result)
+ return PG_BAD_OPTIONS;
if (0 == result)
- return 0;
+ return PG_SUCCESS;
}
- if (-1 == result)
- return 1;
- if ( (GNUNET_YES != ordinary) &&
- (GNUNET_YES != corner) )
+ if ( (! ordinary) &&
+ (! corner) )
{
fprintf (stderr,
"Please use 'ordinary' or 'corner' subcommands.\n");
- return 1;
- }
-
- if ( (GNUNET_YES == corner) &&
- (NULL == alt_instance_id) )
- {
- fprintf (stderr,
- "option '-i' is mandatory with sub-command 'corner'!\n");
- return 1;
+ return PG_NO_SUBCOMMAND;
}
if (NULL == cfg_filename)
cfg_filename = (char *) default_config_file;
- if (NULL == currency)
- {
- TALER_LOG_ERROR ("Option -k is mandatory!\n");
- return MISSING_CURRENCY;
- }
- if (NULL == merchant_url)
- {
- TALER_LOG_ERROR ("Option -m is mandatory!\n");
- return MISSING_MERCHANT_URL;
- }
-
if (NULL != alt_instance_id)
{
GNUNET_assert (0 < GNUNET_asprintf (&alt_instance_url,
@@ -685,28 +605,18 @@ main (int argc,
merchant_url,
&alt_instance_id));
}
-
- if (NULL == (merchantd = TALER_TESTING_run_merchant
- (cfg_filename, merchant_url)))
+ if (NULL == (merchantd = TALER_TESTING_run_merchant (cfg_filename,
+ merchant_url)))
{
TALER_LOG_ERROR ("Failed to launch the merchant\n");
- return FAILED_TO_LAUNCH_MERCHANT;
+ return PG_FAILED_TO_LAUNCH_MERCHANT;
}
-
- if (NULL == bank_url)
- {
- TALER_LOG_ERROR ("Option -b is mandatory!\n");
- terminate_process (merchantd);
- return MISSING_BANK_URL;
- }
-
- if (NULL == (bankd = TALER_TESTING_run_bank
- (cfg_filename,
- bank_url)))
+ if (NULL == (bankd = TALER_TESTING_run_bank (cfg_filename,
+ bank_url)))
{
TALER_LOG_ERROR ("Failed to run the bank\n");
terminate_process (merchantd);
- return FAILED_TO_LAUNCH_BANK;
+ return PG_FAILED_TO_LAUNCH_BANK;
}
/**
@@ -717,13 +627,14 @@ main (int argc,
merchant_payto = "payto://x-taler-bank/localhost/Merchant";
customer_payto = "payto://x-taler-bank/localhost/Customer";
- result = TALER_TESTING_setup_with_exchange
- (run,
- NULL,
- cfg_filename);
-
- terminate_process (merchantd);
- terminate_process (bankd);
+ {
+ int result;
- return (GNUNET_OK == result) ? 0 : result;
+ result = TALER_TESTING_setup_with_exchange (run,
+ NULL,
+ cfg_filename);
+ terminate_process (merchantd);
+ terminate_process (bankd);
+ return (GNUNET_OK == result) ? 0 : PG_RUNTIME_FAILURE;
+ }
}