Coverage Report

Created: 2024-11-15 12:18

/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
/** Check that we never get into a state where an ephemeral dust
51
 *  transaction would be mined without the spend of the dust
52
 *  also being mined. This assumes standardness checks are being
53
 *  enforced.
54
*/
55
void CheckMempoolEphemeralInvariants(const CTxMemPool& tx_pool);
56
57
/** Return indexes of the transaction's outputs that are considered dust
58
 * at given dust_relay_rate.
59
*/
60
std::vector<uint32_t> GetDustIndexes(const CTransactionRef& tx_ref, CFeeRate dust_relay_rate);
61
62
/** For every transaction in tx_pool, check TRUC invariants:
63
 * - a TRUC tx's ancestor count must be within TRUC_ANCESTOR_LIMIT
64
 * - a TRUC tx's descendant count must be within TRUC_DESCENDANT_LIMIT
65
 * - if a TRUC tx has ancestors, its sigop-adjusted vsize must be within TRUC_CHILD_MAX_VSIZE
66
 * - any non-TRUC tx must only have non-TRUC parents
67
 * - any TRUC tx must only have TRUC parents
68
 *   */
69
void CheckMempoolTRUCInvariants(const CTxMemPool& tx_pool);
70
71
#endif // BITCOIN_TEST_UTIL_TXMEMPOOL_H