diff options
Diffstat (limited to 'src/mintdb/test_mintdb.c')
-rw-r--r-- | src/mintdb/test_mintdb.c | 126 |
1 files changed, 69 insertions, 57 deletions
diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c index b93965665..d5399d4c4 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,40 +169,22 @@ 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; - struct TALER_MINTDB_DenominationKeyIssueInformation dki; int ret = GNUNET_SYSERR; - dkp = create_denom_key_pair (1024); - 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.fee_withdraw.currency, CURRENCY); - dki.issue.fee_deposit = dki.issue.fee_withdraw; - 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 (&coin_info); coin_info.denom_pub = dkp->pub; coin_info.denom_sig.rsa_signature = @@ -287,35 +327,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.fee_withdraw.currency, CURRENCY); - dki.issue.fee_deposit = dki.issue.fee_withdraw; - 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; |