Skip to content

Commit a2878cf

Browse files
committed
[unit test] strengthen GetChildrenFromSamePeer tests: results are in recency order
1 parent 7ce3b7e commit a2878cf

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/test/orphanage_tests.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,30 @@ BOOST_AUTO_TEST_CASE(get_children)
597597
// Spends the same outpoint as previous tx. Should still be returned; don't assume outpoints are unique.
598598
auto child_p1n0_p2n0 = MakeTransactionSpending({{parent1->GetHash(), 0}, {parent2->GetHash(), 0}}, det_rand);
599599

600+
const NodeId node0{0};
600601
const NodeId node1{1};
601602
const NodeId node2{2};
603+
const NodeId node3{3};
602604

603605
// All orphans provided by node1
604606
{
605-
std::unique_ptr<node::TxOrphanage> orphanage{node::MakeTxOrphanage()};
607+
auto orphanage{node::MakeTxOrphanage()};
606608
BOOST_CHECK(orphanage->AddTx(child_p1n0, node1));
607609
BOOST_CHECK(orphanage->AddTx(child_p2n1, node1));
608610
BOOST_CHECK(orphanage->AddTx(child_p1n0_p1n1, node1));
609611
BOOST_CHECK(orphanage->AddTx(child_p1n0_p2n0, node1));
610612

611-
std::set<CTransactionRef> expected_parent1_children{child_p1n0, child_p1n0_p2n0, child_p1n0_p1n1};
612-
std::set<CTransactionRef> expected_parent2_children{child_p2n1, child_p1n0_p2n0};
613+
// Also add some other announcers for the same transactions
614+
BOOST_CHECK(!orphanage->AddTx(child_p1n0_p1n1, node0));
615+
BOOST_CHECK(!orphanage->AddTx(child_p2n1, node0));
616+
BOOST_CHECK(!orphanage->AddTx(child_p1n0, node3));
613617

614-
BOOST_CHECK(EqualTxns(expected_parent1_children, orphanage->GetChildrenFromSamePeer(parent1, node1)));
615-
BOOST_CHECK(EqualTxns(expected_parent2_children, orphanage->GetChildrenFromSamePeer(parent2, node1)));
618+
619+
std::vector<CTransactionRef> expected_parent1_children{child_p1n0_p2n0, child_p1n0_p1n1, child_p1n0};
620+
std::vector<CTransactionRef> expected_parent2_children{child_p1n0_p2n0, child_p2n1};
621+
622+
BOOST_CHECK(expected_parent1_children == orphanage->GetChildrenFromSamePeer(parent1, node1));
623+
BOOST_CHECK(expected_parent2_children == orphanage->GetChildrenFromSamePeer(parent2, node1));
616624

617625
// The peer must match
618626
BOOST_CHECK(orphanage->GetChildrenFromSamePeer(parent1, node2).empty());
@@ -642,6 +650,8 @@ BOOST_AUTO_TEST_CASE(get_children)
642650
{
643651
std::set<CTransactionRef> expected_parent1_node1{child_p1n0};
644652

653+
BOOST_CHECK_EQUAL(orphanage->GetChildrenFromSamePeer(parent1, node1).size(), 1);
654+
BOOST_CHECK(orphanage->HaveTxFromPeer(child_p1n0->GetWitnessHash(), node1));
645655
BOOST_CHECK(EqualTxns(expected_parent1_node1, orphanage->GetChildrenFromSamePeer(parent1, node1)));
646656
}
647657

@@ -652,17 +662,20 @@ BOOST_AUTO_TEST_CASE(get_children)
652662
BOOST_CHECK(EqualTxns(expected_parent2_node1, orphanage->GetChildrenFromSamePeer(parent2, node1)));
653663
}
654664

655-
// Children of parent1 from node2:
665+
// Children of parent1 from node2: newest returned first.
656666
{
657-
std::set<CTransactionRef> expected_parent1_node2{child_p1n0_p1n1, child_p1n0_p2n0};
658-
659-
BOOST_CHECK(EqualTxns(expected_parent1_node2, orphanage->GetChildrenFromSamePeer(parent1, node2)));
667+
std::vector<CTransactionRef> expected_parent1_node2{child_p1n0_p2n0, child_p1n0_p1n1};
668+
BOOST_CHECK(orphanage->HaveTxFromPeer(child_p1n0_p1n1->GetWitnessHash(), node2));
669+
BOOST_CHECK(orphanage->HaveTxFromPeer(child_p1n0_p2n0->GetWitnessHash(), node2));
670+
BOOST_CHECK(expected_parent1_node2 == orphanage->GetChildrenFromSamePeer(parent1, node2));
660671
}
661672

662673
// Children of parent2 from node2:
663674
{
664675
std::set<CTransactionRef> expected_parent2_node2{child_p1n0_p2n0};
665676

677+
BOOST_CHECK_EQUAL(1, orphanage->GetChildrenFromSamePeer(parent2, node2).size());
678+
BOOST_CHECK(orphanage->HaveTxFromPeer(child_p1n0_p2n0->GetWitnessHash(), node2));
666679
BOOST_CHECK(EqualTxns(expected_parent2_node2, orphanage->GetChildrenFromSamePeer(parent2, node2)));
667680
}
668681
}

0 commit comments

Comments
 (0)