Merge bitcoin/bitcoin#36868: test: remove unused nodes and restarts from wallet tests
What changed, and why it matters
This commit only cleans up Bitcoin Core's own automated test suite. It removes unused test nodes and an unnecessary double restart in a few wallet-related test scripts. There is no change to the actual Bitcoin node software that users run, so it cannot affect live wallets, transactions, or network security.
No security action needed. This is a routine test-maintenance change; review can be limited to confirming no functional assertions were accidentally removed.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit applies three test-only refactorings: reduce num_nodes in wallet_basic.py from 4 to 3 and remove the now-unneeded start/stop/sync of node 3; reduce num_nodes to 1 in wallet_derivehdkey.py and wallet_signrawtransactionwithwallet.py because the second node was never referenced; and remove a duplicate restart_node(0)/reload_wallets() pair in wallet_sendall.py. All changes are confined to test/functional/*.py and do not alter consensus, wallet, P2P, or RPC runtime behavior.
Changed components
test/functional/wallet_basic.pytest/functional/wallet_derivehdkey.pytest/functional/wallet_sendall.pytest/functional/wallet_signrawtransactionwithwallet.pyInspect captured patch +24 / −32
### test/functional/wallet_basic.py
@@ -26,7 +26,7 @@
class WalletTest(BitcoinTestFramework):
def set_test_params(self):
- self.num_nodes = 4
+ self.num_nodes = 3
self.noban_tx_relay = True # faster tx relay
self.extra_args = [[
"-dustrelayfee=0", "-walletrejectlongchains=0"
@@ -39,12 +39,10 @@ def skip_test_if_missing_module(self):
def setup_network(self):
self.setup_nodes()
- # Only need nodes 0-2 running at start of test
- self.stop_node(3)
self.connect_nodes(0, 1)
self.connect_nodes(1, 2)
self.connect_nodes(0, 2)
- self.sync_all(self.nodes[0:3])
+ self.sync_all()
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
"""Return curr_balance after asserting the fee was in range"""
@@ -70,8 +68,8 @@ def run_test(self):
assert_equal(balances["mine"]["immature"], 50)
assert_equal(balances["mine"]["trusted"], 0)
- self.sync_all(self.nodes[0:3])
- self.generate(self.nodes[1], COINBASE_MATURITY + 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.sync_all()
+ self.generate(self.nodes[1], COINBASE_MATURITY + 1)
assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[1].getbalance(), 50)
@@ -118,7 +116,7 @@ def run_test(self):
assert_equal(self.nodes[0].getbalances()["mine"]["immature"], 0)
# Have node0 mine a block, thus it will collect its own fee.
- self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[0], 1)
# Exercise locking of unspent outputs
unspent_0 = self.nodes[2].listunspent()[0]
@@ -197,7 +195,7 @@ def run_test(self):
assert_equal(len(self.nodes[1].listlockunspent()), 0)
# Have node1 generate 100 blocks (so node0 can recover the fee)
- self.generate(self.nodes[1], COINBASE_MATURITY, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[1], COINBASE_MATURITY)
# node0 should end up with 100 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2
@@ -225,7 +223,7 @@ def run_test(self):
self.nodes[1].sendrawtransaction(hexstring=txns_to_send[1]["hex"], maxfeerate=0)
# Have node1 mine a block to confirm transactions:
- self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[1], 1)
assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 94)
@@ -239,13 +237,13 @@ def run_test(self):
fee_per_byte = Decimal('0.001') / 1000
fee_rate_sat_vb = fee_per_byte * Decimal(1e8)
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False, fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), Decimal('10'))
# Send 10 BTC with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True, fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@@ -254,14 +252,14 @@ def run_test(self):
# Sendmany 10 BTC
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [], fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
node_0_bal += Decimal('10')
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), node_0_bal)
# Sendmany 10 BTC with subtract fee from amount
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address], fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@@ -270,7 +268,7 @@ def run_test(self):
a0 = self.nodes[0].getnewaddress()
a1 = self.nodes[0].getnewaddress()
txid = self.nodes[2].sendmany(dummy='', amounts={a0: 5, a1: 5}, subtractfeefrom=[a0, a1], fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal)
tx = self.nodes[2].gettransaction(txid)
@@ -287,7 +285,7 @@ def run_test(self):
# Test passing fee_rate as a string
txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=str(fee_rate_sat_vb))
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
balance = self.nodes[2].getbalance()
node_2_bal = self.check_fee_amount(balance, node_2_bal - Decimal('10'), explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(balance, node_2_bal)
@@ -297,7 +295,7 @@ def run_test(self):
# Test passing fee_rate as an integer
amount = Decimal("0.0001")
txid = self.nodes[2].sendmany(amounts={address: amount}, fee_rate=fee_rate_sat_vb)
- self.generate(self.nodes[2], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[2], 1)
balance = self.nodes[2].getbalance()
node_2_bal = self.check_fee_amount(balance, node_2_bal - amount, explicit_fee_rate_btc_kvb, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(balance, node_2_bal)
@@ -337,10 +335,6 @@ def run_test(self):
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
self.nodes[2].sendmany, amounts={address: 1}, conf_target=target, estimate_mode=mode)
- self.start_node(3, self.nodes[3].extra_args)
- self.connect_nodes(0, 3)
- self.sync_all()
-
# check if we can list zero value tx as available coins
# 1. create raw_tx
# 2. hex-changed one output to 0.0
@@ -375,16 +369,16 @@ def run_test(self):
self.connect_nodes(0, 1)
self.connect_nodes(1, 2)
self.connect_nodes(0, 2)
- self.sync_all(self.nodes[0:3])
+ self.sync_all()
txid_not_broadcast = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
- self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3])) # mine a block, tx should not be in there
+ self.generate(self.nodes[1], 1) # mine a block, tx should not be in there
assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted
# now broadcast from another node, mine a block, sync, and check the balance
self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex'])
- self.generate(self.nodes[1], 1, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.generate(self.nodes[1], 1)
node_2_bal += 2
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
assert_equal(self.nodes[2].getbalance(), node_2_bal)
@@ -400,9 +394,9 @@ def run_test(self):
self.connect_nodes(0, 1)
self.connect_nodes(1, 2)
self.connect_nodes(0, 2)
- self.sync_blocks(self.nodes[0:3])
+ self.sync_blocks()
- self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:3]))
+ self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks)
node_2_bal += 2
# tx should be added to balance because after restarting the nodes tx should be broadcast
@@ -434,15 +428,15 @@ def run_test(self):
# Mine a block from node0 to an address from node1
coinbase_addr = self.nodes[1].getnewaddress()
- block_hash = self.generatetoaddress(self.nodes[0], 1, coinbase_addr, sync_fun=lambda: self.sync_all(self.nodes[0:3]))[0]
+ block_hash = self.generatetoaddress(self.nodes[0], 1, coinbase_addr)[0]
coinbase_txid = self.nodes[0].getblock(block_hash)['tx'][0]
# Check that the txid and balance is found by node1
self.nodes[1].gettransaction(coinbase_txid)
# check if wallet or blockchain maintenance changes the balance
- self.sync_all(self.nodes[0:3])
- blocks = self.generate(self.nodes[0], 2, sync_fun=lambda: self.sync_all(self.nodes[0:3]))
+ self.sync_all()
+ blocks = self.generate(self.nodes[0], 2)
balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
block_count = self.nodes[0].getblockcount()
### test/functional/wallet_derivehdkey.py
@@ -15,7 +15,7 @@
class WalletDeriveHDKeyTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
- self.num_nodes = 2
+ self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
### test/functional/wallet_sendall.py
@@ -502,8 +502,6 @@ def sendall_fails_when_bump_fees_exceed_maxtxfee(self):
self.assert_sendall_bump_fee_over_limit(fee_rate=400, error="Fee exceeds maximum configured by user (maxtxfee)")
self.restart_node(0)
self.reload_wallets()
- self.restart_node(0)
- self.reload_wallets()
@cleanup
def sendall_anti_fee_sniping(self):
### test/functional/wallet_signrawtransactionwithwallet.py
@@ -39,7 +39,7 @@
class SignRawTransactionWithWalletTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
- self.num_nodes = 2
+ self.num_nodes = 1
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()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.