Skip to content

Commit f818d13

Browse files
committed
fix: use temporary data stream in TestSerializationRoundtrip
1 parent d4202b5 commit f818d13

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/test/util/llmq_tests.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,19 @@ inline std::vector<bool> CreateBitVector(size_t size, const std::vector<size_t>&
8888
template <typename T>
8989
inline bool TestSerializationRoundtrip(const T& obj)
9090
{
91-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
92-
ss << obj;
93-
94-
T deserialized;
95-
ss >> deserialized;
96-
97-
// Re-serialize and compare
98-
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
99-
ss2 << deserialized;
100-
101-
return ss.str() == ss2.str();
91+
// Datastreams we will compare at the end
92+
CDataStream ss_obj(SER_NETWORK, PROTOCOL_VERSION);
93+
CDataStream ss_obj_rt(SER_NETWORK, PROTOCOL_VERSION);
94+
// A temporary datastream to perform serialization round-trip
95+
CDataStream ss_tmp(SER_NETWORK, PROTOCOL_VERSION);
96+
T obj_rt;
97+
98+
ss_obj << obj;
99+
ss_tmp << obj;
100+
ss_tmp >> obj_rt;
101+
ss_obj_rt << obj_rt;
102+
103+
return ss_obj.str() == ss_obj_rt.str();
102104
}
103105

104106
// Helper to create deterministic test data

0 commit comments

Comments
 (0)