Added testcase for reserves_in_insert()

This commit is contained in:
Sree Harsha Totakura 2015-03-06 01:15:46 +01:00
parent cee173a8e2
commit 3c7168aad2
2 changed files with 30 additions and 4 deletions

View File

@ -43,7 +43,7 @@ static pthread_key_t db_conn_threadlocal;
#define QUERY_ERR(result) \
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s: query failed: %s\n", __FUNCTION__, PQresultErrorMessage (result))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed at %s:%u: %s\n", __FILE__, __LINE__, PQresultErrorMessage (result))
/**
* Database connection string, as read from
@ -77,6 +77,12 @@ static char *TALER_MINT_db_connection_cfg_str;
PQclear (result); result = NULL; \
} while (0)
/**
* This the length of the currency strings (without 0-termination) we use. Note
* that we need to use this at the DB layer instead of TALER_CURRENCY_LEN as the
* DB only needs to store 3 bytes instead of 8 bytes.
*/
#define TALER_DB_CURRENCY_LEN 3
/**
* Set the given connection to use a temporary schema
@ -837,11 +843,11 @@ TALER_MINT_DB_reserves_in_insert (PGconn *db,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Reserve does not exist; creating a new one\n");
struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR_SIZED (reserve->pub, sizeof (reserve->pub)),
TALER_DB_QUERY_PARAM_PTR (reserve->pub),
TALER_DB_QUERY_PARAM_PTR (&balance_nbo.value),
TALER_DB_QUERY_PARAM_PTR (&balance_nbo.fraction),
TALER_DB_QUERY_PARAM_PTR_SIZED (balance_nbo.currency,
TALER_CURRENCY_LEN),
TALER_DB_CURRENCY_LEN),
TALER_DB_QUERY_PARAM_PTR (&expiry_nbo),
TALER_DB_QUERY_PARAM_END
};
@ -866,7 +872,7 @@ TALER_MINT_DB_reserves_in_insert (PGconn *db,
result = TALER_DB_exec_prepared (db,
"create_reserves_in_transaction",
params);
if (PGRES_COMMAND_OK != result)
if (PGRES_COMMAND_OK != PQresultStatus(result))
{
QUERY_ERR (result);
goto rollback;

View File

@ -39,6 +39,10 @@ run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
PGconn *db;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
struct Reserve reserve;
struct GNUNET_TIME_Absolute expiry;
struct TALER_Amount amount;
db = NULL;
if (GNUNET_OK != TALER_MINT_DB_init ("postgres:///taler"))
@ -56,6 +60,22 @@ run (void *cls, char *const *args, const char *cfgfile,
result = 3;
goto drop;
}
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&pub, sizeof (pub));
reserve.pub = &pub;
amount.value = 1;
amount.fraction = 1;
strcpy (amount.currency, "EUR");
expiry = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
GNUNET_TIME_UNIT_HOURS);
if (GNUNET_OK != TALER_MINT_DB_reserves_in_insert (db,
&reserve,
amount,
expiry))
{
result = 4;
goto drop;
}
result = 0;
drop:
if (NULL != db)