Coverage Report

Created: 2024-10-21 15:10

/root/bitcoin/src/test/util/txmempool.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2022 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_TXMEMPOOL_H
6
#define BITCOIN_TEST_UTIL_TXMEMPOOL_H
7
8
#include <policy/packages.h>
9
#include <txmempool.h>
10
#include <util/time.h>
11
12
namespace node {
13
struct NodeContext;
14
}
15
struct PackageMempoolAcceptResult;
16
17
CTxMemPool::Options MemPoolOptionsForTest(const node::NodeContext& node);
18
19
struct TestMemPoolEntryHelper {
20
    // Default values
21
    CAmount nFee{0};
22
    NodeSeconds time{};
23
    unsigned int nHeight{1};
24
    uint64_t m_sequence{0};
25
    bool spendsCoinbase{false};
26
    unsigned int sigOpCost{4};
27
    LockPoints lp;
28
29
    CTxMemPoolEntry FromTx(const CMutableTransaction& tx) const;
30
    CTxMemPoolEntry FromTx(const CTransactionRef& tx) const;
31
32
    // Change the default value
33
0
    TestMemPoolEntryHelper& Fee(CAmount _fee) { nFee = _fee; return *this; }
34
0
    TestMemPoolEntryHelper& Time(NodeSeconds tp) { time = tp; return *this; }
35
0
    TestMemPoolEntryHelper& Height(unsigned int _height) { nHeight = _height; return *this; }
36
0
    TestMemPoolEntryHelper& Sequence(uint64_t _seq) { m_sequence = _seq; return *this; }
37
0
    TestMemPoolEntryHelper& SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
38
0
    TestMemPoolEntryHelper& SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
39
};
40
41
/** Check expected properties for every PackageMempoolAcceptResult, regardless of value. Returns
42
 * a string if an error occurs with error populated, nullopt otherwise. If mempool is provided,
43
 * checks that the expected transactions are in mempool (this should be set to nullptr for a test_accept).
44
*/
45
std::optional<std::string>  CheckPackageMempoolAcceptResult(const Package& txns,
46
                                                            const PackageMempoolAcceptResult& result,
47
                                                            bool expect_valid,
48
                                                            const CTxMemPool* mempool);
49
50
/** For every transaction in tx_pool, check TRUC invariants:
51
 * - a TRUC tx's ancestor count must be within TRUC_ANCESTOR_LIMIT
52
 * - a TRUC tx's descendant count must be within TRUC_DESCENDANT_LIMIT
53
 * - if a TRUC tx has ancestors, its sigop-adjusted vsize must be within TRUC_CHILD_MAX_VSIZE
54
 * - any non-TRUC tx must only have non-TRUC parents
55
 * - any TRUC tx must only have TRUC parents
56
 *   */
57
void CheckMempoolTRUCInvariants(const CTxMemPool& tx_pool);
58
59
#endif // BITCOIN_TEST_UTIL_TXMEMPOOL_H