add test case for #3887
This commit is contained in:
parent
2684327176
commit
368b9f8fcb
@ -1369,6 +1369,7 @@ maint_child_death (void *cls)
|
||||
GNUNET_break (0 ==
|
||||
GNUNET_OS_process_kill (exchanged,
|
||||
SIGUSR1));
|
||||
sleep (5); /* make sure signal was received and processed */
|
||||
break;
|
||||
default:
|
||||
GNUNET_break (0);
|
||||
@ -3375,6 +3376,78 @@ run (void *cls)
|
||||
|
||||
/* ************** Test /payback API ************* */
|
||||
|
||||
/* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config,
|
||||
then withdraw a coin and then have it be paid back. */
|
||||
{ .oc = OC_ADMIN_ADD_INCOMING,
|
||||
.label = "payback-create-reserve-1",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
|
||||
.details.admin_add_incoming.transfer_details = "{ \"uuid\":4 }",
|
||||
.details.admin_add_incoming.amount = "EUR:5.01" },
|
||||
/* Withdraw a 5 EUR coin, at fee of 1 ct */
|
||||
{ .oc = OC_WITHDRAW_SIGN,
|
||||
.label = "payback-withdraw-coin-1",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.reserve_withdraw.reserve_reference = "payback-create-reserve-1",
|
||||
.details.reserve_withdraw.amount = "EUR:5" },
|
||||
{ .oc = OC_REVOKE,
|
||||
.label = "revoke-1",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.revoke.ref = "payback-withdraw-coin-1" },
|
||||
{ .oc = OC_PAYBACK,
|
||||
.label = "payback-1",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.payback.ref = "payback-withdraw-coin-1",
|
||||
.details.payback.amount = "EUR:5" },
|
||||
|
||||
|
||||
/* Fill reserve with EUR:1.01, as withdraw fee is 1 ct per config,
|
||||
then withdraw a coin, partially spend it, and then have the rest paid back.
|
||||
(Do not use EUR:5 here as the EUR:5 coin was revoked and we did not
|
||||
bother to create a new one...) */
|
||||
{ .oc = OC_ADMIN_ADD_INCOMING,
|
||||
.label = "payback-create-reserve-2",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
|
||||
.details.admin_add_incoming.transfer_details = "{ \"uuid\":5 }",
|
||||
.details.admin_add_incoming.amount = "EUR:1.01" },
|
||||
/* Withdraw a 1 EUR coin, at fee of 1 ct */
|
||||
{ .oc = OC_WITHDRAW_SIGN,
|
||||
.label = "payback-withdraw-coin-2",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.reserve_withdraw.reserve_reference = "payback-create-reserve-2",
|
||||
.details.reserve_withdraw.amount = "EUR:1" },
|
||||
|
||||
{ .oc = OC_DEPOSIT,
|
||||
.label = "payback-deposit-partial",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.deposit.amount = "EUR:0.5",
|
||||
.details.deposit.coin_ref = "payback-withdraw-coin-2",
|
||||
.details.deposit.wire_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }",
|
||||
.details.deposit.proposal_data = "{ \"items\": [ { \"name\":\"more ice cream\", \"value\":1 } ] }" },
|
||||
{ .oc = OC_REVOKE,
|
||||
.label = "revoke-2",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.revoke.ref = "payback-withdraw-coin-2" },
|
||||
{ .oc = OC_PAYBACK,
|
||||
.label = "payback-2",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.payback.ref = "payback-withdraw-coin-2",
|
||||
.details.payback.amount = "EUR:0.5" },
|
||||
|
||||
/* Test that revoked coins cannot be withdrawn */
|
||||
{ .oc = OC_ADMIN_ADD_INCOMING,
|
||||
.label = "payback-create-reserve-3",
|
||||
.expected_response_code = MHD_HTTP_OK,
|
||||
.details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42}",
|
||||
.details.admin_add_incoming.transfer_details = "{ \"uuid\":6 }",
|
||||
.details.admin_add_incoming.amount = "EUR:1.01" },
|
||||
{ .oc = OC_WITHDRAW_SIGN,
|
||||
.label = "payback-withdraw-coin-3-revoked",
|
||||
.expected_response_code = MHD_HTTP_NOT_FOUND,
|
||||
.details.reserve_withdraw.reserve_reference = "payback-create-reserve-3",
|
||||
.details.reserve_withdraw.amount = "EUR:1" },
|
||||
|
||||
|
||||
/* ************** End of payback API testing************* */
|
||||
#endif
|
||||
@ -3403,6 +3476,40 @@ run (void *cls)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove files from previous runs
|
||||
*/
|
||||
static void
|
||||
cleanup_files ()
|
||||
{
|
||||
struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||
char *dir;
|
||||
|
||||
cfg = GNUNET_CONFIGURATION_create ();
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_load (cfg,
|
||||
"test_exchange_api.conf"))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_CONFIGURATION_destroy (cfg);
|
||||
exit (77);
|
||||
}
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_CONFIGURATION_get_value_filename (cfg,
|
||||
"exchange",
|
||||
"keydir",
|
||||
&dir));
|
||||
if (GNUNET_YES ==
|
||||
GNUNET_DISK_directory_test (dir,
|
||||
GNUNET_NO))
|
||||
GNUNET_break (GNUNET_OK ==
|
||||
GNUNET_DISK_directory_remove (dir));
|
||||
GNUNET_free (dir);
|
||||
GNUNET_CONFIGURATION_destroy (cfg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main function for the testcase for the exchange API.
|
||||
*
|
||||
@ -3443,6 +3550,8 @@ main (int argc,
|
||||
8082);
|
||||
return 77;
|
||||
}
|
||||
cleanup_files ();
|
||||
|
||||
proc = GNUNET_OS_start_process (GNUNET_NO,
|
||||
GNUNET_OS_INHERIT_STD_ALL,
|
||||
NULL, NULL, NULL,
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "taler-exchange-httpd_deposit.h"
|
||||
#include "taler-exchange-httpd_refund.h"
|
||||
#include "taler-exchange-httpd_reserve.h"
|
||||
#include "taler-exchange-httpd_payback.h"
|
||||
#include "taler-exchange-httpd_wire.h"
|
||||
#include "taler-exchange-httpd_refresh.h"
|
||||
#include "taler-exchange-httpd_tracking.h"
|
||||
@ -295,6 +296,13 @@ handle_mhd_request (void *cls,
|
||||
"Only POST is allowed", 0,
|
||||
&TEH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
|
||||
|
||||
{ "/payback", MHD_HTTP_METHOD_POST, "application/json",
|
||||
NULL, 0,
|
||||
&TEH_PAYBACK_handler_payback, MHD_HTTP_OK },
|
||||
{ "/refresh/link", NULL, "text/plain",
|
||||
"Only GET is allowed", 0,
|
||||
&TEH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
|
||||
|
||||
{ NULL, NULL, NULL, NULL, 0, 0 }
|
||||
};
|
||||
static struct TEH_RequestHandler h404 =
|
||||
|
@ -192,7 +192,7 @@ calculate_transaction_list_totals (struct TALER_EXCHANGEDB_TransactionList *tl,
|
||||
}
|
||||
}
|
||||
/* spent = spent - refunded */
|
||||
if (GNUNET_OK !=
|
||||
if (GNUNET_SYSERR ==
|
||||
TALER_amount_subtract (&spent,
|
||||
&spent,
|
||||
&refunded))
|
||||
|
@ -308,6 +308,9 @@ reload_keys_denom_iter (void *cls,
|
||||
|
||||
if (NULL != revocation_master_sig)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Adding denomination key `%s' to revokation set\n",
|
||||
alias);
|
||||
res = store_in_map (ctx->revoked_map,
|
||||
dki);
|
||||
if (GNUNET_NO == res)
|
||||
|
@ -168,7 +168,7 @@ TEH_PAYBACK_handler_payback (struct TEH_RequestHandler *rh,
|
||||
struct GNUNET_JSON_Specification spec[] = {
|
||||
TALER_JSON_spec_denomination_public_key ("denom_pub",
|
||||
&coin.denom_pub),
|
||||
TALER_JSON_spec_denomination_signature ("ub_sig",
|
||||
TALER_JSON_spec_denomination_signature ("denom_sig",
|
||||
&coin.denom_sig),
|
||||
GNUNET_JSON_spec_fixed_auto ("coin_pub",
|
||||
&coin.coin_pub),
|
||||
|
@ -54,7 +54,10 @@ TALER_EXCHANGEDB_denomination_key_revoke (const char *exchange_base_dir,
|
||||
ret = GNUNET_SYSERR;
|
||||
start = GNUNET_TIME_absolute_ntoh (dki->issue.properties.start);
|
||||
GNUNET_asprintf (&fn,
|
||||
"%s" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "%llu.rev",
|
||||
"%s" DIR_SEPARATOR_STR
|
||||
TALER_EXCHANGEDB_DIR_DENOMINATION_KEYS DIR_SEPARATOR_STR
|
||||
"%s" DIR_SEPARATOR_STR
|
||||
"%llu.rev",
|
||||
exchange_base_dir,
|
||||
alias,
|
||||
(unsigned long long) start.abs_value_us);
|
||||
|
Loading…
Reference in New Issue
Block a user