diff options
Diffstat (limited to 'src/exchangedb/test_exchangedb.c')
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 00c7a9ef6..d0ec63f46 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -18,6 +18,7 @@ * @brief test cases for DB interaction functions * @author Sree Harsha Totakura * @author Christian Grothoff + * @author Marcello Stanisci */ #include "platform.h" #include "taler_exchangedb_lib.h" @@ -77,6 +78,12 @@ dead_prepare_cb (void *cls, GNUNET_assert (0); } +/** + * Counter used in auditor-related db functions. Used to count + * expected rows. + */ +unsigned int auditor_row_cnt; + /** * Callback that is called with wire prepare data @@ -103,6 +110,27 @@ mark_prepare_cb (void *cls, rowid)); } +/** + * Callback with data about a prepared wire transfer. + * + * @param cls closure + * @param rowid row identifier used to mark prepared transaction as done + * @param wire_method which wire method is this preparation data for + * @param buf transaction data that was persisted, NULL on error + * @param buf_size number of bytes in @a buf, 0 on error + * @param finished did we complete the transfer yet? + */ +void +audit_wire_cb (void *cls, + unsigned long long rowid, + const char *wire_method, + const char *buf, + size_t buf_size, + int finished) +{ + auditor_row_cnt++; + return; +} /** * Test API relating to persisting the wire plugins preparation data. @@ -134,6 +162,14 @@ test_wire_prepare (struct TALER_EXCHANGEDB_Session *session) session, &dead_prepare_cb, NULL)); + auditor_row_cnt = 0; + FAILIF (GNUNET_OK != + plugin->select_prepare_above_serial_id (plugin->cls, + session, + 0, + &audit_wire_cb, + NULL)); + FAILIF (1 != auditor_row_cnt); return GNUNET_OK; drop: return GNUNET_SYSERR; @@ -465,6 +501,38 @@ check_transfer_data (void *cls, *ok = GNUNET_SYSERR; } +/** + * Function called with details about coins that were melted, + * with the goal of auditing the refresh's execution. + * + * @param cls closure + * @param rowid unique serial ID for the refresh session in our DB + * @param merchant_pub public key of the merchant + * @param coin_pub public key of the coin + * @param coin_sig signature from the coin + * @param amount_with_fee amount that was deposited including fee + * @param transaction_id unique transaction ID chosen by the merchant + * @param h_contract hash of the contract between merchant and customer + * @param refund_deadline by which the merchant adviced that he might want + * to get a refund + * @param wire_deadline by which the merchant adviced that he would like the + * wire transfer to be executed + * @param receiver_wire_account wire details for the merchant, NULL from iterate_matching_deposits() + * @param done flag set if the deposit was already executed (or not) + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop + */ +int +audit_refresh_session_cb (void *cls, + unsigned long long rowid, /* FIXME: decide data type for serial_id! */ + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_CoinSpendSignatureP *coin_sig, + const struct TALER_Amount *amount_with_fee, + uint16_t num_newcoins, + uint16_t noreveal_index) +{ + auditor_row_cnt++; + return GNUNET_OK; +} /** * Function to test melting of coins as part of a refresh session @@ -538,6 +606,14 @@ test_melting (struct TALER_EXCHANGEDB_Session *session) session, &session_hash, &ret_refresh_session)); + + auditor_row_cnt = 0; + FAILIF (GNUNET_OK != plugin->select_refreshs_above_serial_id (plugin->cls, + session, + 0, + &audit_refresh_session_cb, + NULL)); + FAILIF (1 != auditor_row_cnt); FAILIF (ret_refresh_session.num_newcoins != refresh_session.num_newcoins); FAILIF (ret_refresh_session.noreveal_index != refresh_session.noreveal_index); @@ -874,6 +950,128 @@ deposit_cb (void *cls, return GNUNET_OK; } +/** + * Callback for #select_deposits_above_serial_id () + * + * @param cls closure + * @param rowid unique serial ID for the deposit in our DB + * @param merchant_pub public key of the merchant + * @param coin_pub public key of the coin + * @param coin_sig signature from the coin + * @param amount_with_fee amount that was deposited including fee + * @param transaction_id unique transaction ID chosen by the merchant + * @param h_contract hash of the contract between merchant and customer + * @param refund_deadline by which the merchant adviced that he might want + * to get a refund + * @param wire_deadline by which the merchant adviced that he would like the + * wire transfer to be executed + * @param receiver_wire_account wire details for the merchant, NULL from iterate_matching_deposits() + * @param done flag set if the deposit was already executed (or not) + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop + */ +int +audit_deposit_cb (void *cls, + unsigned long long rowid, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_CoinSpendSignatureP *coin_sig, + const struct TALER_Amount *amount_with_fee, + uint64_t transaction_id, + const struct GNUNET_HashCode *h_contract, + struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute wire_deadline, + const json_t *receiver_wire_account, + int done) +{ + auditor_row_cnt++; + return GNUNET_OK; +} + + +/** + * Function called with details about coins that were refunding, + * with the goal of auditing the refund's execution. + * + * @param cls closure + * @param rowid unique serial ID for the refund in our DB + * @param coin_pub public key of the coin + * @param merchant_pub public key of the merchant + * @param merchant_sig signature of the merchant + * @param h_contract hash of the contract between merchant and customer + * @param transaction_id original transaction ID chosen by the merchant + * @param rtransaction_id refund transaction ID chosen by the merchant + * @param amount_with_fee amount that was deposited including fee + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop + */ +int +audit_refund_cb (void *cls, + unsigned long long rowid, /* FIXME: decide data type for serial_id! */ + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantSignatureP *merchant_sig, + const struct GNUNET_HashCode *h_contract, + uint64_t transaction_id, + uint64_t rtransaction_id, + const struct TALER_Amount *amount_with_fee) +{ + auditor_row_cnt++; + return GNUNET_OK; +} + + +/** + * Function called with details about incoming wire transfers. + * + * @param cls closure + * @param rowid unique serial ID for the refresh session in our DB + * @param reserve_pub public key of the reserve (also the WTID) + * @param credit amount that was received + * @param sender_account_details information about the sender's bank account + * @param transfer_details information that uniquely identifies the wire transfer + * @param execution_date when did we receive the funds + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop + */ +int +audit_reserve_in_cb (void *cls, + unsigned long long rowid, /* FIXME: decide data type for serial_id! */ + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_Amount *credit, + const json_t *sender_account_details, + const json_t *transfer_details, + struct GNUNET_TIME_Absolute execution_date) +{ + auditor_row_cnt++; + return GNUNET_OK; +} + +/** + * Function called with details about withdraw operations. + * + * @param cls closure + * @param rowid unique serial ID for the refresh session in our DB + * @param h_blind_ev blinded hash of the coin's public key + * @param denom_pub public denomination key of the deposited coin + * @param denom_sig signature over the deposited coin + * @param reserve_pub public key of the reserve + * @param reserve_sig signature over the withdraw operation + * @param execution_date when did the wallet withdraw the coin + * @param amount_with_fee amount that was withdrawn + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop + */ +int +audit_reserve_out_cb (void *cls, + unsigned long long rowid, /* FIXME: decide data type for serial_id! */ + const struct GNUNET_HashCode *h_blind_ev, + const struct TALER_DenominationPublicKey *denom_pub, + const struct TALER_DenominationSignature *denom_sig, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig, + struct GNUNET_TIME_Absolute execution_date, + const struct TALER_Amount *amount_with_fee) +{ + auditor_row_cnt++; + return GNUNET_OK; +} /** * Test garbage collection. @@ -1121,6 +1319,21 @@ run (void *cls) } } FAILIF (3 != cnt); + + auditor_row_cnt = 0; + FAILIF (GNUNET_OK != + plugin->select_reserves_in_above_serial_id (plugin->cls, + session, + 0, + &audit_reserve_in_cb, + NULL)); + FAILIF (GNUNET_OK != + plugin->select_reserves_out_above_serial_id (plugin->cls, + session, + 0, + &audit_reserve_out_cb, + NULL)); + FAILIF (3 != auditor_row_cnt); /* Tests for deposits */ memset (&deposit, 0, sizeof (deposit)); RND_BLK (&deposit.coin.coin_pub); @@ -1145,6 +1358,14 @@ run (void *cls) plugin->have_deposit (plugin->cls, session, &deposit)); + auditor_row_cnt = 0; + FAILIF (GNUNET_OK != + plugin->select_deposits_above_serial_id (plugin->cls, + session, + 0, + &audit_deposit_cb, + NULL)); + FAILIF (1 != auditor_row_cnt); result = 9; FAILIF (1 != plugin->iterate_matching_deposits (plugin->cls, @@ -1232,7 +1453,15 @@ run (void *cls) plugin->insert_refund (plugin->cls, session, &refund)); + auditor_row_cnt = 0; + FAILIF (GNUNET_OK != + plugin->select_refunds_above_serial_id (plugin->cls, + session, + 0, + &audit_refund_cb, + NULL)); + FAILIF (1 != auditor_row_cnt); tl = plugin->get_coin_transactions (plugin->cls, session, &refund.coin.coin_pub); |