From a2dde02b64a8ee75c9243632eb45a6ceb9b62dd5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 7 Jun 2023 23:11:05 +0200 Subject: major libtalertesting API refactoring, including no longer having taler-specific logic in the test engine core --- src/testing/testing_api_cmd_reserve_status.c | 155 ++++++++++++++++----------- 1 file changed, 92 insertions(+), 63 deletions(-) (limited to 'src/testing/testing_api_cmd_reserve_status.c') diff --git a/src/testing/testing_api_cmd_reserve_status.c b/src/testing/testing_api_cmd_reserve_status.c index a1b7aaefd..7e7b45cd7 100644 --- a/src/testing/testing_api_cmd_reserve_status.c +++ b/src/testing/testing_api_cmd_reserve_status.c @@ -69,26 +69,56 @@ struct StatusState struct TALER_TESTING_Interpreter *is; }; +/** + * Closure for analysis_cb(). + */ +struct AnalysisContext +{ + /** + * Reserve public key we are looking at. + */ + const struct TALER_ReservePublicKeyP *reserve_pub; + + /** + * Length of the @e history array. + */ + unsigned int history_length; + + /** + * Array of history items to match. + */ + const struct TALER_EXCHANGE_ReserveHistoryEntry *history; + + /** + * Array of @e history_length of matched entries. + */ + bool *found; + + /** + * Set to true if an entry could not be found. + */ + bool failure; +}; + /** * Check if @a cmd changed the reserve, if so, find the - * entry in @a history and set the respective index in @a found - * to #GNUNET_YES. If the entry is not found, return #GNUNET_SYSERR. + * entry in our history and set the respective index in found + * to true. If the entry is not found, set failure. * - * @param reserve_pub public key of the reserve for which we have the @a history + * @param cls our `struct AnalysisContext *` * @param cmd command to analyze for impact on history - * @param history_length number of entries in @a history and @a found - * @param history history to check - * @param[in,out] found array to update - * @return #GNUNET_OK if @a cmd action on reserve was found in @a history */ -static enum GNUNET_GenericReturnValue -analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_TESTING_Command *cmd, - unsigned int history_length, - const struct TALER_EXCHANGE_ReserveHistoryEntry *history, - bool *found) +static void +analyze_command (void *cls, + const struct TALER_TESTING_Command *cmd) { + struct AnalysisContext *ac = cls; + const struct TALER_ReservePublicKeyP *reserve_pub = ac->reserve_pub; + const struct TALER_EXCHANGE_ReserveHistoryEntry *history = ac->history; + unsigned int history_length = ac->history_length; + bool *found = ac->found; + if (TALER_TESTING_cmd_is_batch (cmd)) { struct TALER_TESTING_Command *cur; @@ -100,7 +130,8 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, &bcmd)) { GNUNET_break (0); - return GNUNET_SYSERR; + ac->failure = true; + return; } for (unsigned int i = 0; NULL != (*bcmd)[i].label; i++) { @@ -108,33 +139,30 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, if (step == cur) break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */ - if (GNUNET_OK != - analyze_command (reserve_pub, - step, - history_length, - history, - found)) + analyze_command (ac, + step); + if (ac->failure) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Entry for batch step `%s' missing in history\n", step->label); - return GNUNET_SYSERR; + return; } } - return GNUNET_OK; + return; } - else + { const struct TALER_ReservePublicKeyP *rp; if (GNUNET_OK != TALER_TESTING_get_trait_reserve_pub (cmd, &rp)) - return GNUNET_OK; /* command does nothing for reserves */ + return; /* command does nothing for reserves */ if (0 != GNUNET_memcmp (rp, reserve_pub)) - return GNUNET_OK; /* command affects some _other_ reserve */ + return; /* command affects some _other_ reserve */ for (unsigned int j = 0; true; j++) { const struct TALER_EXCHANGE_ReserveHistoryEntry *he; @@ -149,7 +177,7 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Command `%s' has the reserve_pub trait, but does not reserve history trait\n", cmd->label); - return GNUNET_OK; /* command does nothing for reserves */ + return; /* command does nothing for reserves */ } for (unsigned int i = 0; ilabel, j); - return GNUNET_SYSERR; + ac->failure = true; + return; } } } @@ -230,44 +259,42 @@ reserve_status_cb (void *cls, } { bool found[rs->details.ok.history_len]; + struct AnalysisContext ac = { + .reserve_pub = &ss->reserve_pub, + .history = rs->details.ok.history, + .history_length = rs->details.ok.history_len, + .found = found + }; memset (found, 0, sizeof (found)); - for (unsigned int i = 0; i<= (unsigned int) is->ip; i++) + TALER_TESTING_iterate (is, + true, + &analyze_command, + &ac); + if (ac.failure) { - struct TALER_TESTING_Command *cmd = &is->commands[i]; - - if (GNUNET_OK != - analyze_command (&ss->reserve_pub, - cmd, - rs->details.ok.history_len, - rs->details.ok.history, - found)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Entry for command `%s' missing in history\n", - cmd->label); - json_dumpf (rs->hr.reply, - stderr, - JSON_INDENT (2)); - TALER_TESTING_interpreter_fail (ss->is); - return; - } + json_dumpf (rs->hr.reply, + stderr, + JSON_INDENT (2)); + TALER_TESTING_interpreter_fail (ss->is); + return; } for (unsigned int i = 0; idetails.ok.history_len; i++) - if (! found[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "History entry at index %u of type %d not justified by command status\n", - i, - rs->details.ok.history[i].type); - json_dumpf (rs->hr.reply, - stderr, - JSON_INDENT (2)); - TALER_TESTING_interpreter_fail (ss->is); - return; - } + { + if (found[i]) + continue; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "History entry at index %u of type %d not justified by command status\n", + i, + rs->details.ok.history[i].type); + json_dumpf (rs->hr.reply, + stderr, + JSON_INDENT (2)); + TALER_TESTING_interpreter_fail (ss->is); + return; + } } TALER_TESTING_interpreter_next (is); } @@ -287,7 +314,11 @@ status_run (void *cls, { struct StatusState *ss = cls; const struct TALER_TESTING_Command *create_reserve; + struct TALER_EXCHANGE_Handle *exchange + = TALER_TESTING_get_exchange (is); + if (NULL == exchange) + return; ss->is = is; create_reserve = TALER_TESTING_interpreter_lookup_command (is, @@ -310,7 +341,7 @@ status_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_status (is->exchange, + ss->rsh = TALER_EXCHANGE_reserves_status (exchange, ss->reserve_priv, &reserve_status_cb, ss); @@ -332,10 +363,8 @@ status_cleanup (void *cls, if (NULL != ss->rsh) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Command %u (%s) did not complete\n", - ss->is->ip, - cmd->label); + TALER_TESTING_command_incomplete (ss->is, + cmd->label); TALER_EXCHANGE_reserves_status_cancel (ss->rsh); ss->rsh = NULL; } -- cgit v1.2.3