diff options
Diffstat (limited to 'src/auditordb')
| -rw-r--r-- | src/auditordb/plugin_auditordb_postgres.c | 80 | ||||
| -rw-r--r-- | src/auditordb/test_auditordb.c | 555 | 
2 files changed, 546 insertions, 89 deletions
| diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index fa3a6d46..527cc80e 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -1481,13 +1481,8 @@ postgres_get_reserve_info (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("reserve_balance_val", &reserve_balance->value), -    GNUNET_PQ_result_spec_uint32 ("reserve_balance_frac", &reserve_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("reserve_balance_curr", &reserve_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("withdraw_fee_balance_val", &withdraw_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("withdraw_fee_balance_frac", &withdraw_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("withdraw_fee_balance_curr", &withdraw_fee_balance->currency), +    TALER_PQ_result_spec_amount ("reserve_balance", reserve_balance), +    TALER_PQ_result_spec_amount ("withdraw_fee_balance", withdraw_fee_balance),      GNUNET_PQ_result_spec_auto_from_type ("expiration_date", expiration_date), @@ -1655,13 +1650,8 @@ postgres_get_reserve_summary (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("reserve_balance_val", &reserve_balance->value), -    GNUNET_PQ_result_spec_uint32 ("reserve_balance_frac", &reserve_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("reserve_balance_curr", &reserve_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("withdraw_fee_balance_val", &withdraw_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("withdraw_fee_balance_frac", &withdraw_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("withdraw_fee_balance_curr", &withdraw_fee_balance->currency), +    TALER_PQ_result_spec_amount ("reserve_balance", reserve_balance), +    TALER_PQ_result_spec_amount ("withdraw_fee_balance", withdraw_fee_balance),      GNUNET_PQ_result_spec_end    }; @@ -1890,21 +1880,10 @@ postgres_get_denomination_balance (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("denom_balance_val", &denom_balance->value), -    GNUNET_PQ_result_spec_uint32 ("denom_balance_frac", &denom_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("denom_balance_curr", &denom_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("deposit_fee_balance_val", &deposit_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("deposit_fee_balance_frac", &deposit_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("deposit_fee_balance_curr", &deposit_fee_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("melt_fee_balance_val", &melt_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("melt_fee_balance_frac", &melt_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("melt_fee_balance_curr", &melt_fee_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("refund_fee_balance_val", &refund_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("refund_fee_balance_frac", &refund_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("refund_fee_balance_curr", &refund_fee_balance->currency), +    TALER_PQ_result_spec_amount ("denom_balance", denom_balance), +    TALER_PQ_result_spec_amount ("deposit_fee_balance", deposit_fee_balance), +    TALER_PQ_result_spec_amount ("melt_fee_balance", melt_fee_balance), +    TALER_PQ_result_spec_amount ("refund_fee_balance", refund_fee_balance),      GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id", last_reserve_out_serial_id),      GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id", last_deposit_serial_id), @@ -2093,21 +2072,10 @@ postgres_get_denomination_summary (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("denom_balance_val", &denom_balance->value), -    GNUNET_PQ_result_spec_uint32 ("denom_balance_frac", &denom_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("denom_balance_curr", &denom_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("deposit_fee_balance_val", &deposit_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("deposit_fee_balance_frac", &deposit_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("deposit_fee_balance_curr", &deposit_fee_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("melt_fee_balance_val", &melt_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("melt_fee_balance_frac", &melt_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("melt_fee_balance_curr", &melt_fee_balance->currency), - -    GNUNET_PQ_result_spec_uint64 ("refund_fee_balance_val", &refund_fee_balance->value), -    GNUNET_PQ_result_spec_uint32 ("refund_fee_balance_frac", &refund_fee_balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("refund_fee_balance_curr", &refund_fee_balance->currency), +    TALER_PQ_result_spec_amount ("denom_balance", denom_balance), +    TALER_PQ_result_spec_amount ("deposit_fee_balance", deposit_fee_balance), +    TALER_PQ_result_spec_amount ("melt_fee_balance", melt_fee_balance), +    TALER_PQ_result_spec_amount ("refund_fee_balance", refund_fee_balance),      GNUNET_PQ_result_spec_end    }; @@ -2255,9 +2223,7 @@ postgres_get_risk_summary (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("risk_val", &risk->value), -    GNUNET_PQ_result_spec_uint32 ("risk_frac", &risk->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("risk_curr", &risk->currency), +    TALER_PQ_result_spec_amount ("risk", risk),      GNUNET_PQ_result_spec_end    }; @@ -2674,13 +2640,13 @@ postgres_select_historic_reserve_revenue (void *cls,    }    for (int i = 0; i < nrows; i++)    { -    struct GNUNET_TIME_Absolute start_time; -    struct GNUNET_TIME_Absolute end_time; +    struct GNUNET_TIME_Absolute start_date; +    struct GNUNET_TIME_Absolute end_date;      struct TALER_Amount reserve_profits;      struct GNUNET_PQ_ResultSpec rs[] = { -      GNUNET_PQ_result_spec_auto_from_type ("start_time", &start_time), -      GNUNET_PQ_result_spec_auto_from_type ("end_time", &end_time), +      GNUNET_PQ_result_spec_auto_from_type ("start_date", &start_date), +      GNUNET_PQ_result_spec_auto_from_type ("end_date", &end_date),        TALER_PQ_result_spec_amount ("reserve_profits", &reserve_profits), @@ -2694,8 +2660,8 @@ postgres_select_historic_reserve_revenue (void *cls,        return GNUNET_SYSERR;      }      ret = cb (cb_cls, -              start_time, -              end_time, +              start_date, +              end_date,                &reserve_profits);      switch (ret)      { @@ -2732,7 +2698,6 @@ postgres_insert_predicted_result (void *cls,    struct GNUNET_PQ_QueryParam params[] = {      GNUNET_PQ_query_param_auto_from_type (master_pub), -      TALER_PQ_query_param_amount (balance),      GNUNET_PQ_query_param_end @@ -2775,6 +2740,9 @@ postgres_update_predicted_result (void *cls,    int ret;    struct GNUNET_PQ_QueryParam params[] = { +    TALER_PQ_query_param_amount (balance), +    GNUNET_PQ_query_param_auto_from_type (master_pub), +      GNUNET_PQ_query_param_end    }; @@ -2839,9 +2807,7 @@ postgres_get_predicted_balance (void *cls,    GNUNET_assert (1 == nrows);    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_uint64 ("balance_val", &balance->value), -    GNUNET_PQ_result_spec_uint32 ("balance_frac", &balance->fraction), -    GNUNET_PQ_result_spec_auto_from_type ("balance_curr", &balance->currency), +    TALER_PQ_result_spec_amount ("balance", balance),      GNUNET_PQ_result_spec_end    }; diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c index fc7cf522..376739eb 100644 --- a/src/auditordb/test_auditordb.c +++ b/src/auditordb/test_auditordb.c @@ -66,37 +66,6 @@ static struct TALER_AUDITORDB_Plugin *plugin;  /** - * Callback that should never be called. - */ -static void -dead_prepare_cb (void *cls, -                 unsigned long long rowid, -                 const char *wire_method, -                 const char *buf, -                 size_t buf_size) -{ -  GNUNET_assert (0); -} - - -int -select_denomination_info_result (void *cls, -                                 const struct TALER_DenominationKeyValidityPS *issue2) -{ -  const struct TALER_DenominationKeyValidityPS *issue1 = cls; - -  if (0 != memcmp (issue1, issue2, sizeof (*issue2))) -  { -    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -                "select_denomination_info_result: issue does not match\n"); -    GNUNET_break (0); -    return GNUNET_SYSERR; -  } -  return GNUNET_OK; -} - - -/**   * Main function that will be run by the scheduler.   *   * @param cls closure with config @@ -107,6 +76,9 @@ run (void *cls)    struct GNUNET_CONFIGURATION_Handle *cfg = cls;    struct TALER_AUDITORDB_Session *session; +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "loading database plugin\n"); +    if (NULL ==        (plugin = TALER_AUDITORDB_plugin_load (cfg)))    { @@ -128,6 +100,9 @@ run (void *cls)      goto drop;    } +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "initializing\n"); +    struct TALER_Amount value, fee_withdraw, fee_deposit, fee_refresh, fee_refund;    GNUNET_assert (GNUNET_OK == @@ -148,8 +123,10 @@ run (void *cls)    struct TALER_MasterPublicKeyP master_pub;    struct TALER_ReservePublicKeyP reserve_pub; +  struct GNUNET_HashCode rnd_hash;    RND_BLK (&master_pub);    RND_BLK (&reserve_pub); +  RND_BLK (&rnd_hash);    struct TALER_DenominationPrivateKey denom_priv;    struct TALER_DenominationPublicKey denom_pub; @@ -158,7 +135,7 @@ run (void *cls)    denom_pub.rsa_public_key = GNUNET_CRYPTO_rsa_private_key_get_public (denom_priv.rsa_private_key);    GNUNET_CRYPTO_rsa_public_key_hash (denom_pub.rsa_public_key, &denom_pub_hash); -  struct GNUNET_TIME_Absolute now, past, future; +  struct GNUNET_TIME_Absolute now, past, future, date;    now = GNUNET_TIME_absolute_get ();    past = GNUNET_TIME_absolute_subtract (now,                                          GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, @@ -167,6 +144,9 @@ run (void *cls)                                       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,                                                                    4)); +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_denomination_info\n"); +    struct TALER_DenominationKeyValidityPS issue = { 0 };    issue.master = master_pub;    issue.denom_hash = denom_pub_hash; @@ -194,6 +174,25 @@ run (void *cls)                                              session,                                              &issue)); +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: select_denomination_info\n"); + +  int +  select_denomination_info_result (void *cls, +                                   const struct TALER_DenominationKeyValidityPS *issue2) +  { +    const struct TALER_DenominationKeyValidityPS *issue1 = cls; + +    if (0 != memcmp (issue1, issue2, sizeof (*issue2))) +    { +      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                  "select_denomination_info_result: issue does not match\n"); +      GNUNET_break (0); +      return GNUNET_SYSERR; +    } +    return GNUNET_OK; +  } +    FAILIF (GNUNET_OK !=            plugin->select_denomination_info (plugin->cls,                                              session, @@ -201,6 +200,498 @@ run (void *cls)                                              select_denomination_info_result,                                              &issue)); +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_reserve_info\n"); + +  struct TALER_Amount reserve_balance, withdraw_fee_balance; +  struct TALER_Amount reserve_balance2 = {}, withdraw_fee_balance2 = {}; + +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":12.345678", +                                         &reserve_balance)); +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":23.456789", +                                         &withdraw_fee_balance)); + +  uint64_t +      last_reserve_in_serial_id = 1234, +      last_reserve_out_serial_id = 5678, +      last_reserve_in_serial_id2 = 0, +      last_reserve_out_serial_id2 =0; + +  FAILIF (GNUNET_OK != +          plugin->insert_reserve_info (plugin->cls, +                                       session, +                                       &reserve_pub, +                                       &master_pub, +                                       &reserve_balance, +                                       &withdraw_fee_balance, +                                       past, +                                       last_reserve_in_serial_id, +                                       last_reserve_out_serial_id)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_reserve_info\n"); + +  last_reserve_in_serial_id++; +  last_reserve_out_serial_id++; + +  FAILIF (GNUNET_OK != +          plugin->update_reserve_info (plugin->cls, +                                       session, +                                       &reserve_pub, +                                       &master_pub, +                                       &reserve_balance, +                                       &withdraw_fee_balance, +                                       future, +                                       last_reserve_in_serial_id, +                                       last_reserve_out_serial_id)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_reserve_info\n"); + +  FAILIF (GNUNET_OK != +          plugin->get_reserve_info (plugin->cls, +                                    session, +                                    &reserve_pub, +                                    &master_pub, +                                    &reserve_balance2, +                                    &withdraw_fee_balance2, +                                    &date, +                                    &last_reserve_in_serial_id2, +                                    &last_reserve_out_serial_id2)); + +  FAILIF (0 != memcmp (&date, &future, sizeof (future)) +          || 0 != memcmp (&reserve_balance2, &reserve_balance, sizeof (reserve_balance)) +          || 0 != memcmp (&withdraw_fee_balance2, &withdraw_fee_balance, sizeof (withdraw_fee_balance)) +          || last_reserve_in_serial_id2 != last_reserve_in_serial_id +          || last_reserve_out_serial_id2 != last_reserve_out_serial_id); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_reserve_summary\n"); + +  FAILIF (GNUNET_OK != +          plugin->insert_reserve_summary (plugin->cls, +                                          session, +                                          &master_pub, +                                          &withdraw_fee_balance, +                                          &reserve_balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_reserve_summary\n"); + +  FAILIF (GNUNET_OK != +          plugin->update_reserve_summary (plugin->cls, +                                          session, +                                          &master_pub, +                                          &reserve_balance, +                                          &withdraw_fee_balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_reserve_summary\n"); + +  ZR_BLK (&reserve_balance2); +  ZR_BLK (&withdraw_fee_balance2); + +  FAILIF (GNUNET_OK != +          plugin->get_reserve_summary (plugin->cls, +                                       session, +                                       &master_pub, +                                       &reserve_balance2, +                                       &withdraw_fee_balance2)); + +  FAILIF (0 != memcmp (&reserve_balance2, &reserve_balance, sizeof (reserve_balance)) +          || 0 != memcmp (&withdraw_fee_balance2, &withdraw_fee_balance, sizeof (withdraw_fee_balance))); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_denomination_balance\n"); + +  struct TALER_Amount denom_balance, deposit_fee_balance, melt_fee_balance, refund_fee_balance; +  struct TALER_Amount denom_balance2, deposit_fee_balance2, melt_fee_balance2, refund_fee_balance2; + +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":12.345678", +                                         &denom_balance)); +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":23.456789", +                                         &deposit_fee_balance)); +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":34.567890", +                                         &melt_fee_balance)); +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":45.678901", +                                         &refund_fee_balance)); + +  uint64_t +      last_deposit_serial_id = 123, +      last_melt_serial_id = 456, +      last_refund_serial_id = 789, + +      last_deposit_serial_id2 = 0, +      last_melt_serial_id2 = 0, +      last_refund_serial_id2 =0; + +  FAILIF (GNUNET_OK != +          plugin->insert_denomination_balance (plugin->cls, +                                               session, +                                               &denom_pub_hash, +                                               &refund_fee_balance, +                                               &melt_fee_balance, +                                               &deposit_fee_balance, +                                               &denom_balance, +                                               last_reserve_out_serial_id, +                                               last_deposit_serial_id, +                                               last_melt_serial_id, +                                               last_refund_serial_id)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_denomination_balance\n"); + +  last_reserve_out_serial_id++; +  last_deposit_serial_id++; +  last_melt_serial_id++; +  last_refund_serial_id++; + +  FAILIF (GNUNET_OK != +          plugin->update_denomination_balance (plugin->cls, +                                               session, +                                               &denom_pub_hash, +                                               &denom_balance, +                                               &deposit_fee_balance, +                                               &melt_fee_balance, +                                               &refund_fee_balance, +                                               last_reserve_out_serial_id, +                                               last_deposit_serial_id, +                                               last_melt_serial_id, +                                               last_refund_serial_id)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_denomination_balance\n"); + +  FAILIF (GNUNET_OK != +          plugin->get_denomination_balance (plugin->cls, +                                            session, +                                            &denom_pub_hash, +                                            &denom_balance2, +                                            &deposit_fee_balance2, +                                            &melt_fee_balance2, +                                            &refund_fee_balance2, +                                            &last_reserve_out_serial_id2, +                                            &last_deposit_serial_id2, +                                            &last_melt_serial_id2, +                                            &last_refund_serial_id2)); + +  FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance)) +          || 0 != memcmp (&deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance)) +          || 0 != memcmp (&melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance)) +          || 0 != memcmp (&refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance)) +          || last_reserve_out_serial_id2 != last_reserve_out_serial_id +          || last_deposit_serial_id2 != last_deposit_serial_id +          || last_melt_serial_id2 != last_melt_serial_id +          || last_refund_serial_id2 != last_refund_serial_id); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_denomination_summary\n"); + +  FAILIF (GNUNET_OK != +          plugin->insert_denomination_summary (plugin->cls, +                                               session, +                                               &master_pub, +                                               &refund_fee_balance, +                                               &melt_fee_balance, +                                               &deposit_fee_balance, +                                               &denom_balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_denomination_summary\n"); + +  FAILIF (GNUNET_OK != +          plugin->update_denomination_summary (plugin->cls, +                                               session, +                                               &master_pub, +                                               &denom_balance, +                                               &deposit_fee_balance, +                                               &melt_fee_balance, +                                               &refund_fee_balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_denomination_summary\n"); + +  ZR_BLK (&denom_balance2); +  ZR_BLK (&deposit_fee_balance2); +  ZR_BLK (&melt_fee_balance2); +  ZR_BLK (&refund_fee_balance2); + +  FAILIF (GNUNET_OK != +          plugin->get_denomination_summary (plugin->cls, +                                            session, +                                            &master_pub, +                                            &denom_balance2, +                                            &deposit_fee_balance2, +                                            &melt_fee_balance2, +                                            &refund_fee_balance2)); + +  FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance)) +          || 0 != memcmp (&deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance)) +          || 0 != memcmp (&melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance)) +          || 0 != memcmp (&refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance))); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_risk_summary\n"); + +  struct TALER_Amount balance, balance2; + +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":13.57986", +                                         &balance)); + +  FAILIF (GNUNET_OK != +          plugin->insert_risk_summary (plugin->cls, +                                       session, +                                       &master_pub, +                                       &balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_risk_summary\n"); + +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":57.310986", +                                         &balance)); + +  FAILIF (GNUNET_OK != +          plugin->update_risk_summary (plugin->cls, +                                       session, +                                       &master_pub, +                                       &balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_risk_summary\n"); + +  FAILIF (GNUNET_OK != +          plugin->get_risk_summary (plugin->cls, +                                    session, +                                    &master_pub, +                                    &balance2)); + +  FAILIF (0 != memcmp (&balance2, &balance, sizeof (balance))); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_historic_denom_revenue\n"); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_denom_revenue (plugin->cls, +                                                 session, +                                                 &master_pub, +                                                 &denom_pub_hash, +                                                 past, +                                                 &balance, +                                                 &deposit_fee_balance, +                                                 &melt_fee_balance, +                                                 &refund_fee_balance)); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_denom_revenue (plugin->cls, +                                                 session, +                                                 &master_pub, +                                                 &rnd_hash, +                                                 now, +                                                 &balance, +                                                 &deposit_fee_balance, +                                                 &melt_fee_balance, +                                                 &refund_fee_balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: select_historic_denom_revenue\n"); + +  int +  select_historic_denom_revenue_result (void *cls, +                                        const struct GNUNET_HashCode *denom_pub_hash2, +                                        struct GNUNET_TIME_Absolute revenue_timestamp2, +                                        const struct TALER_Amount *revenue_balance2, +                                        const struct TALER_Amount *deposit_fee_balance2, +                                        const struct TALER_Amount *melt_fee_balance2, +                                        const struct TALER_Amount *refund_fee_balance2) +  { +    static int n = 0; + +    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +                "select_historic_denom_revenue_result: row %u\n", n); + +    if (2 <= n++ +        || cls != NULL +        || (0 != memcmp (&revenue_timestamp2, &past, sizeof (past)) +            && 0 != memcmp (&revenue_timestamp2, &now, sizeof (now))) +        || (0 != memcmp (denom_pub_hash2, &denom_pub_hash, sizeof (denom_pub_hash)) +            && 0 != memcmp (denom_pub_hash2, &rnd_hash, sizeof (rnd_hash))) +        || 0 != memcmp (revenue_balance2, &balance, sizeof (balance)) +        || 0 != memcmp (deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance)) +        || 0 != memcmp (melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance)) +        || 0 != memcmp (refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance))) +    { +        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "select_historic_denom_revenue_result: result does not match\n"); +        GNUNET_break (0); +        return GNUNET_SYSERR; +    } +    return GNUNET_OK; +  } + +  FAILIF (GNUNET_OK != +          plugin->select_historic_denom_revenue (plugin->cls, +                                                 session, +                                                 &master_pub, +                                                 select_historic_denom_revenue_result, +                                                 NULL)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_historic_losses\n"); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_losses (plugin->cls, +                                          session, +                                          &master_pub, +                                          &denom_pub_hash, +                                          past, +                                          &balance)); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_losses (plugin->cls, +                                          session, +                                          &master_pub, +                                          &rnd_hash, +                                          past, +                                          &balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: select_historic_losses\n"); + +  int +  select_historic_losses_result (void *cls, +                                 const struct GNUNET_HashCode *denom_pub_hash2, +                                 struct GNUNET_TIME_Absolute loss_timestamp2, +                                 const struct TALER_Amount *loss_balance2) +  { +    static int n = 0; + +    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +                "select_historic_losses_result: row %u\n", n); + +    if (2 <= n++ +        || cls != NULL +        || (0 != memcmp (&loss_timestamp2, &past, sizeof (past)) +            && 0 != memcmp (&loss_timestamp2, &now, sizeof (now))) +        || (0 != memcmp (denom_pub_hash2, &denom_pub_hash, sizeof (denom_pub_hash)) +            && 0 != memcmp (denom_pub_hash2, &rnd_hash, sizeof (rnd_hash))) +        || 0 != memcmp (loss_balance2, &balance, sizeof (balance))) +    { +        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "select_historic_denom_revenue_result: result does not match\n"); +        GNUNET_break (0); +        return GNUNET_SYSERR; +    } +    return GNUNET_OK; +  } + +  FAILIF (GNUNET_OK != +          plugin->select_historic_losses (plugin->cls, +                                          session, +                                          &master_pub, +                                          select_historic_losses_result, +                                          NULL)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_historic_reserve_revenue\n"); + +  struct TALER_Amount reserve_profits; +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":56.789012", +                                         &reserve_profits)); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_reserve_revenue (plugin->cls, +                                                   session, +                                                   &master_pub, +                                                   past, +                                                   future, +                                                   &reserve_profits)); + +  FAILIF (GNUNET_OK != +          plugin->insert_historic_reserve_revenue (plugin->cls, +                                                   session, +                                                   &master_pub, +                                                   now, +                                                   future, +                                                   &reserve_profits)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: select_historic_reserve_revenue\n"); + +  int +  select_historic_reserve_revenue_result (void *cls, +                                          struct GNUNET_TIME_Absolute start_time2, +                                          struct GNUNET_TIME_Absolute end_time2, +                                          const struct TALER_Amount *reserve_profits2) +  { +    static int n = 0; + +    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, +                "select_historic_reserve_revenue_result: row %u\n", n); + +    if (2 <= n++ +        || cls != NULL +        || (0 != memcmp (&start_time2, &past, sizeof (past)) +            && 0 != memcmp (&start_time2, &now, sizeof (now))) +        || 0 != memcmp (&end_time2, &future, sizeof (future)) +        || 0 != memcmp (reserve_profits2, &reserve_profits, sizeof (reserve_profits))) +    { +        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                "select_historic_reserve_revenue_result: result does not match\n"); +        GNUNET_break (0); +        return GNUNET_SYSERR; +    } +    return GNUNET_OK; +  } + +  FAILIF (GNUNET_OK != +          plugin->select_historic_reserve_revenue (plugin->cls, +                                                   session, +                                                   &master_pub, +                                                   select_historic_reserve_revenue_result, +                                                   NULL)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: insert_predicted_result\n"); + +  FAILIF (GNUNET_OK != +          plugin->insert_predicted_result (plugin->cls, +                                           session, +                                           &master_pub, +                                           &balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: update_predicted_result\n"); + +  GNUNET_assert (GNUNET_OK == +                 TALER_string_to_amount (CURRENCY ":78.901234", +                                         &balance)); + +  FAILIF (GNUNET_OK != +          plugin->update_predicted_result (plugin->cls, +                                           session, +                                           &master_pub, +                                           &balance)); + +  GNUNET_log (GNUNET_ERROR_TYPE_INFO, +              "Test: get_predicted_balance\n"); + +  FAILIF (GNUNET_OK != +          plugin->get_predicted_balance (plugin->cls, +                                         session, +                                         &master_pub, +                                         &balance2)); + +  FAILIF (0 != memcmp (&balance2, &balance, sizeof (balance))); +    result = 0;  drop: | 
