fuzz: add basic TxOrphanage::EraseForBlock cov

This commit is contained in:
Greg Sanders 2025-02-20 13:58:09 -05:00
parent 46a9c73083
commit 8400b742fa

View file

@ -47,6 +47,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
CTransactionRef ptx_potential_parent = nullptr;
std::vector<CTransactionRef> tx_history;
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
{
// construct transaction
@ -75,6 +77,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
return new_tx;
}();
tx_history.push_back(tx);
const auto wtxid{tx->GetWitnessHash()};
// Trigger orphanage functions that are called using parents. ptx_potential_parent is a tx we constructed in a
@ -195,6 +199,20 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
Assert(!orphanage.HaveTxFromPeer(tx->GetWitnessHash(), peer_id));
Assert(orphanage.UsageByPeer(peer_id) == 0);
},
[&] {
// Make a block out of txs and then EraseForBlock
CBlock block;
int num_txs = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1000);
for (int i{0}; i < num_txs; ++i) {
auto& tx_to_remove = PickValue(fuzzed_data_provider, tx_history);
block.vtx.push_back(tx_to_remove);
}
orphanage.EraseForBlock(block);
for (const auto& tx_removed : block.vtx) {
Assert(!orphanage.HaveTx(tx_removed->GetWitnessHash()));
Assert(!orphanage.HaveTxFromPeer(tx_removed->GetWitnessHash(), peer_id));
}
},
[&] {
// test mocktime and expiry
SetMockTime(ConsumeTime(fuzzed_data_provider));