Skip to content

Commit 747d8e6

Browse files
committed
Add get_candidate_hashes tests, use constexpr block hashes.
1 parent e2d652a commit 747d8e6

1 file changed

Lines changed: 106 additions & 32 deletions

File tree

test/query/height.cpp

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ BOOST_AUTO_TEST_CASE(query_height__get_candidate_hashes__gapped__expected)
4848
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
4949
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
5050
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
51-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash())));
52-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2.hash())));
53-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash())));
51+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1_hash)));
52+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2_hash)));
53+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3_hash)));
5454
const auto locator = query.get_candidate_hashes({ 0, 1, 3, 4 });
5555
BOOST_REQUIRE_EQUAL(locator.size(), 3u);
56-
BOOST_REQUIRE_EQUAL(locator[0], test::genesis.hash());
57-
BOOST_REQUIRE_EQUAL(locator[1], test::block1.hash());
58-
BOOST_REQUIRE_EQUAL(locator[2], test::block3.hash());
56+
BOOST_REQUIRE_EQUAL(locator[0], test::block0_hash);
57+
BOOST_REQUIRE_EQUAL(locator[1], test::block1_hash);
58+
BOOST_REQUIRE_EQUAL(locator[2], test::block3_hash);
5959
}
6060

6161
// get_confirmed_hashes1
@@ -82,14 +82,14 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_hashes1__gapped__expected)
8282
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
8383
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
8484
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
85-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
86-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
87-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()), false));
85+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
86+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
87+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3_hash), false));
8888
const auto locator = query.get_confirmed_hashes({ 0, 1, 3, 4 });
8989
BOOST_REQUIRE_EQUAL(locator.size(), 3u);
90-
BOOST_REQUIRE_EQUAL(locator[0], test::genesis.hash());
91-
BOOST_REQUIRE_EQUAL(locator[1], test::block1.hash());
92-
BOOST_REQUIRE_EQUAL(locator[2], test::block3.hash());
90+
BOOST_REQUIRE_EQUAL(locator[0], test::block0_hash);
91+
BOOST_REQUIRE_EQUAL(locator[1], test::block1_hash);
92+
BOOST_REQUIRE_EQUAL(locator[2], test::block3_hash);
9393
}
9494

9595
// get_confirmed_hashes2
@@ -105,9 +105,9 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_hashes2__various__expected_size
105105
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
106106
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
107107
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
108-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
109-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
110-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()), false));
108+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
109+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
110+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3_hash), false));
111111
BOOST_REQUIRE_EQUAL(query.get_confirmed_hashes(0, 0).size(), 0u);
112112
BOOST_REQUIRE_EQUAL(query.get_confirmed_hashes(0, 1).size(), 1u);
113113
BOOST_REQUIRE_EQUAL(query.get_confirmed_hashes(0, 2).size(), 2u);
@@ -140,15 +140,15 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_hashes2__three__ascending_order
140140
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
141141
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
142142
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
143-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
144-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
145-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3.hash()), false));
143+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
144+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
145+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3_hash), false));
146146

147147
const auto hashes = query.get_confirmed_hashes(0, 3);
148148
BOOST_REQUIRE_EQUAL(hashes.size(), 3);
149-
BOOST_REQUIRE_EQUAL(hashes[0], test::genesis.hash());
150-
BOOST_REQUIRE_EQUAL(hashes[1], test::block1.hash());
151-
BOOST_REQUIRE_EQUAL(hashes[2], test::block2.hash());
149+
BOOST_REQUIRE_EQUAL(hashes[0], test::block0_hash);
150+
BOOST_REQUIRE_EQUAL(hashes[1], test::block1_hash);
151+
BOOST_REQUIRE_EQUAL(hashes[2], test::block2_hash);
152152
}
153153

154154
// get_confirmed_headers
@@ -178,9 +178,9 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_headers__unconfirmeds__empty)
178178
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
179179
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
180180
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
181-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1.hash())));
182-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2.hash())));
183-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash())));
181+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block1_hash)));
182+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block2_hash)));
183+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3_hash)));
184184
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(0, 0).size(), 0u);
185185
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(0, 42).size(), 1u);
186186
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(42, 0).size(), 0u);
@@ -198,9 +198,9 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_headers__confirmeds__expected_s
198198
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
199199
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
200200
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
201-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
202-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
203-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash())));
201+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
202+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
203+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3_hash)));
204204
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(0, 0).size(), 0u);
205205
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(0, 1).size(), 1u);
206206
BOOST_REQUIRE_EQUAL(query.get_confirmed_headers(0, 2).size(), 2u);
@@ -229,14 +229,88 @@ BOOST_AUTO_TEST_CASE(query_height__get_confirmed_headers__confirmeds__expected_h
229229
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
230230
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
231231
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
232-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1.hash()), false));
233-
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2.hash()), false));
234-
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3.hash())));
232+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
233+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
234+
BOOST_REQUIRE(query.push_candidate(query.to_header(test::block3_hash)));
235235

