2015-03-05 15:59:22 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
2015-06-11 13:02:57 +02:00
|
|
|
* @file mint/test_mintdb.c
|
2015-03-05 15:59:22 +01:00
|
|
|
* @brief test cases for DB interaction functions
|
|
|
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
2015-03-28 12:29:35 +01:00
|
|
|
#include "taler_mintdb_lib.h"
|
|
|
|
#include "taler_mintdb_plugin.h"
|
2015-03-05 15:59:22 +01:00
|
|
|
|
|
|
|
static int result;
|
|
|
|
|
2015-03-06 01:15:46 +01:00
|
|
|
#define FAILIF(cond) \
|
|
|
|
do { \
|
|
|
|
if (!(cond)){ break;} \
|
|
|
|
GNUNET_break (0); \
|
|
|
|
goto drop; \
|
|
|
|
} while (0)
|
|
|
|
|
2015-03-05 15:59:22 +01:00
|
|
|
|
2015-03-07 13:56:26 +01:00
|
|
|
#define RND_BLK(ptr) \
|
|
|
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
|
|
|
|
|
2015-03-07 14:03:01 +01:00
|
|
|
#define ZR_BLK(ptr) \
|
|
|
|
memset (ptr, 0, sizeof (*ptr))
|
|
|
|
|
2015-03-07 13:56:26 +01:00
|
|
|
|
2015-03-09 17:05:35 +01:00
|
|
|
#define CURRENCY "EUR"
|
|
|
|
|
2015-03-28 12:29:35 +01:00
|
|
|
static struct TALER_MINTDB_Plugin *plugin;
|
|
|
|
|
2015-03-06 16:08:39 +01:00
|
|
|
/**
|
|
|
|
* Checks if the given reserve has the given amount of balance and expiry
|
|
|
|
*
|
2015-03-21 14:21:00 +01:00
|
|
|
* @param session the database connection
|
2015-03-06 16:08:39 +01:00
|
|
|
* @param pub the public key of the reserve
|
|
|
|
* @param value balance value
|
|
|
|
* @param fraction balance fraction
|
|
|
|
* @param currency currency of the reserve
|
|
|
|
* @return #GNUNET_OK if the given reserve has the same balance and expiration
|
|
|
|
* as the given parameters; #GNUNET_SYSERR if not
|
|
|
|
*/
|
2015-03-21 14:21:00 +01:00
|
|
|
static int
|
|
|
|
check_reserve (struct TALER_MINTDB_Session *session,
|
2015-03-27 19:58:40 +01:00
|
|
|
const struct TALER_ReservePublicKeyP *pub,
|
2015-03-26 19:29:03 +01:00
|
|
|
uint64_t value,
|
2015-03-21 14:21:00 +01:00
|
|
|
uint32_t fraction,
|
2015-06-11 13:14:59 +02:00
|
|
|
const char *currency)
|
2015-03-06 16:08:39 +01:00
|
|
|
{
|
2015-03-28 14:39:31 +01:00
|
|
|
struct TALER_MINTDB_Reserve reserve;
|
2015-03-22 22:14:30 +01:00
|
|
|
|
|
|
|
reserve.pub = *pub;
|
2015-03-06 16:08:39 +01:00
|
|
|
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
plugin->reserve_get (plugin->cls,
|
|
|
|
session,
|
|
|
|
&reserve));
|
2015-03-06 16:08:39 +01:00
|
|
|
FAILIF (value != reserve.balance.value);
|
|
|
|
FAILIF (fraction != reserve.balance.fraction);
|
|
|
|
FAILIF (0 != strcmp (currency, reserve.balance.currency));
|
|
|
|
|
|
|
|
return GNUNET_OK;
|
|
|
|
drop:
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-07 13:56:26 +01:00
|
|
|
struct DenomKeyPair
|
|
|
|
{
|
2015-03-22 22:14:30 +01:00
|
|
|
struct TALER_DenominationPrivateKey priv;
|
|
|
|
struct TALER_DenominationPublicKey pub;
|
2015-03-07 13:56:26 +01:00
|
|
|
};
|
|
|
|
|
2015-03-21 14:21:00 +01:00
|
|
|
|
2015-05-26 10:06:41 +02:00
|
|
|
/**
|
|
|
|
* Register a denomination in the DB.
|
|
|
|
*
|
|
|
|
* @param dkp the denomination key pair
|
|
|
|
* @param session the DB session
|
|
|
|
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
register_denomination(struct TALER_DenominationPublicKey denom_pub,
|
|
|
|
struct TALER_MINTDB_Session *session)
|
|
|
|
{
|
|
|
|
struct TALER_MINTDB_DenominationKeyIssueInformation dki;
|
|
|
|
dki.denom_pub = denom_pub;
|
|
|
|
dki.issue.start = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
|
|
|
|
dki.issue.expire_withdraw = GNUNET_TIME_absolute_hton
|
|
|
|
(GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
|
|
|
|
GNUNET_TIME_UNIT_HOURS));
|
|
|
|
dki.issue.expire_spend = GNUNET_TIME_absolute_hton
|
|
|
|
(GNUNET_TIME_absolute_add
|
|
|
|
(GNUNET_TIME_absolute_get (),
|
|
|
|
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 2)));
|
|
|
|
dki.issue.expire_legal = GNUNET_TIME_absolute_hton
|
|
|
|
(GNUNET_TIME_absolute_add
|
|
|
|
(GNUNET_TIME_absolute_get (),
|
|
|
|
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 3)));
|
|
|
|
dki.issue.value.value = GNUNET_htonll (1);
|
|
|
|
dki.issue.value.fraction = htonl (100);
|
|
|
|
(void) strcpy (dki.issue.value.currency, CURRENCY);
|
|
|
|
dki.issue.fee_withdraw.value = 0;
|
|
|
|
dki.issue.fee_withdraw.fraction = htonl (100);
|
|
|
|
(void) strcpy (dki.issue.fee_withdraw.currency, CURRENCY);
|
|
|
|
dki.issue.fee_deposit = dki.issue.fee_withdraw;
|
|
|
|
dki.issue.fee_refresh = dki.issue.fee_withdraw;
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
plugin->insert_denomination (plugin->cls,
|
|
|
|
session,
|
|
|
|
&dki))
|
|
|
|
{
|
|
|
|
GNUNET_break(0);
|
|
|
|
return GNUNET_SYSERR;
|
|
|
|
}
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a denominaiton key pair
|
|
|
|
*
|
|
|
|
* @param size the size of the denomination key
|
|
|
|
* @param session the DB session
|
|
|
|
* @return the denominaiton key pair; NULL upon error
|
|
|
|
*/
|
2015-03-21 14:21:00 +01:00
|
|
|
static struct DenomKeyPair *
|
2015-05-26 10:06:41 +02:00
|
|
|
create_denom_key_pair (unsigned int size, struct TALER_MINTDB_Session *session)
|
2015-03-07 13:56:26 +01:00
|
|
|
{
|
|
|
|
struct DenomKeyPair *dkp;
|
|
|
|
|
|
|
|
dkp = GNUNET_new (struct DenomKeyPair);
|
2015-03-22 22:14:30 +01:00
|
|
|
dkp->priv.rsa_private_key = GNUNET_CRYPTO_rsa_private_key_create (size);
|
|
|
|
GNUNET_assert (NULL != dkp->priv.rsa_private_key);
|
|
|
|
dkp->pub.rsa_public_key
|
|
|
|
= GNUNET_CRYPTO_rsa_private_key_get_public (dkp->priv.rsa_private_key);
|
2015-05-26 10:06:41 +02:00
|
|
|
(void) register_denomination (dkp->pub, session);
|
2015-03-07 13:56:26 +01:00
|
|
|
return dkp;
|
|
|
|
}
|
|
|
|
|
2015-03-21 14:21:00 +01:00
|
|
|
|
2015-05-26 10:06:41 +02:00
|
|
|
/**
|
|
|
|
* Destroy a denomination key pair. The key is not necessarily removed from the DB.
|
|
|
|
*
|
|
|
|
* @param dkp the keypair to destroy
|
|
|
|
*/
|
2015-03-09 11:32:00 +01:00
|
|
|
static void
|
2015-04-12 17:16:21 +02:00
|
|
|
destroy_denom_key_pair (struct DenomKeyPair *dkp)
|
2015-03-07 13:56:26 +01:00
|
|
|
{
|
2015-03-22 22:14:30 +01:00
|
|
|
GNUNET_CRYPTO_rsa_public_key_free (dkp->pub.rsa_public_key);
|
|
|
|
GNUNET_CRYPTO_rsa_private_key_free (dkp->priv.rsa_private_key);
|
2015-03-07 13:56:26 +01:00
|
|
|
GNUNET_free (dkp);
|
|
|
|
}
|
|
|
|
|
2015-05-26 10:06:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests on the known_coins relation
|
|
|
|
*
|
|
|
|
* @param session the DB session
|
|
|
|
* @return #GNUNET_OK if the tests are successful; #GNUNET_SYSERR if not.
|
|
|
|
*/
|
2015-05-25 17:40:27 +02:00
|
|
|
static int
|
|
|
|
test_known_coins (struct TALER_MINTDB_Session *session)
|
|
|
|
{
|
|
|
|
struct TALER_CoinPublicInfo coin_info;
|
2015-05-27 14:20:07 +02:00
|
|
|
struct TALER_CoinPublicInfo ret_coin_info;
|
2015-05-25 17:40:27 +02:00
|
|
|
struct DenomKeyPair *dkp;
|
|
|
|
int ret = GNUNET_SYSERR;
|
2015-05-26 10:06:41 +02:00
|
|
|
|
|
|
|
dkp = create_denom_key_pair (1024, session);
|
2015-05-25 17:40:27 +02:00
|
|
|
RND_BLK (&coin_info);
|
|
|
|
coin_info.denom_pub = dkp->pub;
|
|
|
|
coin_info.denom_sig.rsa_signature =
|
|
|
|
GNUNET_CRYPTO_rsa_sign (dkp->priv.rsa_private_key,
|
|
|
|
"foobar", 6);
|
|
|
|
FAILIF (GNUNET_NO !=
|
|
|
|
plugin->get_known_coin (plugin->cls,
|
|
|
|
session,
|
|
|
|
&coin_info.coin_pub,
|
|
|
|
&ret_coin_info));
|
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
plugin->insert_known_coin (plugin->cls,
|
|
|
|
session,
|
|
|
|
&coin_info));
|
|
|
|
FAILIF (GNUNET_YES !=
|
|
|
|
plugin->get_known_coin (plugin->cls,
|
|
|
|
session,
|
|
|
|
&coin_info.coin_pub,
|
|
|
|
&ret_coin_info));
|
|
|
|
FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
|
2015-05-27 14:20:07 +02:00
|
|
|
(ret_coin_info.denom_pub.rsa_public_key,
|
2015-05-25 17:40:27 +02:00
|
|
|
coin_info.denom_pub.rsa_public_key));
|
|
|
|
FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp
|
2015-05-27 14:20:07 +02:00
|
|
|
(ret_coin_info.denom_sig.rsa_signature,
|
2015-05-25 17:40:27 +02:00
|
|
|
coin_info.denom_sig.rsa_signature));
|
2015-05-27 14:20:07 +02:00
|
|
|
GNUNET_CRYPTO_rsa_public_key_free (ret_coin_info.denom_pub.rsa_public_key);
|
|
|
|
GNUNET_CRYPTO_rsa_signature_free (ret_coin_info.denom_sig.rsa_signature);
|
2015-05-25 17:40:27 +02:00
|
|
|
ret = GNUNET_OK;
|
|
|
|
drop:
|
|
|
|
destroy_denom_key_pair (dkp);
|
|
|
|
GNUNET_CRYPTO_rsa_signature_free (coin_info.denom_sig.rsa_signature);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-05 15:59:22 +01:00
|
|
|
/**
|
|
|
|
* Main function that will be run by the scheduler.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
|
|
|
* @param args remaining command-line arguments
|
|
|
|
* @param cfgfile name of the configuration file used (for saving, can be NULL!)
|
2015-03-21 14:21:00 +01:00
|
|
|
* @param cfg configuration
|
2015-03-05 15:59:22 +01:00
|
|
|
*/
|
|
|
|
static void
|
2015-03-21 14:21:00 +01:00
|
|
|
run (void *cls,
|
|
|
|
char *const *args,
|
|
|
|
const char *cfgfile,
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg)
|
2015-03-05 15:59:22 +01:00
|
|
|
{
|
2015-03-21 14:21:00 +01:00
|
|
|
struct TALER_MINTDB_Session *session;
|
2015-03-27 19:58:40 +01:00
|
|
|
struct TALER_ReservePublicKeyP reserve_pub;
|
2015-03-06 01:15:46 +01:00
|
|
|
struct TALER_Amount amount;
|
2015-03-07 13:56:26 +01:00
|
|
|
struct DenomKeyPair *dkp;
|
2015-03-28 14:39:31 +01:00
|
|
|
struct TALER_MINTDB_CollectableBlindcoin cbc;
|
|
|
|
struct TALER_MINTDB_CollectableBlindcoin cbc2;
|
|
|
|
struct TALER_MINTDB_ReserveHistory *rh;
|
|
|
|
struct TALER_MINTDB_ReserveHistory *rh_head;
|
|
|
|
struct TALER_MINTDB_BankTransfer *bt;
|
|
|
|
struct TALER_MINTDB_CollectableBlindcoin *withdraw;
|
|
|
|
struct TALER_MINTDB_Deposit deposit;
|
|
|
|
struct TALER_MINTDB_Deposit deposit2;
|
2015-06-11 13:38:47 +02:00
|
|
|
json_t *wire;
|
|
|
|
json_t *just;
|
2015-03-16 11:01:33 +01:00
|
|
|
const char * const json_wire_str =
|
|
|
|
"{ \"type\":\"SEPA\", \
|
|
|
|
\"IBAN\":\"DE67830654080004822650\", \
|
|
|
|
\"name\":\"GNUnet e.V.\", \
|
|
|
|
\"bic\":\"GENODEF1SLR\", \
|
|
|
|
\"edate\":\"1449930207000\", \
|
|
|
|
\"r\":123456789, \
|
|
|
|
\"address\": \"foobar\"}";
|
2015-03-09 17:05:35 +01:00
|
|
|
unsigned int cnt;
|
2015-03-05 15:59:22 +01:00
|
|
|
|
2015-03-07 13:56:26 +01:00
|
|
|
dkp = NULL;
|
2015-03-09 17:05:35 +01:00
|
|
|
rh = NULL;
|
2015-03-16 11:01:33 +01:00
|
|
|
wire = NULL;
|
2015-03-26 19:29:03 +01:00
|
|
|
session = NULL;
|
2015-03-09 15:35:35 +01:00
|
|
|
ZR_BLK (&cbc);
|
2015-03-07 14:03:01 +01:00
|
|
|
ZR_BLK (&cbc2);
|
2015-03-28 12:29:35 +01:00
|
|
|
if (NULL ==
|
|
|
|
(plugin = TALER_MINTDB_plugin_load (cfg)))
|
2015-03-05 15:59:22 +01:00
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
return;
|
|
|
|
}
|
2015-03-21 14:21:00 +01:00
|
|
|
if (GNUNET_OK !=
|
|
|
|
plugin->create_tables (plugin->cls,
|
|
|
|
GNUNET_YES))
|
2015-03-05 15:59:22 +01:00
|
|
|
{
|
|
|
|
result = 2;
|
|
|
|
goto drop;
|
|
|
|
}
|
2015-03-21 14:21:00 +01:00
|
|
|
if (NULL ==
|
|
|
|
(session = plugin->get_session (plugin->cls,
|
|
|
|
GNUNET_YES)))
|
2015-03-05 15:59:22 +01:00
|
|
|
{
|
|
|
|
result = 3;
|
|
|
|
goto drop;
|
|
|
|
}
|
2015-03-07 13:56:26 +01:00
|
|
|
RND_BLK (&reserve_pub);
|
2015-03-06 01:15:46 +01:00
|
|
|
amount.value = 1;
|
|
|
|
amount.fraction = 1;
|
2015-03-09 17:05:35 +01:00
|
|
|
strcpy (amount.currency, CURRENCY);
|
2015-03-06 01:15:46 +01:00
|
|
|
result = 4;
|
2015-06-11 13:38:47 +02:00
|
|
|
just = json_loads ("{ \"justification\":\"1\" }", 0, NULL);
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
plugin->reserves_in_insert (plugin->cls,
|
|
|
|
session,
|
2015-05-14 14:14:18 +02:00
|
|
|
&reserve_pub,
|
2015-03-21 14:21:00 +01:00
|
|
|
&amount,
|
2015-06-11 13:38:47 +02:00
|
|
|
just));
|
|
|
|
json_decref (just);
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
check_reserve (session,
|
|
|
|
&reserve_pub,
|
|
|
|
amount.value,
|
|
|
|
amount.fraction,
|
2015-06-11 13:14:59 +02:00
|
|
|
amount.currency));
|
2015-06-11 13:38:47 +02:00
|
|
|
just = json_loads ("{ \"justification\":\"2\" }", 0, NULL);
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
plugin->reserves_in_insert (plugin->cls,
|
|
|
|
session,
|
2015-05-14 14:14:18 +02:00
|
|
|
&reserve_pub,
|
2015-03-21 14:21:00 +01:00
|
|
|
&amount,
|
2015-06-11 13:38:47 +02:00
|
|
|
just));
|
|
|
|
json_decref (just);
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
check_reserve (session,
|
|
|
|
&reserve_pub,
|
|
|
|
++amount.value,
|
|
|
|
++amount.fraction,
|
2015-06-11 13:14:59 +02:00
|
|
|
amount.currency));
|
2015-05-26 10:06:41 +02:00
|
|
|
dkp = create_denom_key_pair (1024, session);
|
2015-06-11 13:02:57 +02:00
|
|
|
RND_BLK(&cbc.h_coin_envelope);
|
2015-03-07 13:56:26 +01:00
|
|
|
RND_BLK(&cbc.reserve_sig);
|
|
|
|
cbc.denom_pub = dkp->pub;
|
2015-03-22 22:14:30 +01:00
|
|
|
cbc.sig.rsa_signature
|
|
|
|
= GNUNET_CRYPTO_rsa_sign (dkp->priv.rsa_private_key,
|
2015-06-11 13:02:57 +02:00
|
|
|
&cbc.h_coin_envelope,
|
|
|
|
sizeof (cbc.h_coin_envelope));
|
2015-03-21 14:21:00 +01:00
|
|
|
(void) memcpy (&cbc.reserve_pub,
|
|
|
|
&reserve_pub,
|
|
|
|
sizeof (reserve_pub));
|
2015-03-18 13:50:03 +01:00
|
|
|
amount.value--;
|
|
|
|
amount.fraction--;
|
2015-06-11 13:02:57 +02:00
|
|
|
cbc.amount_with_fee = amount;
|
|
|
|
GNUNET_assert (GNUNET_OK ==
|
|
|
|
TALER_amount_get_zero (CURRENCY, &cbc.withdraw_fee));
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
2015-06-11 12:30:14 +02:00
|
|
|
plugin->insert_withdraw_info (plugin->cls,
|
2015-06-11 13:02:57 +02:00
|
|
|
session,
|
|
|
|
&cbc));
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
check_reserve (session,
|
|
|
|
&reserve_pub,
|
|
|
|
amount.value,
|
|
|
|
amount.fraction,
|
2015-06-11 13:14:59 +02:00
|
|
|
amount.currency));
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_YES !=
|
2015-06-11 12:30:14 +02:00
|
|
|
plugin->get_withdraw_info (plugin->cls,
|
2015-06-11 13:02:57 +02:00
|
|
|
session,
|
|
|
|
&cbc.h_coin_envelope,
|
|
|
|
&cbc2));
|
2015-03-22 22:14:30 +01:00
|
|
|
FAILIF (NULL == cbc2.denom_pub.rsa_public_key);
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (0 != memcmp (&cbc2.reserve_sig,
|
|
|
|
&cbc.reserve_sig,
|
|
|
|
sizeof (cbc2.reserve_sig)));
|
|
|
|
FAILIF (0 != memcmp (&cbc2.reserve_pub,
|
|
|
|
&cbc.reserve_pub,
|
|
|
|
sizeof (cbc2.reserve_pub)));
|
|
|
|
FAILIF (GNUNET_OK !=
|
2015-06-11 13:02:57 +02:00
|
|
|
GNUNET_CRYPTO_rsa_verify (&cbc.h_coin_envelope,
|
2015-03-22 22:14:30 +01:00
|
|
|
cbc2.sig.rsa_signature,
|
|
|
|
dkp->pub.rsa_public_key));
|
2015-03-21 14:21:00 +01:00
|
|
|
rh = plugin->get_reserve_history (plugin->cls,
|
|
|
|
session,
|
|
|
|
&reserve_pub);
|
2015-03-09 17:05:35 +01:00
|
|
|
FAILIF (NULL == rh);
|
2015-03-21 14:21:00 +01:00
|
|
|
rh_head = rh;
|
2015-03-09 17:05:35 +01:00
|
|
|
for (cnt=0; NULL != rh_head; rh_head=rh_head->next, cnt++)
|
|
|
|
{
|
|
|
|
switch (rh_head->type)
|
|
|
|
{
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_BANK_TO_MINT:
|
2015-03-09 17:05:35 +01:00
|
|
|
bt = rh_head->details.bank;
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (0 != memcmp (&bt->reserve_pub,
|
|
|
|
&reserve_pub,
|
|
|
|
sizeof (reserve_pub)));
|
2015-03-09 17:05:35 +01:00
|
|
|
FAILIF (1 != bt->amount.value);
|
|
|
|
FAILIF (1 != bt->amount.fraction);
|
|
|
|
FAILIF (0 != strcmp (CURRENCY, bt->amount.currency));
|
2015-06-11 13:38:47 +02:00
|
|
|
FAILIF (NULL == bt->wire);
|
2015-03-09 17:05:35 +01:00
|
|
|
break;
|
2015-03-28 14:39:31 +01:00
|
|
|
case TALER_MINTDB_RO_WITHDRAW_COIN:
|
2015-03-09 17:05:35 +01:00
|
|
|
withdraw = rh_head->details.withdraw;
|
|
|
|
FAILIF (0 != memcmp (&withdraw->reserve_pub,
|
|
|
|
&reserve_pub,
|
|
|
|
sizeof (reserve_pub)));
|
|
|
|
FAILIF (0 != memcmp (&withdraw->h_coin_envelope,
|
2015-06-11 13:02:57 +02:00
|
|
|
&cbc.h_coin_envelope,
|
|
|
|
sizeof (cbc.h_coin_envelope)));
|
2015-03-09 17:05:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FAILIF (3 != cnt);
|
2015-03-16 11:01:33 +01:00
|
|
|
/* Tests for deposits */
|
|
|
|
RND_BLK (&deposit.coin.coin_pub);
|
|
|
|
deposit.coin.denom_pub = dkp->pub;
|
|
|
|
deposit.coin.denom_sig = cbc.sig;
|
|
|
|
RND_BLK (&deposit.csig);
|
|
|
|
RND_BLK (&deposit.merchant_pub);
|
|
|
|
RND_BLK (&deposit.h_contract);
|
|
|
|
RND_BLK (&deposit.h_wire);
|
|
|
|
wire = json_loads (json_wire_str, 0, NULL);
|
|
|
|
deposit.wire = wire;
|
|
|
|
deposit.transaction_id =
|
|
|
|
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
|
2015-03-22 16:09:01 +01:00
|
|
|
deposit.amount_with_fee = amount;
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_OK !=
|
|
|
|
plugin->insert_deposit (plugin->cls,
|
|
|
|
session, &deposit));
|
|
|
|
FAILIF (GNUNET_YES !=
|
|
|
|
plugin->have_deposit (plugin->cls,
|
|
|
|
session,
|
|
|
|
&deposit));
|
|
|
|
(void) memcpy (&deposit2,
|
|
|
|
&deposit,
|
|
|
|
sizeof (deposit));
|
2015-03-16 11:01:33 +01:00
|
|
|
deposit2.transaction_id++; /* should fail if transaction id is different */
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_NO !=
|
|
|
|
plugin->have_deposit (plugin->cls,
|
|
|
|
session,
|
|
|
|
&deposit2));
|
2015-03-16 11:01:33 +01:00
|
|
|
deposit2.transaction_id = deposit.transaction_id;
|
|
|
|
RND_BLK (&deposit2.merchant_pub); /* should fail if merchant is different */
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_NO !=
|
|
|
|
plugin->have_deposit (plugin->cls,
|
|
|
|
session,
|
|
|
|
&deposit2));
|
|
|
|
(void) memcpy (&deposit2.merchant_pub,
|
|
|
|
&deposit.merchant_pub,
|
|
|
|
sizeof (deposit.merchant_pub));
|
2015-03-16 11:01:33 +01:00
|
|
|
RND_BLK (&deposit2.coin.coin_pub); /* should fail if coin is different */
|
2015-03-21 14:21:00 +01:00
|
|
|
FAILIF (GNUNET_NO !=
|
|
|
|
plugin->have_deposit (plugin->cls,
|
|
|
|
session,
|
|
|
|
&deposit2));
|
2015-04-10 14:04:01 +02:00
|
|
|
/* Tests for refreshing */
|
|
|
|
{
|
|
|
|
struct TALER_MINTDB_RefreshSession refresh_session;
|
|
|
|
struct TALER_MINTDB_RefreshSession ret_refresh_session;
|
|
|
|
struct GNUNET_HashCode session_hash;
|
|
|
|
RND_BLK (&refresh_session);
|
|
|
|
RND_BLK (&session_hash);
|
|
|
|
refresh_session.num_oldcoins = UINT16_MAX;
|
|
|
|
refresh_session.num_newcoins = 1;
|
|
|
|
refresh_session.noreveal_index = 1;
|
|
|
|
FAILIF (GNUNET_OK != plugin->create_refresh_session (plugin->cls,
|
|
|
|
session,
|
|
|
|
&session_hash,
|
|
|
|
&refresh_session));
|
|
|
|
FAILIF (GNUNET_OK != plugin->get_refresh_session (plugin->cls,
|
|
|
|
session,
|
|
|
|
&session_hash,
|
|
|
|
&ret_refresh_session));
|
|
|
|
FAILIF (0 != memcmp (&ret_refresh_session,
|
|
|
|
&refresh_session,
|
|
|
|
sizeof (refresh_session)));
|
|
|
|
}
|
2015-05-25 17:40:27 +02:00
|
|
|
FAILIF (GNUNET_OK != test_known_coins (session));
|
2015-03-05 15:59:22 +01:00
|
|
|
result = 0;
|
2015-03-07 13:56:26 +01:00
|
|
|
|
2015-05-27 14:22:25 +02:00
|
|
|
/* FIXME: test_refresh_melts */
|
2015-03-05 15:59:22 +01:00
|
|
|
drop:
|
2015-03-16 11:01:33 +01:00
|
|
|
if (NULL != wire)
|
|
|
|
json_decref (wire);
|
2015-03-09 17:05:35 +01:00
|
|
|
if (NULL != rh)
|
2015-03-22 13:02:49 +01:00
|
|
|
plugin->free_reserve_history (plugin->cls,
|
|
|
|
rh);
|
2015-03-09 17:05:35 +01:00
|
|
|
rh = NULL;
|
2015-03-21 14:21:00 +01:00
|
|
|
if (NULL != session)
|
|
|
|
GNUNET_break (GNUNET_OK ==
|
|
|
|
plugin->drop_temporary (plugin->cls,
|
|
|
|
session));
|
2015-03-07 13:56:26 +01:00
|
|
|
if (NULL != dkp)
|
2015-04-12 17:16:21 +02:00
|
|
|
destroy_denom_key_pair (dkp);
|
2015-03-22 22:14:30 +01:00
|
|
|
if (NULL != cbc.sig.rsa_signature)
|
|
|
|
GNUNET_CRYPTO_rsa_signature_free (cbc.sig.rsa_signature);
|
|
|
|
if (NULL != cbc2.denom_pub.rsa_public_key)
|
|
|
|
GNUNET_CRYPTO_rsa_public_key_free (cbc2.denom_pub.rsa_public_key);
|
|
|
|
if (NULL != cbc2.sig.rsa_signature)
|
|
|
|
GNUNET_CRYPTO_rsa_signature_free (cbc2.sig.rsa_signature);
|
2015-03-07 13:56:26 +01:00
|
|
|
dkp = NULL;
|
2015-03-28 12:29:35 +01:00
|
|
|
TALER_MINTDB_plugin_unload (plugin);
|
|
|
|
plugin = NULL;
|
2015-03-05 15:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2015-03-21 14:21:00 +01:00
|
|
|
main (int argc,
|
|
|
|
char *const argv[])
|
2015-03-05 15:59:22 +01:00
|
|
|
{
|
|
|
|
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
|
|
|
GNUNET_GETOPT_OPTION_END
|
|
|
|
};
|
2015-03-27 19:58:40 +01:00
|
|
|
char *argv2[] = {
|
2015-03-26 18:31:59 +01:00
|
|
|
"test-mint-db-<plugin_name>", /* will be replaced later */
|
|
|
|
"-c", "test-mint-db-<plugin_name>.conf", /* will be replaced later */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
const char *plugin_name;
|
|
|
|
char *config_filename;
|
2015-03-26 18:36:52 +01:00
|
|
|
char *testname;
|
2015-03-05 15:59:22 +01:00
|
|
|
|
|
|
|
result = -1;
|
2015-03-26 18:31:59 +01:00
|
|
|
if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
plugin_name++;
|
2015-03-26 18:36:52 +01:00
|
|
|
(void) GNUNET_asprintf (&testname,
|
|
|
|
"test-mint-db-%s", plugin_name);
|
2015-03-26 18:31:59 +01:00
|
|
|
(void) GNUNET_asprintf (&config_filename,
|
2015-03-26 18:36:52 +01:00
|
|
|
"%s.conf", testname);
|
2015-03-26 18:31:59 +01:00
|
|
|
argv2[0] = argv[0];
|
|
|
|
argv2[2] = config_filename;
|
2015-03-05 15:59:22 +01:00
|
|
|
if (GNUNET_OK !=
|
2015-03-26 18:31:59 +01:00
|
|
|
GNUNET_PROGRAM_run ((sizeof (argv2)/sizeof (char *)) - 1, argv2,
|
2015-03-26 18:36:52 +01:00
|
|
|
testname,
|
2015-03-05 15:59:22 +01:00
|
|
|
"Test cases for mint database helper functions.",
|
|
|
|
options, &run, NULL))
|
2015-03-26 18:31:59 +01:00
|
|
|
{
|
|
|
|
GNUNET_free (config_filename);
|
2015-03-26 18:36:52 +01:00
|
|
|
GNUNET_free (testname);
|
2015-03-05 15:59:22 +01:00
|
|
|
return 3;
|
2015-03-26 18:31:59 +01:00
|
|
|
}
|
|
|
|
GNUNET_free (config_filename);
|
2015-03-26 18:36:52 +01:00
|
|
|
GNUNET_free (testname);
|
2015-03-05 15:59:22 +01:00
|
|
|
return result;
|
|
|
|
}
|