mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
fuzz: add basic TxOrphanage::EraseForBlock cov
This commit is contained in:
parent
46a9c73083
commit
8400b742fa
1 changed files with 18 additions and 0 deletions
|
@ -47,6 +47,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
||||||
|
|
||||||
CTransactionRef ptx_potential_parent = nullptr;
|
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)
|
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
|
||||||
{
|
{
|
||||||
// construct transaction
|
// construct transaction
|
||||||
|
@ -75,6 +77,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
||||||
return new_tx;
|
return new_tx;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
tx_history.push_back(tx);
|
||||||
|
|
||||||
const auto wtxid{tx->GetWitnessHash()};
|
const auto wtxid{tx->GetWitnessHash()};
|
||||||
|
|
||||||
// Trigger orphanage functions that are called using parents. ptx_potential_parent is a tx we constructed in a
|
// 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.HaveTxFromPeer(tx->GetWitnessHash(), peer_id));
|
||||||
Assert(orphanage.UsageByPeer(peer_id) == 0);
|
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
|
// test mocktime and expiry
|
||||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||||
|
|
Loading…
Add table
Reference in a new issue