diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2022-02-22 14:27:15 +0100 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2022-02-22 14:34:47 +0100 |
commit | 26158fc72505be6323282dc39509fd531c10a290 (patch) | |
tree | 117e5b7a580c056717a0303fc9f82c391207ff67 /src/testing | |
parent | 0141a8216162a33b4656f95a2d5305843ca4aeba (diff) | |
download | exchange-26158fc72505be6323282dc39509fd531c10a290.tar.xz |
[age restriction] progress 16/n - refresh/reveal/link tests
Age restriction works now with withdraw, melt/refresh/reveal and link,
including tests.
However, there is still a problem with the tests: The melting operation
"refresh-melt-failing-age" that should fail (because of conflict), but
currently fails for other reasons. I decided to disable that particular
test (and the next) and submit the patch I have so far.
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_exchange_api.c | 121 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_deposit.c | 14 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_refresh.c | 66 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_withdraw.c | 10 |
4 files changed, 163 insertions, 48 deletions
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c index 957e42e8a..b6dd39c87 100644 --- a/src/testing/test_exchange_api.c +++ b/src/testing/test_exchange_api.c @@ -377,9 +377,9 @@ run (void *cls, * Move money to the exchange's bank account. */ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-age", - "EUR:5.01"), + "EUR:6.01"), TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-age", - "EUR:5.01", + "EUR:6.01", bc.user42_payto, bc.exchange_payto, "create-reserve-age"), @@ -475,7 +475,22 @@ run (void *cls, "EUR:0.98", bc.exchange_payto, bc.user42_payto), - TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c", + TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c3", + ec.exchange_url, + "EUR:0.98", + bc.exchange_payto, + bc.user42_payto), + TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c4", + ec.exchange_url, + "EUR:0.98", + bc.exchange_payto, + bc.user42_payto), + TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-08c", + ec.exchange_url, + "EUR:0.08", + bc.exchange_payto, + bc.user43_payto), + TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-08c2", ec.exchange_url, "EUR:0.08", bc.exchange_payto, @@ -548,6 +563,104 @@ run (void *cls, TALER_TESTING_cmd_end () }; + struct TALER_TESTING_Command refresh_age[] = { + /* Fill reserve with EUR:5, 1ct is for fees. */ + CMD_TRANSFER_TO_EXCHANGE ("refresh-create-reserve-age-1", + "EUR:6.01"), + TALER_TESTING_cmd_check_bank_admin_transfer ( + "ck-refresh-create-reserve-age-1", + "EUR:6.01", + bc.user42_payto, + bc.exchange_payto, + "refresh-create-reserve-age-1"), + /** + * Make previous command effective. + */ + CMD_EXEC_WIREWATCH ("wirewatch-age-2"), + /** + * Withdraw EUR:7 with age restriction for age 13. + */ + TALER_TESTING_cmd_withdraw_amount ("refresh-withdraw-coin-age-1", + "refresh-create-reserve-age-1", + "EUR:5", + 13, + MHD_HTTP_OK), + /* Try to partially spend (deposit) 1 EUR of the 5 EUR coin + * (in full) (merchant would receive EUR:0.99 due to 1 ct + * deposit fee) */// + TALER_TESTING_cmd_deposit ("refresh-deposit-partial-age", + "refresh-withdraw-coin-age-1", + 0, + bc.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:1", + MHD_HTTP_OK), + /** + * Melt the rest of the coin's value + * (EUR:4.00 = 3x EUR:1.03 + 7x EUR:0.13) */ + TALER_TESTING_cmd_melt_double ("refresh-melt-age-1", + "refresh-withdraw-coin-age-1", + MHD_HTTP_OK, + NULL), + /** + * Complete (successful) melt operation, and + * withdraw the coins + */ + TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-age-1", + "refresh-melt-age-1", + MHD_HTTP_OK), + /** + * Do it again to check idempotency + */ + TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-age-1-idempotency", + "refresh-melt-age-1", + MHD_HTTP_OK), + /** + * Test that /refresh/link works + */ + TALER_TESTING_cmd_refresh_link ("refresh-link-age-1", + "refresh-reveal-age-1", + MHD_HTTP_OK), + /** + * Try to spend a refreshed EUR:1 coin + */ + TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1a", + "refresh-reveal-age-1-idempotency", + 0, + bc.user42_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:1", + MHD_HTTP_OK), + /** + * Try to spend a refreshed EUR:0.1 coin + */ + TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1b", + "refresh-reveal-age-1", + 3, + bc.user43_payto, + "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}", + GNUNET_TIME_UNIT_ZERO, + "EUR:0.1", + MHD_HTTP_OK), +#if 0 /* FIXME oec */ + /* Test running a failing melt operation (same operation + * again must fail) */ + TALER_TESTING_cmd_melt ("refresh-melt-failing-age", + "refresh-withdraw-coin-age-1", + MHD_HTTP_CONFLICT, + NULL), + /* Test running a failing melt operation (on a coin that + was itself revealed and subsequently deposited) */ + TALER_TESTING_cmd_melt ("refresh-melt-failing-age-2", + "refresh-reveal-age-1", + MHD_HTTP_CONFLICT, + NULL), + +#endif + TALER_TESTING_cmd_end () + }; /** * This block exercises the aggretation logic by making two payments @@ -1073,6 +1186,8 @@ run (void *cls, withdraw_age), TALER_TESTING_cmd_batch ("spend-age", spend_age), + TALER_TESTING_cmd_batch ("refresh-age", + refresh_age), TALER_TESTING_cmd_batch ("track", track), TALER_TESTING_cmd_batch ("unaggregation", diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index a241c531b..ad1315b28 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -568,23 +568,23 @@ deposit_traits (void *cls, struct TALER_TESTING_Trait traits[] = { /* First two traits are only available if ds->traits is #GNUNET_YES */ - TALER_TESTING_make_trait_exchange_pub (0, &ds->exchange_pub), - TALER_TESTING_make_trait_exchange_sig (0, &ds->exchange_sig), + TALER_TESTING_make_trait_exchange_pub (index, &ds->exchange_pub), + TALER_TESTING_make_trait_exchange_sig (index, &ds->exchange_sig), /* These traits are always available */ - TALER_TESTING_make_trait_coin_priv (0, + TALER_TESTING_make_trait_coin_priv (index, coin_spent_priv), - TALER_TESTING_make_trait_age_commitment (0, + TALER_TESTING_make_trait_age_commitment (index, 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 (0, + TALER_TESTING_make_trait_timestamp (index, &ds->exchange_timestamp), - TALER_TESTING_make_trait_wire_deadline (0, + TALER_TESTING_make_trait_wire_deadline (index, &ds->wire_deadline), - TALER_TESTING_make_trait_refund_deadline (0, + TALER_TESTING_make_trait_refund_deadline (index, &ds->refund_deadline), TALER_TESTING_trait_end () }; diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c index 29ad9d2fa..f287681d8 100644 --- a/src/testing/testing_api_cmd_refresh.c +++ b/src/testing/testing_api_cmd_refresh.c @@ -71,9 +71,10 @@ struct TALER_TESTING_FreshCoinData struct TALER_CoinSpendPrivateKeyP coin_priv; /* - * Age commitment for the coin, NULL if not applicable. + * Fresh age commitment for the coin and its hash, NULL if not applicable. */ struct TALER_AgeCommitment *age_commitment; + struct TALER_AgeCommitmentHash *h_age_commitment; /** * The blinding key (needed for recoup operations). @@ -137,11 +138,6 @@ struct RefreshMeltState */ const struct TALER_CoinSpendPrivateKeyP *melt_priv; - /* - * Age commitment for the coin, NULL if not applicable. - */ - struct TALER_AgeCommitment *age_commitment; - /** * Task scheduled to try later. */ @@ -445,6 +441,8 @@ reveal_cb (void *cls, return; } fc->coin_priv = coin->coin_priv; + fc->age_commitment = coin->age_commitment; + fc->h_age_commitment = coin->h_age_commitment; TALER_denom_sig_deep_copy (&fc->sig, &coin->sig); @@ -836,7 +834,7 @@ refresh_link_run (void *cls, /* finally, use private key from withdraw sign command */ rls->rlh = TALER_EXCHANGE_link (is->exchange, coin_priv, - rms->age_commitment, + rms->refresh_data.melt_age_commitment, &link_cb, rls); @@ -1046,6 +1044,8 @@ melt_run (void *cls, { struct TALER_Amount melt_amount; struct TALER_Amount fresh_amount; + struct TALER_AgeCommitment *age_commitment; + struct TALER_AgeCommitmentHash *h_age_commitment; const struct TALER_DenominationSignature *melt_sig; const struct TALER_EXCHANGE_DenomPublicKey *melt_denom_pub; const struct TALER_TESTING_Command *coin_command; @@ -1070,10 +1070,21 @@ melt_run (void *cls, TALER_TESTING_interpreter_fail (rms->is); return; } + if (GNUNET_OK != TALER_TESTING_get_trait_age_commitment (coin_command, 0, - &rms->age_commitment)) + &age_commitment)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (rms->is); + return; + } + + if (GNUNET_OK != + TALER_TESTING_get_trait_h_age_commitment (coin_command, + 0, + &h_age_commitment)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (rms->is); @@ -1148,31 +1159,13 @@ melt_run (void *cls, rms->refresh_data.melt_amount = melt_amount; rms->refresh_data.melt_sig = *melt_sig; rms->refresh_data.melt_pk = *melt_denom_pub; + rms->refresh_data.melt_age_commitment = age_commitment; + rms->refresh_data.melt_h_age_commitment = h_age_commitment; rms->refresh_data.fresh_pks = rms->fresh_pks; rms->refresh_data.fresh_pks_len = num_fresh_coins; - rms->refresh_data.age_commitment = NULL; GNUNET_assert (age_restricted == - (NULL != rms->age_commitment)); - - if (NULL != rms->age_commitment) - { - struct TALER_AgeCommitment *ac; - uint32_t seed; - - ac = GNUNET_new (struct TALER_AgeCommitment); - seed = GNUNET_CRYPTO_random_u32 ( - GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - - GNUNET_assert (GNUNET_OK == - TALER_age_commitment_derive ( - rms->age_commitment, - seed, - ac)); - - rms->refresh_data.age_commitment = ac; - } + (NULL != age_commitment)); rms->rmh = TALER_EXCHANGE_melt (is->exchange, &rms->rms, @@ -1256,10 +1249,14 @@ melt_traits (void *cls, struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_denom_pub (index, &rms->fresh_pks[index]), - TALER_TESTING_make_trait_coin_priv (0, + TALER_TESTING_make_trait_coin_priv (index, rms->melt_priv), - TALER_TESTING_make_trait_age_commitment (index, - rms->age_commitment), + TALER_TESTING_make_trait_age_commitment ( + index, + rms->refresh_data.melt_age_commitment), + TALER_TESTING_make_trait_h_age_commitment ( + index, + rms->refresh_data.melt_h_age_commitment), TALER_TESTING_make_trait_exchange_wd_value (index, &rms->mbds[index].alg_value), TALER_TESTING_make_trait_refresh_secret (&rms->rms), @@ -1418,6 +1415,7 @@ refresh_reveal_traits (void *cls, if (index >= rrs->num_fresh_coins) return GNUNET_SYSERR; + { struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_coin_priv ( @@ -1426,6 +1424,9 @@ refresh_reveal_traits (void *cls, TALER_TESTING_make_trait_age_commitment ( index, rrs->fresh_coins[index].age_commitment), + TALER_TESTING_make_trait_h_age_commitment ( + index, + rrs->fresh_coins[index].h_age_commitment), TALER_TESTING_make_trait_denom_pub ( index, rrs->fresh_coins[index].pk), @@ -1443,7 +1444,6 @@ refresh_reveal_traits (void *cls, &rrs->psa[index]), TALER_TESTING_trait_end () }; - return TALER_TESTING_get_trait (traits, ret, trait, diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c index 14015c497..3974a1057 100644 --- a/src/testing/testing_api_cmd_withdraw.c +++ b/src/testing/testing_api_cmd_withdraw.c @@ -526,7 +526,7 @@ withdraw_cleanup (void *cls, } if (NULL != ws->age_commitment) { - GNUNET_free (ws->age_commitment); + TALER_age_commitment_free (ws->age_commitment); ws->age_commitment = NULL; } if (NULL != ws->h_age_commitment) @@ -569,7 +569,7 @@ withdraw_traits (void *cls, &ws->exchange_vals), TALER_TESTING_make_trait_denom_pub (0 /* only one coin */, ws->pk), - TALER_TESTING_make_trait_denom_sig (index /* only one coin */, + TALER_TESTING_make_trait_denom_sig (0 /* only one coin */, &ws->sig), TALER_TESTING_make_trait_reserve_priv (&ws->reserve_priv), TALER_TESTING_make_trait_reserve_pub (&ws->reserve_pub), @@ -579,8 +579,8 @@ withdraw_traits (void *cls, (const char **) &ws->reserve_payto_uri), TALER_TESTING_make_trait_exchange_url ( (const char **) &ws->exchange_url), - TALER_TESTING_make_trait_age_commitment (index, ws->age_commitment), - TALER_TESTING_make_trait_h_age_commitment (index, ws->h_age_commitment), + TALER_TESTING_make_trait_age_commitment (0, ws->age_commitment), + TALER_TESTING_make_trait_h_age_commitment (0, ws->h_age_commitment), TALER_TESTING_trait_end () }; @@ -626,7 +626,7 @@ TALER_TESTING_cmd_withdraw_amount (const char *label, ac = GNUNET_new (struct TALER_AgeCommitment); hac = GNUNET_new (struct TALER_AgeCommitmentHash); - seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + seed = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); mask = TALER_extensions_age_restriction_ageMask (); if (GNUNET_OK != |