From 029d3239e12f99012b4e8082aec6e9f8098e0435 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Nov 2017 22:01:17 +0100 Subject: [PATCH] test select_deposits_missing_wire, fix uninitialized wire_deadline in deposit listing --- src/exchangedb/plugin_exchangedb_postgres.c | 7 +- src/exchangedb/test_exchangedb.c | 72 +++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 0faf126e1..93a8c1a8b 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1100,6 +1100,7 @@ postgres_prepare (PGconn *db_conn) ",denom.fee_deposit_curr" ",timestamp" ",refund_deadline" + ",wire_deadline" ",merchant_pub" ",h_contract_terms" ",h_wire" @@ -1313,8 +1314,8 @@ postgres_prepare (PGconn *db_conn) ",tiny" ",done" " FROM deposits" - " WHERE wire_deadline <= $1" - " AND wire_deadline > $2" + " WHERE wire_deadline >= $1" + " AND wire_deadline < $2" " AND NOT (EXISTS (SELECT 1" " FROM refunds" " WHERE (refunds.coin_pub = deposits.coin_pub))" @@ -3833,6 +3834,8 @@ add_coin_deposit (void *cls, &deposit->timestamp), GNUNET_PQ_result_spec_absolute_time ("refund_deadline", &deposit->refund_deadline), + GNUNET_PQ_result_spec_absolute_time ("wire_deadline", + &deposit->wire_deadline), GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", &deposit->merchant_pub), GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 537f33c9a..f04eaf129 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1416,6 +1416,57 @@ payback_cb (void *cls, } +/** + * Function called on deposits that are past their due date + * and have not yet seen a wire transfer. + * + * @param cls closure a `struct TALER_EXCHANGEDB_Deposit *` + * @param rowid deposit table row of the coin's deposit + * @param coin_pub public key of the coin + * @param amount value of the deposit, including fee + * @param wire where should the funds be wired + * @param deadline what was the requested wire transfer deadline + * @param tiny did the exchange defer this transfer because it is too small? + * @param done did the exchange claim that it made a transfer? + */ +static void +wire_missing_cb (void *cls, + uint64_t rowid, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount, + const json_t *wire, + struct GNUNET_TIME_Absolute deadline, + /* bool? */ int tiny, + /* bool? */ int done) +{ + struct TALER_EXCHANGEDB_Deposit *deposit = cls; + struct GNUNET_HashCode h_wire; + + if (NULL != wire) + GNUNET_assert (GNUNET_OK == + TALER_JSON_hash (wire, + &h_wire)); + else + memset (&h_wire, + 0, + sizeof (h_wire)); + if ( (GNUNET_NO != tiny) || + (GNUNET_NO != done) || + (0 != TALER_amount_cmp (amount, + &deposit->amount_with_fee)) || + (0 != memcmp (coin_pub, + &deposit->coin.coin_pub, + sizeof (struct TALER_CoinSpendPublicKeyP))) || + (0 != memcmp (&h_wire, + &deposit->h_wire, + sizeof (struct GNUNET_HashCode))) ) + { + GNUNET_break (0); + result = 66; + } +} + + /** * Main function that will be run by the scheduler. * @@ -1646,6 +1697,7 @@ run (void *cls) deposit.coin.denom_pub = dkp->pub; deposit.coin.denom_sig = cbc.sig; deadline = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&deadline); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_payback_request (plugin->cls, session, @@ -1788,6 +1840,9 @@ run (void *cls) deposit.receiver_wire_account = wire; deposit.amount_with_fee = value; deposit.deposit_fee = fee_deposit; + + deposit.refund_deadline = deadline; + deposit.wire_deadline = deadline; result = 8; FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_deposit (plugin->cls, @@ -1797,6 +1852,23 @@ run (void *cls) plugin->have_deposit (plugin->cls, session, &deposit)); + { + struct GNUNET_TIME_Absolute start_range; + struct GNUNET_TIME_Absolute end_range; + + start_range = GNUNET_TIME_absolute_subtract (deadline, + GNUNET_TIME_UNIT_SECONDS); + end_range = GNUNET_TIME_absolute_add (deadline, + GNUNET_TIME_UNIT_SECONDS); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->select_deposits_missing_wire (plugin->cls, + session, + start_range, + end_range, + &wire_missing_cb, + &deposit)); + FAILIF (8 != result); + } auditor_row_cnt = 0; FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->select_deposits_above_serial_id (plugin->cls,