16#include <boost/test/unit_test.hpp>
23 std::chrono::microseconds RandomTime8s();
24 std::chrono::microseconds RandomTime1y();
25 void BuildSingleTest(Scenario& scenario,
int config);
26 void BuildPriorityTest(Scenario& scenario,
int config);
27 void BuildBigPriorityTest(Scenario& scenario,
int peers);
28 void BuildRequestOrderTest(Scenario& scenario,
int config);
29 void BuildWtxidTest(Scenario& scenario,
int config);
30 void BuildTimeBackwardsTest(Scenario& scenario);
31 void BuildWeirdRequestsTest(Scenario& scenario);
32 void TestInterleavedScenarios();
35constexpr std::chrono::microseconds MIN_TIME = std::chrono::microseconds::min();
36constexpr std::chrono::microseconds MAX_TIME = std::chrono::microseconds::max();
37constexpr std::chrono::microseconds MICROSECOND = std::chrono::microseconds{1};
38constexpr std::chrono::microseconds NO_TIME = std::chrono::microseconds{0};
41using Action = std::pair<std::chrono::microseconds, std::function<void()>>;
53 std::vector<Action> actions;
56 std::set<NodeId> peerset;
59 std::set<uint256> txhashset;
64 std::multiset<std::pair<NodeId, GenTxid>> expired;
67std::chrono::microseconds TxRequestTest::RandomTime8s() {
return std::chrono::microseconds{1 + m_rng.randbits(23)}; }
68std::chrono::microseconds TxRequestTest::RandomTime1y() {
return std::chrono::microseconds{1 + m_rng.randbits(45)}; }
83 std::chrono::microseconds m_now;
84 std::string m_testname;
87 Scenario(
FastRandomContext& rng, Runner& runner, std::chrono::microseconds starttime) : m_rng(rng), m_runner(runner), m_now(starttime) {}
90 void SetTestName(std::string testname)
92 m_testname = std::move(testname);
96 void AdvanceTime(std::chrono::microseconds amount)
98 assert(amount.count() >= 0);
103 void ForgetTxHash(
const uint256& txhash)
105 auto& runner = m_runner;
106 runner.actions.emplace_back(m_now, [=, &runner]() {
107 runner.txrequest.ForgetTxHash(txhash);
108 runner.txrequest.SanityCheck();
113 void ReceivedInv(
NodeId peer,
const GenTxid& gtxid,
bool pref, std::chrono::microseconds reqtime)
115 auto& runner = m_runner;
116 runner.actions.emplace_back(m_now, [=, &runner]() {
117 runner.txrequest.ReceivedInv(peer, gtxid, pref, reqtime);
118 runner.txrequest.SanityCheck();
123 void DisconnectedPeer(
NodeId peer)
125 auto& runner = m_runner;
126 runner.actions.emplace_back(m_now, [=, &runner]() {
127 runner.txrequest.DisconnectedPeer(peer);
128 runner.txrequest.SanityCheck();
133 void RequestedTx(
NodeId peer,
const uint256& txhash, std::chrono::microseconds exptime)
135 auto& runner = m_runner;
136 runner.actions.emplace_back(m_now, [=, &runner]() {
137 runner.txrequest.RequestedTx(peer, txhash, exptime);
138 runner.txrequest.SanityCheck();
145 auto& runner = m_runner;
146 runner.actions.emplace_back(m_now, [=, &runner]() {
147 runner.txrequest.ReceivedResponse(peer, txhash);
148 runner.txrequest.SanityCheck();
163 void Check(
NodeId peer,
const std::vector<GenTxid>& expected,
size_t candidates,
size_t inflight,
164 size_t completed,
const std::string& checkname,
165 std::chrono::microseconds offset = std::chrono::microseconds{0})
167 const auto comment = m_testname +
" " + checkname;
168 auto& runner = m_runner;
169 const auto now = m_now;
170 assert(offset.count() <= 0);
171 runner.actions.emplace_back(m_now, [=, &runner]() {
172 std::vector<std::pair<NodeId, GenTxid>> expired_now;
173 auto ret = runner.txrequest.GetRequestable(peer, now + offset, &expired_now);
174 for (
const auto& entry : expired_now) {
175 runner.expired.insert(entry);
177 runner.txrequest.SanityCheck();
178 runner.txrequest.PostGetRequestableSanityCheck(now + offset);
179 size_t total = candidates + inflight + completed;
180 size_t real_total = runner.txrequest.Count(peer);
181 size_t real_candidates = runner.txrequest.CountCandidates(peer);
182 size_t real_inflight = runner.txrequest.CountInFlight(peer);
183 BOOST_CHECK_MESSAGE(real_total == total,
strprintf(
"[%s] total %i (%i expected)", comment, real_total, total));
184 BOOST_CHECK_MESSAGE(real_inflight == inflight,
strprintf(
"[%s] inflight %i (%i expected)", comment, real_inflight, inflight));
185 BOOST_CHECK_MESSAGE(real_candidates == candidates,
strprintf(
"[%s] candidates %i (%i expected)", comment, real_candidates, candidates));
186 BOOST_CHECK_MESSAGE(
ret == expected,
strprintf(
"[%s] mismatching requestables", comment));
196 const auto& testname = m_testname;
197 auto& runner = m_runner;
198 runner.actions.emplace_back(m_now, [=, &runner]() {
199 auto it = runner.expired.find(std::pair<NodeId, GenTxid>{peer, gtxid});
200 BOOST_CHECK_MESSAGE(it != runner.expired.end(),
"[" + testname +
"] missing expiration");
201 if (it != runner.expired.end()) runner.expired.erase(it);
213 uint256 NewTxHash(
const std::vector<std::vector<NodeId>>& orders = {})
220 for (
const auto& order : orders) {
221 for (
size_t pos = 1; pos < order.size(); ++pos) {
222 uint64_t prio_prev = m_runner.txrequest.ComputePriority(
ret, order[pos - 1],
true);
223 uint64_t prio_cur = m_runner.txrequest.ComputePriority(
ret, order[pos],
true);
224 if (prio_prev <= prio_cur) {
232 ok = m_runner.txhashset.insert(
ret).second;
239 GenTxid NewGTxid(
const std::vector<std::vector<NodeId>>& orders = {})
241 const uint256 txhash{NewTxHash(orders)};
253 ok = m_runner.peerset.insert(
ret).second;
258 std::chrono::microseconds
Now()
const {
return m_now; }
265void TxRequestTest::BuildSingleTest(Scenario& scenario,
int config)
267 auto peer = scenario.NewPeer();
268 auto gtxid = scenario.NewGTxid();
269 bool immediate = config & 1;
270 bool preferred = config & 2;
271 auto delay = immediate ? NO_TIME : RandomTime8s();
273 scenario.SetTestName(
strprintf(
"Single(config=%i)", config));
276 scenario.ReceivedInv(peer, gtxid, preferred, immediate ? MIN_TIME : scenario.Now() + delay);
278 scenario.Check(peer, {gtxid}, 1, 0, 0,
"s1");
280 scenario.Check(peer, {}, 1, 0, 0,
"s2");
281 scenario.AdvanceTime(delay - MICROSECOND);
282 scenario.Check(peer, {}, 1, 0, 0,
"s3");
283 scenario.AdvanceTime(MICROSECOND);
284 scenario.Check(peer, {gtxid}, 1, 0, 0,
"s4");
288 scenario.AdvanceTime(RandomTime8s());
289 auto expiry = RandomTime8s();
290 scenario.Check(peer, {gtxid}, 1, 0, 0,
"s5");
291 scenario.RequestedTx(peer, gtxid.
ToUint256(), scenario.Now() + expiry);
292 scenario.Check(peer, {}, 0, 1, 0,
"s6");
294 if ((config >> 3) == 1) {
295 scenario.AdvanceTime(expiry - MICROSECOND);
296 scenario.Check(peer, {}, 0, 1, 0,
"s7");
297 scenario.AdvanceTime(MICROSECOND);
298 scenario.Check(peer, {}, 0, 0, 0,
"s8");
299 scenario.CheckExpired(peer, gtxid);
302 scenario.AdvanceTime(std::chrono::microseconds{m_rng.
randrange(expiry.count())});
303 scenario.Check(peer, {}, 0, 1, 0,
"s9");
304 if ((config >> 3) == 3) {
305 scenario.ReceivedResponse(peer, gtxid.
ToUint256());
306 scenario.Check(peer, {}, 0, 0, 0,
"s10");
313 scenario.DisconnectedPeer(peer);
315 scenario.ForgetTxHash(gtxid.
ToUint256());
317 scenario.Check(peer, {}, 0, 0, 0,
"s11");
325void TxRequestTest::BuildPriorityTest(Scenario& scenario,
int config)
327 scenario.SetTestName(
strprintf(
"Priority(config=%i)", config));
330 auto peer1 = scenario.NewPeer(), peer2 = scenario.NewPeer();
333 bool prio1 = config & 1;
334 auto gtxid = prio1 ? scenario.NewGTxid({{peer1, peer2}}) : scenario.NewGTxid({{peer2, peer1}});
335 bool pref1 = config & 2, pref2 = config & 4;
337 scenario.ReceivedInv(peer1, gtxid, pref1, MIN_TIME);
338 scenario.Check(peer1, {gtxid}, 1, 0, 0,
"p1");
340 scenario.AdvanceTime(RandomTime8s());
341 scenario.Check(peer1, {gtxid}, 1, 0, 0,
"p2");
344 scenario.ReceivedInv(peer2, gtxid, pref2, MIN_TIME);
351 (pref1 == pref2 && !prio1);
352 NodeId priopeer = stage2_prio ? peer2 : peer1, otherpeer = stage2_prio ? peer1 : peer2;
353 scenario.Check(otherpeer, {}, 1, 0, 0,
"p3");
354 scenario.Check(priopeer, {gtxid}, 1, 0, 0,
"p4");
355 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
356 scenario.Check(otherpeer, {}, 1, 0, 0,
"p5");
357 scenario.Check(priopeer, {gtxid}, 1, 0, 0,
"p6");
361 scenario.RequestedTx(priopeer, gtxid.
ToUint256(), MAX_TIME);
362 scenario.Check(priopeer, {}, 0, 1, 0,
"p7");
363 scenario.Check(otherpeer, {}, 1, 0, 0,
"p8");
364 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
369 scenario.DisconnectedPeer(priopeer);
371 scenario.ReceivedResponse(priopeer, gtxid.
ToUint256());
373 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
374 scenario.Check(priopeer, {}, 0, 0, !(config & 16),
"p8");
375 scenario.Check(otherpeer, {gtxid}, 1, 0, 0,
"p9");
376 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
379 scenario.DisconnectedPeer(otherpeer);
380 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
381 scenario.Check(peer1, {}, 0, 0, 0,
"p10");
382 scenario.Check(peer2, {}, 0, 0, 0,
"p11");
387void TxRequestTest::BuildBigPriorityTest(Scenario& scenario,
int peers)
389 scenario.SetTestName(
strprintf(
"BigPriority(peers=%i)", peers));
392 std::map<NodeId, bool> preferred;
393 std::vector<NodeId> pref_peers, npref_peers;
394 int num_pref = m_rng.
randrange(peers + 1) ;
395 int num_npref = peers - num_pref;
396 for (
int i = 0; i < num_pref; ++i) {
397 pref_peers.push_back(scenario.NewPeer());
398 preferred[pref_peers.back()] =
true;
400 for (
int i = 0; i < num_npref; ++i) {
401 npref_peers.push_back(scenario.NewPeer());
402 preferred[npref_peers.back()] =
false;
405 std::vector<NodeId> request_order;
406 request_order.reserve(num_pref + num_npref);
407 for (
int i = 0; i < num_pref; ++i) request_order.push_back(pref_peers[i]);
408 for (
int i = 0; i < num_npref; ++i) request_order.push_back(npref_peers[i]);
411 std::vector<NodeId> announce_order = request_order;
412 std::shuffle(announce_order.begin(), announce_order.end(), m_rng);
416 auto gtxid = scenario.NewGTxid({pref_peers, npref_peers});
420 std::map<NodeId, std::chrono::microseconds> reqtimes;
421 auto reqtime = scenario.Now();
422 for (
int i = peers - 1; i >= 0; --i) {
423 reqtime += RandomTime8s();
424 reqtimes[request_order[i]] = reqtime;
428 for (
const auto peer : announce_order) {
429 scenario.ReceivedInv(peer, gtxid, preferred[peer], reqtimes[peer]);
431 for (
const auto peer : announce_order) {
432 scenario.Check(peer, {}, 1, 0, 0,
"b1");
437 for (
int i = peers - 1; i >= 0; --i) {
438 scenario.AdvanceTime(reqtimes[request_order[i]] - scenario.Now() - MICROSECOND);
439 scenario.Check(request_order[i], {}, 1, 0, 0,
"b2");
440 scenario.AdvanceTime(MICROSECOND);
441 scenario.Check(request_order[i], {gtxid}, 1, 0, 0,
"b3");
446 for (
int i = 0; i < peers; ++i) {
447 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
448 const int pos = m_rng.
randrange(request_order.size());
449 const auto peer = request_order[pos];
450 request_order.erase(request_order.begin() + pos);
452 scenario.DisconnectedPeer(peer);
453 scenario.Check(peer, {}, 0, 0, 0,
"b4");
455 scenario.ReceivedResponse(peer, gtxid.
ToUint256());
456 scenario.Check(peer, {}, 0, 0, request_order.size() > 0,
"b5");
458 if (request_order.size()) {
459 scenario.Check(request_order[0], {gtxid}, 1, 0, 0,
"b6");
464 for (
const auto peer : announce_order) {
465 scenario.Check(peer, {}, 0, 0, 0,
"b7");
474void TxRequestTest::BuildRequestOrderTest(Scenario& scenario,
int config)
476 scenario.SetTestName(
strprintf(
"RequestOrder(config=%i)", config));
478 auto peer = scenario.NewPeer();
479 auto gtxid1 = scenario.NewGTxid();
480 auto gtxid2 = scenario.NewGTxid();
482 auto reqtime2 = scenario.Now() + RandomTime8s();
483 auto reqtime1 = reqtime2 + RandomTime8s();
485 scenario.ReceivedInv(peer, gtxid1, config & 1, reqtime1);
487 scenario.ReceivedInv(peer, gtxid2, config & 2, reqtime2);
489 scenario.AdvanceTime(reqtime2 - MICROSECOND - scenario.Now());
490 scenario.Check(peer, {}, 2, 0, 0,
"o1");
491 scenario.AdvanceTime(MICROSECOND);
492 scenario.Check(peer, {gtxid2}, 2, 0, 0,
"o2");
493 scenario.AdvanceTime(reqtime1 - MICROSECOND - scenario.Now());
494 scenario.Check(peer, {gtxid2}, 2, 0, 0,
"o3");
495 scenario.AdvanceTime(MICROSECOND);
498 scenario.Check(peer, {gtxid1, gtxid2}, 2, 0, 0,
"o4");
500 scenario.DisconnectedPeer(peer);
501 scenario.Check(peer, {}, 0, 0, 0,
"o5");
509void TxRequestTest::BuildWtxidTest(Scenario& scenario,
int config)
511 scenario.SetTestName(
strprintf(
"Wtxid(config=%i)", config));
513 auto peerT = scenario.NewPeer();
514 auto peerW = scenario.NewPeer();
515 auto txhash = scenario.NewTxHash();
519 auto reqtimeT = m_rng.
randbool() ? MIN_TIME : scenario.Now() + RandomTime8s();
520 auto reqtimeW = m_rng.
randbool() ? MIN_TIME : scenario.Now() + RandomTime8s();
524 scenario.ReceivedInv(peerT, txid, config & 2, reqtimeT);
525 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
526 scenario.ReceivedInv(peerW, wtxid, !(config & 2), reqtimeW);
528 scenario.ReceivedInv(peerW, wtxid, !(config & 2), reqtimeW);
529 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
530 scenario.ReceivedInv(peerT, txid, config & 2, reqtimeT);
535 auto max_reqtime = std::max(reqtimeT, reqtimeW);
536 if (max_reqtime > scenario.Now()) scenario.AdvanceTime(max_reqtime - scenario.Now());
538 scenario.Check(peerT, {txid}, 1, 0, 0,
"w1");
539 scenario.Check(peerW, {}, 1, 0, 0,
"w2");
541 scenario.Check(peerT, {}, 1, 0, 0,
"w3");
542 scenario.Check(peerW, {wtxid}, 1, 0, 0,
"w4");
546 auto expiry = RandomTime8s();
548 scenario.RequestedTx(peerT, txid.ToUint256(), scenario.Now() + expiry);
549 scenario.Check(peerT, {}, 0, 1, 0,
"w5");
550 scenario.Check(peerW, {}, 1, 0, 0,
"w6");
552 scenario.RequestedTx(peerW, wtxid.ToUint256(), scenario.Now() + expiry);
553 scenario.Check(peerT, {}, 1, 0, 0,
"w7");
554 scenario.Check(peerW, {}, 0, 1, 0,
"w8");
559 scenario.AdvanceTime(expiry);
561 scenario.Check(peerT, {}, 0, 0, 1,
"w9");
562 scenario.Check(peerW, {wtxid}, 1, 0, 0,
"w10");
563 scenario.CheckExpired(peerT, txid);
565 scenario.Check(peerT, {txid}, 1, 0, 0,
"w11");
566 scenario.Check(peerW, {}, 0, 0, 1,
"w12");
567 scenario.CheckExpired(peerW, wtxid);
572 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
573 scenario.ForgetTxHash(txhash);
574 scenario.Check(peerT, {}, 0, 0, 0,
"w13");
575 scenario.Check(peerW, {}, 0, 0, 0,
"w14");
579void TxRequestTest::BuildTimeBackwardsTest(Scenario& scenario)
581 auto peer1 = scenario.NewPeer();
582 auto peer2 = scenario.NewPeer();
583 auto gtxid = scenario.NewGTxid({{peer1, peer2}});
586 auto reqtime = scenario.Now() + RandomTime8s();
587 scenario.ReceivedInv(peer2, gtxid,
true, reqtime);
588 scenario.Check(peer2, {}, 1, 0, 0,
"r1");
589 scenario.AdvanceTime(reqtime - scenario.Now());
590 scenario.Check(peer2, {gtxid}, 1, 0, 0,
"r2");
592 scenario.Check(peer2, {}, 1, 0, 0,
"r3", -MICROSECOND);
594 scenario.Check(peer2, {gtxid}, 1, 0, 0,
"r4");
597 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
598 scenario.ReceivedInv(peer1, gtxid,
true, MAX_TIME);
599 scenario.Check(peer2, {gtxid}, 1, 0, 0,
"r5");
600 scenario.Check(peer1, {}, 1, 0, 0,
"r6");
603 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
604 auto expiry = scenario.Now() + RandomTime8s();
605 scenario.RequestedTx(peer1, gtxid.
ToUint256(), expiry);
606 scenario.Check(peer1, {}, 0, 1, 0,
"r7");
607 scenario.Check(peer2, {}, 1, 0, 0,
"r8");
610 scenario.AdvanceTime(expiry - scenario.Now());
611 scenario.Check(peer1, {}, 0, 0, 1,
"r9");
612 scenario.Check(peer2, {gtxid}, 1, 0, 0,
"r10");
613 scenario.CheckExpired(peer1, gtxid);
614 scenario.Check(peer1, {}, 0, 0, 1,
"r11", -MICROSECOND);
615 scenario.Check(peer2, {gtxid}, 1, 0, 0,
"r12", -MICROSECOND);
618 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
619 scenario.DisconnectedPeer(peer2);
620 scenario.Check(peer1, {}, 0, 0, 0,
"r13");
621 scenario.Check(peer2, {}, 0, 0, 0,
"r14");
625void TxRequestTest::BuildWeirdRequestsTest(Scenario& scenario)
627 auto peer1 = scenario.NewPeer();
628 auto peer2 = scenario.NewPeer();
629 auto gtxid1 = scenario.NewGTxid({{peer1, peer2}});
630 auto gtxid2 = scenario.NewGTxid({{peer2, peer1}});
633 scenario.ReceivedInv(peer1, gtxid1,
true, MIN_TIME);
634 scenario.Check(peer1, {gtxid1}, 1, 0, 0,
"q1");
637 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
638 scenario.ReceivedInv(peer2, gtxid2,
true, MIN_TIME);
639 scenario.Check(peer1, {gtxid1}, 1, 0, 0,
"q2");
640 scenario.Check(peer2, {gtxid2}, 1, 0, 0,
"q3");
643 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
644 scenario.RequestedTx(peer1, gtxid2.ToUint256(), MAX_TIME);
645 scenario.Check(peer1, {gtxid1}, 1, 0, 0,
"q4");
646 scenario.Check(peer2, {gtxid2}, 1, 0, 0,
"q5");
649 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
650 auto expiryA = scenario.Now() + RandomTime8s();
651 scenario.RequestedTx(peer1, gtxid1.ToUint256(), expiryA);
652 scenario.Check(peer1, {}, 0, 1, 0,
"q6");
653 scenario.Check(peer2, {gtxid2}, 1, 0, 0,
"q7");
656 auto expiryB = expiryA + RandomTime8s();
657 scenario.RequestedTx(peer1, gtxid1.ToUint256(), expiryB);
658 scenario.Check(peer1, {}, 0, 1, 0,
"q8");
659 scenario.Check(peer2, {gtxid2}, 1, 0, 0,
"q9");
662 scenario.ReceivedInv(peer2, gtxid1,
true, MIN_TIME);
663 scenario.Check(peer1, {}, 0, 1, 0,
"q10");
664 scenario.Check(peer2, {gtxid2}, 2, 0, 0,
"q11");
667 scenario.AdvanceTime(expiryA - scenario.Now());
668 scenario.Check(peer1, {}, 0, 0, 1,
"q12");
669 scenario.Check(peer2, {gtxid2, gtxid1}, 2, 0, 0,
"q13");
670 scenario.CheckExpired(peer1, gtxid1);
673 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
674 scenario.RequestedTx(peer1, gtxid1.ToUint256(), MAX_TIME);
675 scenario.Check(peer1, {}, 0, 0, 1,
"q14");
676 scenario.Check(peer2, {gtxid2, gtxid1}, 2, 0, 0,
"q15");
679 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
680 scenario.ReceivedInv(peer1, gtxid2,
true, MIN_TIME);
681 scenario.Check(peer1, {}, 1, 0, 1,
"q16");
682 scenario.Check(peer2, {gtxid2, gtxid1}, 2, 0, 0,
"q17");
685 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
686 scenario.RequestedTx(peer1, gtxid2.ToUint256(), MAX_TIME);
687 scenario.Check(peer1, {}, 0, 1, 1,
"q18");
688 scenario.Check(peer2, {gtxid1}, 2, 0, 0,
"q19");
691 if (m_rng.
randbool()) scenario.AdvanceTime(RandomTime8s());
692 scenario.RequestedTx(peer2, gtxid2.ToUint256(), MAX_TIME);
693 scenario.Check(peer1, {}, 0, 0, 2,
"q20");
694 scenario.Check(peer2, {gtxid1}, 1, 1, 0,
"q21");
697 scenario.DisconnectedPeer(peer2);
698 scenario.Check(peer1, {}, 0, 0, 0,
"q22");
699 scenario.Check(peer2, {}, 0, 0, 0,
"q23");
702void TxRequestTest::TestInterleavedScenarios()
705 std::vector<std::function<void(Scenario&)>> builders;
707 for (
int n = 0; n < 64; ++n) {
708 builders.emplace_back([
this, n](Scenario& scenario) { BuildWtxidTest(scenario, n); });
709 builders.emplace_back([
this, n](Scenario& scenario) { BuildRequestOrderTest(scenario, n & 3); });
710 builders.emplace_back([
this, n](Scenario& scenario) { BuildSingleTest(scenario, n & 31); });
711 builders.emplace_back([
this, n](Scenario& scenario) { BuildPriorityTest(scenario, n & 31); });
712 builders.emplace_back([
this, n](Scenario& scenario) { BuildBigPriorityTest(scenario, (n & 7) + 1); });
713 builders.emplace_back([
this](Scenario& scenario) { BuildTimeBackwardsTest(scenario); });
714 builders.emplace_back([
this](Scenario& scenario) { BuildWeirdRequestsTest(scenario); });
717 std::shuffle(builders.begin(), builders.end(), m_rng);
720 auto starttime = RandomTime1y();
722 while (builders.size()) {
725 auto scenario_start = starttime + RandomTime8s() + RandomTime8s() + RandomTime8s();
726 Scenario scenario(m_rng, runner, scenario_start);
727 for (
int j = 0; builders.size() && j < 10; ++j) {
728 builders.back()(scenario);
735 std::stable_sort(runner.actions.begin(), runner.actions.end(), [](
const Action& a1,
const Action& a2) {
736 return a1.first < a2.first;
740 for (
auto& action : runner.actions) {
754 for (
int i = 0; i < 5; ++i) {
755 TestInterleavedScenarios();
const uint256 & ToUint256() const LIFETIMEBOUND
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
uint256 rand256() noexcept
generate a random uint256.
bool randbool() noexcept
Generate a random boolean.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Data structure to keep track of, and schedule, transaction downloads from peers.
static transaction_identifier FromUint256(const uint256 &id)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
BOOST_AUTO_TEST_CASE(TxRequestTest)
T Now()
Return the current time point cast to the given precision.