MCPcopy Create free account
hub / github.com/ElementsProject/elements / BuildRequestOrderTest

Function BuildRequestOrderTest

src/test/txrequest_tests.cpp:455–483  ·  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

453 * config is an integer in [0, 4) inclusive, and selects the variant of the test.
454 */
455void BuildRequestOrderTest(Scenario& scenario, int config)
456{
457 scenario.SetTestName(strprintf("RequestOrder(config=%i)", config));
458
459 auto peer = scenario.NewPeer();
460 auto gtxid1 = scenario.NewGTxid();
461 auto gtxid2 = scenario.NewGTxid();
462
463 auto reqtime2 = scenario.Now() + RandomTime8s();
464 auto reqtime1 = reqtime2 + RandomTime8s();
465
466 scenario.ReceivedInv(peer, gtxid1, config & 1, reqtime1);
467 // Simulate time going backwards by giving the second announcement an earlier reqtime.
468 scenario.ReceivedInv(peer, gtxid2, config & 2, reqtime2);
469
470 scenario.AdvanceTime(reqtime2 - MICROSECOND - scenario.Now());
471 scenario.Check(peer, {}, 2, 0, 0, "o1");
472 scenario.AdvanceTime(MICROSECOND);
473 scenario.Check(peer, {gtxid2}, 2, 0, 0, "o2");
474 scenario.AdvanceTime(reqtime1 - MICROSECOND - scenario.Now());
475 scenario.Check(peer, {gtxid2}, 2, 0, 0, "o3");
476 scenario.AdvanceTime(MICROSECOND);
477 // Even with time going backwards in between announcements, the return value of GetRequestable is in
478 // announcement order.
479 scenario.Check(peer, {gtxid1, gtxid2}, 2, 0, 0, "o4");
480
481 scenario.DisconnectedPeer(peer);
482 scenario.Check(peer, {}, 0, 0, 0, "o5");
483}
484
485/** Add to scenario a test that verifies behavior related to both txid and wtxid with the same
486 * hash being announced.

Callers 1

TestInterleavedScenariosFunction · 0.85

Calls 9

RandomTime8sFunction · 0.85
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