diff options
Diffstat (limited to 'src/testing/testing_api_cmd_deposit.c')
-rw-r--r-- | src/testing/testing_api_cmd_deposit.c | 313 |
1 files changed, 190 insertions, 123 deletions
diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 2f55a318c..849c78c70 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018-2021 Taler Systems SA + Copyright (C) 2018-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 published by @@ -69,6 +69,11 @@ struct DepositState unsigned int coin_index; /** + * Our coin signature. + */ + struct TALER_CoinSpendSignatureP coin_sig; + + /** * Wire details of who is depositing -- this would be merchant * wire details in a normal scenario. */ @@ -98,7 +103,12 @@ struct DepositState /** * Deposit handle while operation is running. */ - struct TALER_EXCHANGE_DepositHandle *dh; + struct TALER_EXCHANGE_BatchDepositHandle *dh; + + /** + * Denomination public key of the deposited coin. + */ + const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; /** * Timestamp of the /deposit operation in the wallet (contract signing time). @@ -131,10 +141,16 @@ struct DepositState unsigned int do_retry; /** - * Set to #GNUNET_YES if the /deposit succeeded + * Set to true if the /deposit succeeded * and we now can provide the resulting traits. */ - int deposit_succeeded; + bool deposit_succeeded; + + /** + * Expected entry in the coin history created by this + * operation. + */ + struct TALER_EXCHANGE_CoinHistoryEntry che; /** * When did the exchange receive the deposit? @@ -165,7 +181,7 @@ struct DepositState * When we're referencing another deposit operation, * this will only be set after the command has been started. */ - int command_initialized; + bool command_initialized; /** * Reference to fetch the merchant private key from. @@ -199,8 +215,7 @@ do_retry (void *cls) struct DepositState *ds = cls; ds->retry_task = NULL; - ds->is->commands[ds->is->ip].last_req_time - = GNUNET_TIME_absolute_get (); + TALER_TESTING_touch_cmd (ds->is); deposit_run (ds, NULL, ds->is); @@ -216,7 +231,7 @@ do_retry (void *cls) */ static void deposit_cb (void *cls, - const struct TALER_EXCHANGE_DepositResult *dr) + const struct TALER_EXCHANGE_BatchDepositResult *dr) { struct DepositState *ds = cls; @@ -240,7 +255,7 @@ deposit_cb (void *cls, else ds->backoff = GNUNET_TIME_randomized_backoff (ds->backoff, MAX_BACKOFF); - ds->is->commands[ds->is->ip].num_tries++; + TALER_TESTING_inc_tries (ds->is); GNUNET_assert (NULL == ds->retry_task); ds->retry_task = GNUNET_SCHEDULER_add_delayed (ds->backoff, @@ -249,24 +264,20 @@ deposit_cb (void *cls, return; } } - 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_with_body ( + ds->is, + dr->hr.http_status, + ds->expected_response_code, + dr->hr.reply); + return; } if (MHD_HTTP_OK == dr->hr.http_status) { - ds->deposit_succeeded = GNUNET_YES; - ds->exchange_timestamp = dr->details.success.deposit_timestamp; - ds->exchange_pub = *dr->details.success.exchange_pub; - ds->exchange_sig = *dr->details.success.exchange_sig; + ds->deposit_succeeded = true; + ds->exchange_timestamp = dr->details.ok.deposit_timestamp; + ds->exchange_pub = *dr->details.ok.exchange_pub; + ds->exchange_sig = *dr->details.ok.exchange_sig; } TALER_TESTING_interpreter_next (ds->is); } @@ -288,11 +299,8 @@ deposit_run (void *cls, const struct TALER_TESTING_Command *coin_cmd; const struct TALER_CoinSpendPrivateKeyP *coin_priv; struct TALER_CoinSpendPublicKeyP coin_pub; - const struct TALER_AgeCommitmentProof *age_commitment_proof = NULL; - struct TALER_AgeCommitmentHash h_age_commitment = {0}; - const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; + const struct TALER_AgeCommitmentHash *phac; const struct TALER_DenominationSignature *denom_pub_sig; - struct TALER_CoinSpendSignatureP coin_sig; struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_PrivateContractHashP h_contract_terms; enum TALER_ErrorCode ec; @@ -305,9 +313,32 @@ deposit_run (void *cls, &wire_salt), GNUNET_JSON_spec_end () }; + const char *exchange_url + = TALER_TESTING_get_exchange_url (is); (void) cmd; + if (NULL == exchange_url) + { + GNUNET_break (0); + return; + } ds->is = is; + if (! GNUNET_TIME_absolute_is_zero (ds->refund_deadline.abs_time)) + { + struct GNUNET_TIME_Relative refund_deadline; + + refund_deadline + = GNUNET_TIME_absolute_get_remaining (ds->refund_deadline.abs_time); + ds->wire_deadline + = GNUNET_TIME_relative_to_timestamp ( + GNUNET_TIME_relative_multiply (refund_deadline, + 2)); + } + else + { + ds->refund_deadline = ds->wallet_timestamp; + ds->wire_deadline = GNUNET_TIME_timestamp_get (); + } if (NULL != ds->deposit_reference) { /* We're copying another deposit operation, initialize here. */ @@ -330,9 +361,10 @@ deposit_run (void *cls, ds->contract_terms = json_incref (ods->contract_terms); ds->wallet_timestamp = ods->wallet_timestamp; ds->refund_deadline = ods->refund_deadline; + ds->wire_deadline = ods->wire_deadline; ds->amount = ods->amount; ds->merchant_priv = ods->merchant_priv; - ds->command_initialized = GNUNET_YES; + ds->command_initialized = true; } else if (NULL != ds->merchant_priv_reference) { @@ -386,13 +418,13 @@ deposit_run (void *cls, ds->coin_index, &coin_priv)) || (GNUNET_OK != - TALER_TESTING_get_trait_age_commitment_proof (coin_cmd, - ds->coin_index, - &age_commitment_proof)) || + TALER_TESTING_get_trait_h_age_commitment (coin_cmd, + ds->coin_index, + &phac)) || (GNUNET_OK != TALER_TESTING_get_trait_denom_pub (coin_cmd, ds->coin_index, - &denom_pub)) || + &ds->denom_pub)) || (GNUNET_OK != TALER_TESTING_get_trait_denom_sig (coin_cmd, ds->coin_index, @@ -406,32 +438,10 @@ deposit_run (void *cls, return; } - if (NULL != age_commitment_proof) - { - TALER_age_commitment_hash (&age_commitment_proof->commitment, - &h_age_commitment); - } - ds->deposit_fee = denom_pub->fees.deposit; + ds->deposit_fee = ds->denom_pub->fees.deposit; GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); - if (! GNUNET_TIME_absolute_is_zero (ds->refund_deadline.abs_time)) - { - struct GNUNET_TIME_Relative refund_deadline; - - refund_deadline - = GNUNET_TIME_absolute_get_remaining (ds->refund_deadline.abs_time); - ds->wire_deadline - = - GNUNET_TIME_relative_to_timestamp ( - GNUNET_TIME_relative_multiply (refund_deadline, - 2)); - } - else - { - ds->refund_deadline = ds->wallet_timestamp; - ds->wire_deadline = GNUNET_TIME_timestamp_get (); - } GNUNET_CRYPTO_eddsa_key_get_public (&ds->merchant_priv.eddsa_priv, &merchant_pub.eddsa_pub); { @@ -441,37 +451,65 @@ deposit_run (void *cls, TALER_JSON_merchant_wire_signature_hash (ds->wire_details, &h_wire)); TALER_wallet_deposit_sign (&ds->amount, - &denom_pub->fees.deposit, + &ds->denom_pub->fees.deposit, &h_wire, &h_contract_terms, - &h_age_commitment, - NULL, /* FIXME: add hash of extensions */ - &denom_pub->h_key, + NULL, /* wallet data hash */ + phac, + NULL, /* hash of extensions */ + &ds->denom_pub->h_key, ds->wallet_timestamp, &merchant_pub, ds->refund_deadline, coin_priv, - &coin_sig); + &ds->coin_sig); + ds->che.type = TALER_EXCHANGE_CTT_DEPOSIT; + ds->che.amount = ds->amount; + ds->che.details.deposit.h_wire = h_wire; + ds->che.details.deposit.h_contract_terms = h_contract_terms; + ds->che.details.deposit.no_h_policy = true; + ds->che.details.deposit.no_wallet_data_hash = true; + ds->che.details.deposit.wallet_timestamp = ds->wallet_timestamp; + ds->che.details.deposit.merchant_pub = merchant_pub; + ds->che.details.deposit.refund_deadline = ds->refund_deadline; + ds->che.details.deposit.sig = ds->coin_sig; + ds->che.details.deposit.no_hac = true; + ds->che.details.deposit.deposit_fee = ds->denom_pub->fees.deposit; } GNUNET_assert (NULL == ds->dh); - ds->dh = TALER_EXCHANGE_deposit (is->exchange, - &ds->amount, - ds->wire_deadline, - payto_uri, - &wire_salt, - &h_contract_terms, - &h_age_commitment, - NULL, /* FIXME: add hash of extensions */ - &coin_pub, - denom_pub_sig, - &denom_pub->key, - ds->wallet_timestamp, - &merchant_pub, - ds->refund_deadline, - &coin_sig, - &deposit_cb, - ds, - &ec); + { + struct TALER_EXCHANGE_CoinDepositDetail cdd = { + .amount = ds->amount, + .coin_pub = coin_pub, + .coin_sig = ds->coin_sig, + .denom_sig = *denom_pub_sig, + .h_denom_pub = ds->denom_pub->h_key, + .h_age_commitment = {{{0}}}, + }; + struct TALER_EXCHANGE_DepositContractDetail dcd = { + .wire_deadline = ds->wire_deadline, + .merchant_payto_uri = payto_uri, + .wire_salt = wire_salt, + .h_contract_terms = h_contract_terms, + .wallet_timestamp = ds->wallet_timestamp, + .merchant_pub = merchant_pub, + .refund_deadline = ds->refund_deadline + }; + + if (NULL != phac) + cdd.h_age_commitment = *phac; + + ds->dh = TALER_EXCHANGE_batch_deposit ( + TALER_TESTING_interpreter_get_context (is), + exchange_url, + TALER_TESTING_get_keys (is), + &dcd, + 1, + &cdd, + &deposit_cb, + ds, + &ec); + } if (NULL == ds->dh) { GNUNET_break (0); @@ -499,11 +537,9 @@ deposit_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_EXCHANGE_deposit_cancel (ds->dh); + TALER_TESTING_command_incomplete (ds->is, + cmd->label); + TALER_EXCHANGE_batch_deposit_cancel (ds->dh); ds->dh = NULL; } if (NULL != ds->retry_task) @@ -536,9 +572,11 @@ deposit_traits (void *cls, const struct TALER_TESTING_Command *coin_cmd; /* Will point to coin cmd internals. */ const struct TALER_CoinSpendPrivateKeyP *coin_spent_priv; + struct TALER_CoinSpendPublicKeyP coin_spent_pub; const struct TALER_AgeCommitmentProof *age_commitment_proof; + const struct TALER_AgeCommitmentHash *h_age_commitment; - if (GNUNET_YES != ds->command_initialized) + if (! ds->command_initialized) { /* No access to traits yet. */ GNUNET_break (0); @@ -561,33 +599,55 @@ deposit_traits (void *cls, (GNUNET_OK != TALER_TESTING_get_trait_age_commitment_proof (coin_cmd, ds->coin_index, - &age_commitment_proof)) ) + &age_commitment_proof)) || + (GNUNET_OK != + TALER_TESTING_get_trait_h_age_commitment (coin_cmd, + ds->coin_index, + &h_age_commitment)) ) { GNUNET_break (0); TALER_TESTING_interpreter_fail (ds->is); return GNUNET_NO; } + + GNUNET_CRYPTO_eddsa_key_get_public (&coin_spent_priv->eddsa_priv, + &coin_spent_pub.eddsa_pub); + { struct TALER_TESTING_Trait traits[] = { /* First two traits are only available if - ds->traits is #GNUNET_YES */ - TALER_TESTING_make_trait_exchange_pub (index, &ds->exchange_pub), - TALER_TESTING_make_trait_exchange_sig (index, &ds->exchange_sig), + ds->traits is true */ + TALER_TESTING_make_trait_exchange_pub (0, + &ds->exchange_pub), + TALER_TESTING_make_trait_exchange_sig (0, + &ds->exchange_sig), /* These traits are always available */ - TALER_TESTING_make_trait_coin_priv (index, + TALER_TESTING_make_trait_coin_history (0, + &ds->che), + TALER_TESTING_make_trait_coin_priv (0, coin_spent_priv), - TALER_TESTING_make_trait_age_commitment_proof (index, + TALER_TESTING_make_trait_coin_pub (0, + &coin_spent_pub), + TALER_TESTING_make_trait_denom_pub (0, + ds->denom_pub), + TALER_TESTING_make_trait_coin_sig (0, + &ds->coin_sig), + TALER_TESTING_make_trait_age_commitment_proof (0, age_commitment_proof), + TALER_TESTING_make_trait_h_age_commitment (0, + h_age_commitment), TALER_TESTING_make_trait_wire_details (ds->wire_details), TALER_TESTING_make_trait_contract_terms (ds->contract_terms), TALER_TESTING_make_trait_merchant_priv (&ds->merchant_priv), - TALER_TESTING_make_trait_deposit_amount (&ds->amount), - TALER_TESTING_make_trait_deposit_fee_amount (&ds->deposit_fee), - TALER_TESTING_make_trait_timestamp (index, + TALER_TESTING_make_trait_deposit_amount (0, + &ds->amount), + TALER_TESTING_make_trait_deposit_fee_amount (0, + &ds->deposit_fee), + TALER_TESTING_make_trait_timestamp (0, &ds->exchange_timestamp), - TALER_TESTING_make_trait_wire_deadline (index, + TALER_TESTING_make_trait_wire_deadline (0, &ds->wire_deadline), - TALER_TESTING_make_trait_refund_deadline (index, + TALER_TESTING_make_trait_refund_deadline (0, &ds->refund_deadline), TALER_TESTING_trait_end () }; @@ -603,14 +663,15 @@ deposit_traits (void *cls, struct TALER_TESTING_Command -TALER_TESTING_cmd_deposit (const char *label, - const char *coin_reference, - unsigned int coin_index, - const char *target_account_payto, - const char *contract_terms, - struct GNUNET_TIME_Relative refund_deadline, - const char *amount, - unsigned int expected_response_code) +TALER_TESTING_cmd_deposit ( + const char *label, + const char *coin_reference, + unsigned int coin_index, + const char *target_account_payto, + const char *contract_terms, + struct GNUNET_TIME_Relative refund_deadline, + const char *amount, + unsigned int expected_response_code) { struct DepositState *ds; @@ -650,7 +711,7 @@ TALER_TESTING_cmd_deposit (const char *label, TALER_string_to_amount (amount, &ds->amount)); ds->expected_response_code = expected_response_code; - ds->command_initialized = GNUNET_YES; + ds->command_initialized = true; { struct TALER_TESTING_Command cmd = { .cls = ds, @@ -666,15 +727,16 @@ TALER_TESTING_cmd_deposit (const char *label, struct TALER_TESTING_Command -TALER_TESTING_cmd_deposit_with_ref (const char *label, - const char *coin_reference, - unsigned int coin_index, - const char *target_account_payto, - const char *contract_terms, - struct GNUNET_TIME_Relative refund_deadline, - const char *amount, - unsigned int expected_response_code, - const char *merchant_priv_reference) +TALER_TESTING_cmd_deposit_with_ref ( + const char *label, + const char *coin_reference, + unsigned int coin_index, + const char *target_account_payto, + const char *contract_terms, + struct GNUNET_TIME_Relative refund_deadline, + const char *amount, + unsigned int expected_response_code, + const char *merchant_priv_reference) { struct DepositState *ds; @@ -696,21 +758,25 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label, GNUNET_assert (0); } ds->wallet_timestamp = GNUNET_TIME_timestamp_get (); - json_object_set_new (ds->contract_terms, - "timestamp", - GNUNET_JSON_from_timestamp (ds->wallet_timestamp)); + GNUNET_assert (0 == + json_object_set_new (ds->contract_terms, + "timestamp", + GNUNET_JSON_from_timestamp ( + ds->wallet_timestamp))); if (0 != refund_deadline.rel_value_us) { ds->refund_deadline = GNUNET_TIME_relative_to_timestamp (refund_deadline); - json_object_set_new (ds->contract_terms, - "refund_deadline", - GNUNET_JSON_from_timestamp (ds->refund_deadline)); + GNUNET_assert (0 == + json_object_set_new (ds->contract_terms, + "refund_deadline", + GNUNET_JSON_from_timestamp ( + ds->refund_deadline))); } GNUNET_assert (GNUNET_OK == TALER_string_to_amount (amount, &ds->amount)); ds->expected_response_code = expected_response_code; - ds->command_initialized = GNUNET_YES; + ds->command_initialized = true; { struct TALER_TESTING_Command cmd = { .cls = ds, @@ -726,9 +792,10 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label, struct TALER_TESTING_Command -TALER_TESTING_cmd_deposit_replay (const char *label, - const char *deposit_reference, - unsigned int expected_response_code) +TALER_TESTING_cmd_deposit_replay ( + const char *label, + const char *deposit_reference, + unsigned int expected_response_code) { struct DepositState *ds; |