55#include < test/util/llmq_tests.h>
66#include < test/util/setup_common.h>
77
8- #include < llmq/snapshot.h>
98#include < streams.h>
109#include < univalue.h>
1110
11+ #include < llmq/params.h>
12+ #include < llmq/snapshot.h>
13+
1214#include < boost/test/unit_test.hpp>
1315
1416#include < vector>
@@ -116,23 +118,16 @@ BOOST_AUTO_TEST_CASE(quorum_snapshot_empty_data_test)
116118 // Test with empty data
117119 CQuorumSnapshot emptySnapshot ({}, MODE_NO_SKIPPING, {});
118120
119- // TODO: Serialization roundtrip tests are disabled because CQuorumSnapshot uses custom
120- // serialization for bit vectors that may not produce byte-identical output after roundtrip.
121- // These tests should be re-enabled once proper equality operators are implemented for CQuorumSnapshot.
122- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
123- // BOOST_CHECK(TestSerializationRoundtrip(emptySnapshot));
121+ // Test serialization roundtrip
122+ BOOST_CHECK (TestSerializationRoundtrip (emptySnapshot));
124123
125124 // Test with empty active members but non-empty skip list
126125 CQuorumSnapshot snapshot1 ({}, MODE_SKIPPING_ENTRIES, {1 , 2 , 3 });
127- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
128- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
129- // BOOST_CHECK(TestSerializationRoundtrip(snapshot1));
126+ BOOST_CHECK (TestSerializationRoundtrip (snapshot1));
130127
131128 // Test with non-empty active members but empty skip list
132129 CQuorumSnapshot snapshot2 ({true , false , true }, MODE_NO_SKIPPING, {});
133- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
134- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
135- // BOOST_CHECK(TestSerializationRoundtrip(snapshot2));
130+ BOOST_CHECK (TestSerializationRoundtrip (snapshot2));
136131}
137132
138133BOOST_AUTO_TEST_CASE (quorum_snapshot_bit_serialization_test)
@@ -141,32 +136,24 @@ BOOST_AUTO_TEST_CASE(quorum_snapshot_bit_serialization_test)
141136
142137 // Test single bit
143138 CQuorumSnapshot snapshot1 ({true }, MODE_NO_SKIPPING, {});
144- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
145- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
146- // BOOST_CHECK(TestSerializationRoundtrip(snapshot1));
139+ BOOST_CHECK (TestSerializationRoundtrip (snapshot1));
147140
148141 // Test 8 bits (full byte)
149142 CQuorumSnapshot snapshot8 (std::vector<bool >(8 , true ), MODE_NO_SKIPPING, {});
150- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
151- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
152- // BOOST_CHECK(TestSerializationRoundtrip(snapshot8));
143+ BOOST_CHECK (TestSerializationRoundtrip (snapshot8));
153144
154145 // Test 9 bits (more than one byte)
155146 CQuorumSnapshot snapshot9 (std::vector<bool >(9 , false ), MODE_NO_SKIPPING, {});
156147 snapshot9.activeQuorumMembers [8 ] = true ; // Set last bit
157- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
158- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
159- // BOOST_CHECK(TestSerializationRoundtrip(snapshot9));
148+ BOOST_CHECK (TestSerializationRoundtrip (snapshot9));
160149
161150 // Test alternating pattern
162151 std::vector<bool > alternating (16 );
163152 for (size_t i = 0 ; i < alternating.size (); i++) {
164153 alternating[i] = (i % 2 == 0 );
165154 }
166155 CQuorumSnapshot snapshotAlt (alternating, MODE_NO_SKIPPING, {});
167- // TODO: See above - custom bit vector serialization prevents byte-identical roundtrip
168- // TODO: Enable serialization roundtrip test once CQuorumSnapshot serialization is fixed
169- // BOOST_CHECK(TestSerializationRoundtrip(snapshotAlt));
156+ BOOST_CHECK (TestSerializationRoundtrip (snapshotAlt));
170157}
171158
172159BOOST_AUTO_TEST_CASE (quorum_rotation_info_construction_test)
@@ -175,8 +162,8 @@ BOOST_AUTO_TEST_CASE(quorum_rotation_info_construction_test)
175162
176163 // Test default state
177164 BOOST_CHECK (!rotInfo.extraShare );
178- BOOST_CHECK (! rotInfo.quorumSnapshotAtHMinus4C . has_value ( ));
179- BOOST_CHECK (! rotInfo.mnListDiffAtHMinus4C . has_value ( ));
165+ BOOST_CHECK_EQUAL (:: SerializeHash ( rotInfo.quorumSnapshotAtHMinus4C ), :: SerializeHash ( CQuorumSnapshot () ));
166+ BOOST_CHECK_EQUAL (:: SerializeHash ( rotInfo.mnListDiffAtHMinus4C ), :: SerializeHash ( CSimplifiedMNListDiff () ));
180167 BOOST_CHECK (rotInfo.lastCommitmentPerIndex .empty ());
181168 BOOST_CHECK (rotInfo.quorumSnapshotList .empty ());
182169 BOOST_CHECK (rotInfo.mnListDiffList .empty ());
@@ -185,7 +172,7 @@ BOOST_AUTO_TEST_CASE(quorum_rotation_info_construction_test)
185172// Note: CQuorumRotationInfo serialization requires complex setup
186173// This is better tested in functional tests
187174
188- BOOST_AUTO_TEST_CASE (get_quorum_rotation_info_test )
175+ BOOST_AUTO_TEST_CASE (get_quorum_rotation_info_serialization_test )
189176{
190177 CGetQuorumRotationInfo getInfo;
191178
@@ -194,19 +181,46 @@ BOOST_AUTO_TEST_CASE(get_quorum_rotation_info_test)
194181 getInfo.blockRequestHash = GetTestBlockHash (100 );
195182 getInfo.extraShare = true ;
196183
197- // TODO: CGetQuorumRotationInfo serialization test disabled - uses standard SERIALIZE_METHODS
198- // but may have issues with empty vectors. Should investigate and re-enable.
199- // TODO: Enable serialization roundtrip test once CGetQuorumsBaseBlockInfo serialization is fixed
200- // BOOST_CHECK(TestSerializationRoundtrip(getInfo));
184+ // Test serialization
185+ BOOST_CHECK (TestSerializationRoundtrip (getInfo));
201186
202187 // Test with empty base block hashes
203188 CGetQuorumRotationInfo emptyInfo;
204189 emptyInfo.blockRequestHash = GetTestBlockHash (200 );
205190 emptyInfo.extraShare = false ;
206191
207- // TODO: See above - investigate serialization issues with empty base block hashes
208- // TODO: Enable serialization roundtrip test once CGetQuorumsBaseBlockInfo serialization is fixed
209- // BOOST_CHECK(TestSerializationRoundtrip(emptyInfo));
192+ BOOST_CHECK (TestSerializationRoundtrip (emptyInfo));
193+ }
194+
195+ BOOST_AUTO_TEST_CASE (quorum_rotation_info_serialization_test)
196+ {
197+ // Note: mnListDiff{smth} testing requires proper CSimplifiedMNListDiff setup
198+ // which is complex and better tested in functional tests
199+
200+ // Test CQuorumRotationInfo serialization with various optional field combinations
201+ CQuorumRotationInfo rotInfo;
202+
203+ // Set up basic required fields
204+ rotInfo.quorumSnapshotAtHMinusC = CQuorumSnapshot ({true , false , true }, MODE_SKIPPING_ENTRIES, {1 , 2 });
205+ rotInfo.quorumSnapshotAtHMinus2C = CQuorumSnapshot ({false , true , false }, MODE_NO_SKIPPING, {});
206+ rotInfo.quorumSnapshotAtHMinus3C = CQuorumSnapshot ({true , true , false }, MODE_ALL_SKIPPED, {3 });
207+
208+ // Test without extraShare
209+ rotInfo.extraShare = false ;
210+ BOOST_CHECK (TestSerializationRoundtrip (rotInfo));
211+
212+ // Test with extraShare but uninitialized optional fields
213+ rotInfo.extraShare = true ;
214+ BOOST_CHECK (TestSerializationRoundtrip (rotInfo));
215+
216+ // Test with extraShare and initialized snapshot
217+ rotInfo.quorumSnapshotAtHMinus4C = CQuorumSnapshot ({false , false , true }, MODE_SKIPPING_ENTRIES, {4 , 5 , 6 });
218+ BOOST_CHECK (TestSerializationRoundtrip (rotInfo));
219+
220+ CFinalCommitment commitment{GetLLMQParams (Consensus::LLMQType::LLMQ_TEST), uint256::ONE};
221+ rotInfo.lastCommitmentPerIndex .push_back (commitment);
222+ rotInfo.quorumSnapshotList .push_back (CQuorumSnapshot ({false , false , true }, MODE_SKIPPING_ENTRIES, {7 , 8 }));
223+ BOOST_CHECK (TestSerializationRoundtrip (rotInfo));
210224}
211225
212226BOOST_AUTO_TEST_CASE (quorum_snapshot_json_test)
0 commit comments