From 2dea0454254180d79464dc6afd3312b1caf369a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 22 Jul 2025 10:04:30 -0700 Subject: [PATCH] test: make `obfuscation_serialize` more thorough See: https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2216849672 Co-authored-by: Ryan Ofsky --- src/test/streams_tests.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 44aaf4d1775..43d06a7d0bf 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -58,19 +58,24 @@ BOOST_AUTO_TEST_CASE(obfuscation_hexkey) BOOST_AUTO_TEST_CASE(obfuscation_serialize) { - const Obfuscation original{m_rng.randbytes()}; + Obfuscation obfuscation{}; + BOOST_CHECK(!obfuscation); - // Serialization - DataStream ds; - ds << original; + // Test loading a key. + std::vector key_in{m_rng.randbytes(Obfuscation::KEY_SIZE)}; + DataStream ds_in; + ds_in << key_in; + BOOST_CHECK_EQUAL(ds_in.size(), 1 + Obfuscation::KEY_SIZE); // serialized as a vector + ds_in >> obfuscation; - BOOST_CHECK_EQUAL(ds.size(), 1 + Obfuscation::KEY_SIZE); // serialized as a vector + // Test saving the key. + std::vector key_out; + DataStream ds_out; + ds_out << obfuscation; + ds_out >> key_out; - // Deserialization - Obfuscation recovered{}; - ds >> recovered; - - BOOST_CHECK_EQUAL(recovered.HexKey(), original.HexKey()); + // Make sure saved key is the same. + BOOST_CHECK_EQUAL_COLLECTIONS(key_in.begin(), key_in.end(), key_out.begin(), key_out.end()); } BOOST_AUTO_TEST_CASE(obfuscation_empty)