From e18e0809b7657688c8301632f3e803686610fa6f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Nov 2023 13:29:40 +0100 Subject: towards testing coin history API properly --- src/testing/testing_api_cmd_coin_history.c | 161 +++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 44 deletions(-) (limited to 'src/testing/testing_api_cmd_coin_history.c') diff --git a/src/testing/testing_api_cmd_coin_history.c b/src/testing/testing_api_cmd_coin_history.c index 2de125932..d4b95fb48 100644 --- a/src/testing/testing_api_cmd_coin_history.c +++ b/src/testing/testing_api_cmd_coin_history.c @@ -104,7 +104,85 @@ struct AnalysisContext }; -#if 0 +/** + * Compare @a h1 and @a h2. + * + * @param h1 a history entry + * @param h2 a history entry + * @return 0 if @a h1 and @a h2 are equal + */ +static int +history_entry_cmp ( + const struct TALER_EXCHANGE_CoinHistoryEntry *h1, + const struct TALER_EXCHANGE_CoinHistoryEntry *h2) +{ + if (h1->type != h2->type) + return 1; + if (0 != TALER_amount_cmp (&h1->amount, + &h2->amount)) + return 1; + switch (h1->type) + { + case TALER_EXCHANGE_CTT_NONE: + GNUNET_break (0); + break; + case TALER_EXCHANGE_CTT_DEPOSIT: + if (0 != GNUNET_memcmp (&h1->details.deposit.sig, + &h2->details.deposit.sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_MELT: + if (0 != GNUNET_memcmp (&h1->details.melt.sig, + &h2->details.melt.sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_REFUND: + if (0 != GNUNET_memcmp (&h1->details.refund.sig, + &h2->details.refund.sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_RECOUP: + if (0 != GNUNET_memcmp (&h1->details.recoup.coin_sig, + &h2->details.recoup.coin_sig)) + return 1; + if (0 != GNUNET_memcmp (&h1->details.recoup.exchange_sig, + &h2->details.recoup.exchange_sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_RECOUP_REFRESH: + if (0 != GNUNET_memcmp (&h1->details.recoup_refresh.coin_sig, + &h2->details.recoup_refresh.coin_sig)) + return 1; + if (0 != GNUNET_memcmp (&h1->details.recoup_refresh.exchange_sig, + &h2->details.recoup_refresh.exchange_sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_OLD_COIN_RECOUP: + if (0 != GNUNET_memcmp (&h1->details.old_coin_recoup.exchange_sig, + &h2->details.old_coin_recoup.exchange_sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_PURSE_DEPOSIT: + if (0 != GNUNET_memcmp (&h1->details.purse_deposit.coin_sig, + &h2->details.purse_deposit.coin_sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_PURSE_REFUND: + if (0 != GNUNET_memcmp (&h1->details.purse_refund.exchange_sig, + &h2->details.purse_refund.exchange_sig)) + return 1; + return 0; + case TALER_EXCHANGE_CTT_RESERVE_OPEN_DEPOSIT: + if (0 != GNUNET_memcmp (&h1->details.reserve_open_deposit.coin_sig, + &h2->details.reserve_open_deposit.coin_sig)) + return 1; + return 0; + } + GNUNET_assert (0); + return -1; +} + + /** * Check if @a cmd changed the coin, if so, find the * entry in our history and set the respective index in found @@ -156,64 +234,59 @@ analyze_command (void *cls, return; } + for (unsigned int j = 0; true; j++) { - const struct TALER_CoinPublicKeyP *rp; + const struct TALER_CoinSpendPublicKeyP *rp; + const struct TALER_EXCHANGE_CoinHistoryEntry *he; + bool matched = false; if (GNUNET_OK != TALER_TESTING_get_trait_coin_pub (cmd, + j, &rp)) - return; /* command does nothing for coins */ + break; /* command does nothing for coins */ if (0 != GNUNET_memcmp (rp, coin_pub)) - return; /* command affects some _other_ coin */ - for (unsigned int j = 0; true; j++) + continue; /* command affects some _other_ coin */ + if (GNUNET_OK != + TALER_TESTING_get_trait_coin_history (cmd, + j, + &he)) { - const struct TALER_EXCHANGE_CoinHistoryEntry *he; - bool matched = false; - - if (GNUNET_OK != - TALER_TESTING_get_trait_coin_history (cmd, - j, - &he)) - { - /* NOTE: only for debugging... */ - if (0 == j) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Command `%s' has the coin_pub, but lacks coin history trait\n", - cmd->label); - return; /* command does nothing for coins */ - } - for (unsigned int i = 0; ilabel); + return; /* command does nothing for coins */ + } + for (unsigned int i = 0; ilabel, - j); - ac->failure = true; - return; + found[i] = true; + matched = true; + break; } } + if (! matched) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Command `%s' coin history entry #%u not found\n", + cmd->label, + j); + ac->failure = true; + return; + } } } -#endif - - /** * Check that the coin balance and HTTP response code are * both acceptable. @@ -325,7 +398,6 @@ coin_history_cb (void *cls, return; } (void) ac; -#if FIXME TALER_TESTING_iterate (is, true, &analyze_command, @@ -338,6 +410,7 @@ coin_history_cb (void *cls, TALER_TESTING_interpreter_fail (ss->is); return; } +#if FIXME for (unsigned int i = 0; idetails.ok.history_len; i++) { if (found[i]) -- cgit v1.2.3