diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-03 18:23:46 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-03 18:23:46 -0400 |
commit | 33d332a637d77524f140a20c0b636177276224a9 (patch) | |
tree | a0aa460e89e7379c6fd83ba19229bec54779c7d8 | |
parent | c4dc3bf39183559ddcfeafba65ef3d8635bc13fe (diff) | |
download | merchant-33d332a637d77524f140a20c0b636177276224a9.tar.gz merchant-33d332a637d77524f140a20c0b636177276224a9.tar.bz2 merchant-33d332a637d77524f140a20c0b636177276224a9.zip |
test GET /private/transfers
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-transfers.c | 57 | ||||
-rw-r--r-- | src/lib/merchant_api_get_transfers.c | 6 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 8 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_transfers.c | 124 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_transfers.c | 46 |
5 files changed, 196 insertions, 45 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-transfers.c b/src/backend/taler-merchant-httpd_private-get-transfers.c index f98b785b..8020fbe8 100644 --- a/src/backend/taler-merchant-httpd_private-get-transfers.c +++ b/src/backend/taler-merchant-httpd_private-get-transfers.c @@ -55,14 +55,12 @@ transfer_cb (void *cls, json_t *ja = cls; json_t *r; - r = json_pack ("{s:o, s:o, s:s, s:s, s:I, s:b, s:b}", + r = json_pack ("{s:o, s:o, s:s, s:s, s:I}", "credit_amount", TALER_JSON_from_amount (credit_amount), "wtid", GNUNET_JSON_from_data_auto (wtid), "payto_uri", payto_uri, "exchange_url", exchange_url, - "transfer_serial_id", (json_int_t) transfer_serial_id, - "verified", verified ? 1 : 0, - "confirmed", confirmed ? 1 : 0); + "transfer_serial_id", (json_int_t) transfer_serial_id); GNUNET_assert (NULL != r); if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != execution_time.abs_value_us) @@ -72,6 +70,16 @@ transfer_cb (void *cls, "execution_time", GNUNET_JSON_from_time_abs (execution_time))); GNUNET_assert (0 == + json_object_set_new ( + r, + "verified", + json_boolean (verified ? 1 : 0))); + GNUNET_assert (0 == + json_object_set_new ( + r, + "confirmed", + json_boolean (confirmed ? 1 : 0))); + GNUNET_assert (0 == json_array_append_new (ja, r)); } @@ -177,43 +185,20 @@ TMH_private_get_transfers (const struct TMH_RequestHandler *rh, } else { - if (limit > 0) + if (limit < 0) offset = INT64_MAX; else offset = 0; } } - { - const char *verified_s; - - verified_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "verified"); - if (NULL == verified_s) - { - verified = TALER_EXCHANGE_YNA_ALL; - } - else if (0 == strcasecmp (verified_s, - "yes")) - { - verified = TALER_EXCHANGE_YNA_YES; - } - else if (0 == strcasecmp (verified_s, - "no")) - { - verified = TALER_EXCHANGE_YNA_NO; - } - else if (0 == strcasecmp (verified_s, - "all")) - { - verified = TALER_EXCHANGE_YNA_ALL; - } - else - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "verified"); - } + if (! (TALER_arg_to_yna (connection, + "verified", + TALER_EXCHANGE_YNA_ALL, + &verified)) ) + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_PARAMETER_MALFORMED, + "verified"); TMH_db->preflight (TMH_db->cls); { diff --git a/src/lib/merchant_api_get_transfers.c b/src/lib/merchant_api_get_transfers.c index 552311c4..5d08dba1 100644 --- a/src/lib/merchant_api_get_transfers.c +++ b/src/lib/merchant_api_get_transfers.c @@ -130,6 +130,8 @@ handle_transfers_get_finished (void *cls, struct TALER_MERCHANT_TransferData); ok = true; json_array_foreach (transfers, i, transfer) { + /* FIXME: handle 'execution_time', 'verified', and/or 'confirmed' + not present in the response. */ struct TALER_MERCHANT_TransferData *td = &tds[i]; struct GNUNET_JSON_Specification ispec[] = { TALER_JSON_spec_amount ("credit_amount", @@ -140,7 +142,7 @@ handle_transfers_get_finished (void *cls, &td->payto_uri), GNUNET_JSON_spec_string ("exchange_url", &td->exchange_url), - GNUNET_JSON_spec_uint64 ("credit_serial", + GNUNET_JSON_spec_uint64 ("transfer_serial_id", &td->credit_serial), GNUNET_JSON_spec_absolute_time ("execution_time", &td->execution_time), @@ -278,7 +280,7 @@ TALER_MERCHANT_transfers_get ( before_s = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (before)); after_s = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (after)); gth->url = TALER_url_join (backend_url, - "transfers", + "private/transfers", "payto_uri", payto_uri, "verified", diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index eb3e7def..02a70f33 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -383,12 +383,18 @@ run (void *cls, merchant_payto), TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1", &bc.exchange_auth, - "payto://x-taler-bank/localhost/3", + PAYTO_I1, merchant_url, "EUR:4.98", MHD_HTTP_OK, "deposit-simple", NULL), + TALER_TESTING_cmd_merchant_get_transfers ("get-transfers-1", + merchant_url, + PAYTO_I1, + MHD_HTTP_OK, + "post-transfer-1", + NULL), TALER_TESTING_cmd_merchant_delete_order ("delete-order-1", merchant_url, "1", diff --git a/src/testing/testing_api_cmd_get_transfers.c b/src/testing/testing_api_cmd_get_transfers.c index d0efa13a..34889e88 100644 --- a/src/testing/testing_api_cmd_get_transfers.c +++ b/src/testing/testing_api_cmd_get_transfers.c @@ -117,9 +117,127 @@ get_transfers_cb ( TALER_TESTING_interpreter_fail (gts->is); return; } - // { - // FIXME: check that list of returned transactions matches our expectations! - // } + for (unsigned int i = 0; i < transfers_length; ++i) + { + const struct TALER_TESTING_Command *transfer_cmd; + + transfer_cmd = TALER_TESTING_interpreter_lookup_command ( + gts->is, + gts->transfers[i]); + { + const struct TALER_WireTransferIdentifierRawP *wtid; + + if (GNUNET_OK != + TALER_TESTING_get_trait_wtid (transfer_cmd, + 0, + &wtid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer id\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + if (0 != GNUNET_memcmp (wtid, + &transfers[i].wtid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer id does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const char *payto_uri; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (transfer_cmd, + 0, + &payto_uri)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer payto uri\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + if (0 != strcmp (payto_uri, + transfers[i].payto_uri)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer payto uri does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const struct TALER_Amount *credit_amount; + + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (transfer_cmd, + 0, + &credit_amount)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer credit amount\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + if ((GNUNET_OK != TALER_amount_cmp_currency (credit_amount, + &transfers[i].credit_amount)) + || + (0 != TALER_amount_cmp (credit_amount, + &transfers[i].credit_amount))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer credit amount does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const char *exchange_url; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (transfer_cmd, + 1, + &exchange_url)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer exchange url\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + if (0 != strcmp (exchange_url, + transfers[i].exchange_url)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer exchange url does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + { + const struct GNUNET_TIME_Absolute *execution_time; + + if (GNUNET_OK != + TALER_TESTING_get_trait_absolute_time (transfer_cmd, + 0, + &execution_time)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch wire transfer execution time\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + if (execution_time->abs_value_us != + transfers[i].execution_time.abs_value_us) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Wire transfer execution time does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/testing/testing_api_cmd_post_transfers.c b/src/testing/testing_api_cmd_post_transfers.c index 768b76a4..100ea32d 100644 --- a/src/testing/testing_api_cmd_post_transfers.c +++ b/src/testing/testing_api_cmd_post_transfers.c @@ -98,6 +98,11 @@ struct PostTransfersState * Set to true once @e wtid and @e exchange_url are initialized. */ bool found; + + /** + * When the exchange executed the transfer. + */ + struct GNUNET_TIME_Absolute execution_time; }; @@ -142,9 +147,10 @@ transfers_cb (void *cls, { case MHD_HTTP_OK: { - /* - struct TALER_Amount total; + // struct TALER_Amount total; + pts->execution_time = execution_time; + /* if (0 > TALER_amount_subtract (&total, total_amount, @@ -284,6 +290,39 @@ transfers_cb (void *cls, /** + * Offers information from the POST /transfers CMD state to other + * commands. + * + * @param cls closure + * @param ret[out] result (could be anything) + * @param trait name of the trait + * @param index index number of the object to extract. + * @return #GNUNET_OK on success + */ +static int +post_transfers_traits (void *cls, + const void **ret, + const char *trait, + unsigned int index) +{ + struct PostTransfersState *pts = cls; + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_wtid (0, &pts->wtid), + TALER_TESTING_make_trait_string (0, pts->payto_uri), + TALER_TESTING_make_trait_amount_obj (0, &pts->credit_amount), + TALER_TESTING_make_trait_string (1, pts->exchange_url), + TALER_TESTING_make_trait_absolute_time (0, &pts->execution_time), + TALER_TESTING_trait_end (), + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); +} + + +/** * Callbacks of this type are used to serve the result of asking * the bank for the debit transaction history. * @@ -468,7 +507,8 @@ TALER_TESTING_cmd_merchant_post_transfer ( .cls = pts, .label = label, .run = &post_transfers_run, - .cleanup = &post_transfers_cleanup + .cleanup = &post_transfers_cleanup, + .traits = &post_transfers_traits }; return cmd; |