diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-04-27 13:09:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-04-27 13:09:41 +0200 |
commit | d623cab1a351040cca8729540327f948eb3027aa (patch) | |
tree | 2c73e0b394926aa1ab328b05c49269227b941fe1 /src/testing | |
parent | 1396afc13664e11fe869c1cfa2ad690df7856c21 (diff) | |
download | exchange-d623cab1a351040cca8729540327f948eb3027aa.tar.xz |
-work on p2p payments
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_exchange_p2p.c | 2 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_contract_get.c | 71 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_purse_deposit.c | 14 |
3 files changed, 69 insertions, 18 deletions
diff --git a/src/testing/test_exchange_p2p.c b/src/testing/test_exchange_p2p.c index c70fe9d8b..8e5fea0e7 100644 --- a/src/testing/test_exchange_p2p.c +++ b/src/testing/test_exchange_p2p.c @@ -160,6 +160,7 @@ run (void *cls, TALER_TESTING_cmd_contract_get ( "push-get-contract", MHD_HTTP_OK, + true, /* for merge */ "purse-with-deposit"), TALER_TESTING_cmd_purse_merge ( "purse-merge-into-reserve", @@ -181,6 +182,7 @@ run (void *cls, TALER_TESTING_cmd_contract_get ( "pull-get-contract", MHD_HTTP_OK, + false, /* for deposit */ "purse-create-with-reserve"), TALER_TESTING_cmd_purse_deposit_coins ( "purse-deposit-coins", diff --git a/src/testing/testing_api_cmd_contract_get.c b/src/testing/testing_api_cmd_contract_get.c index 9432fdeef..10a43aa3b 100644 --- a/src/testing/testing_api_cmd_contract_get.c +++ b/src/testing/testing_api_cmd_contract_get.c @@ -41,6 +41,11 @@ struct ContractGetState json_t *contract_terms; /** + * Private key to decrypt the contract. + */ + struct TALER_ContractDiffiePrivateP contract_priv; + + /** * Set to the returned merge key. */ struct TALER_PurseMergePrivateKeyP merge_priv; @@ -70,6 +75,12 @@ struct ContractGetState */ unsigned int expected_response_code; + /** + * True if this is for a 'merge' operation, + * 'false' if this is for a 'deposit' operation. + */ + bool merge; + }; @@ -109,10 +120,42 @@ get_cb (void *cls, const struct TALER_PurseMergePrivateKeyP *mp; const json_t *ct; - /* check that we got what we expected to get! */ - if (GNUNET_OK != - TALER_TESTING_get_trait_merge_priv (ref, - &mp)) + ds->purse_pub = dr->details.success.purse_pub; + if (ds->merge) + { + if (GNUNET_OK != + TALER_TESTING_get_trait_merge_priv (ref, + &mp)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + ds->contract_terms = + TALER_CRYPTO_contract_decrypt_for_merge ( + &ds->contract_priv, + &ds->purse_pub, + dr->details.success.econtract, + dr->details.success.econtract_size, + &ds->merge_priv); + if (0 != + GNUNET_memcmp (mp, + &ds->merge_priv)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (ds->is); + return; + } + } + else + { + ds->contract_terms = + TALER_CRYPTO_contract_decrypt_for_deposit ( + &ds->contract_priv, + dr->details.success.econtract, + dr->details.success.econtract_size); + } + if (NULL == ds->contract_terms) { GNUNET_break (0); TALER_TESTING_interpreter_fail (ds->is); @@ -126,26 +169,14 @@ get_cb (void *cls, TALER_TESTING_interpreter_fail (ds->is); return; } - if (0 != - GNUNET_memcmp (mp, - &dr->details.success.merge_priv)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (ds->is); - return; - } if (1 != /* 1: equal, 0: not equal */ json_equal (ct, - dr->details.success.contract_terms)) + ds->contract_terms)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (ds->is); return; } - ds->contract_terms = json_incref ( - (json_t *) dr->details.success.contract_terms); - ds->merge_priv = dr->details.success.merge_priv; - ds->purse_pub = dr->details.success.purse_pub; } TALER_TESTING_interpreter_next (ds->is); } @@ -180,6 +211,7 @@ get_run (void *cls, TALER_TESTING_interpreter_fail (ds->is); return; } + ds->contract_priv = *contract_priv; ds->dh = TALER_EXCHANGE_contract_get ( is->exchange, contract_priv, @@ -246,7 +278,8 @@ get_traits (void *cls, TALER_TESTING_trait_end () }; - return TALER_TESTING_get_trait (traits, + /* skip 'merge_priv' if we are in 'merge' mode */ + return TALER_TESTING_get_trait (&traits[ds->merge ? 0 : 1], ret, trait, index); @@ -257,6 +290,7 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_contract_get ( const char *label, unsigned int expected_http_status, + bool for_merge, const char *contract_ref) { struct ContractGetState *ds; @@ -264,6 +298,7 @@ TALER_TESTING_cmd_contract_get ( ds = GNUNET_new (struct ContractGetState); ds->expected_response_code = expected_http_status; ds->contract_ref = contract_ref; + ds->merge = for_merge; { struct TALER_TESTING_Command cmd = { .cls = ds, diff --git a/src/testing/testing_api_cmd_purse_deposit.c b/src/testing/testing_api_cmd_purse_deposit.c index c1466088f..ed4967776 100644 --- a/src/testing/testing_api_cmd_purse_deposit.c +++ b/src/testing/testing_api_cmd_purse_deposit.c @@ -154,9 +154,23 @@ deposit_run (void *cls, { struct PurseDepositState *ds = cls; struct TALER_EXCHANGE_PurseDeposit deposits[ds->num_coin_references]; + const struct TALER_PurseContractPublicKeyP *purse_pub; + const struct TALER_TESTING_Command *purse_cmd; (void) cmd; ds->is = is; + + purse_cmd = TALER_TESTING_interpreter_lookup_command (is, + ds->purse_ref); + if (GNUNET_OK != + TALER_TESTING_get_trait_purse_pub (purse_cmd, + &purse_pub)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ds->purse_pub = *purse_pub; for (unsigned int i = 0; i<ds->num_coin_references; i++) { const struct Coin *cr = &ds->coin_references[i]; |