236236
const auto headers = query.get_confirmed_headers(1, 3);
237237
BOOST_REQUIRE_EQUAL(headers.size(), 2u);
238-
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[0]), test::block1.hash());
239-
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[1]), test::block2.hash());
238+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[0]), test::block1_hash);
239+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[1]), test::block2_hash);
240+
}
241+
242+
BOOST_AUTO_TEST_CASE(query_height__get_confirmed_headers__over_top__reduced_count)
243+
{
244+
settings settings{};
245+
settings.path = TEST_DIRECTORY;
246+
test::chunk_store store{ settings };
247+
test::query_accessor query{ store };
248+
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
249+
BOOST_REQUIRE(query.initialize(test::genesis));
250+
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
251+
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
252+
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
253+
BOOST_REQUIRE(query.set(test::block4, test::context, false, false));
254+
BOOST_REQUIRE(query.set(test::block5, test::context, false, false));
255+
BOOST_REQUIRE(query.set(test::block6, test::context, false, false));
256+
BOOST_REQUIRE(query.set(test::block7, test::context, false, false));
257+
BOOST_REQUIRE(query.set(test::block8, test::context, false, false));
258+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
259+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
260+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3_hash), false));
261+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block4_hash), false));
262+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block5_hash), false));
263+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block6_hash), false));
264+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block7_hash), false));
265+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block8_hash), false));
266+
267+
// limit = min(1000, add1(8) - 3) = 6
268+
// last = 3 + sub1(6) = 8
269+
// first = 3
270+
// count = add1(8 - 3) = 6
271+
const auto headers = query.get_confirmed_headers(3, 1000);
272+
BOOST_REQUIRE_EQUAL(headers.size(), 6u);
273+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[0]), test::block3_hash);
274+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[1]), test::block4_hash);
275+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[2]), test::block5_hash);
276+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[3]), test::block6_hash);
277+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[4]), test::block7_hash);
278+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[5]), test::block8_hash);
279+
}
280+
281+
BOOST_AUTO_TEST_CASE(query_height__get_confirmed_headers__under_top__full_count)
282+
{
283+
settings settings{};
284+
settings.path = TEST_DIRECTORY;
285+
test::chunk_store store{ settings };
286+
test::query_accessor query{ store };
287+
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
288+
BOOST_REQUIRE(query.initialize(test::genesis));
289+
BOOST_REQUIRE(query.set(test::block1, test::context, false, false));
290+
BOOST_REQUIRE(query.set(test::block2, test::context, false, false));
291+
BOOST_REQUIRE(query.set(test::block3, test::context, false, false));
292+
BOOST_REQUIRE(query.set(test::block4, test::context, false, false));
293+
BOOST_REQUIRE(query.set(test::block5, test::context, false, false));
294+
BOOST_REQUIRE(query.set(test::block6, test::context, false, false));
295+
BOOST_REQUIRE(query.set(test::block7, test::context, false, false));
296+
BOOST_REQUIRE(query.set(test::block8, test::context, false, false));
297+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block1_hash), false));
298+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block2_hash), false));
299+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block3_hash), false));
300+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block4_hash), false));
301+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block5_hash), false));
302+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block6_hash), false));
303+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block7_hash), false));
304+
BOOST_REQUIRE(query.push_confirmed(query.to_header(test::block8_hash), false));
305+
306+
const auto headers = query.get_confirmed_headers(2, 6);
307+
BOOST_REQUIRE_EQUAL(headers.size(), 6u);
308+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[0]), test::block2_hash);
309+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[1]), test::block3_hash);
310+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[2]), test::block4_hash);
311+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[3]), test::block5_hash);
312+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[4]), test::block6_hash);
313+
BOOST_REQUIRE_EQUAL(query.get_header_key(headers[5]), test::block7_hash);
240314
}
241315

242316
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)