Coverage Report

Created: 2026-09-01 13:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/test/util/validation.h
Line
Count
Source
1
// Copyright (c) 2020-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_TEST_UTIL_VALIDATION_H
6
#define BITCOIN_TEST_UTIL_VALIDATION_H
7
8
#include <consensus/amount.h>
9
#include <primitives/transaction.h>
10
#include <util/task_runner.h>
11
#include <validation.h>
12
13
#include <cstddef>
14
#include <functional>
15
#include <thread>
16
#include <utility>
17
#include <vector>
18
19
namespace node {
20
class BlockManager;
21
}
22
class CValidationInterface;
23
class FakeNodeClock;
24
struct TestingSetup;
25
26
/// Runs callbacks synchronously and deterministically, while avoiding DEBUG_LOCKORDER false positives.
27
class ImmediateBackgroundTaskRunner : public util::TaskRunnerInterface
28
{
29
public:
30
915k
    void insert(std::function<void()> func) override { std::thread(std::move(func)).join(); }
31
2
    void flush() override {}
32
226k
    size_t size() override { return 0; }
33
};
34
35
struct TestBlockManager : public node::BlockManager {
36
    /** Test-only method to clear internal state for fuzzing */
37
    void CleanupForFuzzing();
38
};
39
40
struct TestChainstateManager : public ChainstateManager {
41
    /** Disable the next write of all chainstates */
42
    void DisableNextWrite();
43
    /** Reset the ibd cache to its initial state */
44
    void ResetIbd();
45
    /** Toggle IsInitialBlockDownload from true to false */
46
    void JumpOutOfIbd();
47
    /** Wrappers that avoid making chainstatemanager internals public for tests */
48
    void InvalidBlockFound(CBlockIndex* pindex, const BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
49
    void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
50
    CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
51
    void ResetBestInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
52
};
53
54
class ValidationInterfaceTest
55
{
56
public:
57
    static void BlockConnected(
58
        const kernel::ChainstateRole& role,
59
        CValidationInterface& obj,
60
        const std::shared_ptr<const CBlock>& block,
61
        const CBlockIndex* pindex);
62
};
63
64
std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock);
65
66
#endif // BITCOIN_TEST_UTIL_VALIDATION_H