Merge bitcoin/bitcoin#28857: test, refactor: Magic bytes array followup

1e5b86171e test: Add test for array serialization (TheCharlatan)
d49d198840 refactor: Initialize magic bytes in constructor initializer (TheCharlatan)

Pull request description:

  This is a followup-PR for #28423

  * Initialize magic bytes in constructor
  * Add a small unit test for serializing arrays.

ACKs for top commit:
  sipa:
    utACK 1e5b86171e
  maflcko:
    lgtm ACK 1e5b86171e

Tree-SHA512: 0f58d2332dc501ca9fd419f40ed4f977c83dce0169e9a0eee1ffc9f8daa2d2ef7e7df18205ba076f55d90ae6c4a20d2b51ab303150d38470a962bcc58a66f6e7
This commit is contained in:
fanquake
2023-11-14 15:38:29 +00:00
4 changed files with 15 additions and 6 deletions

View File

@@ -85,6 +85,8 @@ BOOST_AUTO_TEST_CASE(sizes)
BOOST_CHECK_EQUAL(GetSerializeSize(int64_t(0), 0), 8U);
BOOST_CHECK_EQUAL(GetSerializeSize(uint64_t(0), 0), 8U);
BOOST_CHECK_EQUAL(GetSerializeSize(bool(0), 0), 1U);
BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 1>{0}, 0), 1U);
BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 2>{0, 0}, 0), 2U);
}
BOOST_AUTO_TEST_CASE(varints)
@@ -179,6 +181,16 @@ BOOST_AUTO_TEST_CASE(vector_bool)
BOOST_CHECK((HashWriter{} << vec1).GetHash() == (HashWriter{} << vec2).GetHash());
}
BOOST_AUTO_TEST_CASE(array)
{
std::array<uint8_t, 32> array1{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1};
DataStream ds;
ds << array1;
std::array<uint8_t, 32> array2;
ds >> array2;
BOOST_CHECK(array1 == array2);
}
BOOST_AUTO_TEST_CASE(noncanonical)
{
// Write some non-canonical CompactSize encodings, and