implement tests for extended DB API

This commit is contained in:
Christian Grothoff 2017-04-02 22:34:45 +02:00
parent b95522c1dd
commit b988eb92fc
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 92 additions and 12 deletions

View File

@ -2363,7 +2363,7 @@ TEH_DB_execute_payback (struct MHD_Connection *connection,
ret = TEH_plugin->insert_payback_request (TEH_plugin->cls,
session,
&reserve_pub,
coin,
&coin->coin_pub,
coin_sig,
coin_blind,
&amount,

View File

@ -516,7 +516,7 @@ postgres_create_tables (void *cls)
/* Table for /payback information */
SQLEXEC("CREATE TABLE IF NOT EXISTS payback "
"(reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
",coin_pub BYTEA NOT NULL REFERENCES known_coins (coin_pub) ON DELETE CASCADE"
",coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)"
",coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)"
",coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)"
",amount_val INT8 NOT NULL"
@ -1454,8 +1454,6 @@ postgres_prepare (PGconn *db_conn)
" WHERE payback.coin_pub=$1",
1, NULL);
/* Used in #postgres_get_reserve_by_h_blind() */
PREPARE ("reserve_by_h_blind",
"SELECT"
@ -5625,7 +5623,7 @@ postgres_select_wire_out_above_serial_id (void *cls,
* @param cls closure
* @param session database connection
* @param reserve_pub public key of the reserve that is being refunded
* @param coin information about the coin
* @param coin_pub public key of the coin
* @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_PAYBACK
* @param coin_blind blinding key of the coin
* @param amount total amount to be paid back
@ -5639,7 +5637,7 @@ static int
postgres_insert_payback_request (void *cls,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_DenominationBlindingKeyP *coin_blind,
const struct TALER_Amount *amount,
@ -5652,7 +5650,7 @@ postgres_insert_payback_request (void *cls,
struct TALER_EXCHANGEDB_Reserve reserve;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
GNUNET_PQ_query_param_auto_from_type (coin_pub),
GNUNET_PQ_query_param_auto_from_type (coin_sig),
GNUNET_PQ_query_param_auto_from_type (coin_blind),
TALER_PQ_query_param_amount (amount),

View File

@ -1336,6 +1336,9 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
}
/**
* Main function that will be run by the scheduler.
*
@ -1346,6 +1349,9 @@ run (void *cls)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct TALER_EXCHANGEDB_Session *session;
struct TALER_CoinSpendSignatureP coin_sig;
struct GNUNET_TIME_Absolute deadline;
struct TALER_DenominationBlindingKeyP coin_blind;
struct TALER_ReservePublicKeyP reserve_pub;
struct DenomKeyPair *dkp;
struct TALER_EXCHANGEDB_CollectableBlindcoin cbc;
@ -1501,6 +1507,21 @@ run (void *cls)
GNUNET_CRYPTO_rsa_verify (&cbc.h_coin_envelope,
cbc2.sig.rsa_signature,
dkp->pub.rsa_public_key));
RND_BLK (&coin_sig);
RND_BLK (&coin_blind);
FAILIF (GNUNET_OK !=
plugin->insert_payback_request (plugin->cls,
session,
&reserve_pub,
&deposit.coin.coin_pub,
&coin_sig,
&coin_blind,
&value,
&cbc.h_coin_envelope,
&deadline));
result = 7;
rh = plugin->get_reserve_history (plugin->cls,
session,
@ -1532,9 +1553,32 @@ run (void *cls)
&cbc.h_coin_envelope,
sizeof (cbc.h_coin_envelope)));
break;
case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
{
struct TALER_EXCHANGEDB_Payback *payback = rh_head->details.payback;
FAILIF (0 != memcmp (&payback->coin_sig,
&coin_sig,
sizeof (coin_sig)));
FAILIF (0 != memcmp (&payback->coin_blind,
&coin_blind,
sizeof (coin_blind)));
FAILIF (0 != memcmp (&payback->reserve_pub,
&reserve_pub,
sizeof (reserve_pub)));
FAILIF (0 != memcmp (&payback->coin_pub,
&deposit.coin.coin_pub,
sizeof (deposit.coin.coin_pub)));
FAILIF (0 != TALER_amount_cmp (&payback->value,
&value));
}
break;
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
GNUNET_break (0); /* FIXME: #4956 */
break;
}
}
FAILIF (3 != cnt);
FAILIF (4 != cnt);
auditor_row_cnt = 0;
FAILIF (GNUNET_OK !=
@ -1550,6 +1594,7 @@ run (void *cls)
&audit_reserve_out_cb,
NULL));
FAILIF (3 != auditor_row_cnt);
/* Tests for deposits */
memset (&deposit, 0, sizeof (deposit));
RND_BLK (&deposit.coin.coin_pub);
@ -1567,7 +1612,8 @@ run (void *cls)
result = 8;
FAILIF (GNUNET_OK !=
plugin->insert_deposit (plugin->cls,
session, &deposit));
session,
&deposit));
FAILIF (GNUNET_YES !=
plugin->have_deposit (plugin->cls,
session,
@ -1660,6 +1706,21 @@ run (void *cls)
plugin->insert_refund (plugin->cls,
session,
&refund));
RND_BLK (&coin_sig);
RND_BLK (&coin_blind);
FAILIF (GNUNET_OK !=
plugin->insert_payback_request (plugin->cls,
session,
&reserve_pub,
&deposit.coin.coin_pub,
&coin_sig,
&coin_blind,
&value,
&cbc.h_coin_envelope,
&deadline));
auditor_row_cnt = 0;
FAILIF (GNUNET_OK !=
plugin->select_refunds_above_serial_id (plugin->cls,
@ -1747,12 +1808,33 @@ run (void *cls)
matched |= 4;
break;
}
case TALER_EXCHANGEDB_TT_PAYBACK:
{
struct TALER_EXCHANGEDB_Payback *payback = tlp->details.payback;
FAILIF (0 != memcmp (&payback->coin_sig,
&coin_sig,
sizeof (coin_sig)));
FAILIF (0 != memcmp (&payback->coin_blind,
&coin_blind,
sizeof (coin_blind)));
FAILIF (0 != memcmp (&payback->reserve_pub,
&reserve_pub,
sizeof (reserve_pub)));
FAILIF (0 != memcmp (&payback->coin_pub,
&deposit.coin.coin_pub,
sizeof (deposit.coin.coin_pub)));
FAILIF (0 != TALER_amount_cmp (&payback->value,
&value));
matched |= 8;
break;
}
default:
FAILIF (1);
break;
}
}
FAILIF (5 != matched);
FAILIF (13 != matched);
plugin->free_coin_transaction_list (plugin->cls,
tl);

View File

@ -1949,7 +1949,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param cls closure
* @param session database connection
* @param reserve_pub public key of the reserve that is being refunded
* @param coin information about the coin
* @param coin_pub public key of the coin
* @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_PAYBACK
* @param coin_blind blinding key of the coin
* @param h_blind_ev blinded envelope, as calculated by the exchange
@ -1964,7 +1964,7 @@ struct TALER_EXCHANGEDB_Plugin
(*insert_payback_request)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_DenominationBlindingKeyP *coin_blind,
const struct TALER_Amount *amount,