aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_exchange_service.h6
-rw-r--r--src/include/taler_testing_lib.h8
-rw-r--r--src/lib/exchange_api_purse_create_with_merge.c13
-rw-r--r--src/testing/testing_api_cmd_purse_deposit.c83
-rw-r--r--src/testing/testing_api_cmd_purse_merge.c2
-rw-r--r--src/testing/testing_api_cmd_reserve_purse.c10
6 files changed, 110 insertions, 12 deletions
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index d3ec7d2b5..3cca8b9a2 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -4510,6 +4510,12 @@ struct TALER_EXCHANGE_PurseCreateMergeResponse
struct TALER_EXCHANGE_HttpResponse hr;
/**
+ * Reserve signature generated for the request
+ * (client-side).
+ */
+ const struct TALER_ReserveSignatureP *reserve_sig;
+
+ /**
* Details depending on the HTTP status.
*/
union
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index ff3936cfe..289af9aa1 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -964,10 +964,9 @@ TALER_TESTING_parse_coin_reference (
* @return 0 if @a h1 and @a h2 are equal
*/
int
-TALER_TESTING_history_entry_cmp (const struct
- TALER_EXCHANGE_ReserveHistoryEntry *h1,
- const struct
- TALER_EXCHANGE_ReserveHistoryEntry *h2);
+TALER_TESTING_history_entry_cmp (
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *h2);
/* ************** Specific interpreter commands ************ */
@@ -2721,6 +2720,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
op (merge_pub, const struct TALER_PurseMergePublicKeyP) \
op (contract_priv, const struct TALER_ContractDiffiePrivateP) \
op (reserve_priv, const struct TALER_ReservePrivateKeyP) \
+ op (reserve_sig, const struct TALER_ReserveSignatureP) \
op (h_payto, const struct TALER_PaytoHashP) \
op (planchet_secret, const struct TALER_PlanchetMasterSecretP) \
op (refresh_secret, const struct TALER_RefreshMasterSecretP) \
diff --git a/src/lib/exchange_api_purse_create_with_merge.c b/src/lib/exchange_api_purse_create_with_merge.c
index 35d52b915..32b88c597 100644
--- a/src/lib/exchange_api_purse_create_with_merge.c
+++ b/src/lib/exchange_api_purse_create_with_merge.c
@@ -81,6 +81,11 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle
struct TALER_ReservePublicKeyP reserve_pub;
/**
+ * Reserve signature affirming our merge.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
* Public key of the purse.
*/
struct TALER_PurseContractPublicKeyP purse_pub;
@@ -119,7 +124,8 @@ handle_purse_create_with_merge_finished (void *cls,
const json_t *j = response;
struct TALER_EXCHANGE_PurseCreateMergeResponse dr = {
.hr.reply = j,
- .hr.http_status = (unsigned int) response_code
+ .hr.http_status = (unsigned int) response_code,
+ .reserve_sig = &pcm->reserve_sig
};
pcm->job = NULL;
@@ -259,7 +265,6 @@ TALER_EXCHANGE_purse_create_with_merge (
struct GNUNET_CURL_Context *ctx;
json_t *create_with_merge_obj;
CURL *eh;
- struct TALER_ReserveSignatureP reserve_sig;
char arg_str[sizeof (pcm->reserve_pub) * 2 + 32];
uint32_t min_age = 0;
struct TALER_PurseMergePublicKeyP merge_pub;
@@ -381,7 +386,7 @@ TALER_EXCHANGE_purse_create_with_merge (
min_age,
flags,
reserve_priv,
- &reserve_sig);
+ &pcm->reserve_sig);
if (upload_contract)
{
TALER_CRYPTO_contract_encrypt_for_deposit (
@@ -429,7 +434,7 @@ TALER_EXCHANGE_purse_create_with_merge (
GNUNET_JSON_pack_data_auto ("merge_sig",
&merge_sig),
GNUNET_JSON_pack_data_auto ("reserve_sig",
- &reserve_sig),
+ &pcm->reserve_sig),
GNUNET_JSON_pack_data_auto ("purse_pub",
&pcm->purse_pub),
GNUNET_JSON_pack_data_auto ("purse_sig",
diff --git a/src/testing/testing_api_cmd_purse_deposit.c b/src/testing/testing_api_cmd_purse_deposit.c
index ed4967776..b15ba97cf 100644
--- a/src/testing/testing_api_cmd_purse_deposit.c
+++ b/src/testing/testing_api_cmd_purse_deposit.c
@@ -88,6 +88,12 @@ struct PurseDepositState
const char *purse_ref;
/**
+ * Reserve history entry that corresponds to this operation.
+ * Will be of type #TALER_EXCHANGE_RTT_MERGE.
+ * Only valid if @e purse_complete is true.
+ */
+ struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history;
+ /**
* Expected HTTP response code.
*/
unsigned int expected_response_code;
@@ -101,6 +107,11 @@ struct PurseDepositState
* Minimum age to apply to all deposits.
*/
uint8_t min_age;
+
+ /**
+ * Set to true if this deposit filled the purse.
+ */
+ bool purse_complete;
};
@@ -134,7 +145,71 @@ deposit_cb (void *cls,
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
- // FIXME: any data to keep from reply?
+ if (-1 !=
+ TALER_amount_cmp (&dr->details.success.total_deposited,
+ &dr->details.success.purse_value_after_fees))
+ {
+ const struct TALER_TESTING_Command *purse_cmd;
+ const struct TALER_ReserveSignatureP *reserve_sig;
+ const struct GNUNET_TIME_Timestamp *merge_timestamp;
+
+ purse_cmd = TALER_TESTING_interpreter_lookup_command (ds->is,
+ ds->purse_ref);
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_sig (purse_cmd,
+ &reserve_sig))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ds->is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_timestamp (purse_cmd,
+ 0,
+ &merge_timestamp))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ds->is);
+ return;
+ }
+
+ /* Deposits complete, create trait! */
+ ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE;
+ ds->reserve_history.amount
+ = dr->details.success.purse_value_after_fees;
+#if 0
+ {
+ const struct TALER_EXCHANGE_Keys *keys;
+ const struct TALER_EXCHANGE_GlobalFee *gf;
+
+ keys = TALER_EXCHANGE_get_keys (ds->is->exchange);
+ GNUNET_assert (NULL != keys);
+ gf = TALER_EXCHANGE_get_global_fee (keys,
+ *merge_timestamp);
+ GNUNET_assert (NULL != gf);
+ }
+#endif
+ /* Note: change when flags below changes! */
+ TALER_amount_set_zero (
+ ds->reserve_history.amount.currency,
+ &ds->reserve_history.details.merge_details.purse_fee);
+ ds->reserve_history.details.merge_details.h_contract_terms
+ = dr->details.success.h_contract_terms;
+ ds->reserve_history.details.merge_details.merge_pub
+ = dr->details.success.merge_pub;
+ ds->reserve_history.details.merge_details.reserve_sig
+ = *reserve_sig;
+ ds->reserve_history.details.merge_details.merge_timestamp
+ = *merge_timestamp;
+ ds->reserve_history.details.merge_details.purse_expiration
+ = dr->details.success.purse_expiration;
+ ds->reserve_history.details.merge_details.min_age
+ = ds->min_age;
+ ds->reserve_history.details.merge_details.flags
+ = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
+ ds->purse_complete = true;
+ }
}
TALER_TESTING_interpreter_next (ds->is);
}
@@ -293,11 +368,15 @@ deposit_traits (void *cls,
{
struct PurseDepositState *ds = cls;
struct TALER_TESTING_Trait traits[] = {
+ /* history entry MUST be first due to response code logic below! */
+ TALER_TESTING_make_trait_reserve_history (&ds->reserve_history),
TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
TALER_TESTING_trait_end ()
};
- return TALER_TESTING_get_trait (traits,
+ return TALER_TESTING_get_trait (ds->purse_complete
+ ? &traits[0] /* we have reserve history */
+ : &traits[1], /* skip reserve history */
ret,
trait,
index);
diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c
index 28193b3e8..456ba66fc 100644
--- a/src/testing/testing_api_cmd_purse_merge.c
+++ b/src/testing/testing_api_cmd_purse_merge.c
@@ -140,7 +140,7 @@ merge_cb (void *cls,
gf = TALER_EXCHANGE_get_global_fee (keys,
ds->merge_timestamp);
GNUNET_assert (NULL != gf);
- ds->reserve_history.amount = gf->fees.purse;
+ ds->reserve_history.amount = ds->value_after_fees;
ds->reserve_history.details.merge_details.purse_fee = gf->fees.purse;
ds->reserve_history.details.merge_details.h_contract_terms
= ds->h_contract_terms;
diff --git a/src/testing/testing_api_cmd_reserve_purse.c b/src/testing/testing_api_cmd_reserve_purse.c
index b923e1cc6..b57fff2bd 100644
--- a/src/testing/testing_api_cmd_reserve_purse.c
+++ b/src/testing/testing_api_cmd_reserve_purse.c
@@ -47,6 +47,12 @@ struct ReservePurseState
struct TALER_ReservePrivateKeyP reserve_priv;
/**
+ * Reserve signature generated for the request
+ * (client-side).
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
* Private key of the purse.
*/
struct TALER_PurseContractPrivateKeyP purse_priv;
@@ -118,6 +124,7 @@ purse_cb (void *cls,
struct ReservePurseState *ds = cls;
ds->dh = NULL;
+ ds->reserve_sig = *dr->reserve_sig;
if (ds->expected_response_code != dr->hr.http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -187,7 +194,7 @@ purse_run (void *cls,
&ds->contract_priv,
ds->contract_terms,
true /* upload contract */,
- false /* do not pay purse fee -- FIXME: make this a choice to test this case! */,
+ false /* do not pay purse fee -- FIXME: make this a choice to test this case; then update testing_api_cmd_purse_deposit flags logic to match! */,
ds->merge_timestamp,
&purse_cb,
ds);
@@ -254,6 +261,7 @@ purse_traits (void *cls,
TALER_TESTING_make_trait_merge_priv (&ds->merge_priv),
TALER_TESTING_make_trait_contract_priv (&ds->contract_priv),
TALER_TESTING_make_trait_reserve_priv (&ds->reserve_priv),
+ TALER_TESTING_make_trait_reserve_sig (&ds->reserve_sig),
TALER_TESTING_trait_end ()
};