-deduplicate and expand reserve history validation logic in testing library

This commit is contained in:
Christian Grothoff 2022-05-23 10:36:39 +02:00
parent fcaf508647
commit b3844e4923
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 133 additions and 153 deletions

View File

@ -1471,11 +1471,6 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
struct struct
{ {
/**
* Fee paid for the request.
*/
struct TALER_Amount history_fee;
/** /**
* When was the request made. * When was the request made.
*/ */

View File

@ -956,6 +956,20 @@ TALER_TESTING_parse_coin_reference (
unsigned int *idx); unsigned int *idx);
/**
* Compare @a h1 and @a h2.
*
* @param h1 a history entry
* @param h2 a history entry
* @return 0 if @a h1 and @a h2 are equal
*/
int
TALER_TESTING_history_entry_cmp (const struct
TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct
TALER_EXCHANGE_ReserveHistoryEntry *h2);
/* ************** Specific interpreter commands ************ */ /* ************** Specific interpreter commands ************ */

View File

@ -475,7 +475,7 @@ parse_history (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
GNUNET_JSON_spec_fixed_auto ("reserve_sig", GNUNET_JSON_spec_fixed_auto ("reserve_sig",
&rh->details.history_details.reserve_sig), &rh->details.history_details.reserve_sig),
TALER_JSON_spec_amount_any ("history_fee", TALER_JSON_spec_amount_any ("history_fee",
&rh->details.history_details.history_fee), &rh->amount),
GNUNET_JSON_spec_timestamp ("request_timestamp", GNUNET_JSON_spec_timestamp ("request_timestamp",
&rh->details.history_details.request_timestamp), &rh->details.history_details.request_timestamp),
GNUNET_JSON_spec_end () GNUNET_JSON_spec_end ()
@ -493,7 +493,7 @@ parse_history (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
if (GNUNET_OK != if (GNUNET_OK !=
TALER_wallet_reserve_history_verify ( TALER_wallet_reserve_history_verify (
rh->details.history_details.request_timestamp, rh->details.history_details.request_timestamp,
&rh->details.history_details.history_fee, &rh->amount,
uc->reserve_pub, uc->reserve_pub,
&rh->details.history_details.reserve_sig)) &rh->details.history_details.reserve_sig))
{ {

View File

@ -25,6 +25,118 @@
#include "taler_testing_lib.h" #include "taler_testing_lib.h"
int
TALER_TESTING_history_entry_cmp (const struct
TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct
TALER_EXCHANGE_ReserveHistoryEntry *h2)
{
if (h1->type != h2->type)
return 1;
switch (h1->type)
{
case TALER_EXCHANGE_RTT_CREDIT:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 == strcasecmp (h1->details.in_details.sender_url,
h2->details.in_details.sender_url)) &&
(h1->details.in_details.wire_reference ==
h2->details.in_details.wire_reference) &&
(GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
==,
h2->details.in_details.timestamp)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_WITHDRAWAL:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.withdraw.fee,
&h2->details.withdraw.fee)) )
/* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
so we cannot test for it here. but if the amount matches,
that should be good enough. */
return 0;
return 1;
case TALER_EXCHANGE_RTT_RECOUP:
/* exchange_sig, exchange_pub and timestamp are NOT available
from the original recoup response, hence here NOT check(able/ed) */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
&h2->details.recoup_details.coin_pub)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_CLOSE:
/* testing_api_cmd_exec_closer doesn't set the
receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
so we cannot test for it here. but if the amount matches,
that should be good enough. */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.close_details.fee,
&h2->details.close_details.fee)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_HISTORY:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(GNUNET_TIME_timestamp_cmp (
h1->details.history_details.request_timestamp,
==,
h2->details.history_details.
request_timestamp)) &&
(0 ==
GNUNET_memcmp (&h1->details.history_details.reserve_sig,
&h2->details.history_details.reserve_sig)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_MERGE:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.merge_details.purse_fee,
&h2->details.merge_details.purse_fee)) &&
(GNUNET_TIME_timestamp_cmp (h1->details.merge_details.merge_timestamp,
==,
h2->details.merge_details.merge_timestamp))
&&
(GNUNET_TIME_timestamp_cmp (h1->details.merge_details.purse_expiration,
==,
h2->details.merge_details.purse_expiration))
&&
(0 ==
GNUNET_memcmp (&h1->details.merge_details.merge_pub,
&h2->details.merge_details.merge_pub)) &&
(0 ==
GNUNET_memcmp (&h1->details.merge_details.h_contract_terms,
&h2->details.merge_details.h_contract_terms)) &&
(0 ==
GNUNET_memcmp (&h1->details.merge_details.purse_pub,
&h2->details.merge_details.purse_pub)) &&
(0 ==
GNUNET_memcmp (&h1->details.merge_details.reserve_sig,
&h2->details.merge_details.reserve_sig)) &&
(h1->details.merge_details.min_age ==
h2->details.merge_details.min_age) &&
(h1->details.merge_details.flags ==
h2->details.merge_details.flags) )
return 0;
return 1;
}
GNUNET_assert (0);
return 1;
}
enum GNUNET_GenericReturnValue enum GNUNET_GenericReturnValue
TALER_TESTING_parse_coin_reference ( TALER_TESTING_parse_coin_reference (
const char *coin_reference, const char *coin_reference,

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2014-2020 Taler Systems SA Copyright (C) 2014-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as it under the terms of the GNU General Public License as
@ -70,76 +70,6 @@ struct HistoryState
}; };
/**
* Compare @a h1 and @a h2.
*
* @param h1 a history entry
* @param h2 a history entry
* @return 0 if @a h1 and @a h2 are equal
*/
static int
history_entry_cmp (const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct TALER_EXCHANGE_ReserveHistoryEntry *h2)
{
if (h1->type != h2->type)
return 1;
switch (h1->type)
{
case TALER_EXCHANGE_RTT_CREDIT:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 == strcasecmp (h1->details.in_details.sender_url,
h2->details.in_details.sender_url)) &&
(h1->details.in_details.wire_reference ==
h2->details.in_details.wire_reference) &&
(GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
==,
h2->details.in_details.timestamp)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_WITHDRAWAL:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.withdraw.fee,
&h2->details.withdraw.fee)) )
/* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
so we cannot test for it here. but if the amount matches,
that should be good enough. */
return 0;
return 1;
case TALER_EXCHANGE_RTT_RECOUP:
/* exchange_sig, exchange_pub and timestamp are NOT available
from the original recoup response, hence here NOT check(able/ed) */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
&h2->details.recoup_details.coin_pub)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_CLOSE:
/* testing_api_cmd_exec_closer doesn't set the
receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
so we cannot test for it here. but if the amount matches,
that should be good enough. */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.close_details.fee,
&h2->details.close_details.fee)) )
return 0;
return 1;
}
GNUNET_assert (0);
return 1;
}
/** /**
* Check if @a cmd changed the reserve, if so, find the * Check if @a cmd changed the reserve, if so, find the
* entry in @a history and set the respective index in @a found * entry in @a history and set the respective index in @a found
@ -216,7 +146,7 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
if (found[i]) if (found[i])
continue; /* already found, skip */ continue; /* already found, skip */
if (0 == if (0 ==
history_entry_cmp (he, TALER_TESTING_history_entry_cmp (he,
&history[i])) &history[i]))
{ {
found[i] = GNUNET_YES; found[i] = GNUNET_YES;
@ -336,7 +266,6 @@ history_run (void *cls,
create_reserve create_reserve
= TALER_TESTING_interpreter_lookup_command (is, = TALER_TESTING_interpreter_lookup_command (is,
ss->reserve_reference); ss->reserve_reference);
if (NULL == create_reserve) if (NULL == create_reserve)
{ {
GNUNET_break (0); GNUNET_break (0);

View File

@ -70,76 +70,6 @@ struct StatusState
}; };
/**
* Compare @a h1 and @a h2.
*
* @param h1 a history entry
* @param h2 a history entry
* @return 0 if @a h1 and @a h2 are equal
*/
static int
history_entry_cmp (const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
const struct TALER_EXCHANGE_ReserveHistoryEntry *h2)
{
if (h1->type != h2->type)
return 1;
switch (h1->type)
{
case TALER_EXCHANGE_RTT_CREDIT:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 == strcasecmp (h1->details.in_details.sender_url,
h2->details.in_details.sender_url)) &&
(h1->details.in_details.wire_reference ==
h2->details.in_details.wire_reference) &&
(GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
==,
h2->details.in_details.timestamp)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_WITHDRAWAL:
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.withdraw.fee,
&h2->details.withdraw.fee)) )
/* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
so we cannot test for it here. but if the amount matches,
that should be good enough. */
return 0;
return 1;
case TALER_EXCHANGE_RTT_RECOUP:
/* exchange_sig, exchange_pub and timestamp are NOT available
from the original recoup response, hence here NOT check(able/ed) */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
&h2->details.recoup_details.coin_pub)) )
return 0;
return 1;
case TALER_EXCHANGE_RTT_CLOSE:
/* testing_api_cmd_exec_closer doesn't set the
receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
so we cannot test for it here. but if the amount matches,
that should be good enough. */
if ( (0 ==
TALER_amount_cmp (&h1->amount,
&h2->amount)) &&
(0 ==
TALER_amount_cmp (&h1->details.close_details.fee,
&h2->details.close_details.fee)) )
return 0;
return 1;
}
GNUNET_assert (0);
return 1;
}
/** /**
* Check if @a cmd changed the reserve, if so, find the * Check if @a cmd changed the reserve, if so, find the
* entry in @a history and set the respective index in @a found * entry in @a history and set the respective index in @a found
@ -216,7 +146,7 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
if (found[i]) if (found[i])
continue; /* already found, skip */ continue; /* already found, skip */
if (0 == if (0 ==
history_entry_cmp (he, TALER_TESTING_history_entry_cmp (he,
&history[i])) &history[i]))
{ {
found[i] = GNUNET_YES; found[i] = GNUNET_YES;