From 1fe26d5d2e7094045fa5c319b047e901ff617d84 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 10 Apr 2017 17:59:33 +0200 Subject: also test reserve history after payback --- src/exchange-lib/exchange_api_reserve.c | 11 ++++- src/exchange-lib/test_exchange_api.c | 62 ++++++++++++++++++++++++++- src/exchange/taler-exchange-httpd_responses.c | 5 ++- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c index 6dd48866f..0ed8cca00 100644 --- a/src/exchange-lib/exchange_api_reserve.c +++ b/src/exchange-lib/exchange_api_reserve.c @@ -274,7 +274,7 @@ parse_reserve_history (struct TALER_EXCHANGE_Handle *exchange, &rhistory[off].details.payback_details.exchange_sig), GNUNET_JSON_spec_fixed_auto ("exchange_pub", &rhistory[off].details.payback_details.exchange_pub), - GNUNET_JSON_spec_absolute_time ("timetamp", + GNUNET_JSON_spec_absolute_time ("timestamp", ×tamp), TALER_JSON_spec_amount ("amount", &rhistory[off].amount), @@ -325,6 +325,15 @@ parse_reserve_history (struct TALER_EXCHANGE_Handle *exchange, GNUNET_break_op (0); return GNUNET_SYSERR; } + if (GNUNET_OK != + TALER_amount_add (&total_in, + &total_in, + &rhistory[off].amount)) + { + /* overflow in history already!? inconceivable! Bad exchange! */ + GNUNET_break_op (0); + return GNUNET_SYSERR; + } /* end type==PAYBACK */ } else if (0 == strcasecmp (type, diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index b4cd108fc..5b64e79bd 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -921,6 +921,38 @@ compare_reserve_withdraw_history (const struct TALER_EXCHANGE_ReserveHistory *h, } +/** + * Check if the given historic event @a h corresponds to the given + * command @a cmd. + * + * @param h event in history + * @param cmd an #OC_WITHDRAW_SIGN command + * @return #GNUNET_OK if they match, #GNUNET_SYSERR if not + */ +static int +compare_reserve_payback_history (const struct TALER_EXCHANGE_ReserveHistory *h, + const struct Command *cmd) +{ + struct TALER_Amount amount; + + if (TALER_EXCHANGE_RTT_PAYBACK != h->type) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (cmd->details.payback.amount, + &amount)); + if (0 != TALER_amount_cmp (&amount, + &h->amount)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + /** * Function called with the result of a /reserve/status request. * @@ -945,6 +977,7 @@ reserve_status_cb (void *cls, struct InterpreterState *is = cls; struct Command *cmd = &is->commands[is->ip]; struct Command *rel; + const struct Command *xrel; unsigned int i; unsigned int j; struct TALER_Amount amount; @@ -1007,6 +1040,24 @@ reserve_status_cb (void *cls, j++; } break; + case OC_PAYBACK: + xrel = find_command (is, + rel->details.payback.ref); + if (0 == strcmp (cmd->details.reserve_status.reserve_reference, + xrel->details.reserve_withdraw.reserve_reference)) + { + if ( (j >= history_length) || + (GNUNET_OK != + compare_reserve_payback_history (&history[j], + rel)) ) + { + GNUNET_break (0); + fail (is); + return; + } + j++; + } + break; default: /* unreleated, just skip */ break; @@ -1088,6 +1139,9 @@ reserve_withdraw_cb (void *cls, case MHD_HTTP_FORBIDDEN: /* nothing to check */ break; + case MHD_HTTP_NOT_FOUND: + /* nothing to check */ + break; default: /* Unsupported status code (by test harness) */ GNUNET_break (0); @@ -2666,7 +2720,7 @@ interpreter_run (void *cls) const struct Command *ref; ref = find_command (is, - cmd->details.revoke.ref); + cmd->details.payback.ref); GNUNET_assert (NULL != ref); cmd->details.payback.ph = TALER_EXCHANGE_payback (exchange, @@ -3399,6 +3453,12 @@ run (void *cls) .expected_response_code = MHD_HTTP_OK, .details.payback.ref = "payback-withdraw-coin-1", .details.payback.amount = "EUR:5" }, + /* Check the money is back with the reserve */ + { .oc = OC_WITHDRAW_STATUS, + .label = "payback-reserve-status-1", + .expected_response_code = MHD_HTTP_OK, + .details.reserve_status.reserve_reference = "payback-create-reserve-1", + .details.reserve_status.expected_balance = "EUR:5.00" }, /* Fill reserve with EUR:2.02, as withdraw fee is 1 ct per config, diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index 111337c7e..eea534195 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -745,12 +745,13 @@ compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh, GNUNET_assert (0 == json_array_append_new (json_history, - json_pack ("{s:s, s:o, s:o, s:o, s:o}", + json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}", "type", "PAYBACK", "exchange_pub", GNUNET_JSON_from_data_auto (&pub), "exchange_sig", GNUNET_JSON_from_data_auto (&sig), "timestamp", GNUNET_JSON_from_time_abs (payback->timestamp), - "amount", TALER_JSON_from_amount (&payback->value)))); + "amount", TALER_JSON_from_amount (&payback->value), + "details", GNUNET_JSON_from_data_auto (&pc)))); break; case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK: value = pos->details.bank->amount; -- cgit v1.2.3