v31.1-roots.1 · Commit 4: [PATCH 04/17] feat(mining): preserve Roots priority and template policies
test/functional/mining_roots_template.py
Before: /dev/null · After: test/functional/mining_roots_template.py
File metadata
new file mode 100644 index 0000000000000000000000000000000000000000..add23b266847dd6f56af8350c46d589fbe1c3822
Download original patch · Release notes
Diff rows 1–56 of 56. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/mining_roots_template.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# Copyright (c) 2026 The Bitcoin Core developers
|
| 3 |
+
# Distributed under the MIT software license, see the accompanying
|
| 4 |
+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
+
"""Roots local template resource boundaries and coin-age priority selection."""
|
| 6 |
+
from decimal import Decimal
|
| 7 |
+
|
| 8 |
+
from test_framework.test_framework import BitcoinTestFramework
|
| 9 |
+
from test_framework.util import assert_equal
|
| 10 |
+
from test_framework.wallet import MiniWallet
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class RootsTemplateTest(BitcoinTestFramework):
|
| 14 |
+
def set_test_params(self):
|
| 15 |
+
self.num_nodes = 1
|
| 16 |
+
self.extra_args = [["-blockprioritysize=0", "-blockmintxfee=0.00002"]]
|
| 17 |
+
|
| 18 |
+
def run_test(self):
|
| 19 |
+
node = self.nodes[0]
|
| 20 |
+
wallet = MiniWallet(node)
|
| 21 |
+
self.generate(wallet, 101)
|
| 22 |
+
tx = wallet.send_self_transfer(from_node=node, fee_rate=Decimal("0.00001"))
|
| 23 |
+
txid = tx["txid"]
|
| 24 |
+
size = len(bytes.fromhex(tx["hex"]))
|
| 25 |
+
weight = tx["tx"].get_weight()
|
| 26 |
+
|
| 27 |
+
def check_template(args, included):
|
| 28 |
+
self.restart_node(0, extra_args=args)
|
| 29 |
+
entries = node.getblocktemplate({"rules": ["segwit"]})["transactions"]
|
| 30 |
+
assert_equal([entry["txid"] for entry in entries], [txid] if included else [])
|
| 31 |
+
if included:
|
| 32 |
+
assert_equal(entries[0]["fee"], int(tx["fee"] * 100_000_000))
|
| 33 |
+
|
| 34 |
+
# Default/disabled priority cannot bypass the explicitly higher fee floor.
|
| 35 |
+
check_template(["-blockprioritysize=0", "-blockmintxfee=0.00002"], False)
|
| 36 |
+
check_template(["-blockprioritysize=100000", "-blockmintxfee=0.00002"], True)
|
| 37 |
+
# Equality is excluded; one byte/weight unit above it includes the tx.
|
| 38 |
+
common = ["-blockprioritysize=0", "-blockmintxfee=0"]
|
| 39 |
+
for delta, included in [(0, False), (1, True)]:
|
| 40 |
+
check_template(common + [f"-blockmaxsize={1000 + size + delta}"], included)
|
| 41 |
+
check_template(common + [f"-blockmaxweight={8000 + weight + delta}"], included)
|
| 42 |
+
# Both caps apply together; an unconstraining one cannot override the other.
|
| 43 |
+
check_template(common + [f"-blockmaxsize={1000 + size}", "-blockmaxweight=4000000"], False)
|
| 44 |
+
check_template(common + ["-blockmaxsize=4000000", f"-blockmaxweight={8000 + weight}"], False)
|
| 45 |
+
# A reserve exceeding the weight limit normalizes to an empty template.
|
| 46 |
+
check_template(common + ["-blockmaxweight=8000", "-blockreservedweight=9000"], False)
|
| 47 |
+
check_template(common + ["-blockmaxsize=0", "-blockprioritysize=9223372036854775807"], False)
|
| 48 |
+
# The local size cap never changes block-connection consensus validity.
|
| 49 |
+
before = node.getblockcount()
|
| 50 |
+
block = self.generateblock(node, output=wallet.get_address(), transactions=[tx["hex"]])
|
| 51 |
+
assert_equal(node.getblockcount(), before + 1)
|
| 52 |
+
assert txid in node.getblock(block["hash"])["tx"]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == '__main__':
|
| 56 |
+
RootsTemplateTest(__file__).main()
|