@@ -392,4 +392,58 @@ BOOST_AUTO_TEST_CASE(too_large_orphan_tx)
392
392
BOOST_CHECK (orphanage.AddTx (MakeTransactionRef (tx), 0 ));
393
393
}
394
394
395
+ BOOST_AUTO_TEST_CASE (process_block)
396
+ {
397
+ FastRandomContext det_rand{true };
398
+ TxOrphanageTest orphanage{det_rand};
399
+
400
+ // Create outpoints that will be spent by transactions in the block
401
+ std::vector<COutPoint> outpoints;
402
+ const uint32_t num_outpoints{6 };
403
+ outpoints.reserve (num_outpoints);
404
+ for (uint32_t i{0 }; i < num_outpoints; ++i) {
405
+ // All the hashes should be different, but change the n just in case.
406
+ outpoints.emplace_back (Txid::FromUint256 (det_rand.rand256 ()), i);
407
+ }
408
+
409
+ CBlock block;
410
+ const NodeId node{0 };
411
+
412
+ auto control_tx = MakeTransactionSpending ({}, det_rand);
413
+ BOOST_CHECK (orphanage.AddTx (control_tx, node));
414
+
415
+ auto bo_tx_same_txid = MakeTransactionSpending ({outpoints.at (0 )}, det_rand);
416
+ BOOST_CHECK (orphanage.AddTx (bo_tx_same_txid, node));
417
+ block.vtx .emplace_back (bo_tx_same_txid);
418
+
419
+ // 2 transactions with the same txid but different witness
420
+ auto b_tx_same_txid_diff_witness = MakeTransactionSpending ({outpoints.at (1 )}, det_rand);
421
+ block.vtx .emplace_back (b_tx_same_txid_diff_witness);
422
+
423
+ auto o_tx_same_txid_diff_witness = MakeMutation (b_tx_same_txid_diff_witness);
424
+ BOOST_CHECK (orphanage.AddTx (o_tx_same_txid_diff_witness, node));
425
+
426
+ // 2 different transactions that spend the same input.
427
+ auto b_tx_conflict = MakeTransactionSpending ({outpoints.at (2 )}, det_rand);
428
+ block.vtx .emplace_back (b_tx_conflict);
429
+
430
+ auto o_tx_conflict = MakeTransactionSpending ({outpoints.at (2 )}, det_rand);
431
+ BOOST_CHECK (orphanage.AddTx (o_tx_conflict, node));
432
+
433
+ // 2 different transactions that have 1 overlapping input.
434
+ auto b_tx_conflict_partial = MakeTransactionSpending ({outpoints.at (3 ), outpoints.at (4 )}, det_rand);
435
+ block.vtx .emplace_back (b_tx_conflict_partial);
436
+
437
+ auto o_tx_conflict_partial_2 = MakeTransactionSpending ({outpoints.at (4 ), outpoints.at (5 )}, det_rand);
438
+ BOOST_CHECK (orphanage.AddTx (o_tx_conflict_partial_2, node));
439
+
440
+ orphanage.EraseForBlock (block);
441
+ for (const auto & expected_removed : {bo_tx_same_txid, o_tx_same_txid_diff_witness, o_tx_conflict, o_tx_conflict_partial_2}) {
442
+ const auto & expected_removed_wtxid = expected_removed->GetWitnessHash ();
443
+ BOOST_CHECK (!orphanage.HaveTx (expected_removed_wtxid));
444
+ }
445
+ // Only remaining tx is control_tx
446
+ BOOST_CHECK_EQUAL (orphanage.Size (), 1 );
447
+ BOOST_CHECK (orphanage.HaveTx (control_tx->GetWitnessHash ()));
448
+ }
395
449
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments