From 8c1493240e667b329e0a9238e5aeaeb7f61df693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:30:58 +0200 Subject: [PATCH] Avoid out of date code --- nano/rpc_test/rpc.cpp | 7 ++++- nano/test_common/telemetry.cpp | 48 +++++++++------------------------- nano/test_common/telemetry.hpp | 8 +----- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 4365ac1d24..87ab6fbd0e 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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 ("node_id").is_initialized ()); ASSERT_FALSE (response.get_optional ("signature").is_initialized ()); } diff --git a/nano/test_common/telemetry.cpp b/nano/test_common/telemetry.cpp index db2465e074..af07b3ecdd 100644 --- a/nano/test_common/telemetry.cpp +++ b/nano/test_common/telemetry.cpp @@ -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> (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{}); - 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); diff --git a/nano/test_common/telemetry.hpp b/nano/test_common/telemetry.hpp index 3efdd06cf6..35892b3db6 100644 --- a/nano/test_common/telemetry.hpp +++ b/nano/test_common/telemetry.hpp @@ -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 &); } \ No newline at end of file