Skip to content

Commit

Permalink
Avoid out of date code
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jul 15, 2024
1 parent c4eca37 commit 8c14932
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 43 deletions.
7 changes: 6 additions & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6775,7 +6775,12 @@ TEST (rpc, telemetry_all)
nano::telemetry_data telemetry_data;
auto const should_ignore_identification_metrics = true;
ASSERT_FALSE (telemetry_data.deserialize_json (config, should_ignore_identification_metrics));
ASSERT_TRUE (nano::test::compare_telemetry_data (telemetry_data, node->local_telemetry ()));
auto local_telemetry = node->local_telemetry ();
// Ignore the identification metrics
local_telemetry.signature.clear ();
local_telemetry.node_id.clear ();
local_telemetry.timestamp = telemetry_data.timestamp = {};
ASSERT_EQ (telemetry_data, local_telemetry);
ASSERT_FALSE (response.get_optional<std::string> ("node_id").is_initialized ());
ASSERT_FALSE (response.get_optional<std::string> ("signature").is_initialized ());
}
Expand Down
48 changes: 13 additions & 35 deletions nano/test_common/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,34 @@

namespace
{
void compare_telemetry_data_impl (const nano::telemetry_data & data_a, const nano::telemetry_data & data_b, bool & result)
{
ASSERT_EQ (data_a.block_count, data_b.block_count);
ASSERT_EQ (data_a.cemented_count, data_b.cemented_count);
ASSERT_EQ (data_a.bandwidth_cap, data_b.bandwidth_cap);
ASSERT_EQ (data_a.peer_count, data_b.peer_count);
ASSERT_EQ (data_a.protocol_version, data_b.protocol_version);
ASSERT_EQ (data_a.unchecked_count, data_b.unchecked_count);
ASSERT_EQ (data_a.account_count, data_b.account_count);
ASSERT_LE (data_a.uptime, data_b.uptime);
ASSERT_EQ (data_a.genesis_block, data_b.genesis_block);
ASSERT_EQ (data_a.major_version, nano::get_major_node_version ());
ASSERT_EQ (data_a.minor_version, nano::get_minor_node_version ());
ASSERT_EQ (data_a.patch_version, nano::get_patch_node_version ());
ASSERT_EQ (data_a.pre_release_version, nano::get_pre_release_node_version ());
ASSERT_EQ (data_a.maker, static_cast<std::underlying_type_t<nano::telemetry_maker>> (nano::telemetry_maker::nf_node));
ASSERT_GT (data_a.timestamp, std::chrono::system_clock::now () - std::chrono::seconds (100));
ASSERT_EQ (data_a.active_difficulty, data_b.active_difficulty);
ASSERT_EQ (data_a.unknown_data, std::vector<uint8_t>{});
result = true;
}
}

bool nano::test::compare_telemetry_data (const nano::telemetry_data & data_a, const nano::telemetry_data & data_b)
{
bool result = false;
compare_telemetry_data_impl (data_a, data_b, result);
return result;
}

namespace
{
void compare_telemetry_impl (const nano::telemetry_data & data, nano::node const & node, bool & result)
void compare_telemetry_impl (nano::telemetry_data data, nano::node const & node, bool & result)
{
ASSERT_FALSE (data.validate_signature ());
ASSERT_EQ (data.node_id, node.node_id.pub);

auto data_node = node.local_telemetry ();

// Ignore timestamps and uptime
data.timestamp = data_node.timestamp = {};
data.uptime = data_node.uptime = {};

// Signature should be different because uptime/timestamp will have changed.
nano::telemetry_data data_l = data;
data_l.signature.clear ();
data_l.sign (node.node_id);
ASSERT_NE (data.signature, data_l.signature);

ASSERT_TRUE (nano::test::compare_telemetry_data (data, node.local_telemetry ()));
// Clear signatures for comparison
data.signature.clear ();
data_node.signature.clear ();

ASSERT_EQ (data, data_node);

result = true;
}
}

bool nano::test::compare_telemetry (const nano::telemetry_data & data, const nano::node & node)
bool nano::test::compare_telemetry (nano::telemetry_data data, const nano::node & node)
{
bool result = false;
compare_telemetry_impl (data, node, result);
Expand Down
8 changes: 1 addition & 7 deletions nano/test_common/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ class telemetry_data;

namespace nano::test
{
/**
* Compares telemetry data without signatures
* @return true if comparison OK
*/
bool compare_telemetry_data (nano::telemetry_data const &, nano::telemetry_data const &);

/**
* Compares telemetry data and checks signature matches node_id
* @return true if comparison OK
*/
bool compare_telemetry (nano::telemetry_data const &, nano::node const &);
bool compare_telemetry (nano::telemetry_data, nano::node const &);
}

0 comments on commit 8c14932

Please sign in to comment.