MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BuildRequestOrderTest

Method BuildRequestOrderTest

src/test/txrequest_tests.cpp:474–502  ·  view source on GitHub ↗

Add to scenario a test with one peer announcing two transactions, to verify they are * fetched in announcement order. * * config is an integer in [0, 4) inclusive, and selects the variant of the test. */

Source from the content-addressed store, hash-verified

472 * config is an integer in [0, 4) inclusive, and selects the variant of the test.
473 */
474void TxRequestTest::BuildRequestOrderTest(Scenario& scenario, int config)
475{
476 scenario.SetTestName(strprintf("RequestOrder(config=%i)", config));
477
478 auto peer = scenario.NewPeer();
479 auto gtxid1 = scenario.NewGTxid();
480 auto gtxid2 = scenario.NewGTxid();
481
482 auto reqtime2 = scenario.Now() + RandomTime8s();
483 auto reqtime1 = reqtime2 + RandomTime8s();
484
485 scenario.ReceivedInv(peer, gtxid1, config & 1, reqtime1);
486 // Simulate time going backwards by giving the second announcement an earlier reqtime.
487 scenario.ReceivedInv(peer, gtxid2, config & 2, reqtime2);
488
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);
496 // Even with time going backwards in between announcements, the return value of GetRequestable is in
497 // announcement order.
498 scenario.Check(peer, {gtxid1, gtxid2}, 2, 0, 0, "o4");
499
500 scenario.DisconnectedPeer(peer);
501 scenario.Check(peer, {}, 0, 0, 0, "o5");
502}
503
504/** Add to scenario a test that verifies behavior related to both txid and wtxid with the same
505 * hash being announced.

Callers

nothing calls this directly

Calls 8

SetTestNameMethod · 0.80
NewPeerMethod · 0.80
NewGTxidMethod · 0.80
NowMethod · 0.45
ReceivedInvMethod · 0.45
AdvanceTimeMethod · 0.45
CheckMethod · 0.45
DisconnectedPeerMethod · 0.45

Tested by

no test coverage detected