test: Simple test for importing unused(KEY)
What changed, and why it matters
This commit adds a new automated test to Bitcoin Core that checks the behavior of importing a special 'unused(KEY)' wallet descriptor. It verifies that importing a public-only version is rejected for wallets that have private keys enabled, while importing a private-key version succeeds and registers the expected extended public key. There is no change to production wallet code, no bug fix, and no security-relevant behavior beyond normal test coverage.
No security action required. Review as ordinary test coverage if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff extends test/functional/wallet_importdescriptors.py with test_import_unused_key(). The test creates a blank wallet, confirms it has no HD keys, then attempts to import descsum_create(f’unused({xpub})’) with timestamp ‘now’ and expects failure with RPC error -4 (‘Cannot import descriptor without private keys to a wallet with private keys enabled’). It then imports descsum_create(f’unused({xprv})’) and asserts success, one HD key, and that the derived xpub matches. Finally it unloads the wallet. The run_test() method is updated to call the new helper. No C++/Python production logic is modified.
Changed components
test/functional/wallet_importdescriptors.pyInspect captured patch +25 / −0
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index bfb25c63..c22bf103 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -65,6 +65,29 @@ class ImportDescriptorsTest(BitcoinTestFramework):
assert_equal(result[0]['error']['code'], error_code)
assert_equal(result[0]['error']['message'], error_message)
+ def test_import_unused_key(self):
+ self.log.info("Test import of unused(KEY)")
+ self.nodes[0].createwallet(wallet_name="import_unused", blank=True)
+ wallet = self.nodes[0].get_wallet_rpc("import_unused")
+
+ assert_equal(len(wallet.gethdkeys()), 0)
+
+ xprv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg"
+ xpub = "tpubD6NzVbkrYhZ4YNXVQbNhMK1WqguFsUXceaVJKbmno2aZ3B6QfbMeraaYvnBSGpV3vxLyTTK9DYT1yoEck4XUScMzXoQ2U2oSmE2JyMedq3H"
+ self.test_importdesc({"desc":descsum_create(f"unused({xpub})"),
+ "timestamp": "now"},
+ success=False,
+ error_code=-4,
+ error_message='Cannot import descriptor without private keys to a wallet with private keys enabled',
+ wallet=wallet)
+ self.test_importdesc({"timestamp": "now", "desc": descsum_create(f"unused({xprv})")},
+ success=True,
+ wallet=wallet)
+ hdkeys = wallet.gethdkeys()
+ assert_equal(len(hdkeys), 1)
+ assert_equal(hdkeys[0]["xpub"], xpub)
+ wallet.unloadwallet()
+
def run_test(self):
self.log.info('Setting up wallets')
self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False)
@@ -822,5 +845,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
)
+ self.test_import_unused_key()
+
if __name__ == '__main__':
ImportDescriptorsTest(__file__).main()
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.