Skip to content

Commit

Permalink
test: getdescriptorinfo/importdescriptors with whitespace in pubkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoerg committed Jan 15, 2025
1 parent 3fdcc0c commit 93df337
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/functional/rpc_getdescriptorinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def run_test(self):
assert_raises_rpc_error(-1, 'getdescriptorinfo', self.nodes[0].getdescriptorinfo)
assert_raises_rpc_error(-3, 'JSON value of type number is not of expected type string', self.nodes[0].getdescriptorinfo, 1)
assert_raises_rpc_error(-5, "'' is not a valid descriptor function", self.nodes[0].getdescriptorinfo, "")
assert_raises_rpc_error(-5, "pk(): Pubkey ' 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798' is invalid due to whitespace", self.nodes[0].getdescriptorinfo, "pk( 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)")
assert_raises_rpc_error(-5, "pk(): Pubkey '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 ' is invalid due to whitespace", self.nodes[0].getdescriptorinfo, "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 )")
assert_raises_rpc_error(-5, "Multi: Pubkey ' 03a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7' is invalid due to whitespace", self.nodes[0].getdescriptorinfo, "wsh(multi(2, 03a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7,03774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb,03d01115d548e7561b15c38f004d734633687cf4419620095bc5b0f47070afe85a))")

# P2PK output with the specified public key.
self.test_desc('pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)', isrange=False, issolvable=True, hasprivatekeys=False)
Expand Down
14 changes: 14 additions & 0 deletions test/functional/wallet_importdescriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ def run_test(self):
assert_equal(info["ismine"], True)
assert_equal(info["ischange"], True)

self.log.info("Should not import a descriptor with an invalid public key due to whitespace")
self.test_importdesc({"desc": descsum_create("pkh( " + key.pubkey + ")"),
"timestamp": "now",
"internal": True},
error_code=-5,
error_message=f"pkh(): Pubkey ' {key.pubkey}' is invalid due to whitespace",
success=False)
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + " )"),
"timestamp": "now",
"internal": True},
error_code=-5,
error_message=f"pkh(): Pubkey '{key.pubkey} ' is invalid due to whitespace",
success=False)

# # Test importing of a P2SH-P2WPKH descriptor
key = get_generate_key()
self.log.info("Should not import a p2sh-p2wpkh descriptor without checksum")
Expand Down

0 comments on commit 93df337

Please sign in to comment.