test: test invalid or missing timestamp throws importdescriptors
What changed, and why it matters
This commit only adds new automated tests for the Bitcoin Core wallet's importdescriptors RPC. It checks that the command correctly rejects requests with a missing or invalid timestamp. No production wallet code is changed, so this cannot introduce a security vulnerability or fix one in running software.
No security action needed. Review as a normal test-quality improvement.
Security signals we found
No changes to consensus, networking, wallet logic, or cryptography
Only functional test code is modified
Added assertions are for expected error handling paths
Evidence from the diff
The diff modifies test/functional/wallet_importdescriptors.py. It extends the helper test_importdesc to support asserting on global JSON-RPC errors (JSONRPCException) in addition to per-item result errors. It then adds two test cases verifying that importdescriptors returns RPC error code -3 for a missing timestamp field and for a non-numeric/non-‘now’ timestamp string. The underlying validation behavior in the wallet RPC implementation is unchanged.
Changed components
test/functional/wallet_importdescriptors.pyInspect captured patch +28 / −1
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index be6db78a..4597283f 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -47,7 +47,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
- def test_importdesc(self, req, success, error_code=None, error_message=None, warnings=None, wallet=None):
+ def test_importdesc(self, req, success, global_error=False, error_code=None, error_message=None, warnings=None, wallet=None):
"""Run importdescriptors and assert success"""
if warnings is None:
warnings = []
@@ -55,6 +55,14 @@ class ImportDescriptorsTest(BitcoinTestFramework):
if wallet is not None:
wrpc = wallet
+ if global_error and not success:
+ try:
+ result = wrpc.importdescriptors([req])
+ except JSONRPCException as e:
+ assert_equal(e.error["code"], error_code)
+ assert_equal(e.error["message"], error_message)
+ return
+
result = wrpc.importdescriptors([req])
observed_warnings = []
if 'warnings' in result[0]:
@@ -220,6 +228,25 @@ class ImportDescriptorsTest(BitcoinTestFramework):
error_code=-8,
error_message='Descriptor not found.')
+ # Test import fails if one timestamp is invalid or missing
+ self.log.info("Import should fail if timestamp is missing or an invalid timestamp is present in the request")
+ key = get_generate_key()
+ import_request = {"desc": descsum_create("pkh(" + key.pubkey + ")"), "label": "Descriptor import test"}
+ self.test_importdesc(import_request,
+ success=False,
+ global_error=True,
+ error_code=-3,
+ error_message="Missing required timestamp field for key")
+
+ import_request = {"desc": descsum_create("pkh(" + key.pubkey + ")"),
+ "timestamp": "this_is_not_a_valid_timestamp",
+ "label": "Descriptor import test"}
+ self.test_importdesc(import_request,
+ success=False,
+ global_error=True,
+ error_code=-3,
+ error_message='Expected number or "now" timestamp value for key. got type string')
+
# # Test importing of a P2PKH descriptor
key = get_generate_key()
self.log.info("Should import a p2pkh descriptor")
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.