diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-06-13 21:05:32 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-06-13 21:06:06 +0200 |
commit | f432e22ff0e34ae0573cee58b783adbfbc54d1ec (patch) | |
tree | 95e88d564b94ad6c2ff5cbc8eeaf50e0cc70dd16 /src/backenddb | |
parent | bd79ca83a26aec30d5b5e60ef573b56d5f8c8645 (diff) |
Add error when coins are not sufficient to pay a refund
back.
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 15 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 23 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index dee509cd..d51f4019 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -2039,6 +2039,9 @@ process_deposits_cb (void *cls, } + /** + * Check if the refund is bigger than the previous awarded. + */ if (-1 == TALER_amount_cmp (&attempted_refund, &previous_refund)) { @@ -2053,6 +2056,18 @@ process_deposits_cb (void *cls, } /** + * Check if all the refund has been allocated + */ + if ( (0 != ctx->refund->value) || + (0 != ctx->refund->fraction) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "This refund is bigger than the coins capacity\n"); + ctx->err = GNUNET_NO; + return; + } + + /** * NOTE: we don't check if all the refund has been covered. * Although this should be checked, it's safe to assume yes, * as the business will never issue a refund bigger than the diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index d1ddaa46..0c9b455e 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -136,6 +136,12 @@ static struct TALER_Amount little_refund_amount; static struct TALER_Amount right_second_refund_amount; /** + * Refund amount meant to raise an error because the + * contract's coins aren't enough to pay it back + */ +static struct TALER_Amount too_big_refund_amount; + +/** * Public key of the coin. Set to some random value. */ static struct TALER_CoinSpendPublicKeyP coin_pub; @@ -394,7 +400,7 @@ run (void *cls) refund_deadline = GNUNET_TIME_absolute_get(); GNUNET_TIME_round_abs (&refund_deadline); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":2", + TALER_string_to_amount (CURRENCY ":5", &amount_with_fee)); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":0.000010", @@ -409,8 +415,11 @@ run (void *cls) TALER_string_to_amount (CURRENCY ":1", &little_refund_amount)); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":4", + TALER_string_to_amount (CURRENCY ":3", &right_second_refund_amount)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":30", + &too_big_refund_amount)); RND_BLK (&coin_pub); deposit_proof = json_object (); GNUNET_assert (0 == @@ -578,7 +587,15 @@ run (void *cls) &h_contract_terms, &merchant_pub, &right_second_refund_amount, - "make refund testing fail")); + "right refund increase")); + + FAILIF (GNUNET_NO != + plugin->increase_refund_for_contract (plugin->cls, + &h_contract_terms, + &merchant_pub, + &too_big_refund_amount, + "make refund testing fail due" + " to too big refund amount")); if (-1 == result) result = 0; |