test: Invalid label name coverage

This commit is contained in:
Aurèle Oulès 2022-09-27 11:10:01 +02:00
parent 552b51e682
commit 65e78bda7c
No known key found for this signature in database
GPG Key ID: 55F3976F7001D998

View File

@ -28,6 +28,44 @@ class WalletLabelsTest(BitcoinTestFramework):
def skip_test_if_missing_module(self): def skip_test_if_missing_module(self):
self.skip_if_no_wallet() self.skip_if_no_wallet()
def invalid_label_name_test(self):
node = self.nodes[0]
address = node.getnewaddress()
pubkey = node.getaddressinfo(address)['pubkey']
rpc_calls = [
[node.getnewaddress],
[node.setlabel, address],
[node.getaddressesbylabel],
[node.importpubkey, pubkey],
[node.addmultisigaddress, 1, [pubkey]],
[node.getreceivedbylabel],
[node.listsinceblock, node.getblockhash(0), 1, False, True, False],
]
if self.options.descriptors:
response = node.importdescriptors([{
'desc': f'pkh({pubkey})',
'label': '*',
'timestamp': 'now',
}])
else:
rpc_calls.extend([
[node.importprivkey, node.dumpprivkey(address)],
[node.importaddress, address],
])
response = node.importmulti([{
'scriptPubKey': {'address': address},
'label': '*',
'timestamp': 'now',
}])
assert_equal(response[0]['success'], False)
assert_equal(response[0]['error']['code'], -11)
assert_equal(response[0]['error']['message'], "Invalid label name")
for rpc_call in rpc_calls:
assert_raises_rpc_error(-11, "Invalid label name", *rpc_call, "*")
def run_test(self): def run_test(self):
# Check that there's no UTXO on the node # Check that there's no UTXO on the node
node = self.nodes[0] node = self.nodes[0]
@ -138,6 +176,8 @@ class WalletLabelsTest(BitcoinTestFramework):
# in the label. This is a no-op. # in the label. This is a no-op.
change_label(node, labels[2].addresses[0], labels[2], labels[2]) change_label(node, labels[2].addresses[0], labels[2], labels[2])
self.invalid_label_name_test()
if self.options.descriptors: if self.options.descriptors:
# This is a descriptor wallet test because of segwit v1+ addresses # This is a descriptor wallet test because of segwit v1+ addresses
self.log.info('Check watchonly labels') self.log.info('Check watchonly labels')