summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-05-24 12:02:26 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2018-05-24 12:02:26 +0200
commitafceb5b1c993b9429a620bec61b8eafc71ce144a (patch)
tree3f4c8d29678c292fbcc4b3451e0ea0914e4f4653
parent63d4c63b9131cf26a548686bf9b5e30242f0b533 (diff)
downloadmerchant-afceb5b1c993b9429a620bec61b8eafc71ce144a.tar.gz
merchant-afceb5b1c993b9429a620bec61b8eafc71ce144a.tar.bz2
merchant-afceb5b1c993b9429a620bec61b8eafc71ce144a.zip
Splitting pay CMD.
The pay CMD used to be aborted in the _old_ test case got split in two CMDs, one per coin, in order to make sure that the good coins is _always_ deposited before we abort and ask for refund. This should fix #5330.
-rw-r--r--src/lib/merchant_api_pay.c4
-rw-r--r--src/lib/test_merchant_api.c43
-rw-r--r--src/lib/testing_api_cmd_pay.c3
3 files changed, 43 insertions, 7 deletions
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 973a9b5e..93b6478a 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -337,6 +337,10 @@ handle_pay_finished (void *cls,
case 0:
break;
case MHD_HTTP_OK:
+ /* Tolerating Not Acceptable because sometimes
+ * - especially in tests - we might want to POST
+ * coins one at a time. */
+ case MHD_HTTP_NOT_ACCEPTABLE:
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the merchant is buggy
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index f0d7f499..db9e11e3 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -3690,8 +3690,11 @@ interpreter_run (void *cls)
(is,
cmd->details.pay_abort_refund.abort_ref)));
GNUNET_assert (OC_PAY_ABORT == ref->oc);
+
GNUNET_assert (ref->details.pay_abort.num_refunds >
+ /* 'num_coin' is actually the coin _index_ */
cmd->details.pay_abort_refund.num_coin);
+
re = &ref->details.pay_abort.res[cmd->details.pay_abort_refund.num_coin];
GNUNET_assert (GNUNET_OK ==
@@ -4862,7 +4865,8 @@ run (void *cls)
= "create-reserve-11",
.details.reserve_status.expected_balance = "EUR:0" },
- /* Create proposal */
+ /* Create proposal, to be partially paid, then
+ * abort-refunded, and then paid again. */
{ .oc = OC_PROPOSAL,
.label = "create-proposal-11",
.expected_response_code = MHD_HTTP_OK,
@@ -4884,28 +4888,55 @@ run (void *cls)
[ {\"description\":\"ice cream\",\
\"value\":\"{EUR:10}\"} ] }"},
- /* execute simple payment, re-using one ancient coin */
+ /**
+ * The following two OC_PAY CMDs used to be one.
+ *
+ * However, This caused the refund to be issued _randomly_,
+ * because the order the good coin and the double-spent
+ * coin were deposited was random. Therefore, when
+ * the bad coin was first deposited, the CMD returned
+ * (403) and the good coin was never deposited. This
+ * used to make the "abort refund" CMD fail, since it
+ * expected at least one coin to be refunded.
+ *
+ * The workaround is to _split_ the payment, so as to make
+ * sure that the good coin is always deposited, therefore
+ * having _always_ one coin to get a refund for.
+ *
+ * The test case could now work even without the second
+ * half of the split, but we keep it for "historical"
+ * reasons. */
{ .oc = OC_PAY,
- .label = "pay-fail-partial-double-11",
+ .label = "pay-fail-partial-double-11-not_acceptable",
+ .expected_response_code = MHD_HTTP_NOT_ACCEPTABLE,
+ .details.pay.contract_ref = "create-proposal-11",
+ .details.pay.coin_ref = "withdraw-coin-11a",
+ /* These amounts are given per coin! */
+ .details.pay.refund_fee = "EUR:0.01",
+ .details.pay.amount_with_fee = "EUR:5",
+ .details.pay.amount_without_fee = "EUR:4.99" },
+ { .oc = OC_PAY,
+ .label = "pay-fail-partial-double-11-forbidden",
.expected_response_code = MHD_HTTP_FORBIDDEN,
.details.pay.contract_ref = "create-proposal-11",
- .details.pay.coin_ref = "withdraw-coin-11a;withdraw-coin-1",
+ .details.pay.coin_ref = "withdraw-coin-1",
/* These amounts are given per coin! */
.details.pay.refund_fee = "EUR:0.01",
.details.pay.amount_with_fee = "EUR:5",
.details.pay.amount_without_fee = "EUR:4.99" },
- /* Try to replay payment reusing coin */
{ .oc = OC_PAY_ABORT,
.label = "pay-abort-11",
.expected_response_code = MHD_HTTP_OK,
- .details.pay_abort.pay_ref = "pay-fail-partial-double-11",
+ .details.pay_abort.pay_ref = "pay-fail-partial-double-11-not_acceptable",
},
{ .oc = OC_PAY_ABORT_REFUND,
.label = "pay-abort-refund-11",
.expected_response_code = MHD_HTTP_OK,
+ /* Will provide the refund permission. */
.details.pay_abort_refund.abort_ref = "pay-abort-11",
+ /* Coin _index_ to be refunded. */
.details.pay_abort_refund.num_coin = 0,
.details.pay_abort_refund.refund_amount = "EUR:5",
.details.pay_abort_refund.refund_fee = "EUR:0.01" },
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index a1ed690e..e6a5aa63 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -1422,7 +1422,8 @@ pay_again_cleanup (void *cls,
/**
* Make a "pay again" test command. Its purpose is to
* take all the data from a aborted "pay" CMD, and use
- * good coins to correctly pay for it.
+ * good coins - found in @a coin_reference - to correctly
+ * pay for it.
*
* @param label command label
* @param merchant_url merchant base URL