diff options
Diffstat (limited to 'src/testing/test_taler_exchange_aggregator.c')
-rw-r--r-- | src/testing/test_taler_exchange_aggregator.c | 257 |
1 files changed, 78 insertions, 179 deletions
diff --git a/src/testing/test_taler_exchange_aggregator.c b/src/testing/test_taler_exchange_aggregator.c index bee7e37e5..2d7acc6dc 100644 --- a/src/testing/test_taler_exchange_aggregator.c +++ b/src/testing/test_taler_exchange_aggregator.c @@ -31,24 +31,9 @@ /** - * Helper structure to keep exchange configuration values. + * Our credentials. */ -static struct TALER_TESTING_ExchangeConfiguration ec; - -/** - * Bank configuration data. - */ -static struct TALER_TESTING_BankConfiguration bc; - -/** - * Contains plugin. - */ -static struct TALER_TESTING_DatabaseConnection dbc; - -/** - * Return value from main(). - */ -static int result; +struct TALER_TESTING_Credentials cred; /** * Name of the configuration file to use. @@ -71,24 +56,6 @@ static char *config_filename; /** - * Function run on shutdown to unload the DB plugin. - * - * @param cls NULL - */ -static void -unload_db (void *cls) -{ - (void) cls; - if (NULL != dbc.plugin) - { - dbc.plugin->drop_tables (dbc.plugin->cls); - TALER_EXCHANGEDB_plugin_unload (dbc.plugin); - dbc.plugin = NULL; - } -} - - -/** * Collects all the tests. */ static void @@ -96,11 +63,13 @@ run (void *cls, struct TALER_TESTING_Interpreter *is) { struct TALER_TESTING_Command all[] = { - TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees", - config_filename, - "EUR:0.01", - "EUR:0.01"), - // check no aggregation happens on a empty database + TALER_TESTING_cmd_run_fakebank ("run-fakebank", + cred.cfg, + "exchange-account-1"), + TALER_TESTING_cmd_system_start ("start-taler", + config_filename, + "-e", + NULL), CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty-db", config_filename), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"), @@ -108,7 +77,7 @@ run (void *cls, /* check aggregation happens on the simplest case: one deposit into the database. */ TALER_TESTING_cmd_insert_deposit ("do-deposit-1", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -119,15 +88,15 @@ run (void *cls, config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1", - ec.exchange_url, + cred.exchange_url, "EUR:0.89", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-1"), /* check aggregation accumulates well. */ TALER_TESTING_cmd_insert_deposit ("do-deposit-2a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -136,7 +105,7 @@ run (void *cls, "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-2b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -148,15 +117,15 @@ run (void *cls, config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-2", - ec.exchange_url, + cred.exchange_url, "EUR:1.79", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-2"), /* check that different merchants stem different aggregations. */ TALER_TESTING_cmd_insert_deposit ("do-deposit-3a", - &dbc, + cred.cfg, "bob", "4", GNUNET_TIME_timestamp_get (), @@ -164,7 +133,7 @@ run (void *cls, "EUR:1", "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-3b", - &dbc, + cred.cfg, "bob", "5", GNUNET_TIME_timestamp_get (), @@ -172,7 +141,7 @@ run (void *cls, "EUR:1", "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-3c", - &dbc, + cred.cfg, "alice", "4", GNUNET_TIME_timestamp_get (), @@ -183,25 +152,25 @@ run (void *cls, config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3a", - ec.exchange_url, + cred.exchange_url, "EUR:0.89", - bc.exchange_payto, + cred.exchange_payto, "payto://x-taler-bank/localhost/4?receiver-name=4"), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3b", - ec.exchange_url, + cred.exchange_url, "EUR:0.89", - bc.exchange_payto, + cred.exchange_payto, "payto://x-taler-bank/localhost/4?receiver-name=4"), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3c", - ec.exchange_url, + cred.exchange_url, "EUR:0.89", - bc.exchange_payto, + cred.exchange_payto, "payto://x-taler-bank/localhost/5?receiver-name=5"), TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-3"), /* checking that aggregator waits for the deadline. */ TALER_TESTING_cmd_insert_deposit ("do-deposit-4a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -211,7 +180,7 @@ run (void *cls, "EUR:0.2", "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-4b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -230,14 +199,14 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-4-delayed", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-4", - ec.exchange_url, + cred.exchange_url, "EUR:0.19", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), // test picking all deposits at earliest deadline TALER_TESTING_cmd_insert_deposit ("do-deposit-5a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -248,7 +217,7 @@ run (void *cls, "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-5b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -267,13 +236,13 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-5-delayed", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-5", - ec.exchange_url, + cred.exchange_url, "EUR:0.19", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), /* Test NEVER running 'tiny' unless they make up minimum unit */ TALER_TESTING_cmd_insert_deposit ("do-deposit-6a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -285,7 +254,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -293,7 +262,7 @@ run (void *cls, "EUR:0.102", "EUR:0.1"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6c", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -305,7 +274,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6c-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6d", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -317,7 +286,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-6d-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-6e", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -327,14 +296,14 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6e", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-6", - ec.exchange_url, + cred.exchange_url, "EUR:0.01", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), /* Test profiteering if wire deadline is short */ TALER_TESTING_cmd_insert_deposit ("do-deposit-7a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -346,7 +315,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-7a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-7b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -356,14 +325,14 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-profit", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7", - ec.exchange_url, + cred.exchange_url, "EUR:0.01", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), /* Now check profit was actually taken */ TALER_TESTING_cmd_insert_deposit ("do-deposit-7c", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -373,14 +342,14 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-loss", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7", - ec.exchange_url, + cred.exchange_url, "EUR:0.01", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), /* Test that aggregation would happen fully if wire deadline is long */ TALER_TESTING_cmd_insert_deposit ("do-deposit-8a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -394,7 +363,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-8a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-8b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -410,7 +379,7 @@ run (void *cls, /* now trigger aggregate with large transaction and short deadline */ TALER_TESTING_cmd_insert_deposit ("do-deposit-8c", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -420,14 +389,14 @@ run (void *cls, CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-8", config_filename), TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-8", - ec.exchange_url, + cred.exchange_url, "EUR:0.03", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), /* Test aggregation with fees and rounding profits. */ TALER_TESTING_cmd_insert_deposit ("do-deposit-9a", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -441,7 +410,7 @@ run (void *cls, TALER_TESTING_cmd_check_bank_empty ( "expect-empty-transactions-after-9a-tiny"), TALER_TESTING_cmd_insert_deposit ("do-deposit-9b", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -457,7 +426,7 @@ run (void *cls, /* now trigger aggregate with large transaction and short deadline */ TALER_TESTING_cmd_insert_deposit ("do-deposit-9c", - &dbc, + cred.cfg, "bob", USER42_ACCOUNT, GNUNET_TIME_timestamp_get (), @@ -468,49 +437,15 @@ run (void *cls, config_filename), /* 0.009 + 0.009 + 0.022 - 0.001 - 0.002 - 0.008 = 0.029 => 0.02 */ TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-9", - ec.exchange_url, + cred.exchange_url, "EUR:0.01", - bc.exchange_payto, - bc.user42_payto), + cred.exchange_payto, + cred.user42_payto), TALER_TESTING_cmd_end () }; - TALER_TESTING_run_with_fakebank (is, - all, - bc.exchange_auth.wire_gateway_url); -} - - -/** - * Prepare database and launch the test. - * - * @param cls unused - * @param is interpreter to use - */ -static void -prepare_database (void *cls, - struct TALER_TESTING_Interpreter *is) -{ - dbc.plugin = TALER_EXCHANGEDB_plugin_load (is->cfg); - if (NULL == dbc.plugin) - { - GNUNET_break (0); - result = 77; - TALER_TESTING_interpreter_fail (is); - return; - } - if (GNUNET_OK != - dbc.plugin->preflight (dbc.plugin->cls)) - { - GNUNET_break (0); - result = 77; - TALER_TESTING_interpreter_fail (is); - return; - } - GNUNET_SCHEDULER_add_shutdown (&unload_db, - NULL); - run (NULL, - is); + TALER_TESTING_run (is, + all); } @@ -519,7 +454,6 @@ main (int argc, char *const argv[]) { const char *plugin_name; - char *testname; if (NULL == (plugin_name = strrchr (argv[0], (int) '-'))) { @@ -527,52 +461,17 @@ main (int argc, return -1; } plugin_name++; - (void) GNUNET_asprintf (&testname, - "test-taler-exchange-aggregator-%s", - plugin_name); (void) GNUNET_asprintf (&config_filename, - "%s.conf", - testname); - - GNUNET_log_setup ("test_taler_exchange_aggregator", - "INFO", - NULL); - - /* these might get in the way */ - unsetenv ("XDG_DATA_HOME"); - unsetenv ("XDG_CONFIG_HOME"); - - TALER_TESTING_cleanup_files (config_filename); - - if (GNUNET_OK != - TALER_TESTING_prepare_exchange (config_filename, - GNUNET_YES, - &ec)) - { - TALER_LOG_WARNING ("Could not prepare the exchange.\n"); - return 77; - } - - if (GNUNET_OK != - TALER_TESTING_prepare_fakebank (config_filename, - "exchange-account-1", - &bc)) - { - TALER_LOG_WARNING ("Could not prepare the fakebank\n"); - return 77; - } - result = GNUNET_OK; - if (GNUNET_OK != - TALER_TESTING_setup_with_exchange (&prepare_database, - NULL, - config_filename)) - { - TALER_LOG_WARNING ("Could not prepare database for tests.\n"); - return result; - } - GNUNET_free (config_filename); - GNUNET_free (testname); - return GNUNET_OK == result ? 0 : 1; + "test-taler-exchange-aggregator-%s.conf", + plugin_name); + return TALER_TESTING_main (argv, + "INFO", + config_filename, + "exchange-account-1", + TALER_TESTING_BS_FAKEBANK, + &cred, + &run, + NULL); } |