diff options
Diffstat (limited to 'src/testing/testing_api_cmd_purse_merge.c')
-rw-r--r-- | src/testing/testing_api_cmd_purse_merge.c | 182 |
1 files changed, 145 insertions, 37 deletions
diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c index 27aa120ed..cf9d4f996 100644 --- a/src/testing/testing_api_cmd_purse_merge.c +++ b/src/testing/testing_api_cmd_purse_merge.c @@ -62,7 +62,7 @@ struct PurseMergeState const char *merge_ref; /** - * Refernece to the reserve, or NULL (!). + * Reference to the reserve, or NULL (!). */ const char *reserve_ref; @@ -72,6 +72,54 @@ struct PurseMergeState struct TALER_TESTING_Interpreter *is; /** + * Hash of the payto://-URI for the reserve we are + * merging into. + */ + struct TALER_PaytoHashP h_payto; + + /** + * Set to the KYC requirement row *if* the exchange replied with + * a request for KYC. + */ + uint64_t requirement_row; + + /** + * Reserve history entry that corresponds to this operation. + * Will be of type #TALER_EXCHANGE_RTT_MERGE. + */ + struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history; + + /** + * Public key of the purse. + */ + struct TALER_PurseContractPublicKeyP purse_pub; + + /** + * Public key of the merge capability. + */ + struct TALER_PurseMergePublicKeyP merge_pub; + + /** + * Contract value. + */ + struct TALER_Amount value_after_fees; + + /** + * Hash of the contract. + */ + struct TALER_PrivateContractHashP h_contract_terms; + + /** + * When does the purse expire. + */ + struct GNUNET_TIME_Timestamp purse_expiration; + + /** + * Minimum age of deposits into the purse. + */ + uint32_t min_age; + + /** * Expected HTTP response code. */ unsigned int expected_response_code; @@ -93,18 +141,45 @@ merge_cb (void *cls, struct PurseMergeState *ds = cls; ds->dh = NULL; + switch (dr->hr.http_status) + { + case MHD_HTTP_OK: + ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE; + ds->reserve_history.amount = ds->value_after_fees; + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero ( + ds->value_after_fees.currency, + &ds->reserve_history.details.merge_details.purse_fee)); + ds->reserve_history.details.merge_details.h_contract_terms + = ds->h_contract_terms; + ds->reserve_history.details.merge_details.merge_pub + = ds->merge_pub; + ds->reserve_history.details.merge_details.purse_pub + = ds->purse_pub; + ds->reserve_history.details.merge_details.reserve_sig + = *dr->reserve_sig; + ds->reserve_history.details.merge_details.merge_timestamp + = ds->merge_timestamp; + ds->reserve_history.details.merge_details.purse_expiration + = ds->purse_expiration; + ds->reserve_history.details.merge_details.min_age + = ds->min_age; + ds->reserve_history.details.merge_details.flags + = TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE; + break; + case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS: + /* KYC required */ + ds->requirement_row = + dr->details.unavailable_for_legal_reasons.requirement_row; + break; + } + + if (ds->expected_response_code != dr->hr.http_status) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u to command %s in %s:%u\n", - dr->hr.http_status, - ds->is->commands[ds->is->ip].label, - __FILE__, - __LINE__); - json_dumpf (dr->hr.reply, - stderr, - 0); - TALER_TESTING_interpreter_fail (ds->is); + TALER_TESTING_unexpected_status (ds->is, + dr->hr.http_status, + ds->expected_response_code); return; } TALER_TESTING_interpreter_next (ds->is); @@ -124,13 +199,8 @@ merge_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct PurseMergeState *ds = cls; - const struct TALER_PurseContractPublicKeyP *purse_pub; const struct TALER_PurseMergePrivateKeyP *merge_priv; const json_t *ct; - struct TALER_PrivateContractHashP h_contract_terms; - uint32_t min_age = 0; - struct TALER_Amount value_after_fees; - struct GNUNET_TIME_Timestamp purse_expiration; const struct TALER_TESTING_Command *ref; (void) cmd; @@ -146,14 +216,20 @@ merge_run (void *cls, TALER_TESTING_interpreter_fail (ds->is); return; } - if (GNUNET_OK != - TALER_TESTING_get_trait_purse_pub (ref, - &purse_pub)) { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (ds->is); - return; + const struct TALER_PurseContractPublicKeyP *purse_pub; + + if (GNUNET_OK != + TALER_TESTING_get_trait_purse_pub (ref, + &purse_pub)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + ds->purse_pub = *purse_pub; } + if (GNUNET_OK != TALER_TESTING_get_trait_contract_terms (ref, &ct)) @@ -164,7 +240,7 @@ merge_run (void *cls, } if (GNUNET_OK != TALER_JSON_contract_hash (ct, - &h_contract_terms)) + &ds->h_contract_terms)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (ds->is); @@ -173,12 +249,12 @@ merge_run (void *cls, { struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_timestamp ("pay_deadline", - &purse_expiration), + &ds->purse_expiration), TALER_JSON_spec_amount_any ("amount", - &value_after_fees), + &ds->value_after_fees), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_uint32 ("minimum_age", - &min_age), + &ds->min_age), NULL), GNUNET_JSON_spec_end () }; @@ -217,17 +293,43 @@ merge_run (void *cls, } GNUNET_CRYPTO_eddsa_key_get_public (&ds->reserve_priv.eddsa_priv, &ds->reserve_pub.eddsa_pub); + { + char *payto_uri; + const char *exchange_url; + const struct TALER_TESTING_Command *exchange_cmd; + + exchange_cmd = TALER_TESTING_interpreter_get_command (is, + "exchange"); + if (NULL == exchange_cmd) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_exchange_url (exchange_cmd, + &exchange_url)); + payto_uri = TALER_reserve_make_payto (exchange_url, + &ds->reserve_pub); + TALER_payto_hash (payto_uri, + &ds->h_payto); + GNUNET_free (payto_uri); + } + GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv, + &ds->merge_pub.eddsa_pub); ds->merge_timestamp = GNUNET_TIME_timestamp_get (); ds->dh = TALER_EXCHANGE_account_merge ( - is->exchange, + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_exchange_url (is), + TALER_TESTING_get_keys (is), NULL, /* no wad */ &ds->reserve_priv, - purse_pub, + &ds->purse_pub, merge_priv, - &h_contract_terms, - min_age, - &value_after_fees, - purse_expiration, + &ds->h_contract_terms, + ds->min_age, + &ds->value_after_fees, + ds->purse_expiration, ds->merge_timestamp, &merge_cb, ds); @@ -257,10 +359,8 @@ merge_cleanup (void *cls, if (NULL != ds->dh) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Command %u (%s) did not complete\n", - ds->is->ip, - cmd->label); + TALER_TESTING_command_incomplete (ds->is, + cmd->label); TALER_EXCHANGE_account_merge_cancel (ds->dh); ds->dh = NULL; } @@ -285,12 +385,20 @@ merge_traits (void *cls, { struct PurseMergeState *ds = cls; struct TALER_TESTING_Trait traits[] = { + /* history entry MUST be first due to response code logic below! */ + TALER_TESTING_make_trait_reserve_history (0, + &ds->reserve_history), + TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub), TALER_TESTING_make_trait_timestamp (0, &ds->merge_timestamp), + TALER_TESTING_make_trait_legi_requirement_row (&ds->requirement_row), + TALER_TESTING_make_trait_h_payto (&ds->h_payto), TALER_TESTING_trait_end () }; - return TALER_TESTING_get_trait (traits, + return TALER_TESTING_get_trait ((ds->expected_response_code == MHD_HTTP_OK) + ? &traits[0] /* we have reserve history */ + : &traits[1], /* skip reserve history */ ret, trait, index); |