diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bank-lib/fakebank.c | 1 | ||||
-rw-r--r-- | src/include/taler_testing_lib.h | 22 | ||||
-rw-r--r-- | src/lib/test_taler_exchange_aggregator.c | 55 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_insert_deposit.c | 180 |
4 files changed, 208 insertions, 50 deletions
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index 15b21ba39..8dc268bba 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -1293,7 +1293,6 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h) h); } - #else /** * Schedule MHD. This function should be called initially when an diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 48214aed5..9b0ca422c 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -94,6 +94,22 @@ struct TALER_TESTING_ExchangeConfiguration }; +/** + * Connection to the database: aggregates + * plugin and session handles. + */ +struct TALER_TESTING_DatabaseConnection +{ + /** + * Database plugin. + */ + struct TALER_EXCHANGEDB_Plugin *plugin; + + /** + * Session with the database. + */ + struct TALER_EXCHANGEDB_Session *session; +}; /** * Prepare launching an exchange. Checks that the configured @@ -1667,7 +1683,7 @@ TALER_TESTING_cmd_connect_with_state (const char *label, * Make the "insert-deposit" CMD. * * @param label command label. - * @param config_filename configuration filename. + * @param dbc collects plugin and session handles * @param merchant_name Human-readable name of the merchant. * @param merchant_account value indicating the merchant at its bank. * @param wire_deadline point in time where the aggregator should have @@ -1678,10 +1694,10 @@ TALER_TESTING_cmd_connect_with_state (const char *label, */ struct TALER_TESTING_Command TALER_TESTING_cmd_insert_deposit (const char *label, - const char *config_filename, + const struct TALER_TESTING_DatabaseConnection *dbc, const char *merchant_name, const char *merchant_account, - struct GNUNET_TIME_Absolute wire_deadline, + struct GNUNET_TIME_Relative wire_deadline, const char *amount_with_fee, const char *deposit_fee); diff --git a/src/lib/test_taler_exchange_aggregator.c b/src/lib/test_taler_exchange_aggregator.c index 075effc2d..52734a896 100644 --- a/src/lib/test_taler_exchange_aggregator.c +++ b/src/lib/test_taler_exchange_aggregator.c @@ -40,6 +40,11 @@ static struct TALER_TESTING_ExchangeConfiguration ec; static struct TALER_TESTING_BankConfiguration bc; /** + * Contains plugin and session. + */ +static struct TALER_TESTING_DatabaseConnection dbc; + +/** * Return value from main(). */ static int result; @@ -50,16 +55,6 @@ static int result; static char *config_filename; /** - * Database plugin. - */ -static struct TALER_EXCHANGEDB_Plugin *plugin; - -/** - * Our session with the database. - */ -static struct TALER_EXCHANGEDB_Session *session; - -/** * Private key we use for fake coins. */ static struct GNUNET_CRYPTO_RsaPrivateKey *coin_pk; @@ -69,6 +64,9 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *coin_pk; */ static struct GNUNET_CRYPTO_RsaPublicKey *coin_pub; +#define MERCHANT_ACCOUNT "irrelevant-merchant-account-uri" + +#if 0 /** * Setup (fake) information about a coin used in deposit. * @@ -95,8 +93,9 @@ fake_issue (struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) TALER_string_to_amount_nbo ("EUR:0.1", &issue->properties.fee_refund)); } +#endif - +#if 0 /** * Setup (fake) information about a coin used in deposit. * @@ -114,7 +113,7 @@ fake_coin (struct TALER_CoinPublicInfo *coin) coin->denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign_fdh (coin_pk, &hc); } - +#endif #if 0 /** @@ -874,8 +873,8 @@ prepare_database (void *cls, { // connect to the database. - plugin = TALER_EXCHANGEDB_plugin_load (cfg); - if (NULL == plugin) + dbc.plugin = TALER_EXCHANGEDB_plugin_load (cfg); + if (NULL == dbc.plugin) { GNUNET_break (0); result = 77; @@ -883,17 +882,17 @@ prepare_database (void *cls, } if (GNUNET_OK != - plugin->create_tables (plugin->cls)) + dbc.plugin->create_tables (dbc.plugin->cls)) { GNUNET_break (0); - TALER_EXCHANGEDB_plugin_unload (plugin); - plugin = NULL; + TALER_EXCHANGEDB_plugin_unload (dbc.plugin); + dbc.plugin = NULL; result = 77; return GNUNET_NO; } - session = plugin->get_session (plugin->cls); - GNUNET_assert (NULL != session); + dbc.session = dbc.plugin->get_session (dbc.plugin->cls); + GNUNET_assert (NULL != dbc.session); return GNUNET_OK; } @@ -907,6 +906,16 @@ run (void *cls, struct TALER_TESTING_Interpreter *is) { struct TALER_TESTING_Command all[] = { + TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-empty-db", + config_filename), + TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"), + TALER_TESTING_cmd_insert_deposit ("do-deposit-1", + &dbc, + "bob", + MERCHANT_ACCOUNT, // not relevant + GNUNET_TIME_UNIT_ZERO, + "EUR:1", + "EUR:0.1"), TALER_TESTING_cmd_end () }; @@ -921,9 +930,6 @@ main (int argc, { const char *plugin_name; char *testname; - struct GNUNET_OS_Process *proc; - struct GNUNET_CONFIGURATION_Handle *cfg; - struct GNUNET_SIGNAL_Context *shc_chld; if (NULL == (plugin_name = strrchr (argv[0], (int) '-'))) { @@ -948,7 +954,6 @@ main (int argc, TALER_TESTING_cleanup_files (config_filename); - // BUG: FAILS NOW. if (GNUNET_OK != TALER_TESTING_prepare_exchange (config_filename, &ec)) { @@ -981,10 +986,10 @@ main (int argc, NULL, // no exchange process handle. GNUNET_NO); // do not try to connect to the exchange - GNUNET_CRYPTO_rsa_private_key_free (coin_pk); - GNUNET_CRYPTO_rsa_public_key_free (coin_pub); GNUNET_free (config_filename); GNUNET_free (testname); + dbc.plugin->drop_tables (dbc.plugin->cls); + TALER_EXCHANGEDB_plugin_unload (dbc.plugin); return GNUNET_OK == result ? 0 : 1; } diff --git a/src/lib/testing_api_cmd_insert_deposit.c b/src/lib/testing_api_cmd_insert_deposit.c index 0e7ea661d..a5a285b0c 100644 --- a/src/lib/testing_api_cmd_insert_deposit.c +++ b/src/lib/testing_api_cmd_insert_deposit.c @@ -24,11 +24,13 @@ * @author Christian Grothoff */ #include "platform.h" +#include "taler_util.h" #include "taler_json_lib.h" #include <gnunet/gnunet_curl_lib.h> #include "auditor_api_handle.h" #include "taler_signatures.h" #include "taler_testing_lib.h" +#include "taler_exchangedb_plugin.h" /** @@ -39,7 +41,7 @@ struct InsertDepositState /** * Configuration file used by the command. */ - const char *config_filename; + const struct TALER_TESTING_DatabaseConnection *dbc; /** * Human-readable name of the shop. @@ -55,7 +57,7 @@ struct InsertDepositState * Deadline before which the aggregator should * send the payment to the merchant. */ - struct GNUNET_TIME_Absolute wire_deadline; + struct GNUNET_TIME_Relative wire_deadline; /** * Amount to deposit, inclusive of deposit fee. @@ -68,6 +70,35 @@ struct InsertDepositState const char *deposit_fee; }; +/** + * Setup (fake) information about a coin used in deposit. + * + * @param[out] issue information to initialize with "valid" data + */ +static void +fake_issue (struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue) +{ + memset (issue, 0, sizeof (struct + TALER_EXCHANGEDB_DenominationKeyInformationP)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount_nbo ("EUR:1", + &issue->properties.value)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount_nbo ("EUR:0.1", + &issue->properties.fee_withdraw)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount_nbo ("EUR:0.1", + &issue->properties.fee_deposit)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount_nbo ("EUR:0.1", + &issue->properties.fee_refresh)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount_nbo ("EUR:0.1", + &issue->properties.fee_refund)); +} + + + /** * Run the command. @@ -82,7 +113,122 @@ insert_deposit_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct InsertDepositState *ids = cls; - // TODO + struct TALER_EXCHANGEDB_Deposit deposit; + struct TALER_MerchantPrivateKeyP merchant_priv; + struct TALER_EXCHANGEDB_DenominationKeyInformationP issue; + struct TALER_DenominationPublicKey dpk; + struct GNUNET_CRYPTO_RsaPrivateKey *denom_priv; + struct GNUNET_HashCode hc; + + // prepare and store issue first. + fake_issue (&issue); + denom_priv = GNUNET_CRYPTO_rsa_private_key_create (1024); + dpk.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public (denom_priv); + GNUNET_CRYPTO_rsa_public_key_hash (dpk.rsa_public_key, + &issue.properties.denom_hash); + + if ( (GNUNET_OK != + ids->dbc->plugin->start (ids->dbc->plugin->cls, + ids->dbc->session, + "talertestinglib: denomination insertion")) || + (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls, + ids->dbc->session, + &dpk, + &issue)) || + (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + ids->dbc->plugin->commit (ids->dbc->plugin->cls, + ids->dbc->session)) ) + { + TALER_TESTING_interpreter_fail (is); + return; + } + + // prepare and store deposit now. + memset (&deposit, + 0, + sizeof (deposit)); + + GNUNET_CRYPTO_kdf (&merchant_priv, + sizeof (struct TALER_MerchantPrivateKeyP), + "merchant-priv", + strlen ("merchant-priv"), + ids->merchant_name, + strlen (ids->merchant_name), + NULL, + 0); + GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv, + &deposit.merchant_pub.eddsa_pub); + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &deposit.h_contract_terms); + if ( (GNUNET_OK != + TALER_string_to_amount (ids->amount_with_fee, + &deposit.amount_with_fee)) || + (GNUNET_OK != + TALER_string_to_amount (ids->deposit_fee, + &deposit.deposit_fee)) ) + { + TALER_TESTING_interpreter_fail (is); + return; + } + + GNUNET_CRYPTO_rsa_public_key_hash (dpk.rsa_public_key, + &deposit.coin.denom_pub_hash); + + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &hc); + deposit.coin.denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign_fdh (denom_priv, + &hc); + { + char *str; + + GNUNET_asprintf (&str, + "payto://x-taler-bank/localhost:8082/%s", + ids->merchant_account); + deposit.receiver_wire_account + = json_pack ("{s:s, s:s}", + "salt", "this-is-a-salt-value", + "url", str); + GNUNET_free (str); + } + + GNUNET_assert (GNUNET_OK == + TALER_JSON_merchant_wire_signature_hash ( + deposit.receiver_wire_account, + &deposit.h_wire)); + deposit.timestamp = GNUNET_TIME_absolute_get (); + GNUNET_TIME_round_abs (&deposit.timestamp); + deposit.wire_deadline = GNUNET_TIME_relative_to_absolute ( + ids->wire_deadline); + GNUNET_TIME_round_abs (&deposit.wire_deadline); + + /* finally, actually perform the DB operation */ + if ( (GNUNET_OK != + ids->dbc->plugin->start (ids->dbc->plugin->cls, + ids->dbc->session, + "libtalertesting: insert deposit")) || + (0 > + ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls, + ids->dbc->session, + &deposit.coin)) || + (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls, + ids->dbc->session, + &deposit)) || + (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + ids->dbc->plugin->commit (ids->dbc->plugin->cls, + ids->dbc->session)) ) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + } + + GNUNET_CRYPTO_rsa_signature_free (deposit.coin.denom_sig.rsa_signature); + GNUNET_CRYPTO_rsa_public_key_free (dpk.rsa_public_key); + GNUNET_CRYPTO_rsa_private_key_free (denom_priv); + json_decref (deposit.receiver_wire_account); + + TALER_TESTING_interpreter_next (is); } @@ -97,9 +243,9 @@ static void insert_deposit_cleanup (void *cls, const struct TALER_TESTING_Command *cmd) { - struct InsertDepositState *ds = cls; - - GNUNET_free (ds); + struct InsertDepositState *ids = cls; + + GNUNET_free (ids); } @@ -118,16 +264,7 @@ insert_deposit_traits (void *cls, const char *trait, unsigned int index) { - struct InsertDepositState *ids = cls; - struct TALER_TESTING_Trait traits[] = { - // FIXME: needed? - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); + return GNUNET_NO; } @@ -135,7 +272,7 @@ insert_deposit_traits (void *cls, * Make the "insert-deposit" CMD. * * @param label command label. - * @param config_filename configuration filename. + * @param dbc collects database plugin and session handles. * @param merchant_name Human-readable name of the merchant. * @param merchant_account value indicating the merchant at its bank. * @param wire_deadline point in time where the aggregator should have @@ -146,10 +283,10 @@ insert_deposit_traits (void *cls, */ struct TALER_TESTING_Command TALER_TESTING_cmd_insert_deposit (const char *label, - const char *config_filename, + const struct TALER_TESTING_DatabaseConnection *dbc, const char *merchant_name, const char *merchant_account, - struct GNUNET_TIME_Absolute wire_deadline, + struct GNUNET_TIME_Relative wire_deadline, const char *amount_with_fee, const char *deposit_fee) { @@ -157,7 +294,7 @@ TALER_TESTING_cmd_insert_deposit (const char *label, struct InsertDepositState *ids; ids = GNUNET_new (struct InsertDepositState); - ids->config_filename = config_filename; + ids->dbc = dbc; ids->merchant_name = merchant_name; ids->merchant_account = merchant_account; ids->wire_deadline = wire_deadline; @@ -169,8 +306,9 @@ TALER_TESTING_cmd_insert_deposit (const char *label, cmd.run = &insert_deposit_run; cmd.cleanup = &insert_deposit_cleanup; cmd.traits = &insert_deposit_traits; + return cmd; } -/* end of testing_auditor_api_cmd_exec_auditor_dbinit.c */ +/* end of testing_api_cmd_insert_deposit.c */ |