Add to scenario a test that verifies behavior related to both txid and wtxid with the same * hash being announced. * * config is an integer in [0, 4) inclusive, and selects the variant of the test used. */
| 507 | * config is an integer in [0, 4) inclusive, and selects the variant of the test used. |
| 508 | */ |
| 509 | void TxRequestTest::BuildWtxidTest(Scenario& scenario, int config) |
| 510 | { |
| 511 | scenario.SetTestName(strprintf("Wtxid(config=%i)", config)); |
| 512 | |
| 513 | auto peerT = scenario.NewPeer(); |
| 514 | auto peerW = scenario.NewPeer(); |
| 515 | auto txhash = scenario.NewTxHash(); |
| 516 | auto txid{Txid::FromUint256(txhash)}; |
| 517 | auto wtxid{Wtxid::FromUint256(txhash)}; |
| 518 | |
| 519 | auto reqtimeT = m_rng.randbool() ? MIN_TIME : scenario.Now() + RandomTime8s(); |
| 520 | auto reqtimeW = m_rng.randbool() ? MIN_TIME : scenario.Now() + RandomTime8s(); |
| 521 | |
| 522 | // Announce txid first or wtxid first. |
| 523 | if (config & 1) { |
| 524 | scenario.ReceivedInv(peerT, txid, config & 2, reqtimeT); |
| 525 | if (m_rng.randbool()) scenario.AdvanceTime(RandomTime8s()); |
| 526 | scenario.ReceivedInv(peerW, wtxid, !(config & 2), reqtimeW); |
| 527 | } else { |
| 528 | scenario.ReceivedInv(peerW, wtxid, !(config & 2), reqtimeW); |
| 529 | if (m_rng.randbool()) scenario.AdvanceTime(RandomTime8s()); |
| 530 | scenario.ReceivedInv(peerT, txid, config & 2, reqtimeT); |
| 531 | } |
| 532 | |
| 533 | // Let time pass if needed, and check that the preferred announcement (txid or wtxid) |
| 534 | // is correctly to-be-requested (and with the correct wtxidness). |
| 535 | auto max_reqtime = std::max(reqtimeT, reqtimeW); |
| 536 | if (max_reqtime > scenario.Now()) scenario.AdvanceTime(max_reqtime - scenario.Now()); |
| 537 | if (config & 2) { |
| 538 | scenario.Check(peerT, {txid}, 1, 0, 0, "w1"); |
| 539 | scenario.Check(peerW, {}, 1, 0, 0, "w2"); |
| 540 | } else { |
| 541 | scenario.Check(peerT, {}, 1, 0, 0, "w3"); |
| 542 | scenario.Check(peerW, {wtxid}, 1, 0, 0, "w4"); |
| 543 | } |
| 544 | |
| 545 | // Let the preferred announcement be requested. It's not going to be delivered. |
| 546 | auto expiry = RandomTime8s(); |
| 547 | if (config & 2) { |
| 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"); |
| 551 | } else { |
| 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"); |
| 555 | } |
| 556 | |
| 557 | // After reaching expiration time of the preferred announcement, verify that the |
| 558 | // remaining one is requestable |
| 559 | scenario.AdvanceTime(expiry); |
| 560 | if (config & 2) { |
| 561 | scenario.Check(peerT, {}, 0, 0, 1, "w9"); |
| 562 | scenario.Check(peerW, {wtxid}, 1, 0, 0, "w10"); |
| 563 | scenario.CheckExpired(peerT, txid); |
| 564 | } else { |
| 565 | scenario.Check(peerT, {txid}, 1, 0, 0, "w11"); |
| 566 | scenario.Check(peerW, {}, 0, 0, 1, "w12"); |
nothing calls this directly
no test coverage detected