Merge bitcoin/bitcoin#36863: test: fix wallet tests that check the wrong wallet
What changed, and why it matters
This commit fixes two mistakes in Bitcoin Core's automated test scripts. In one test, the code was accidentally checking the wrong digital wallet (w7 instead of w8), so it never verified that a new 'avoid reuse' wallet worked correctly. In another test, the code was copying one node's wallet backup to all four nodes, meaning only the first node was actually being tested for keypool recovery. These are test-only bugs with no effect on the live Bitcoin Core software users run.
No security action required. Treat as ordinary test-quality improvement. Reviewers may want to confirm the revised tests pass in CI.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit applies two test-only fixes: (1) wallet_createwallet.py now calls walletpassphrase on w8 rather than w7 after creating the avoid_reuse wallet w8, so the intended assertion is actually exercised; (2) wallet_keypool_topup.py now backs up and restores each node’s own wallet (nodes 1-4) instead of repeatedly copying node1’s backup, and adds an assert_debug_log check for ‘Rescanning last’ to ensure the restore/rescan path is not silently skipped. No production wallet logic is changed.
Changed components
test/functional/wallet_createwallet.pytest/functional/wallet_keypool_topup.pyInspect captured patch +16 / −14
### test/functional/wallet_createwallet.py
@@ -182,7 +182,7 @@ def run_test(self):
self.log.info('Test making a wallet with avoid reuse flag')
self.nodes[0].createwallet('w8', False, False, '', True) # Use positional arguments to check for bug where avoid_reuse could not be set for wallets without needing them to be encrypted
w8 = node.get_wallet_rpc('w8')
- assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
+ assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w8.walletpassphrase, '', 60)
assert_equal(w8.getwalletinfo()["avoid_reuse"], True)
self.log.info('Using a passphrase with private keys disabled returns error')
### test/functional/wallet_keypool_topup.py
@@ -4,12 +4,14 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test HD Wallet keypool restore function.
-Two nodes. Node1 is under test. Node0 is providing transactions and generating blocks.
+Node0 is providing transactions and generating blocks. Nodes 1-4 are under test,
+one for each output type (legacy, p2sh-segwit, bech32 and bech32m).
-- Start node1, shutdown and backup wallet.
-- Generate 110 keys (enough to drain the keypool). Store key 90 (in the initial keypool) and key 110 (beyond the initial keypool). Send funds to key 90 and key 110.
-- Stop node1, clear the datadir, move wallet file back into the datadir and restart node1.
-- connect node1 to node0. Verify that they sync and node1 receives its funds."""
+- Back up the wallet of each node under test.
+- For each node under test:
+ - Generate 110 keys (enough to drain the keypool). Store key 90 (in the initial keypool) and key 110 (beyond the initial keypool). Send funds to key 90 and key 110.
+ - Stop the node, restore its wallet backup and restart it.
+ - Connect it to node0. Verify that they sync, the node receives its funds and the keys up to key 110 are marked as used."""
import shutil
from test_framework.blocktools import COINBASE_MATURITY
@@ -31,14 +33,11 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
- wallet_path = self.nodes[1].wallets_path / self.default_wallet_name / self.wallet_data_filename
- wallet_backup_path = self.nodes[1].datadir_path / "wallet.bak"
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
- self.log.info("Make backup of wallet")
- self.stop_node(1)
- shutil.copyfile(wallet_path, wallet_backup_path)
- self.start_node(1, self.extra_args[1])
+ self.log.info("Make backup of each wallet")
+ for node in self.nodes[1:]:
+ node.backupwallet(node.datadir_path / "wallet.bak")
for i in [1, 2, 3, 4]:
self.connect_nodes(0, i)
@@ -69,9 +68,12 @@ def run_test(self):
self.generate(self.nodes[0], 1)
self.log.info("Restart node with wallet backup")
+ node = self.nodes[idx]
self.stop_node(idx)
- shutil.copyfile(wallet_backup_path, wallet_path)
- self.start_node(idx, self.extra_args[idx])
+ shutil.copyfile(node.datadir_path / "wallet.bak", node.wallets_path / self.default_wallet_name / self.wallet_data_filename)
+ # The backup predates the funding transactions, so the restored wallet can only find them by rescanning
+ with node.assert_debug_log(expected_msgs=["Rescanning last"]):
+ self.start_node(idx, self.extra_args[idx])
self.connect_nodes(0, idx)
self.sync_all()
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.