Finishing CMD to insert denomination and deposit into database.

This commit is contained in:
Marcello Stanisci 2020-01-16 18:37:07 +01:00
parent 23507d8565
commit 1e26fc824c
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
4 changed files with 208 additions and 50 deletions

View File

@ -1293,7 +1293,6 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h)
h); h);
} }
#else #else
/** /**
* Schedule MHD. This function should be called initially when an * Schedule MHD. This function should be called initially when an

View File

@ -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 * 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. * Make the "insert-deposit" CMD.
* *
* @param label command label. * @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_name Human-readable name of the merchant.
* @param merchant_account value indicating the merchant at its bank. * @param merchant_account value indicating the merchant at its bank.
* @param wire_deadline point in time where the aggregator should have * @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 struct TALER_TESTING_Command
TALER_TESTING_cmd_insert_deposit (const char *label, 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_name,
const char *merchant_account, const char *merchant_account,
struct GNUNET_TIME_Absolute wire_deadline, struct GNUNET_TIME_Relative wire_deadline,
const char *amount_with_fee, const char *amount_with_fee,
const char *deposit_fee); const char *deposit_fee);

View File

@ -39,6 +39,11 @@ static struct TALER_TESTING_ExchangeConfiguration ec;
*/ */
static struct TALER_TESTING_BankConfiguration bc; static struct TALER_TESTING_BankConfiguration bc;
/**
* Contains plugin and session.
*/
static struct TALER_TESTING_DatabaseConnection dbc;
/** /**
* Return value from main(). * Return value from main().
*/ */
@ -49,16 +54,6 @@ static int result;
*/ */
static char *config_filename; 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. * Private key we use for fake coins.
*/ */
@ -69,6 +64,9 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *coin_pk;
*/ */
static struct GNUNET_CRYPTO_RsaPublicKey *coin_pub; 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. * 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", TALER_string_to_amount_nbo ("EUR:0.1",
&issue->properties.fee_refund)); &issue->properties.fee_refund));
} }
#endif
#if 0
/** /**
* Setup (fake) information about a coin used in deposit. * 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, coin->denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_sign_fdh (coin_pk,
&hc); &hc);
} }
#endif
#if 0 #if 0
/** /**
@ -874,8 +873,8 @@ prepare_database (void *cls,
{ {
// connect to the database. // connect to the database.
plugin = TALER_EXCHANGEDB_plugin_load (cfg); dbc.plugin = TALER_EXCHANGEDB_plugin_load (cfg);
if (NULL == plugin) if (NULL == dbc.plugin)
{ {
GNUNET_break (0); GNUNET_break (0);
result = 77; result = 77;
@ -883,17 +882,17 @@ prepare_database (void *cls,
} }
if (GNUNET_OK != if (GNUNET_OK !=
plugin->create_tables (plugin->cls)) dbc.plugin->create_tables (dbc.plugin->cls))
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_EXCHANGEDB_plugin_unload (plugin); TALER_EXCHANGEDB_plugin_unload (dbc.plugin);
plugin = NULL; dbc.plugin = NULL;
result = 77; result = 77;
return GNUNET_NO; return GNUNET_NO;
} }
session = plugin->get_session (plugin->cls); dbc.session = dbc.plugin->get_session (dbc.plugin->cls);
GNUNET_assert (NULL != session); GNUNET_assert (NULL != dbc.session);
return GNUNET_OK; return GNUNET_OK;
} }
@ -907,6 +906,16 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is) struct TALER_TESTING_Interpreter *is)
{ {
struct TALER_TESTING_Command all[] = { 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 () TALER_TESTING_cmd_end ()
}; };
@ -921,9 +930,6 @@ main (int argc,
{ {
const char *plugin_name; const char *plugin_name;
char *testname; 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) '-'))) if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
{ {
@ -948,7 +954,6 @@ main (int argc,
TALER_TESTING_cleanup_files (config_filename); TALER_TESTING_cleanup_files (config_filename);
// BUG: FAILS NOW.
if (GNUNET_OK != TALER_TESTING_prepare_exchange (config_filename, if (GNUNET_OK != TALER_TESTING_prepare_exchange (config_filename,
&ec)) &ec))
{ {
@ -981,10 +986,10 @@ main (int argc,
NULL, // no exchange process handle. NULL, // no exchange process handle.
GNUNET_NO); // do not try to connect to the exchange 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 (config_filename);
GNUNET_free (testname); GNUNET_free (testname);
dbc.plugin->drop_tables (dbc.plugin->cls);
TALER_EXCHANGEDB_plugin_unload (dbc.plugin);
return GNUNET_OK == result ? 0 : 1; return GNUNET_OK == result ? 0 : 1;
} }

View File

@ -24,11 +24,13 @@
* @author Christian Grothoff * @author Christian Grothoff
*/ */
#include "platform.h" #include "platform.h"
#include "taler_util.h"
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h> #include <gnunet/gnunet_curl_lib.h>
#include "auditor_api_handle.h" #include "auditor_api_handle.h"
#include "taler_signatures.h" #include "taler_signatures.h"
#include "taler_testing_lib.h" #include "taler_testing_lib.h"
#include "taler_exchangedb_plugin.h"
/** /**
@ -39,7 +41,7 @@ struct InsertDepositState
/** /**
* Configuration file used by the command. * Configuration file used by the command.
*/ */
const char *config_filename; const struct TALER_TESTING_DatabaseConnection *dbc;
/** /**
* Human-readable name of the shop. * Human-readable name of the shop.
@ -55,7 +57,7 @@ struct InsertDepositState
* Deadline before which the aggregator should * Deadline before which the aggregator should
* send the payment to the merchant. * 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. * Amount to deposit, inclusive of deposit fee.
@ -68,6 +70,35 @@ struct InsertDepositState
const char *deposit_fee; 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. * Run the command.
@ -82,7 +113,122 @@ insert_deposit_run (void *cls,
struct TALER_TESTING_Interpreter *is) struct TALER_TESTING_Interpreter *is)
{ {
struct InsertDepositState *ids = cls; 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, insert_deposit_cleanup (void *cls,
const struct TALER_TESTING_Command *cmd) const struct TALER_TESTING_Command *cmd)
{ {
struct InsertDepositState *ds = cls; struct InsertDepositState *ids = cls;
GNUNET_free (ds); GNUNET_free (ids);
} }
@ -118,16 +264,7 @@ insert_deposit_traits (void *cls,
const char *trait, const char *trait,
unsigned int index) unsigned int index)
{ {
struct InsertDepositState *ids = cls; return GNUNET_NO;
struct TALER_TESTING_Trait traits[] = {
// FIXME: needed?
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
} }
@ -135,7 +272,7 @@ insert_deposit_traits (void *cls,
* Make the "insert-deposit" CMD. * Make the "insert-deposit" CMD.
* *
* @param label command label. * @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_name Human-readable name of the merchant.
* @param merchant_account value indicating the merchant at its bank. * @param merchant_account value indicating the merchant at its bank.
* @param wire_deadline point in time where the aggregator should have * @param wire_deadline point in time where the aggregator should have
@ -146,10 +283,10 @@ insert_deposit_traits (void *cls,
*/ */
struct TALER_TESTING_Command struct TALER_TESTING_Command
TALER_TESTING_cmd_insert_deposit (const char *label, 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_name,
const char *merchant_account, const char *merchant_account,
struct GNUNET_TIME_Absolute wire_deadline, struct GNUNET_TIME_Relative wire_deadline,
const char *amount_with_fee, const char *amount_with_fee,
const char *deposit_fee) const char *deposit_fee)
{ {
@ -157,7 +294,7 @@ TALER_TESTING_cmd_insert_deposit (const char *label,
struct InsertDepositState *ids; struct InsertDepositState *ids;
ids = GNUNET_new (struct InsertDepositState); ids = GNUNET_new (struct InsertDepositState);
ids->config_filename = config_filename; ids->dbc = dbc;
ids->merchant_name = merchant_name; ids->merchant_name = merchant_name;
ids->merchant_account = merchant_account; ids->merchant_account = merchant_account;
ids->wire_deadline = wire_deadline; ids->wire_deadline = wire_deadline;
@ -169,8 +306,9 @@ TALER_TESTING_cmd_insert_deposit (const char *label,
cmd.run = &insert_deposit_run; cmd.run = &insert_deposit_run;
cmd.cleanup = &insert_deposit_cleanup; cmd.cleanup = &insert_deposit_cleanup;
cmd.traits = &insert_deposit_traits; cmd.traits = &insert_deposit_traits;
return cmd; return cmd;
} }
/* end of testing_auditor_api_cmd_exec_auditor_dbinit.c */ /* end of testing_api_cmd_insert_deposit.c */