Merge bitcoin/bitcoin#36914: test: simplify wallet_basic and rpc_getblockfilter tests
What changed, and why it matters
This commit only cleans up two internal test scripts for the Bitcoin Core project. It replaces a manual network disconnect/reconnect pattern with a simpler way to create an unconnected block header, and removes a hard-coded number in favor of using the actual number of test nodes. There are no changes to the live Bitcoin software that users run, and nothing that affects real funds, transactions, or network security.
No action needed. This is a routine test-only refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies two functional test files: test/functional/rpc_getblockfilter.py and test/functional/wallet_basic.py. In rpc_getblockfilter.py, it uses generateblock(…, submit=False) to produce a block header that can be submitted directly via submitheader, eliminating the previous disconnect_nodes/connect_nodes/sync_blocks dance. In wallet_basic.py, it replaces range(3) and literal 3 with len(self.nodes) and direct iteration over self.nodes. These are purely stylistic/refactoring changes within the test suite.
Changed components
test/functional/rpc_getblockfilter.pytest/functional/wallet_basic.pyInspect captured patch +6 / −11
### test/functional/rpc_getblockfilter.py
@@ -50,21 +50,16 @@ def run_test(self):
bad_block_hash = "0123456789abcdef" * 4
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockfilter, bad_block_hash, "basic")
- self.disconnect_nodes(0, 1)
-
# Test getblockfilter for a known header before connecting its block
- block_hash = self.generate(self.nodes[1], 1, sync_fun=self.no_op)[0]
- self.nodes[0].submitheader(self.nodes[1].getblockheader(block_hash, False))
+ block = self.generateblock(self.nodes[1], output="raw(55)", transactions=[], submit=False)
+ self.nodes[0].submitheader(block["hex"][:160])
# The header is known, but the block has never been connected
assert_raises_rpc_error(
-5, "Filter not found. Block was not connected to active chain.",
- self.nodes[0].getblockfilter, block_hash, "basic",
+ self.nodes[0].getblockfilter, block["hash"], "basic",
)
- self.connect_nodes(0, 1)
- self.sync_blocks()
-
# Test getblockfilter with undefined filter type
genesis_hash = self.nodes[0].getblockhash(0)
assert_raises_rpc_error(-5, "Unknown filtertype", self.nodes[0].getblockfilter, genesis_hash, "unknown")
### test/functional/wallet_basic.py
@@ -437,7 +437,7 @@ def run_test(self):
# check if wallet or blockchain maintenance changes the balance
self.sync_all()
blocks = self.generate(self.nodes[0], 2)
- balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
+ balance_nodes = [node.getbalance() for node in self.nodes]
block_count = self.nodes[0].getblockcount()
# Check modes:
@@ -462,8 +462,8 @@ def run_test(self):
self.start_node(1, ['-reindex', "-limitclustercount=" + str(chainlimit)])
self.start_node(2, ['-reindex', "-limitclustercount=" + str(chainlimit)])
# reindex will leave rpc warm up "early"; Wait for it to finish
- self.wait_until(lambda: [block_count] * 3 == [self.nodes[i].getblockcount() for i in range(3)])
- assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])
+ self.wait_until(lambda: [block_count] * len(self.nodes) == [node.getblockcount() for node in self.nodes])
+ assert_equal(balance_nodes, [node.getbalance() for node in self.nodes])
# Exercise listsinceblock with the last two blocks
coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0])Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.