validation.h raw
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 <validation.h>
9
10 namespace node {
11 class BlockManager;
12 }
13 class CValidationInterface;
14
15 struct TestBlockManager : public node::BlockManager {
16 /** Test-only method to clear internal state for fuzzing */
17 void CleanupForFuzzing();
18 };
19
20 struct TestChainstateManager : public ChainstateManager {
21 /** Disable the next write of all chainstates */
22 void DisableNextWrite();
23 /** Reset the ibd cache to its initial state */
24 void ResetIbd();
25 /** Toggle IsInitialBlockDownload from true to false */
26 void JumpOutOfIbd();
27 /** Wrappers that avoid making chainstatemanager internals public for tests */
28 void InvalidBlockFound(CBlockIndex* pindex, const BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
29 void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
30 CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
31 void ResetBestInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
32 };
33
34 class ValidationInterfaceTest
35 {
36 public:
37 static void BlockConnected(
38 const kernel::ChainstateRole& role,
39 CValidationInterface& obj,
40 const std::shared_ptr<const CBlock>& block,
41 const CBlockIndex* pindex);
42 };
43
44 #endif // BITCOIN_TEST_UTIL_VALIDATION_H
45