diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-11-03 07:51:19 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-11-05 10:37:37 +0100 |
commit | a26c2c9a882534e7035215419a073e1368fddec9 (patch) | |
tree | 5ccd8f8645e1e19e52ced402ab69eb2e5f9a81ca | |
parent | f1767625194600dfd1428ae72832832dffc9f94f (diff) |
-more work on testing
-rw-r--r-- | src/testing/testing_api_cmd_bank_history_credit.c | 130 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_bank_history_debit.c | 106 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_bank_transfer.c | 17 |
3 files changed, 44 insertions, 209 deletions
diff --git a/src/testing/testing_api_cmd_bank_history_credit.c b/src/testing/testing_api_cmd_bank_history_credit.c index e54f8fb07..6dbb2b993 100644 --- a/src/testing/testing_api_cmd_bank_history_credit.c +++ b/src/testing/testing_api_cmd_bank_history_credit.c @@ -149,7 +149,7 @@ print_expected (struct History *h, TALER_amount2s (&cd->amount), (unsigned long long) h[i].row_id, TALER_B2S (&cd->details.reserve.reserve_pub), - cd->debit_account_uri); + cd->debit_account_uri.full_payto); break; case TALER_BANK_CT_KYCAUTH: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -159,7 +159,7 @@ print_expected (struct History *h, TALER_amount2s (&cd->amount), (unsigned long long) h[i].row_id, TALER_B2S (&cd->details.kycauth.account_pub), - cd->debit_account_uri); + cd->debit_account_uri.full_payto); break; case TALER_BANK_CT_WAD: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -170,7 +170,7 @@ print_expected (struct History *h, (unsigned long long) h[i].row_id, TALER_B2S (&cd->details.wad.wad_id), cd->details.wad.origin_exchange_url, - cd->debit_account_uri); + cd->debit_account_uri.full_payto); break; } } @@ -231,8 +231,8 @@ command_cb (void *cls, struct IteratorContext *ic = cls; struct HistoryState *hs = ic->hs; const uint64_t *row_id; - const char *credit_account; - const char *debit_account; + const struct TALER_FullPayto *credit_account; + const struct TALER_FullPayto *debit_account; const struct TALER_Amount *amount; const struct TALER_ReservePublicKeyP *reserve_pub; const char *exchange_credit_url; @@ -294,8 +294,8 @@ command_cb (void *cls, return; } TALER_LOG_INFO ("Found history: %s->%s for account %s\n", - debit_account, - credit_account, + debit_account->full_payto, + credit_account->full_payto, hs->account_url); /* found matching record, make sure we have room */ if (ic->pos == ic->total) @@ -303,12 +303,12 @@ command_cb (void *cls, ic->total, ic->pos * 2); ic->h[ic->pos].url - = GNUNET_strdup (debit_account); + = GNUNET_strdup (debit_account->full_payto); ic->h[ic->pos].row_id = *row_id; ic->h[ic->pos].credit_details.type = TALER_BANK_CT_RESERVE; - ic->h[ic->pos].credit_details.debit_account_uri + ic->h[ic->pos].credit_details.debit_account_uri.full_payto = ic->h[ic->pos].url; ic->h[ic->pos].credit_details.amount = *amount; @@ -377,69 +377,6 @@ build_history (struct HistoryState *hs, /** - * Normalize IBAN-based payto URI in @a in. - * - * @param in input payto://-URI to normalize - * @return normalized IBAN for the test - */ -static char * -normalize (const char *in) -{ - char *npt; - const char *q = strchr (in, - '?'); - const char *mptr; - const char *bic; - const char *iban; - - if (NULL == q) - npt = GNUNET_strdup (in); - else - npt = GNUNET_strndup (in, - q - in); - if (0 != strncasecmp (npt, - "payto://", - strlen ("payto://"))) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Invalid payto: %s\n", - npt); - GNUNET_free (npt); - return NULL; - } - mptr = npt + strlen ("payto://"); - bic = strchr (mptr, '/'); - if (NULL == bic) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Invalid payto: %s\n", - npt); - GNUNET_free (npt); - return NULL; - } - bic++; - iban = strchr (bic, '/'); - if (NULL != iban) - { - /* need to remove bic */ - char *n; - - iban++; - GNUNET_asprintf (&n, - "payto://%.*s/%s", - (int) ((bic - mptr) - 1), - mptr, - iban); - GNUNET_free (npt); - npt = n; - } - return npt; -} - - -/** * Check that the "/history/incoming" response matches the * CMD whose offset in the list of CMDs is @a off. * @@ -456,9 +393,6 @@ check_result (struct History *h, unsigned int off, const struct TALER_BANK_CreditDetails *credit_details) { - char *u1; - char *u2; - if (off >= total) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -471,61 +405,50 @@ check_result (struct History *h, off); return GNUNET_SYSERR; } - u1 = normalize (h[off].credit_details.debit_account_uri); - if (NULL == u1) - return GNUNET_SYSERR; - u2 = normalize (credit_details->debit_account_uri); - if (NULL == u2) - { - GNUNET_free (u1); - return GNUNET_SYSERR; - } if ( (h[off].credit_details.type != credit_details->type) || (0 != TALER_amount_cmp (&h[off].credit_details.amount, &credit_details->amount)) || - (0 != strcasecmp (u1, - u2)) ) + (0 != TALER_full_payto_normalize_and_cmp ( + h[off].credit_details.debit_account_uri, + credit_details->debit_account_uri)) ) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected debit_account_uri: %s with %s\n", - u1, + h[off].credit_details.debit_account_uri.full_payto, TALER_amount2s (&h[off].credit_details.amount)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "actual debit_account_uri: %s with %s\n", - u2, + credit_details->debit_account_uri.full_payto, TALER_amount2s (&credit_details->amount)); print_expected (h, total, off); - GNUNET_free (u1); - GNUNET_free (u2); return GNUNET_SYSERR; } switch (credit_details->type) { case TALER_BANK_CT_RESERVE: - if (0 != GNUNET_memcmp (&h[off].credit_details.details.reserve.reserve_pub, - &credit_details->details.reserve.reserve_pub)) + if (0 != + GNUNET_memcmp (&h[off].credit_details.details.reserve.reserve_pub, + &credit_details->details.reserve.reserve_pub)) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected debit_account_uri: %s with %s for %s\n", - u1, + h[off].credit_details.debit_account_uri.full_payto, TALER_amount2s (&h[off].credit_details.amount), TALER_B2S (&h[off].credit_details.details.reserve.reserve_pub) ); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "actual debit_account_uri: %s with %s for %s\n", - u2, + credit_details->debit_account_uri.full_payto, TALER_amount2s (&credit_details->amount), TALER_B2S (&credit_details->details.reserve.reserve_pub)); print_expected (h, total, off); - GNUNET_free (u1); - GNUNET_free (u2); return GNUNET_SYSERR; } break; @@ -536,20 +459,18 @@ check_result (struct History *h, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected debit_account_uri: %s with %s for %s\n", - u1, + h[off].credit_details.debit_account_uri.full_payto, TALER_amount2s (&h[off].credit_details.amount), TALER_B2S (&h[off].credit_details.details.kycauth.account_pub) ); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "actual debit_account_uri: %s with %s for %s\n", - u2, + credit_details->debit_account_uri.full_payto, TALER_amount2s (&credit_details->amount), TALER_B2S (&credit_details->details.kycauth.account_pub)); print_expected (h, total, off); - GNUNET_free (u1); - GNUNET_free (u2); return GNUNET_SYSERR; } break; @@ -562,28 +483,23 @@ check_result (struct History *h, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected debit_account_uri: %s with %s for %s-%s\n", - u1, + h[off].credit_details.debit_account_uri.full_payto, TALER_amount2s (&h[off].credit_details.amount), h[off].credit_details.details.wad.origin_exchange_url, TALER_B2S (&h[off].credit_details.details.wad.wad_id)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "actual debit_account_uri: %s with %s for %s-%s\n", - u2, + credit_details->debit_account_uri.full_payto, TALER_amount2s (&credit_details->amount), credit_details->details.wad.origin_exchange_url, TALER_B2S (&credit_details->details.wad.wad_id)); print_expected (h, total, off); - GNUNET_free (u1); - GNUNET_free (u2); return GNUNET_SYSERR; } break; } - - GNUNET_free (u1); - GNUNET_free (u2); return GNUNET_OK; } diff --git a/src/testing/testing_api_cmd_bank_history_debit.c b/src/testing/testing_api_cmd_bank_history_debit.c index 1cb7320fa..b6e6ea40c 100644 --- a/src/testing/testing_api_cmd_bank_history_debit.c +++ b/src/testing/testing_api_cmd_bank_history_debit.c @@ -52,10 +52,6 @@ struct History */ char *c_url; - /** - * URL to free. - */ - char *d_url; }; @@ -146,7 +142,7 @@ print_expected (struct History *h, TALER_amount2s (&h[i].details.amount), (unsigned long long) h[i].row_id, TALER_B2S (&h[i].details.wtid), - h[i].details.credit_account_uri); + h[i].details.credit_account_uri.full_payto); } } @@ -204,10 +200,9 @@ command_cb (void *cls, { struct IteratorContext *ic = cls; struct HistoryState *hs = ic->hs; - const uint64_t *row_id; - const char *debit_account; - const char *credit_account; + const struct TALER_FullPayto *debit_account; + const struct TALER_FullPayto *credit_account; const struct TALER_Amount *amount; const struct TALER_WireTransferIdentifierRawP *wtid; const char *exchange_base_url; @@ -256,17 +251,17 @@ command_cb (void *cls, return; } TALER_LOG_INFO ("Found history: %s->%s for account %s\n", - debit_account, - credit_account, + debit_account->full_payto, + credit_account->full_payto, hs->account_url); /* found matching record, make sure we have room */ if (ic->pos == ic->total) GNUNET_array_grow (ic->h, ic->total, ic->pos * 2); - ic->h[ic->pos].c_url = GNUNET_strdup (credit_account); - ic->h[ic->pos].d_url = GNUNET_strdup (debit_account); - ic->h[ic->pos].details.credit_account_uri = ic->h[ic->pos].c_url; + ic->h[ic->pos].c_url = GNUNET_strdup (credit_account->full_payto); + ic->h[ic->pos].details.credit_account_uri.full_payto + = ic->h[ic->pos].c_url; ic->h[ic->pos].details.amount = *amount; ic->h[ic->pos].row_id = *row_id; ic->h[ic->pos].details.wtid = *wtid; @@ -335,69 +330,6 @@ build_history (struct HistoryState *hs, /** - * Normalize IBAN-based payto URI in @a in. - * - * @param in input payto://-URI to normalize - * @return normalized IBAN for the test - */ -static char * -normalize (const char *in) -{ - char *npt; - const char *q = strchr (in, - '?'); - const char *mptr; - const char *bic; - const char *iban; - - if (NULL == q) - npt = GNUNET_strdup (in); - else - npt = GNUNET_strndup (in, - q - in); - if (0 != strncasecmp (npt, - "payto://", - strlen ("payto://"))) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Invalid payto: %s\n", - npt); - GNUNET_free (npt); - return NULL; - } - mptr = npt + strlen ("payto://"); - bic = strchr (mptr, '/'); - if (NULL == bic) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Invalid payto: %s\n", - npt); - GNUNET_free (npt); - return NULL; - } - bic++; - iban = strchr (bic, '/'); - if (NULL != iban) - { - /* need to remove bic */ - char *n; - - iban++; - GNUNET_asprintf (&n, - "payto://%.*s/%s", - (int) ((bic - mptr) - 1), - mptr, - iban); - GNUNET_free (npt); - npt = n; - } - return npt; -} - - -/** * Check that the "/history/outgoing" response matches the * CMD whose offset in the list of CMDs is @a off. * @@ -414,9 +346,6 @@ check_result (struct History *h, unsigned int off, const struct TALER_BANK_DebitDetails *details) { - char *u1; - char *u2; - if (off >= total) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -429,31 +358,23 @@ check_result (struct History *h, off); return GNUNET_SYSERR; } - u1 = normalize (h[off].details.credit_account_uri); - if (NULL == u1) - return GNUNET_SYSERR; - u2 = normalize (details->credit_account_uri); - if (NULL == u2) - { - GNUNET_free (u1); - return GNUNET_SYSERR; - } if ( (0 != GNUNET_memcmp (&h[off].details.wtid, &details->wtid)) || (0 != TALER_amount_cmp (&h[off].details.amount, &details->amount)) || - (0 != strcasecmp (u1, - u2)) ) + (0 != TALER_full_payto_normalize_and_cmp ( + h[off].details.credit_account_uri, + details->credit_account_uri)) ) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected debit_account_uri: %s with %s for %s\n", - u1, + h[off].details.credit_account_uri.full_payto, TALER_amount2s (&h[off].details.amount), TALER_B2S (&h[off].details.wtid)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "actual debit_account_uri: %s with %s for %s\n", - u2, + details->credit_account_uri.full_payto, TALER_amount2s (&details->amount), TALER_B2S (&details->wtid)); print_expected (h, @@ -631,7 +552,6 @@ history_cleanup (void *cls, for (unsigned int off = 0; off<hs->total; off++) { GNUNET_free (hs->h[off].c_url); - GNUNET_free (hs->h[off].d_url); } GNUNET_free (hs->h); GNUNET_free (hs); diff --git a/src/testing/testing_api_cmd_bank_transfer.c b/src/testing/testing_api_cmd_bank_transfer.c index bfb29e120..35cd397e7 100644 --- a/src/testing/testing_api_cmd_bank_transfer.c +++ b/src/testing/testing_api_cmd_bank_transfer.c @@ -57,12 +57,12 @@ struct TransferState /** * Money receiver payto URL. */ - char *payto_debit_account; + struct TALER_FullPayto payto_debit_account; /** * Money receiver account URL. */ - const char *payto_credit_account; + struct TALER_FullPayto payto_credit_account; /** * Username to use for authentication. @@ -231,7 +231,7 @@ transfer_run (void *cls, "Transfer of %s from %s to %s\n", TALER_amount2s (&fts->amount), fts->account_debit_url, - fts->payto_credit_account); + fts->payto_credit_account.full_payto); TALER_BANK_prepare_transfer (fts->payto_credit_account, &fts->amount, fts->exchange_base_url, @@ -282,7 +282,6 @@ transfer_cleanup (void *cls, GNUNET_SCHEDULER_cancel (fts->retry_task); fts->retry_task = NULL; } - GNUNET_free (fts->payto_debit_account); GNUNET_free (fts); } @@ -309,9 +308,9 @@ transfer_traits (void *cls, fts->exchange_base_url), TALER_TESTING_make_trait_bank_row (&fts->serial_id), TALER_TESTING_make_trait_credit_payto_uri ( - fts->payto_credit_account), + &fts->payto_credit_account), TALER_TESTING_make_trait_debit_payto_uri ( - fts->payto_debit_account), + &fts->payto_debit_account), TALER_TESTING_make_trait_amount (&fts->amount), TALER_TESTING_make_trait_timestamp (0, &fts->timestamp), TALER_TESTING_make_trait_wtid (&fts->wtid), @@ -329,8 +328,8 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_transfer (const char *label, const char *amount, const struct TALER_BANK_AuthenticationData *auth, - const char *payto_debit_account, - const char *payto_credit_account, + struct TALER_FullPayto payto_debit_account, + struct TALER_FullPayto payto_credit_account, const struct TALER_WireTransferIdentifierRawP *wtid, const char *exchange_base_url) { @@ -339,7 +338,7 @@ TALER_TESTING_cmd_transfer (const char *label, fts = GNUNET_new (struct TransferState); fts->account_debit_url = auth->wire_gateway_url; fts->exchange_base_url = exchange_base_url; - fts->payto_debit_account = GNUNET_strdup (payto_debit_account); + fts->payto_debit_account = payto_debit_account; fts->payto_credit_account = payto_credit_account; fts->auth = *auth; fts->wtid = *wtid; |