diff options
Diffstat (limited to 'src/mintdb/test_mintdb.c')
-rw-r--r-- | src/mintdb/test_mintdb.c | 142 |
1 files changed, 113 insertions, 29 deletions
diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c index 212e763bc..55a8395e3 100644 --- a/src/mintdb/test_mintdb.c +++ b/src/mintdb/test_mintdb.c @@ -89,8 +89,60 @@ struct DenomKeyPair }; +/** + * 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 + */ static struct DenomKeyPair * -create_denom_key_pair (unsigned int size) +create_denom_key_pair (unsigned int size, struct TALER_MINTDB_Session *session) { struct DenomKeyPair *dkp; @@ -99,10 +151,16 @@ create_denom_key_pair (unsigned int 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); + (void) register_denomination (dkp->pub, session); return dkp; } +/** + * Destroy a denomination key pair. The key is not necessarily removed from the DB. + * + * @param dkp the keypair to destroy + */ static void destroy_denom_key_pair (struct DenomKeyPair *dkp) { @@ -111,6 +169,57 @@ destroy_denom_key_pair (struct DenomKeyPair *dkp) GNUNET_free (dkp); } + +/** + * Tests on the known_coins relation + * + * @param session the DB session + * @return #GNUNET_OK if the tests are successful; #GNUNET_SYSERR if not. + */ +static int +test_known_coins (struct TALER_MINTDB_Session *session) +{ + struct TALER_CoinPublicInfo coin_info; + struct TALER_CoinPublicInfo ret_coin_info; + struct DenomKeyPair *dkp; + int ret = GNUNET_SYSERR; + + dkp = create_denom_key_pair (1024, session); + 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 + (ret_coin_info.denom_pub.rsa_public_key, + coin_info.denom_pub.rsa_public_key)); + FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp + (ret_coin_info.denom_sig.rsa_signature, + coin_info.denom_sig.rsa_signature)); + 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); + ret = GNUNET_OK; + drop: + destroy_denom_key_pair (dkp); + GNUNET_CRYPTO_rsa_signature_free (coin_info.denom_sig.rsa_signature); + return ret; +} + + /** * Main function that will be run by the scheduler. * @@ -211,34 +320,7 @@ run (void *cls, ++amount.fraction, amount.currency, expiry.abs_value_us)); - dkp = create_denom_key_pair (1024); - { - struct TALER_MINTDB_DenominationKeyIssueInformation dki; - dki.denom_pub = dkp->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.value.currency, CURRENCY); - dki.issue.fee_refresh = dki.issue.fee_withdraw; - FAILIF (GNUNET_OK != - plugin->insert_denomination (plugin->cls, - session, - &dki)); - } + dkp = create_denom_key_pair (1024, session); RND_BLK(&h_blind); RND_BLK(&cbc.reserve_sig); cbc.denom_pub = dkp->pub; @@ -374,8 +456,10 @@ run (void *cls, &refresh_session, sizeof (refresh_session))); } + FAILIF (GNUNET_OK != test_known_coins (session)); result = 0; + /* FIXME: test_refresh_melts */ drop: if (NULL != wire) json_decref (wire); |