summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <sreeharsha@totakura.in>2015-03-06 01:15:46 +0100
committerSree Harsha Totakura <sreeharsha@totakura.in>2015-03-06 01:15:46 +0100
commit3c7168aad2d61d27ce340fb7337ec7f49add75c7 (patch)
treeb2061f84ec61a8df0cdfe0360972f5a73c9e4ecf
parentcee173a8e242e3536c1013e92fd1a01912a2a8e8 (diff)
downloadexchange-3c7168aad2d61d27ce340fb7337ec7f49add75c7.tar.gz
exchange-3c7168aad2d61d27ce340fb7337ec7f49add75c7.tar.bz2
exchange-3c7168aad2d61d27ce340fb7337ec7f49add75c7.zip
Added testcase for reserves_in_insert()
-rw-r--r--src/mint/mint_db.c14
-rw-r--r--src/mint/test_mint_db.c20
2 files changed, 30 insertions, 4 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c
index 71e222008..2797f2169 100644
--- a/src/mint/mint_db.c
+++ b/src/mint/mint_db.c
@@ -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;
diff --git a/src/mint/test_mint_db.c b/src/mint/test_mint_db.c
index 4fa84eb38..192bc1e09 100644
--- a/src/mint/test_mint_db.c
+++ b/src/mint/test_mint_db.c
@@ -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)