Skip to content

Commit 0892202

Browse files
fanquakevijaydasmp
authored andcommitted
Merge bitcoin#28857: test, refactor: Magic bytes array followup
1e5b861 test: Add test for array serialization (TheCharlatan) d49d198 refactor: Initialize magic bytes in constructor initializer (TheCharlatan) Pull request description: This is a followup-PR for bitcoin#28423 * Initialize magic bytes in constructor * Add a small unit test for serializing arrays. ACKs for top commit: sipa: utACK 1e5b861 maflcko: lgtm ACK 1e5b861 Tree-SHA512: 0f58d2332dc501ca9fd419f40ed4f977c83dce0169e9a0eee1ffc9f8daa2d2ef7e7df18205ba076f55d90ae6c4a20d2b51ab303150d38470a962bcc58a66f6e7
1 parent cfad414 commit 0892202

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/test/serialize_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ BOOST_AUTO_TEST_CASE(sizes)
8484
BOOST_CHECK_EQUAL(GetSerializeSize(int64_t(0), 0), 8U);
8585
BOOST_CHECK_EQUAL(GetSerializeSize(uint64_t(0), 0), 8U);
8686
BOOST_CHECK_EQUAL(GetSerializeSize(bool(0), 0), 1U);
87+
BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 1>{0}, 0), 1U);
88+
BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 2>{0, 0}, 0), 2U);
8789
}
8890

8991
BOOST_AUTO_TEST_CASE(varints)
@@ -178,6 +180,16 @@ BOOST_AUTO_TEST_CASE(vector_bool)
178180
BOOST_CHECK(SerializeHash(vec1) == SerializeHash(vec2));
179181
}
180182

183+
BOOST_AUTO_TEST_CASE(array)
184+
{
185+
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};
186+
DataStream ds;
187+
ds << array1;
188+
std::array<uint8_t, 32> array2;
189+
ds >> array2;
190+
BOOST_CHECK(array1 == array2);
191+
}
192+
181193
BOOST_AUTO_TEST_CASE(noncanonical)
182194
{
183195
// Write some non-canonical CompactSize encodings, and

0 commit comments

Comments
 (0)