@@ -597,22 +597,30 @@ BOOST_AUTO_TEST_CASE(get_children)
597
597
// Spends the same outpoint as previous tx. Should still be returned; don't assume outpoints are unique.
598
598
auto child_p1n0_p2n0 = MakeTransactionSpending ({{parent1->GetHash (), 0 }, {parent2->GetHash (), 0 }}, det_rand);
599
599
600
+ const NodeId node0{0 };
600
601
const NodeId node1{1 };
601
602
const NodeId node2{2 };
603
+ const NodeId node3{3 };
602
604
603
605
// All orphans provided by node1
604
606
{
605
- std::unique_ptr<node::TxOrphanage> orphanage{node::MakeTxOrphanage ()};
607
+ auto orphanage{node::MakeTxOrphanage ()};
606
608
BOOST_CHECK (orphanage->AddTx (child_p1n0, node1));
607
609
BOOST_CHECK (orphanage->AddTx (child_p2n1, node1));
608
610
BOOST_CHECK (orphanage->AddTx (child_p1n0_p1n1, node1));
609
611
BOOST_CHECK (orphanage->AddTx (child_p1n0_p2n0, node1));
610
612
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));
613
617
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));
616
624
617
625
// The peer must match
618
626
BOOST_CHECK (orphanage->GetChildrenFromSamePeer (parent1, node2).empty ());
@@ -642,6 +650,8 @@ BOOST_AUTO_TEST_CASE(get_children)
642
650
{
643
651
std::set<CTransactionRef> expected_parent1_node1{child_p1n0};
644
652
653
+ BOOST_CHECK_EQUAL (orphanage->GetChildrenFromSamePeer (parent1, node1).size (), 1 );
654
+ BOOST_CHECK (orphanage->HaveTxFromPeer (child_p1n0->GetWitnessHash (), node1));
645
655
BOOST_CHECK (EqualTxns (expected_parent1_node1, orphanage->GetChildrenFromSamePeer (parent1, node1)));
646
656
}
647
657
@@ -652,17 +662,20 @@ BOOST_AUTO_TEST_CASE(get_children)
652
662
BOOST_CHECK (EqualTxns (expected_parent2_node1, orphanage->GetChildrenFromSamePeer (parent2, node1)));
653
663
}
654
664
655
- // Children of parent1 from node2:
665
+ // Children of parent1 from node2: newest returned first.
656
666
{
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));
660
671
}
661
672
662
673
// Children of parent2 from node2:
663
674
{
664
675
std::set<CTransactionRef> expected_parent2_node2{child_p1n0_p2n0};
665
676
677
+ BOOST_CHECK_EQUAL (1 , orphanage->GetChildrenFromSamePeer (parent2, node2).size ());
678
+ BOOST_CHECK (orphanage->HaveTxFromPeer (child_p1n0_p2n0->GetWitnessHash (), node2));
666
679
BOOST_CHECK (EqualTxns (expected_parent2_node2, orphanage->GetChildrenFromSamePeer (parent2, node2)));
667
680
}
668
681
}
0 commit comments