summaryrefslogtreecommitdiff
path: root/src/testing/test_exchange_p2p.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/test_exchange_p2p.c')
-rw-r--r--src/testing/test_exchange_p2p.c311
1 files changed, 198 insertions, 113 deletions
diff --git a/src/testing/test_exchange_p2p.c b/src/testing/test_exchange_p2p.c
index ba6d5bbf2..093730ff2 100644
--- a/src/testing/test_exchange_p2p.c
+++ b/src/testing/test_exchange_p2p.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014--2022 Taler Systems SA
+ Copyright (C) 2014--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -20,13 +20,9 @@
* @file testing/test_exchange_p2p.c
* @brief testcase to test exchange's P2P payments
* @author Christian Grothoff
- *
- * TODO:
- * - Test setup with KYC where purse merge is only
- * allowed for reserves with KYC completed.
- * - Test purse creation with reserve purse quota
*/
#include "platform.h"
+#include "taler_attributes.h"
#include "taler_util.h"
#include "taler_signatures.h"
#include "taler_exchange_service.h"
@@ -46,18 +42,13 @@
static char *config_file;
/**
- * Exchange configuration data.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_BankConfiguration bc;
+struct TALER_TESTING_Credentials cred;
/**
* Some tests behave differently when using CS as we cannot
- * re-use the coin private key for different denominations
+ * reuse the coin private key for different denominations
* due to the derivation of it with the /csr values. Hence
* some tests behave differently in CS mode, hence this
* flag.
@@ -71,7 +62,7 @@ static bool uses_cs;
* @param label label to use for the command.
*/
#define CMD_EXEC_WIREWATCH(label) \
- TALER_TESTING_cmd_exec_wirewatch (label, config_file)
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, "exchange-account-2")
/**
* Execute the taler-exchange-aggregator, closer and transfer commands with
@@ -94,8 +85,8 @@ static bool uses_cs;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
- &bc.exchange_auth, \
- bc.user42_payto)
+ &cred.ba, \
+ cred.user42_payto)
/**
* Main function that will tell the interpreter what commands to
@@ -126,13 +117,13 @@ run (void *cls,
MHD_HTTP_OK),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
"EUR:5.04",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-1"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-2",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-2"),
/**
* Make a reserve exist, according to the previous
@@ -161,7 +152,7 @@ run (void *cls,
};
struct TALER_TESTING_Command push[] = {
TALER_TESTING_cmd_purse_create_with_deposit (
- "purse-with-deposit",
+ "purse-with-deposit-for-delete",
MHD_HTTP_OK,
"{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
true, /* upload contract */
@@ -169,11 +160,24 @@ run (void *cls,
"withdraw-coin-1",
"EUR:1.01",
NULL),
+ TALER_TESTING_cmd_purse_delete (
+ "purse-with-deposit-delete",
+ MHD_HTTP_NO_CONTENT,
+ "purse-with-deposit-for-delete"),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-with-deposit",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"ice cream\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "withdraw-coin-1",
+ "EUR:1.00",
+ NULL),
TALER_TESTING_cmd_purse_poll (
"push-poll-purse-before-merge",
MHD_HTTP_OK,
"purse-with-deposit",
- "EUR:1",
+ "EUR:0.99",
true,
GNUNET_TIME_UNIT_MINUTES),
TALER_TESTING_cmd_contract_get (
@@ -195,13 +199,13 @@ run (void *cls,
TALER_TESTING_cmd_status (
"push-check-post-merge-reserve-balance-get",
"create-reserve-1",
- "EUR:1.03",
+ "EUR:1.02",
MHD_HTTP_OK),
/* POST history doesn't yet support P2P transfers */
- TALER_TESTING_cmd_reserve_status (
+ TALER_TESTING_cmd_reserve_history (
"push-check-post-merge-reserve-balance-post",
"create-reserve-1",
- "EUR:1.03",
+ "EUR:1.02",
MHD_HTTP_OK),
/* Test conflicting merge */
TALER_TESTING_cmd_purse_merge (
@@ -218,6 +222,7 @@ run (void *cls,
MHD_HTTP_OK,
"{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_UNIT_MINUTES, /* expiration */
"create-reserve-1"),
TALER_TESTING_cmd_contract_get (
@@ -251,18 +256,26 @@ run (void *cls,
"create-reserve-1",
"EUR:2.02",
MHD_HTTP_OK),
- /* POST history doesn't yet support P2P transfers */
- TALER_TESTING_cmd_reserve_status (
+ TALER_TESTING_cmd_reserve_history (
"push-check-post-merge-reserve-balance-post",
"create-reserve-1",
"EUR:2.02",
MHD_HTTP_OK),
+ TALER_TESTING_cmd_purse_deposit_coins (
+ "purse-deposit-coins-idempotent",
+ MHD_HTTP_OK,
+ 0 /* min age */,
+ "purse-create-with-reserve",
+ "withdraw-coin-1",
+ "EUR:1.01",
+ NULL),
/* create 2nd purse for a deposit conflict */
TALER_TESTING_cmd_purse_create_with_reserve (
"purse-create-with-reserve-2",
MHD_HTTP_OK,
"{\"amount\":\"EUR:4\",\"summary\":\"beer\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_UNIT_MINUTES, /* expiration */
"create-reserve-1"),
TALER_TESTING_cmd_purse_deposit_coins (
@@ -282,6 +295,7 @@ run (void *cls,
MHD_HTTP_OK,
"{\"amount\":\"EUR:2\",\"summary\":\"ice cream\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_SECONDS,
1), /* expiration */
@@ -356,37 +370,143 @@ run (void *cls,
NULL),
TALER_TESTING_cmd_end ()
};
+ struct TALER_TESTING_Command reserves[] = {
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-100",
+ "EUR:1.04"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-100",
+ "EUR:1.04",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-100"),
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-101",
+ "EUR:1.04"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-101",
+ "EUR:1.04",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-101"),
+ CMD_EXEC_WIREWATCH ("wirewatch-100"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-100",
+ "create-reserve-100",
+ "EUR:1",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-fail",
+ "create-reserve-101",
+ "EUR:0",
+ GNUNET_TIME_UNIT_YEARS,
+ 5, /* min purses */
+ MHD_HTTP_PAYMENT_REQUIRED,
+ NULL,
+ NULL),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-ok-a",
+ "create-reserve-101",
+ "EUR:0.01",
+ GNUNET_TIME_UNIT_MONTHS,
+ 1, /* min purses */
+ MHD_HTTP_OK,
+ NULL,
+ NULL),
+ TALER_TESTING_cmd_status ("status-101-open-paid",
+ "create-reserve-101",
+ "EUR:1.03",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-ok-b",
+ "create-reserve-101",
+ "EUR:0",
+ GNUNET_TIME_UNIT_MONTHS,
+ 2, /* min purses */
+ MHD_HTTP_OK,
+ "withdraw-coin-100",
+ "EUR:0.03", /* 0.02 for the reserve open, 0.01 for deposit fee */
+ NULL,
+ NULL),
+ /* Use purse creation with purse quota here */
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-a",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-b",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-fail",
+ MHD_HTTP_CONFLICT,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_reserve_get_attestable ("reserve-101-attestable",
+ "create-reserve-101",
+ MHD_HTTP_NOT_FOUND,
+ NULL),
+ TALER_TESTING_cmd_reserve_get_attestable ("reserve-101-attest",
+ "create-reserve-101",
+ MHD_HTTP_NOT_FOUND,
+ "nx-attribute-name",
+ NULL),
+ TALER_TESTING_cmd_oauth ("start-oauth-service",
+ 6666),
+ TALER_TESTING_cmd_reserve_close ("reserve-101-close-kyc",
+ "create-reserve-101",
+ /* 42b => not to origin */
+ "payto://x-taler-bank/localhost/42?receiver-name=42b",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
+
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-close-pending",
+ "reserve-101-close-kyc",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-close-kyc",
+ "reserve-101-close-kyc",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-close-ok",
+ "reserve-101-close-kyc",
+ MHD_HTTP_NO_CONTENT),
+ /* Now it should pass */
+ TALER_TESTING_cmd_reserve_close ("reserve-101-close",
+ "create-reserve-101",
+ /* 42b => not to origin */
+ "payto://x-taler-bank/localhost/42?receiver-name=42b",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_exec_closer ("close-reserves-101",
+ config_file,
+ "EUR:1.02",
+ "EUR:0.01",
+ "create-reserve-101"),
+ TALER_TESTING_cmd_exec_transfer ("close-reserves-101-transfer",
+ config_file),
+ TALER_TESTING_cmd_status ("reserve-101-closed-status",
+ "create-reserve-101",
+ "EUR:0",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end ()
+ };
struct TALER_TESTING_Command commands[] = {
- /* setup exchange */
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_extensions ("offline-sign-extensions",
- config_file),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-wire-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_exec_offline_sign_global_fees ("offline-sign-global-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_DAYS,
- 1),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_batch ("withdraw",
withdraw),
TALER_TESTING_cmd_batch ("push",
@@ -395,14 +515,15 @@ run (void *cls,
pull),
TALER_TESTING_cmd_batch ("expire",
expire),
+ TALER_TESTING_cmd_batch ("reserves",
+ reserves),
/* End the suite. */
TALER_TESTING_cmd_end ()
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
@@ -410,62 +531,26 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
-
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
-
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- uses_cs = (0 == strcmp (cipher, "cs"));
- GNUNET_asprintf (&config_file,
- "test_exchange_api-%s.conf",
- cipher);
- GNUNET_free (cipher);
-
- /* Check fakebank port is available and get config */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 78;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 2;
- break;
- default:
- GNUNET_break (0);
- return 3;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ uses_cs = (0 == strcmp (cipher, "cs"));
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}