mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
test: test invalid or missing timestamp throws importdescriptors
Also adds global_error to test_importdesc to make it able to test per-item errors or global RPC errors
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user