From d55b093de8d5a39d7796ca68a4990ee4e9669c16 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 30 May 2022 19:31:49 +0200 Subject: -fix reserve history, include in tests --- src/testing/test_exchange_api.c | 33 +++++++++++++++++++++------ src/testing/testing_api_cmd_batch_withdraw.c | 2 ++ src/testing/testing_api_cmd_reserve_history.c | 28 +++++++++++++++-------- src/testing/testing_api_cmd_reserve_status.c | 21 ++++++++++++----- src/testing/testing_api_helpers_exchange.c | 1 + 5 files changed, 63 insertions(+), 22 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c index ea929460b..f7318d648 100644 --- a/src/testing/test_exchange_api.c +++ b/src/testing/test_exchange_api.c @@ -565,8 +565,8 @@ run (void *cls, MHD_HTTP_OK), CMD_EXEC_AGGREGATOR ("aggregation-attempt"), - TALER_TESTING_cmd_check_bank_empty - ("far-future-aggregation-b"), + TALER_TESTING_cmd_check_bank_empty ( + "far-future-aggregation-b"), TALER_TESTING_cmd_end () }; @@ -1136,14 +1136,14 @@ run (void *cls, * Move money to the exchange's bank account. */ CMD_TRANSFER_TO_EXCHANGE ("create-batch-reserve-1", - "EUR:6.02"), + "EUR:6.03"), TALER_TESTING_cmd_reserve_poll ("poll-batch-reserve-1", "create-batch-reserve-1", - "EUR:6.02", + "EUR:6.03", GNUNET_TIME_UNIT_MINUTES, MHD_HTTP_OK), TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-batch-reserve-1", - "EUR:6.02", + "EUR:6.03", bc.user42_payto, bc.exchange_payto, "create-batch-reserve-1"), @@ -1166,11 +1166,19 @@ run (void *cls, "EUR:1", NULL), /** - * Check the reserve is depleted. + * Check the reserve is (almost) depleted. */ TALER_TESTING_cmd_status ("status-batch-1", "create-batch-reserve-1", - "EUR:0", + "EUR:0.01", + MHD_HTTP_OK), + TALER_TESTING_cmd_reserve_history ("history-batch-1", + "create-batch-reserve-1", + "EUR:0", + MHD_HTTP_OK), + TALER_TESTING_cmd_status ("status-batch-2", + "create-batch-reserve-1", + "EUR:0.0", MHD_HTTP_OK), /** * Spend the coins. @@ -1240,6 +1248,17 @@ run (void *cls, "payto://x-taler-bank/localhost/2?receiver-name=2", MHD_HTTP_NO_CONTENT, false), + TALER_TESTING_cmd_exec_offline_sign_global_fees ( + "offline-sign-global-fees", + config_file, + "EUR:0.01", + "EUR:0.01", + "EUR:0.01", + "EUR:0.01", + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_DAYS, + 1), TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys", config_file), TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees", diff --git a/src/testing/testing_api_cmd_batch_withdraw.c b/src/testing/testing_api_cmd_batch_withdraw.c index f135f5def..fb290f1e8 100644 --- a/src/testing/testing_api_cmd_batch_withdraw.c +++ b/src/testing/testing_api_cmd_batch_withdraw.c @@ -429,6 +429,8 @@ batch_withdraw_traits (void *cls, TALER_TESTING_trait_end () }; + if (index >= ws->num_coins) + return GNUNET_NO; return TALER_TESTING_get_trait ((ws->expected_response_code == MHD_HTTP_OK) ? &traits[0] /* we have reserve history */ : &traits[1], /* skip reserve history */ diff --git a/src/testing/testing_api_cmd_reserve_history.c b/src/testing/testing_api_cmd_reserve_history.c index e63cca868..96a0a1de3 100644 --- a/src/testing/testing_api_cmd_reserve_history.c +++ b/src/testing/testing_api_cmd_reserve_history.c @@ -114,8 +114,6 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, { struct TALER_TESTING_Command *step = &(*bcmd)[i]; - 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, @@ -128,10 +126,12 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, step->label); return GNUNET_SYSERR; } + if (step == cur) + break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */ } return GNUNET_OK; } - else + { const struct TALER_ReservePublicKeyP *rp; @@ -146,6 +146,7 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, for (unsigned int j = 0; true; j++) { const struct TALER_EXCHANGE_ReserveHistoryEntry *he; + bool matched = false; if (GNUNET_OK != TALER_TESTING_get_trait_reserve_history (cmd, @@ -168,14 +169,18 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, &history[i])) { found[i] = true; - return GNUNET_OK; + matched = true; + break; } } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Command `%s' reserve history entry #%u not found\n", - cmd->label, - j); - return GNUNET_SYSERR; + if (! matched) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Command `%s' reserve history entry #%u not found\n", + cmd->label, + j); + return GNUNET_SYSERR; + } } } } @@ -237,9 +242,13 @@ reserve_history_cb (void *cls, if (0 != TALER_amount_cmp (&eb, &rs->details.ok.balance)) { + GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected amount in reserve: %s\n", TALER_amount_to_string (&rs->details.ok.balance)); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected balance of: %s\n", + TALER_amount_to_string (&eb)); TALER_TESTING_interpreter_fail (ss->is); return; } @@ -351,6 +360,7 @@ history_traits (void *cls, /* history entry MUST be first due to response code logic below! */ TALER_TESTING_make_trait_reserve_history (0, &hs->reserve_history), + TALER_TESTING_make_trait_reserve_pub (&hs->reserve_pub), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_cmd_reserve_status.c b/src/testing/testing_api_cmd_reserve_status.c index 9abd99f0b..76639e49c 100644 --- a/src/testing/testing_api_cmd_reserve_status.c +++ b/src/testing/testing_api_cmd_reserve_status.c @@ -138,6 +138,7 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, for (unsigned int j = 0; true; j++) { const struct TALER_EXCHANGE_ReserveHistoryEntry *he; + bool matched = false; if (GNUNET_OK != TALER_TESTING_get_trait_reserve_history (cmd, @@ -159,14 +160,18 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub, &history[i])) { found[i] = true; - return GNUNET_OK; + matched = true; + break; } } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Command `%s' reserve history entry #%u not found\n", - cmd->label, - j); - return GNUNET_SYSERR; + if (! matched) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Command `%s' reserve history entry #%u not found\n", + cmd->label, + j); + return GNUNET_SYSERR; + } } } } @@ -213,9 +218,13 @@ reserve_status_cb (void *cls, if (0 != TALER_amount_cmp (&eb, &rs->details.ok.balance)) { + GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected amount in reserve: %s\n", TALER_amount_to_string (&rs->details.ok.balance)); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected balance of: %s\n", + TALER_amount_to_string (&eb)); TALER_TESTING_interpreter_fail (ss->is); return; } diff --git a/src/testing/testing_api_helpers_exchange.c b/src/testing/testing_api_helpers_exchange.c index c47a1c2fb..d813021bd 100644 --- a/src/testing/testing_api_helpers_exchange.c +++ b/src/testing/testing_api_helpers_exchange.c @@ -184,6 +184,7 @@ TALER_TESTING_exchange_db_reset (const char *config_filename) "taler-exchange-dbinit", "taler-exchange-dbinit", "-c", config_filename, + "-L", "WARNING", "-r", NULL); if (NULL == proc) -- cgit v1.2.3