diff options
Diffstat (limited to 'src/testing/testing_api_cmd_reserve_history.c')
-rw-r--r-- | src/testing/testing_api_cmd_reserve_history.c | 162 |
1 files changed, 98 insertions, 64 deletions
diff --git a/src/testing/testing_api_cmd_reserve_history.c b/src/testing/testing_api_cmd_reserve_history.c index beba23f11..e9cc11a6d 100644 --- a/src/testing/testing_api_cmd_reserve_history.c +++ b/src/testing/testing_api_cmd_reserve_history.c @@ -79,24 +79,55 @@ struct HistoryState /** + * 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; @@ -108,28 +139,26 @@ 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++) { struct TALER_TESTING_Command *step = &(*bcmd)[i]; - 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; } if (step == cur) break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */ } - return GNUNET_OK; + return; } { @@ -138,11 +167,11 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, 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; @@ -156,9 +185,9 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, /* NOTE: only for debugging... */ if (0 == j) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Command `%s' has the reserve_pub trait, but does not reserve history trait\n", + "Command `%s' has the reserve_pub, but lacks 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; i<history_length; i++) { @@ -179,7 +208,8 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, "Command `%s' reserve history entry #%u not found\n", cmd->label, j); - return GNUNET_SYSERR; + ac->failure = true; + return; } } } @@ -200,15 +230,19 @@ reserve_history_cb (void *cls, struct HistoryState *ss = cls; struct TALER_TESTING_Interpreter *is = ss->is; struct TALER_Amount eb; + struct TALER_EXCHANGE_Handle *exchange + = TALER_TESTING_get_exchange (is); ss->rsh = NULL; + if (NULL == exchange) + return; if (MHD_HTTP_OK == rs->hr.http_status) { const struct TALER_EXCHANGE_Keys *keys; const struct TALER_EXCHANGE_GlobalFee *gf; ss->reserve_history.type = TALER_EXCHANGE_RTT_HISTORY; - keys = TALER_EXCHANGE_get_keys (ss->is->exchange); + keys = TALER_EXCHANGE_get_keys (exchange); GNUNET_assert (NULL != keys); gf = TALER_EXCHANGE_get_global_fee (keys, rs->ts); @@ -254,44 +288,42 @@ reserve_history_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; i<rs->details.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 history\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 history\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); } @@ -311,7 +343,11 @@ history_run (void *cls, { struct HistoryState *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, @@ -333,7 +369,7 @@ history_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv, &ss->reserve_pub.eddsa_pub); - ss->rsh = TALER_EXCHANGE_reserves_history (is->exchange, + ss->rsh = TALER_EXCHANGE_reserves_history (exchange, ss->reserve_priv, &reserve_history_cb, ss); @@ -388,10 +424,8 @@ history_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_history_cancel (ss->rsh); ss->rsh = NULL; } |