From a458eab0ccccc1d2dd3ecd724e629728ba686b7d Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 6 Mar 2015 16:08:39 +0100 Subject: [PATCH] db: Extend testcase --- src/mint/test_mint_db.c | 58 ++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/mint/test_mint_db.c b/src/mint/test_mint_db.c index 195fa275b..fcd8311de 100644 --- a/src/mint/test_mint_db.c +++ b/src/mint/test_mint_db.c @@ -33,6 +33,39 @@ static int result; } while (0) +/** + * Checks if the given reserve has the given amount of balance and expiry + * + * @param db the database connection + * @param pub the public key of the reserve + * @param value balance value + * @param fraction balance fraction + * @param currency currency of the reserve + * @param expiry expiration of the reserve + * @return #GNUNET_OK if the given reserve has the same balance and expiration + * as the given parameters; #GNUNET_SYSERR if not + */ +int +check_reserve (PGconn *db, + struct GNUNET_CRYPTO_EddsaPublicKey *pub, + uint32_t value, uint32_t fraction, const char *currency, + uint64_t expiry) +{ + struct Reserve reserve; + reserve.pub = pub; + + FAILIF (GNUNET_OK != TALER_MINT_DB_reserve_get (db, &reserve)); + FAILIF (value != reserve.balance.value); + FAILIF (fraction != reserve.balance.fraction); + FAILIF (0 != strcmp (currency, reserve.balance.currency)); + FAILIF (expiry != reserve.expiry.abs_value_us); + + return GNUNET_OK; + drop: + return GNUNET_SYSERR; +} + + /** * Main function that will be run by the scheduler. * @@ -80,15 +113,22 @@ run (void *cls, char *const *args, const char *cfgfile, &reserve, amount, expiry)); - { - struct Reserve g_reserve; - g_reserve.pub = &pub; - FAILIF (GNUNET_OK != TALER_MINT_DB_reserve_get (db, &g_reserve)); - FAILIF (amount.value != g_reserve.balance.value); - FAILIF (amount.fraction != g_reserve.balance.fraction); - FAILIF (0 != strcmp (amount.currency, g_reserve.balance.currency)); - FAILIF (expiry.abs_value_us != g_reserve.expiry.abs_value_us); - } + FAILIF (GNUNET_OK != check_reserve (db, + &pub, + amount.value, + amount.fraction, + amount.currency, + expiry.abs_value_us)); + FAILIF (GNUNET_OK != TALER_MINT_DB_reserves_in_insert (db, + &reserve, + amount, + expiry)); + FAILIF (GNUNET_OK != check_reserve (db, + &pub, + ++amount.value, + ++amount.fraction, + amount.currency, + expiry.abs_value_us)); result = 0; drop: if (NULL != db)