diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-07-05 20:43:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-07-05 20:43:28 +0200 |
commit | 6de49ea2c02e311e5f5366005bd3497a9bb25187 (patch) | |
tree | a221b9c784b4e004eb5972e18516653d1aea6a5c /src/testing | |
parent | e428783e2e0295186dc4eae273df8a3f8b75df60 (diff) | |
parent | ed5b98a2c2308fbd44b906a30286d2689fd304dd (diff) | |
download | exchange-6de49ea2c02e311e5f5366005bd3497a9bb25187.tar.xz |
Merge branch 'protocolv8'
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/test_auditor_api.c | 1 | ||||
-rw-r--r-- | src/testing/test_exchange_api.c | 7 | ||||
-rw-r--r-- | src/testing/test_exchange_api_twisted.c | 14 | ||||
-rw-r--r-- | src/testing/test_taler_exchange_aggregator.c | 24 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_auditor_deposit_confirmation.c | 8 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_bank_admin_add_incoming.c | 112 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_batch.c | 22 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_deposit.c | 84 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_deposits_get.c | 22 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_insert_deposit.c | 26 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_refund.c | 29 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_rewind.c | 222 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_stat.c | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_transfer_get.c | 33 | ||||
-rw-r--r-- | src/testing/testing_api_loop.c | 11 | ||||
-rw-r--r-- | src/testing/testing_api_trait_json.c | 42 | ||||
-rw-r--r-- | src/testing/testing_api_trait_number.c | 80 | ||||
-rw-r--r-- | src/testing/testing_api_trait_time.c | 44 |
19 files changed, 611 insertions, 172 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index d73e89b3c..014faa469 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -61,6 +61,7 @@ libtalertesting_la_SOURCES = \ testing_api_cmd_refund.c \ testing_api_cmd_refresh.c \ testing_api_cmd_revoke.c \ + testing_api_cmd_rewind.c \ testing_api_cmd_serialize_keys.c \ testing_api_cmd_signal.c \ testing_api_cmd_sleep.c \ diff --git a/src/testing/test_auditor_api.c b/src/testing/test_auditor_api.c index 7b6996264..0ff28b29b 100644 --- a/src/testing/test_auditor_api.c +++ b/src/testing/test_auditor_api.c @@ -353,7 +353,6 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-ok", MHD_HTTP_OK, "EUR:5", - "EUR:0.01", "deposit-refund-1"), /** * Spend 4.99 EUR of the refunded 4.99 EUR coin (1ct gone diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c index 0c3f48379..eb6a2b1bb 100644 --- a/src/testing/test_exchange_api.c +++ b/src/testing/test_exchange_api.c @@ -346,6 +346,8 @@ run (void *cls, NULL, 0, MHD_HTTP_NOT_FOUND), + TALER_TESTING_cmd_sleep ("sleep-before-aggregator", + 1), /* Run transfers. Note that _actual_ aggregation will NOT * happen here, as each deposit operation is run with a * fresh merchant public key, so the aggregator will treat @@ -528,18 +530,15 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-ok", MHD_HTTP_OK, "EUR:5", - "EUR:0.01", "deposit-refund-1"), TALER_TESTING_cmd_refund ("refund-ok-double", MHD_HTTP_OK, "EUR:5", - "EUR:0.01", "deposit-refund-1"), /* Previous /refund(s) had id == 0. */ TALER_TESTING_cmd_refund_with_id ("refund-conflicting", MHD_HTTP_CONFLICT, "EUR:5", - "EUR:0.01", "deposit-refund-1", 1), /** @@ -573,7 +572,6 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-fail", MHD_HTTP_GONE, "EUR:4.99", - "EUR:0.01", "deposit-refund-2"), TALER_TESTING_cmd_check_bank_empty ("check-empty-after-refund"), /** @@ -607,7 +605,6 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-ok-fast", MHD_HTTP_OK, "EUR:5", - "EUR:0.01", "deposit-refund-1b"), /** * Run transfers. This will do the transfer as refund deadline diff --git a/src/testing/test_exchange_api_twisted.c b/src/testing/test_exchange_api_twisted.c index 9aac3d1e3..c99c7410d 100644 --- a/src/testing/test_exchange_api_twisted.c +++ b/src/testing/test_exchange_api_twisted.c @@ -173,12 +173,6 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-currency-mismatch", MHD_HTTP_BAD_REQUEST, "USD:5", - "USD:0.01", - "deposit-refund-1"), - TALER_TESTING_cmd_refund ("refund-fee-above-amount", - MHD_HTTP_BAD_REQUEST, - "EUR:5", - "EUR:10", "deposit-refund-1"), TALER_TESTING_cmd_flip_upload ("flip-upload", CONFIG_FILE, @@ -186,7 +180,6 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-bad-sig", MHD_HTTP_FORBIDDEN, "EUR:5", - "EUR:0.01", "deposit-refund-1"), /* This next deposit CMD is only used to provide a @@ -207,17 +200,10 @@ run (void *cls, TALER_TESTING_cmd_refund ("refund-deposit-not-found", MHD_HTTP_NOT_FOUND, "EUR:5", - "EUR:0.01", "deposit-refund-to-fail"), TALER_TESTING_cmd_refund ("refund-insufficient-funds", MHD_HTTP_PRECONDITION_FAILED, "EUR:50", - "EUR:0.01", - "deposit-refund-1"), - TALER_TESTING_cmd_refund ("refund-fee-too-low", - MHD_HTTP_BAD_REQUEST, - "EUR:5", - "EUR:0.000001", "deposit-refund-1"), TALER_TESTING_cmd_end () }; diff --git a/src/testing/test_taler_exchange_aggregator.c b/src/testing/test_taler_exchange_aggregator.c index eaa621cfe..d5c392d3a 100644 --- a/src/testing/test_taler_exchange_aggregator.c +++ b/src/testing/test_taler_exchange_aggregator.c @@ -108,6 +108,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -126,6 +127,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -134,6 +136,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -153,6 +156,7 @@ run (void *cls, &dbc, "bob", "4", + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -160,6 +164,7 @@ run (void *cls, &dbc, "bob", "5", + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -167,6 +172,7 @@ run (void *cls, &dbc, "alice", "4", + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:1", "EUR:0.1"), @@ -195,6 +201,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -204,6 +211,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -229,6 +237,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), @@ -239,6 +248,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -263,6 +273,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), @@ -274,6 +285,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), @@ -281,6 +293,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), @@ -292,6 +305,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.102", "EUR:0.1"), @@ -303,6 +317,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.112", "EUR:0.1"), @@ -319,6 +334,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.109", "EUR:0.1"), @@ -330,6 +346,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.119", "EUR:0.1"), @@ -346,6 +363,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.122", "EUR:0.1"), @@ -362,6 +380,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -375,6 +394,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -390,6 +410,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.122", "EUR:0.1"), @@ -406,6 +427,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -419,6 +441,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), @@ -434,6 +457,7 @@ run (void *cls, &dbc, "bob", USER42_ACCOUNT, + GNUNET_TIME_absolute_get (), GNUNET_TIME_UNIT_ZERO, "EUR:0.112", "EUR:0.1"), diff --git a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c index 247399a9d..1442380bf 100644 --- a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c +++ b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c @@ -203,6 +203,7 @@ deposit_confirmation_run (void *cls, const struct TALER_TESTING_Command *deposit_cmd; struct GNUNET_HashCode h_wire; struct GNUNET_HashCode h_contract_terms; + const struct GNUNET_TIME_Absolute *exchange_timestamp = NULL; struct GNUNET_TIME_Absolute timestamp; struct GNUNET_TIME_Absolute refund_deadline; struct TALER_Amount amount_without_fee; @@ -238,6 +239,11 @@ deposit_confirmation_run (void *cls, TALER_TESTING_get_trait_exchange_sig (deposit_cmd, dcs->coin_index, &exchange_sig)); + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_absolute_time (deposit_cmd, + dcs->coin_index, + &exchange_timestamp)); + GNUNET_assert (NULL != exchange_timestamp); keys = TALER_EXCHANGE_get_keys (dcs->is->exchange); GNUNET_assert (NULL != keys); spk = TALER_EXCHANGE_get_signing_key_info (keys, @@ -309,7 +315,7 @@ deposit_confirmation_run (void *cls, dcs->dc = TALER_AUDITOR_deposit_confirmation (dcs->auditor, &h_wire, &h_contract_terms, - timestamp, + *exchange_timestamp, refund_deadline, &amount_without_fee, &coin_pub, diff --git a/src/testing/testing_api_cmd_bank_admin_add_incoming.c b/src/testing/testing_api_cmd_bank_admin_add_incoming.c index 2399825d9..d8b1d7b02 100644 --- a/src/testing/testing_api_cmd_bank_admin_add_incoming.c +++ b/src/testing/testing_api_cmd_bank_admin_add_incoming.c @@ -82,6 +82,11 @@ struct AdminAddIncomingState struct TALER_ReservePrivateKeyP reserve_priv; /** + * Whether we know the private key or not. + */ + bool reserve_priv_known; + + /** * Reserve public key matching @e reserve_priv. */ struct TALER_ReservePublicKeyP reserve_pub; @@ -271,6 +276,7 @@ admin_add_incoming_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct AdminAddIncomingState *fts = cls; + bool have_public = false; (void) cmd; /* Use reserve public key as subject */ @@ -278,6 +284,7 @@ admin_add_incoming_run (void *cls, { const struct TALER_TESTING_Command *ref; const struct TALER_ReservePrivateKeyP *reserve_priv; + const struct TALER_ReservePublicKeyP *reserve_pub; ref = TALER_TESTING_interpreter_lookup_command (is, fts->reserve_reference); @@ -292,11 +299,23 @@ admin_add_incoming_run (void *cls, 0, &reserve_priv)) { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; + if (GNUNET_OK != TALER_TESTING_get_trait_reserve_pub (ref, + 0, + &reserve_pub)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + have_public = true; + fts->reserve_pub.eddsa_pub = reserve_pub->eddsa_pub; + fts->reserve_priv_known = false; + } + else + { + fts->reserve_priv.eddsa_priv = reserve_priv->eddsa_priv; + fts->reserve_priv_known = true; } - fts->reserve_priv.eddsa_priv = reserve_priv->eddsa_priv; } else { @@ -349,6 +368,7 @@ admin_add_incoming_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } + fts->reserve_priv_known = true; GNUNET_free (keys); GNUNET_free (section); GNUNET_CONFIGURATION_destroy (cfg); @@ -358,10 +378,12 @@ admin_add_incoming_run (void *cls, /* No referenced reserve, no instance to take priv * from, no explicit subject given: create new key! */ GNUNET_CRYPTO_eddsa_key_create (&fts->reserve_priv.eddsa_priv); + fts->reserve_priv_known = true; } } - GNUNET_CRYPTO_eddsa_key_get_public (&fts->reserve_priv.eddsa_priv, - &fts->reserve_pub.eddsa_pub); + if (! have_public) + GNUNET_CRYPTO_eddsa_key_get_public (&fts->reserve_priv.eddsa_priv, + &fts->reserve_pub.eddsa_pub); fts->reserve_history.type = TALER_EXCHANGE_RTT_CREDIT; fts->reserve_history.amount = fts->amount; fts->reserve_history.details.in_details.sender_url @@ -432,30 +454,58 @@ admin_add_incoming_traits (void *cls, unsigned int index) { struct AdminAddIncomingState *fts = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_bank_row (&fts->serial_id), - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, - fts->payto_debit_account), - /* Used as a marker, content does not matter */ - TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, - "payto://void/the-exchange"), - TALER_TESTING_make_trait_url (TALER_TESTING_UT_EXCHANGE_BANK_ACCOUNT_URL, - fts->exchange_credit_url), - TALER_TESTING_make_trait_amount_obj (0, &fts->amount), - TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), - TALER_TESTING_make_trait_reserve_priv (0, - &fts->reserve_priv), - TALER_TESTING_make_trait_reserve_pub (0, - &fts->reserve_pub), - TALER_TESTING_make_trait_reserve_history (0, - &fts->reserve_history), - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); + if (fts->reserve_priv_known) + { + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_bank_row (&fts->serial_id), + TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, + fts->payto_debit_account), + /* Used as a marker, content does not matter */ + TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, + "payto://void/the-exchange"), + TALER_TESTING_make_trait_url (TALER_TESTING_UT_EXCHANGE_BANK_ACCOUNT_URL, + fts->exchange_credit_url), + TALER_TESTING_make_trait_amount_obj (0, &fts->amount), + TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), + TALER_TESTING_make_trait_reserve_priv (0, + &fts->reserve_priv), + TALER_TESTING_make_trait_reserve_pub (0, + &fts->reserve_pub), + TALER_TESTING_make_trait_reserve_history (0, + &fts->reserve_history), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); + } + else + { + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_bank_row (&fts->serial_id), + TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT, + fts->payto_debit_account), + /* Used as a marker, content does not matter */ + TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT, + "payto://void/the-exchange"), + TALER_TESTING_make_trait_url (TALER_TESTING_UT_EXCHANGE_BANK_ACCOUNT_URL, + fts->exchange_credit_url), + TALER_TESTING_make_trait_amount_obj (0, &fts->amount), + TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), + TALER_TESTING_make_trait_reserve_pub (0, + &fts->reserve_pub), + TALER_TESTING_make_trait_reserve_history (0, + &fts->reserve_history), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); + } } @@ -548,7 +598,7 @@ TALER_TESTING_cmd_admin_add_incoming (const char *label, * @param payto_debit_account which account sends money * @param auth authentication data * @param ref reference to a command that can offer a reserve - * private key. + * private key or public key. * @return the command. */ struct TALER_TESTING_Command diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c index 2d50f8efa..ca23d7fd9 100644 --- a/src/testing/testing_api_cmd_batch.c +++ b/src/testing/testing_api_cmd_batch.c @@ -228,5 +228,27 @@ TALER_TESTING_cmd_batch_get_current (const struct TALER_TESTING_Command *cmd) { struct BatchState *bs = cmd->cls; + GNUNET_assert (cmd->run == &batch_run); return &bs->batch[bs->batch_ip]; } + + +/** + * Set what command the batch should be at. + * + * @param cmd current batch command + * @param new_ip where to move the IP + */ +void +TALER_TESTING_cmd_batch_set_current (const struct TALER_TESTING_Command *cmd, + unsigned int new_ip) +{ + struct BatchState *bs = cmd->cls; + + /* sanity checks */ + GNUNET_assert (cmd->run == &batch_run); + for (unsigned int i = 0; i < new_ip; i++) + GNUNET_assert (NULL != bs->batch[i].label); + /* actual logic */ + bs->batch_ip = new_ip; +} diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 9468e7acb..e7a4c2988 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -53,6 +53,11 @@ struct DepositState struct TALER_Amount amount; /** + * Deposit fee. + */ + struct TALER_Amount deposit_fee; + + /** * Reference to any command that is able to provide a coin. */ const char *coin_reference; @@ -91,9 +96,9 @@ struct DepositState struct TALER_EXCHANGE_DepositHandle *dh; /** - * Timestamp of the /deposit operation. + * Timestamp of the /deposit operation in the wallet (contract signing time). */ - struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_TIME_Absolute wallet_timestamp; /** * Interpreter state. @@ -127,6 +132,11 @@ struct DepositState int deposit_succeeded; /** + * When did the exchange receive the deposit? + */ + struct GNUNET_TIME_Absolute exchange_timestamp; + + /** * Signing key used by the exchange to sign the * deposit confirmation. */ @@ -198,6 +208,7 @@ do_retry (void *cls) * * @param cls closure. * @param hr HTTP response details + * @param exchange_timestamp when did the exchange receive the deposit permission * @param exchange_sig signature provided by the exchange * (NULL on errors) * @param exchange_pub public key of the exchange, @@ -206,6 +217,7 @@ do_retry (void *cls) static void deposit_cb (void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, + const struct GNUNET_TIME_Absolute exchange_timestamp, const struct TALER_ExchangeSignatureP *exchange_sig, const struct TALER_ExchangePublicKeyP *exchange_pub) { @@ -254,6 +266,7 @@ deposit_cb (void *cls, if (MHD_HTTP_OK == hr->http_status) { ds->deposit_succeeded = GNUNET_YES; + ds->exchange_timestamp = exchange_timestamp; ds->exchange_pub = *exchange_pub; ds->exchange_sig = *exchange_sig; } @@ -305,7 +318,7 @@ deposit_run (void *cls, ds->coin_index = ods->coin_index; ds->wire_details = json_incref (ods->wire_details); ds->contract_terms = json_incref (ods->contract_terms); - ds->timestamp = ods->timestamp; + ds->wallet_timestamp = ods->wallet_timestamp; ds->refund_deadline = ods->refund_deadline; ds->amount = ods->amount; ds->merchant_priv = ods->merchant_priv; @@ -366,6 +379,7 @@ deposit_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } + ds->deposit_fee = denom_pub->fee_deposit; GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); @@ -379,39 +393,27 @@ deposit_run (void *cls, } else { - ds->refund_deadline = ds->timestamp; - wire_deadline = GNUNET_TIME_relative_to_absolute - (GNUNET_TIME_UNIT_ZERO); + ds->refund_deadline = ds->wallet_timestamp; + wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); } GNUNET_CRYPTO_eddsa_key_get_public (&ds->merchant_priv.eddsa_priv, &merchant_pub.eddsa_pub); - (void) GNUNET_TIME_round_abs (&wire_deadline); - { - struct TALER_DepositRequestPS dr; - - memset (&dr, 0, sizeof (dr)); - dr.purpose.size = htonl - (sizeof (struct TALER_DepositRequestPS)); - dr.purpose.purpose = htonl - (TALER_SIGNATURE_WALLET_COIN_DEPOSIT); - dr.h_contract_terms = h_contract_terms; + struct GNUNET_HashCode h_wire; + GNUNET_assert (GNUNET_OK == TALER_JSON_merchant_wire_signature_hash (ds->wire_details, - &dr.h_wire)); - dr.timestamp = GNUNET_TIME_absolute_hton (ds->timestamp); - dr.refund_deadline = GNUNET_TIME_absolute_hton - (ds->refund_deadline); - TALER_amount_hton (&dr.amount_with_fee, - &ds->amount); - TALER_amount_hton (&dr.deposit_fee, - &denom_pub->fee_deposit); - dr.merchant = merchant_pub; - dr.coin_pub = coin_pub; - GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv, - &dr, - &coin_sig.eddsa_signature); + &h_wire)); + TALER_EXCHANGE_deposit_permission_sign (&ds->amount, + &denom_pub->fee_deposit, + &h_wire, + &h_contract_terms, + coin_priv, + ds->wallet_timestamp, + &merchant_pub, + ds->refund_deadline, + &coin_sig); } ds->dh = TALER_EXCHANGE_deposit (is->exchange, &ds->amount, @@ -421,7 +423,7 @@ deposit_run (void *cls, &coin_pub, denom_pub_sig, &denom_pub->key, - ds->timestamp, + ds->wallet_timestamp, &merchant_pub, ds->refund_deadline, &coin_sig, @@ -532,8 +534,14 @@ deposit_traits (void *cls, ds->contract_terms), TALER_TESTING_make_trait_merchant_priv (0, &ds->merchant_priv), - TALER_TESTING_make_trait_amount_obj (0, - &ds->amount), + TALER_TESTING_make_trait_amount_obj ( + TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_VALUE, + &ds->amount), + TALER_TESTING_make_trait_amount_obj ( + TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_FEE, + &ds->deposit_fee), + TALER_TESTING_make_trait_absolute_time (0, + &ds->exchange_timestamp), TALER_TESTING_trait_end () }; @@ -599,12 +607,12 @@ TALER_TESTING_cmd_deposit (const char *label, label); GNUNET_assert (0); } - ds->timestamp = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&ds->timestamp); + ds->wallet_timestamp = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&ds->wallet_timestamp); json_object_set_new (ds->contract_terms, "timestamp", - GNUNET_JSON_from_time_abs (ds->timestamp)); + GNUNET_JSON_from_time_abs (ds->wallet_timestamp)); if (0 != refund_deadline.rel_value_us) { ds->refund_deadline = GNUNET_TIME_relative_to_absolute (refund_deadline); @@ -687,12 +695,12 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label, label); GNUNET_assert (0); } - ds->timestamp = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&ds->timestamp); + ds->wallet_timestamp = GNUNET_TIME_absolute_get (); + (void) GNUNET_TIME_round_abs (&ds->wallet_timestamp); json_object_set_new (ds->contract_terms, "timestamp", - GNUNET_JSON_from_time_abs (ds->timestamp)); + GNUNET_JSON_from_time_abs (ds->wallet_timestamp)); if (0 != refund_deadline.rel_value_us) { ds->refund_deadline = GNUNET_TIME_relative_to_absolute (refund_deadline); diff --git a/src/testing/testing_api_cmd_deposits_get.c b/src/testing/testing_api_cmd_deposits_get.c index fd02e75bb..d5617ec25 100644 --- a/src/testing/testing_api_cmd_deposits_get.c +++ b/src/testing/testing_api_cmd_deposits_get.c @@ -81,29 +81,17 @@ struct TrackTransactionState * * @param cls closure. * @param hr HTTP response details - * @param exchange_pub public key of the exchange - * @param wtid wire transfer identifier, NULL if exchange did not - * execute the transaction yet. - * @param execution_time actual or planned execution time for the - * wire transfer. - * @param coin_contribution contribution to the total amount of - * the deposited coin (can be NULL). + * @param dd data about the wire transfer associated with the deposit */ static void deposit_wtid_cb (void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *coin_contribution) + const struct TALER_EXCHANGE_DepositData *dd) { struct TrackTransactionState *tts = cls; struct TALER_TESTING_Interpreter *is = tts->is; struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; - (void) coin_contribution; - (void) exchange_pub; - (void) execution_time; tts->tth = NULL; if (tts->expected_response_code != hr->http_status) { @@ -123,7 +111,7 @@ deposit_wtid_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: - tts->wtid = *wtid; + tts->wtid = dd->wtid; if (NULL != tts->bank_transfer_reference) { const struct TALER_TESTING_Command *bank_transfer_cmd; @@ -151,7 +139,7 @@ deposit_wtid_cb (void *cls, } /* Compare that expected and gotten subjects match. */ - if (0 != GNUNET_memcmp (wtid, + if (0 != GNUNET_memcmp (&dd->wtid, wtid_want)) { GNUNET_break (0); @@ -159,6 +147,8 @@ deposit_wtid_cb (void *cls, return; } } + + break; case MHD_HTTP_ACCEPTED: /* allowed, nothing to check here */ diff --git a/src/testing/testing_api_cmd_insert_deposit.c b/src/testing/testing_api_cmd_insert_deposit.c index 356528009..cff2884aa 100644 --- a/src/testing/testing_api_cmd_insert_deposit.c +++ b/src/testing/testing_api_cmd_insert_deposit.c @@ -58,6 +58,11 @@ struct InsertDepositState struct GNUNET_TIME_Relative wire_deadline; /** + * When did the exchange receive the deposit? + */ + struct GNUNET_TIME_Absolute exchange_timestamp; + + /** * Amount to deposit, inclusive of deposit fee. */ const char *amount_with_fee; @@ -210,6 +215,7 @@ insert_deposit_run (void *cls, (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls, ids->dbc->session, + ids->exchange_timestamp, &deposit)) || (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != ids->dbc->plugin->commit (ids->dbc->plugin->cls, @@ -275,6 +281,7 @@ insert_deposit_traits (void *cls, * @param dbc collects database plugin and session handles. * @param merchant_name Human-readable name of the merchant. * @param merchant_account merchant's account name (NOT a payto:// URI) + * @param exchange_timestamp when did the exchange receive the deposit * @param wire_deadline point in time where the aggregator should have * wired money to the merchant. * @param amount_with_fee amount to deposit (inclusive of deposit fee) @@ -282,21 +289,24 @@ insert_deposit_traits (void *cls, * @return the command. */ struct TALER_TESTING_Command -TALER_TESTING_cmd_insert_deposit (const char *label, - const struct - TALER_TESTING_DatabaseConnection *dbc, - const char *merchant_name, - const char *merchant_account, - struct GNUNET_TIME_Relative wire_deadline, - const char *amount_with_fee, - const char *deposit_fee) +TALER_TESTING_cmd_insert_deposit ( + const char *label, + const struct TALER_TESTING_DatabaseConnection *dbc, + const char *merchant_name, + const char *merchant_account, + struct GNUNET_TIME_Absolute exchange_timestamp, + struct GNUNET_TIME_Relative wire_deadline, + const char *amount_with_fee, + const char *deposit_fee) { struct InsertDepositState *ids; + GNUNET_TIME_round_abs (&exchange_timestamp); ids = GNUNET_new (struct InsertDepositState); ids->dbc = dbc; ids->merchant_name = merchant_name; ids->merchant_account = merchant_account; + ids->exchange_timestamp = exchange_timestamp; ids->wire_deadline = wire_deadline; ids->amount_with_fee = amount_with_fee; ids->deposit_fee = deposit_fee; diff --git a/src/testing/testing_api_cmd_refund.c b/src/testing/testing_api_cmd_refund.c index 47f5a0609..e662ace2e 100644 --- a/src/testing/testing_api_cmd_refund.c +++ b/src/testing/testing_api_cmd_refund.c @@ -44,11 +44,6 @@ struct RefundState const char *refund_amount; /** - * Expected refund fee. - */ - const char *refund_fee; - - /** * Reference to any command that can provide a coin to refund. */ const char *coin_reference; @@ -81,6 +76,7 @@ struct RefundState * * @param cls closure * @param hr HTTP response details + * @param refund_fee the refund fee the exchange charged * @param exchange_pub public key the exchange * used for signing @a obj. * @param exchange_sig actual signature confirming the refund @@ -88,6 +84,7 @@ struct RefundState static void refund_cb (void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, + const struct TALER_Amount *refund_fee, const struct TALER_ExchangePublicKeyP *exchange_pub, const struct TALER_ExchangeSignatureP *exchange_sig) { @@ -95,6 +92,7 @@ refund_cb (void *cls, struct RefundState *rs = cls; struct TALER_TESTING_Command *refund_cmd; + (void) refund_fee; refund_cmd = &rs->is->commands[rs->is->ip]; rs->rh = NULL; if (rs->expected_response_code != hr->http_status) @@ -133,7 +131,6 @@ refund_run (void *cls, struct TALER_CoinSpendPublicKeyP coin; const json_t *contract_terms; struct GNUNET_HashCode h_contract_terms; - struct TALER_Amount refund_fee; struct TALER_Amount refund_amount; const struct TALER_MerchantPrivateKeyP *merchant_priv; const struct TALER_TESTING_Command *coin_cmd; @@ -153,19 +150,6 @@ refund_run (void *cls, TALER_TESTING_interpreter_fail (is); return; } - if (GNUNET_OK != - TALER_string_to_amount (rs->refund_fee, - &refund_fee)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse amount `%s' at %u/%s\n", - rs->refund_fee, - is->ip, - cmd->label); - TALER_TESTING_interpreter_fail (is); - return; - } - coin_cmd = TALER_TESTING_interpreter_lookup_command (is, rs->coin_reference); if (NULL == coin_cmd) @@ -211,7 +195,6 @@ refund_run (void *cls, } rs->rh = TALER_EXCHANGE_refund (rs->exchange, &refund_amount, - &refund_fee, &h_contract_terms, &coin, rs->refund_transaction_id, @@ -254,7 +237,6 @@ refund_cleanup (void *cls, * @param label command label. * @param expected_response_code expected HTTP status code. * @param refund_amount the amount to ask a refund for. - * @param refund_fee expected refund fee. * @param coin_reference reference to a command that can * provide a coin to be refunded. * @@ -264,7 +246,6 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_refund (const char *label, unsigned int expected_response_code, const char *refund_amount, - const char *refund_fee, const char *coin_reference) { struct RefundState *rs; @@ -273,7 +254,6 @@ TALER_TESTING_cmd_refund (const char *label, rs->expected_response_code = expected_response_code; rs->refund_amount = refund_amount; - rs->refund_fee = refund_fee; rs->coin_reference = coin_reference; { struct TALER_TESTING_Command cmd = { @@ -295,7 +275,6 @@ TALER_TESTING_cmd_refund (const char *label, * @param label command label. * @param expected_response_code expected HTTP status code. * @param refund_amount the amount to ask a refund for. - * @param refund_fee expected refund fee. * @param coin_reference reference to a command that can * provide a coin to be refunded. * @param refund_transaction_id transaction id to use @@ -308,7 +287,6 @@ TALER_TESTING_cmd_refund_with_id (const char *label, unsigned int expected_response_code, const char *refund_amount, - const char *refund_fee, const char *coin_reference, uint64_t refund_transaction_id) { @@ -317,7 +295,6 @@ TALER_TESTING_cmd_refund_with_id rs = GNUNET_new (struct RefundState); rs->expected_response_code = expected_response_code; rs->refund_amount = refund_amount; - rs->refund_fee = refund_fee; rs->coin_reference = coin_reference; rs->refund_transaction_id = refund_transaction_id; { diff --git a/src/testing/testing_api_cmd_rewind.c b/src/testing/testing_api_cmd_rewind.c new file mode 100644 index 000000000..cde966d7f --- /dev/null +++ b/src/testing/testing_api_cmd_rewind.c @@ -0,0 +1,222 @@ +/* + This file is part of TALER + Copyright (C) 2014-2020 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 the Free Software Foundation; either version 3, or + (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + <http://www.gnu.org/licenses/> +*/ +/** + * @file testing/testing_api_cmd_rewind.c + * @brief command to rewind the instruction pointer. + * @author Marcello Stanisci + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_exchange_service.h> +#include <taler/taler_testing_lib.h> +#include "taler_testing_lib.h" + + +/** + * State for a "rewind" CMD. + */ +struct RewindIpState +{ + /** + * Instruction pointer to set into the interpreter. + */ + const char *target_label; + + /** + * How many times this set should take place. However, this value lives at + * the calling process, and this CMD is only in charge of checking and + * decremeting it. + */ + unsigned int counter; +}; + + +/** + * Only defined to respect the API. + */ +static void +rewind_ip_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + (void) cls; + (void) cmd; +} + + +/** + * Seek for the @a target command in @a batch (and rewind to it + * if successful). + * + * @param is the interpreter state (for failures) + * @param cmd batch to search for @a target + * @param target command to search for + * @return #GNUNET_OK on success, #GNUNET_NO if target was not found, + * #GNUNET_SYSERR if target is in the future and we failed + */ +static int +seek_batch (struct TALER_TESTING_Interpreter *is, + const struct TALER_TESTING_Command *cmd, + const struct TALER_TESTING_Command *target) +{ + unsigned int new_ip; +#define BATCH_INDEX 1 + struct TALER_TESTING_Command *batch; + struct TALER_TESTING_Command *current; + struct TALER_TESTING_Command *icmd; + const struct TALER_TESTING_Command *match; + + current = TALER_TESTING_cmd_batch_get_current (cmd); + GNUNET_assert (GNUNET_OK == + TALER_TESTING_get_trait_cmd (cmd, + BATCH_INDEX, + &batch)); + match = NULL; + for (new_ip = 0; + NULL != (icmd = &batch[new_ip]); + new_ip++) + { + if (current == target) + current = NULL; + if (icmd == target) + { + match = icmd; + break; + } + if (TALER_TESTING_cmd_is_batch (icmd)) + { + int ret = seek_batch (is, + icmd, + target); + if (GNUNET_SYSERR == ret) + return GNUNET_SYSERR; /* failure! */ + if (GNUNET_OK == ret) + { + match = icmd; + break; + } + } + } + if (NULL == current) + { + /* refuse to jump forward */ + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return GNUNET_SYSERR; + } + if (NULL == match) + return GNUNET_NO; /* not found */ + TALER_TESTING_cmd_batch_set_current (cmd, + new_ip); + return GNUNET_OK; +} + + +/** + * Run the "rewind" CMD. + * + * @param cls closure. + * @param cmd command being executed now. + * @param is the interpreter state. + */ +static void +rewind_ip_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct RewindIpState *ris = cls; + const struct TALER_TESTING_Command *target; + unsigned int new_ip; + + (void) cmd; + if (0 == ris->counter) + { + TALER_TESTING_interpreter_next (is); + return; + } + target + = TALER_TESTING_interpreter_lookup_command (is, + ris->target_label); + if (NULL == target) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ris->counter--; + for (new_ip = 0; + NULL != is->commands[new_ip].label; + new_ip++) + { + const struct TALER_TESTING_Command *cmd = &is->commands[new_ip]; + + if (cmd == target) + break; + if (TALER_TESTING_cmd_is_batch (cmd)) + { + int ret = seek_batch (is, + cmd, + target); + if (GNUNET_SYSERR == ret) + return; /* failure! */ + if (GNUNET_OK == ret) + break; + } + } + if (new_ip > is->ip) + { + /* refuse to jump forward */ + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + is->ip = new_ip - 1; /* -1 because the next function will advance by one */ + TALER_TESTING_interpreter_next (is); +} + + +/** + * Make the instruction pointer point to @a new_ip + * only if @a counter is greater than zero. + * + * @param label command label + * @param target_label label of the new instruction pointer's destination after the jump; + * must be before the current instruction + * @param counter counts how many times the rewinding is to happen. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_rewind_ip (const char *label, + const char *target_label, + unsigned int counter) +{ + struct RewindIpState *ris; + + ris = GNUNET_new (struct RewindIpState); + ris->target_label = target_label; + ris->counter = counter; + { + struct TALER_TESTING_Command cmd = { + .cls = ris, + .label = label, + .run = &rewind_ip_run, + .cleanup = &rewind_ip_cleanup + }; + + return cmd; + } +} diff --git a/src/testing/testing_api_cmd_stat.c b/src/testing/testing_api_cmd_stat.c index cf6d0b484..9461a22cf 100644 --- a/src/testing/testing_api_cmd_stat.c +++ b/src/testing/testing_api_cmd_stat.c @@ -40,7 +40,6 @@ stat_cleanup (void *cls, (void) cls; (void) cmd; /* nothing to clean. */ - return; } diff --git a/src/testing/testing_api_cmd_transfer_get.c b/src/testing/testing_api_cmd_transfer_get.c index 699313e56..3ca319cb5 100644 --- a/src/testing/testing_api_cmd_transfer_get.c +++ b/src/testing/testing_api_cmd_transfer_get.c @@ -121,37 +121,18 @@ track_transfer_cleanup (void *cls, * * @param cls closure. * @param hr HTTP response details - * @param exchange_pub public key the exchange used for signing - * the response. - * @param h_wire hash of the wire transfer address the transfer - * went to, or NULL on error. - * @param execution_time time when the exchange claims to have - * performed the wire transfer. - * @param total_amount total amount of the wire transfer, or NULL - * if the exchange could not provide any @a wtid (set only - * if @a http_status is "200 OK"). - * @param wire_fee wire fee that was charged by the exchange. - * @param details_length length of the @a details array. - * @param details array with details about the combined - * transactions. + * @param ta transfer data returned by the exchange */ static void track_transfer_cb (void *cls, const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const struct GNUNET_HashCode *h_wire, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - unsigned int details_length, - const struct TALER_TrackTransferDetails *details) + const struct TALER_EXCHANGE_TransferData *ta) { struct TrackTransferState *tts = cls; struct TALER_TESTING_Interpreter *is = tts->is; struct TALER_TESTING_Command *cmd = &is->commands[is->ip]; struct TALER_Amount expected_amount; - (void) exchange_pub; tts->tth = NULL; if (tts->expected_response_code != hr->http_status) { @@ -193,14 +174,14 @@ track_transfer_cb (void *cls, TALER_TESTING_interpreter_fail (is); return; } - if (0 != TALER_amount_cmp (total_amount, + if (0 != TALER_amount_cmp (&ta->total_amount, &expected_amount)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Total amount mismatch to command %s - " "%s vs %s\n", cmd->label, - TALER_amount_to_string (total_amount), + TALER_amount_to_string (&ta->total_amount), TALER_amount_to_string (&expected_amount)); json_dumpf (hr->reply, stderr, @@ -219,7 +200,7 @@ track_transfer_cb (void *cls, return; } - if (0 != TALER_amount_cmp (wire_fee, + if (0 != TALER_amount_cmp (&ta->wire_fee, &expected_amount)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -266,7 +247,7 @@ track_transfer_cb (void *cls, TALER_JSON_merchant_wire_signature_hash (wire_details, &h_wire_details)); if (0 != GNUNET_memcmp (&h_wire_details, - h_wire)) + &ta->h_wire)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wire hash missmath to command %s\n", @@ -301,7 +282,7 @@ track_transfer_cb (void *cls, TALER_TESTING_interpreter_fail (is); return; } - if (0 != TALER_amount_cmp (total_amount, + if (0 != TALER_amount_cmp (&ta->total_amount, total_amount_from_reference)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index 992dcbfda..fceff4234 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c @@ -69,6 +69,7 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is, #define BATCH_INDEX 1 struct TALER_TESTING_Command *batch; struct TALER_TESTING_Command *current; + struct TALER_TESTING_Command *icmd; const struct TALER_TESTING_Command *match; current = TALER_TESTING_cmd_batch_get_current (cmd); @@ -79,15 +80,15 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is, /* We must do the loop forward, but we can find the last match */ match = NULL; for (unsigned int j = 0; - NULL != (cmd = &batch[j])->label; + NULL != (icmd = &batch[j])->label; j++) { - if (current == cmd) + if (current == icmd) break; /* do not go past current command */ - if ( (NULL != cmd->label) && - (0 == strcmp (cmd->label, + if ( (NULL != icmd->label) && + (0 == strcmp (icmd->label, label)) ) - match = cmd; + match = icmd; } if (NULL != match) return match; diff --git a/src/testing/testing_api_trait_json.c b/src/testing/testing_api_trait_json.c index cbddad53e..e12f1e9a1 100644 --- a/src/testing/testing_api_trait_json.c +++ b/src/testing/testing_api_trait_json.c @@ -30,6 +30,7 @@ #define TALER_TESTING_TRAIT_WIRE_DETAILS "wire-details" #define TALER_TESTING_TRAIT_EXCHANGE_KEYS "exchange-keys" +#define TALER_TESTING_TRAIT_JSON "json" /** * Obtain serialized exchange keys from @a cmd. @@ -120,4 +121,45 @@ TALER_TESTING_make_trait_wire_details } +/** + * Obtain json from @a cmd. + * + * @param cmd command to extract the json from. + * @param index index number associate with the json on offer. + * @param[out] json where to write the json. + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_json (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const json_t **json) +{ + return cmd->traits (cmd->cls, + (const void **) json, + TALER_TESTING_TRAIT_JSON, + index); +} + + +/** + * Offer json in a trait. + * + * @param index index number associate with the json + * on offer. + * @param json json to offer. + * @return the trait. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_json (unsigned int index, + const json_t *json) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_JSON, + .ptr = (const json_t *) json + }; + return ret; +} + + /* end of testing_api_trait_json.c */ diff --git a/src/testing/testing_api_trait_number.c b/src/testing/testing_api_trait_number.c index 50ce6d8c7..ed25593ef 100644 --- a/src/testing/testing_api_trait_number.c +++ b/src/testing/testing_api_trait_number.c @@ -28,7 +28,9 @@ #include "taler_testing_lib.h" #define TALER_TESTING_TRAIT_UINT "uint" +#define TALER_TESTING_TRAIT_UINT32 "uint-32" #define TALER_TESTING_TRAIT_UINT64 "uint-64" +#define TALER_TESTING_TRAIT_INT64 "int-64" #define TALER_TESTING_TRAIT_BANK_ROW "bank-transaction-row" @@ -73,6 +75,45 @@ TALER_TESTING_make_trait_uint (unsigned int index, /** + * Obtain a "number" value from @a cmd, 32-bit version. + * + * @param cmd command to extract the number from. + * @param index the number's index number. + * @param[out] n set to the number coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_uint32 (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const uint32_t **n) +{ + return cmd->traits (cmd->cls, + (const void **) n, + TALER_TESTING_TRAIT_UINT32, + index); +} + + +/** + * Offer number trait, 32-bit version. + * + * @param index the number's index number. + * @param n number to offer. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_uint32 (unsigned int index, + const uint32_t *n) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_UINT32, + .ptr = (const void *) n + }; + return ret; +} + + +/** * Obtain a "number" value from @a cmd, 64-bit version. * * @param cmd command to extract the number from. @@ -112,6 +153,45 @@ TALER_TESTING_make_trait_uint64 (unsigned int index, /** + * Obtain a "number" value from @a cmd, 64-bit signed version. + * + * @param cmd command to extract the number from. + * @param index the number's index number. + * @param[out] n set to the number coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_int64 (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const int64_t **n) +{ + return cmd->traits (cmd->cls, + (const void **) n, + TALER_TESTING_TRAIT_INT64, + index); +} + + +/** + * Offer number trait, 64-bit signed version. + * + * @param index the number's index number. + * @param n number to offer. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_int64 (unsigned int index, + const int64_t *n) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_INT64, + .ptr = (const void *) n + }; + return ret; +} + + +/** * Obtain a bank transaction row value from @a cmd. * * @param cmd command to extract the number from. diff --git a/src/testing/testing_api_trait_time.c b/src/testing/testing_api_trait_time.c index c77489bfa..207246bed 100644 --- a/src/testing/testing_api_trait_time.c +++ b/src/testing/testing_api_trait_time.c @@ -29,6 +29,7 @@ #include "taler_testing_lib.h" #define TALER_TESTING_TRAIT_TIME_ABS "time-abs" +#define TALER_TESTING_TRAIT_TIME_REL "time-rel" /** * Obtain a absolute time from @a cmd. @@ -73,4 +74,47 @@ TALER_TESTING_make_trait_absolute_time } +/** + * Obtain a relative time from @a cmd. + * + * @param cmd command to extract trait from + * @param index which time to pick if + * @a cmd has multiple on offer. + * @param[out] time set to the wanted WTID. + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_get_trait_relative_time ( + const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct GNUNET_TIME_Relative **time) +{ + return cmd->traits (cmd->cls, + (const void **) time, + TALER_TESTING_TRAIT_TIME_REL, + index); +} + + +/** + * Offer a relative time. + * + * @param index associate the object with this index + * @param time which object should be returned + * @return the trait. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_relative_time ( + unsigned int index, + const struct GNUNET_TIME_Relative *time) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_TIME_REL, + .ptr = (const void *) time + }; + return ret; +} + + /* end of testing_api_trait_time.c */ |