mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-26 09:01:12 +02:00
test: make obfuscation_serialize
more thorough
See: https://github.com/bitcoin/bitcoin/pull/31144#discussion_r2216849672 Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
@@ -58,19 +58,24 @@ BOOST_AUTO_TEST_CASE(obfuscation_hexkey)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(obfuscation_serialize)
|
BOOST_AUTO_TEST_CASE(obfuscation_serialize)
|
||||||
{
|
{
|
||||||
const Obfuscation original{m_rng.randbytes<Obfuscation::KEY_SIZE>()};
|
Obfuscation obfuscation{};
|
||||||
|
BOOST_CHECK(!obfuscation);
|
||||||
|
|
||||||
// Serialization
|
// Test loading a key.
|
||||||
DataStream ds;
|
std::vector key_in{m_rng.randbytes<std::byte>(Obfuscation::KEY_SIZE)};
|
||||||
ds << original;
|
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<std::byte> key_out;
|
||||||
|
DataStream ds_out;
|
||||||
|
ds_out << obfuscation;
|
||||||
|
ds_out >> key_out;
|
||||||
|
|
||||||
// Deserialization
|
// Make sure saved key is the same.
|
||||||
Obfuscation recovered{};
|
BOOST_CHECK_EQUAL_COLLECTIONS(key_in.begin(), key_in.end(), key_out.begin(), key_out.end());
|
||||||
ds >> recovered;
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(recovered.HexKey(), original.HexKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(obfuscation_empty)
|
BOOST_AUTO_TEST_CASE(obfuscation_empty)
|
||||||
|
Reference in New Issue
Block a user