finish checks for /withdraw/status

This commit is contained in:
Christian Grothoff 2015-07-09 12:11:01 +02:00
parent 443b0db2c7
commit fdbedcd457

View File

@ -23,7 +23,6 @@
* TODO: * TODO:
* - enhance interpreter to allow for testing of failure conditions * - enhance interpreter to allow for testing of failure conditions
* (i.e. double-spending, insufficient funds on withdraw) * (i.e. double-spending, insufficient funds on withdraw)
* - add checks for /withdraw/status
*/ */
#include "platform.h" #include "platform.h"
#include "taler_util.h" #include "taler_util.h"
@ -160,6 +159,11 @@ struct Command
*/ */
struct TALER_MINT_WithdrawStatusHandle *wsh; struct TALER_MINT_WithdrawStatusHandle *wsh;
/**
* Expected reserve balance.
*/
const char *expected_balance;
} withdraw_status; } withdraw_status;
struct struct
@ -441,6 +445,7 @@ compare_withdraw_sign_history (const struct TALER_MINT_ReserveHistory *h,
const struct Command *cmd) const struct Command *cmd)
{ {
struct TALER_Amount amount; struct TALER_Amount amount;
struct TALER_Amount amount_with_fee;
if (TALER_MINT_RTT_WITHDRAWAL != h->type) if (TALER_MINT_RTT_WITHDRAWAL != h->type)
{ {
@ -450,13 +455,15 @@ compare_withdraw_sign_history (const struct TALER_MINT_ReserveHistory *h,
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (cmd->details.withdraw_sign.amount, TALER_string_to_amount (cmd->details.withdraw_sign.amount,
&amount)); &amount));
// FIXME: should fail (amount with vs. amount without fee!) GNUNET_assert (GNUNET_OK ==
if (0 != TALER_amount_cmp (&amount, TALER_amount_add (&amount_with_fee,
&amount,
&cmd->details.withdraw_sign.pk->fee_withdraw));
if (0 != TALER_amount_cmp (&amount_with_fee,
&h->amount)) &h->amount))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_OK; /* FIXME: returning OK for now, as the above return GNUNET_SYSERR;
fails due to fee/no-fee mismatch */
} }
return GNUNET_OK; return GNUNET_OK;
} }
@ -486,6 +493,7 @@ withdraw_status_cb (void *cls,
struct Command *rel; struct Command *rel;
unsigned int i; unsigned int i;
unsigned int j; unsigned int j;
struct TALER_Amount amount;
cmd->details.withdraw_status.wsh = NULL; cmd->details.withdraw_status.wsh = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
@ -546,8 +554,19 @@ withdraw_status_cb (void *cls,
fail (is); fail (is);
return; return;
} }
/* FIXME: check the amount... */ if (NULL != cmd->details.withdraw_status.expected_balance)
{
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (cmd->details.withdraw_status.expected_balance,
&amount));
if (0 != TALER_amount_cmp (&amount,
balance))
{
GNUNET_break (0);
fail (is);
return;
}
}
is->ip++; is->ip++;
is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
is); is);
@ -1191,7 +1210,8 @@ run (void *cls,
.details.withdraw_sign.amount = "EUR:5" }, .details.withdraw_sign.amount = "EUR:5" },
{ .oc = OC_WITHDRAW_STATUS, { .oc = OC_WITHDRAW_STATUS,
.label = "withdraw-status-1", .label = "withdraw-status-1",
.details.withdraw_status.reserve_reference = "create-reserve-1" }, .details.withdraw_status.reserve_reference = "create-reserve-1",
.details.withdraw_status.expected_balance = "EUR:0" },
{ .oc = OC_DEPOSIT, { .oc = OC_DEPOSIT,
.label = "deposit-simple", .label = "deposit-simple",
.details.deposit.amount = "EUR:5", .details.deposit.amount = "EUR:5",