test: add rpc getaddressinfo labels test coverage
This commit is contained in:
parent
0f3539ac6d
commit
33f5fc32e5
6 changed files with 58 additions and 22 deletions
|
@ -88,6 +88,11 @@ def get_multisig(node):
|
||||||
p2sh_p2wsh_script=CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),
|
p2sh_p2wsh_script=CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),
|
||||||
p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
|
p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
|
||||||
|
|
||||||
|
def labels_value(name="", purpose="receive"):
|
||||||
|
"""Generate a getaddressinfo labels array from a name and purpose.
|
||||||
|
Often used as the value of a labels kwarg for calling test_address below."""
|
||||||
|
return [{"name": name, "purpose": purpose}]
|
||||||
|
|
||||||
def test_address(node, address, **kwargs):
|
def test_address(node, address, **kwargs):
|
||||||
"""Get address info for `address` and test whether the returned values are as expected."""
|
"""Get address info for `address` and test whether the returned values are as expected."""
|
||||||
addr_info = node.getaddressinfo(address)
|
addr_info = node.getaddressinfo(address)
|
||||||
|
|
|
@ -15,6 +15,10 @@ from test_framework.util import (
|
||||||
connect_nodes,
|
connect_nodes,
|
||||||
wait_until,
|
wait_until,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import (
|
||||||
|
labels_value,
|
||||||
|
test_address,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WalletTest(BitcoinTestFramework):
|
class WalletTest(BitcoinTestFramework):
|
||||||
|
@ -390,7 +394,7 @@ class WalletTest(BitcoinTestFramework):
|
||||||
for label in [u'рыба', u'𝅘𝅥𝅯']:
|
for label in [u'рыба', u'𝅘𝅥𝅯']:
|
||||||
addr = self.nodes[0].getnewaddress()
|
addr = self.nodes[0].getnewaddress()
|
||||||
self.nodes[0].setlabel(addr, label)
|
self.nodes[0].setlabel(addr, label)
|
||||||
assert_equal(self.nodes[0].getaddressinfo(addr)['label'], label)
|
test_address(self.nodes[0], addr, label=label, labels=labels_value(name=label))
|
||||||
assert label in self.nodes[0].listlabels()
|
assert label in self.nodes[0].listlabels()
|
||||||
self.nodes[0].rpc.ensure_ascii = True # restore to default
|
self.nodes[0].rpc.ensure_ascii = True # restore to default
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,10 @@ with and without a label.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.wallet_util import test_address
|
from test_framework.wallet_util import (
|
||||||
|
labels_value,
|
||||||
|
test_address,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImportWithLabel(BitcoinTestFramework):
|
class ImportWithLabel(BitcoinTestFramework):
|
||||||
|
@ -36,7 +39,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
address,
|
address,
|
||||||
iswatchonly=True,
|
iswatchonly=True,
|
||||||
ismine=False,
|
ismine=False,
|
||||||
label=label)
|
label=label,
|
||||||
|
labels=labels_value(name=label))
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Import the watch-only address's private key without a "
|
"Import the watch-only address's private key without a "
|
||||||
|
@ -47,7 +51,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
|
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
address,
|
address,
|
||||||
label=label)
|
label=label,
|
||||||
|
labels=labels_value(name=label))
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Test importaddress without label and importprivkey with label."
|
"Test importaddress without label and importprivkey with label."
|
||||||
|
@ -59,7 +64,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
address2,
|
address2,
|
||||||
iswatchonly=True,
|
iswatchonly=True,
|
||||||
ismine=False,
|
ismine=False,
|
||||||
label="")
|
label="",
|
||||||
|
labels=labels_value())
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Import the watch-only address's private key with a "
|
"Import the watch-only address's private key with a "
|
||||||
|
@ -71,7 +77,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
|
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
address2,
|
address2,
|
||||||
label=label2)
|
label=label2,
|
||||||
|
labels=labels_value(name=label2))
|
||||||
|
|
||||||
self.log.info("Test importaddress with label and importprivkey with label.")
|
self.log.info("Test importaddress with label and importprivkey with label.")
|
||||||
self.log.info("Import a watch-only address with a label.")
|
self.log.info("Import a watch-only address with a label.")
|
||||||
|
@ -82,7 +89,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
address3,
|
address3,
|
||||||
iswatchonly=True,
|
iswatchonly=True,
|
||||||
ismine=False,
|
ismine=False,
|
||||||
label=label3_addr)
|
label=label3_addr,
|
||||||
|
labels=labels_value(name=label3_addr))
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Import the watch-only address's private key with a "
|
"Import the watch-only address's private key with a "
|
||||||
|
@ -94,7 +102,8 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
|
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
address3,
|
address3,
|
||||||
label=label3_priv)
|
label=label3_priv,
|
||||||
|
labels=labels_value(name=label3_priv))
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Test importprivkey won't label new dests with the same "
|
"Test importprivkey won't label new dests with the same "
|
||||||
|
@ -109,6 +118,7 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
iswatchonly=True,
|
iswatchonly=True,
|
||||||
ismine=False,
|
ismine=False,
|
||||||
label=label4_addr,
|
label=label4_addr,
|
||||||
|
labels=labels_value(name=label4_addr),
|
||||||
embedded=None)
|
embedded=None)
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
|
@ -123,10 +133,13 @@ class ImportWithLabel(BitcoinTestFramework):
|
||||||
|
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
embedded_addr,
|
embedded_addr,
|
||||||
label="")
|
label="",
|
||||||
|
labels=labels_value())
|
||||||
|
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
address4,
|
address4,
|
||||||
label=label4_addr)
|
label=label4_addr,
|
||||||
|
labels=labels_value(name=label4_addr))
|
||||||
|
|
||||||
self.stop_nodes()
|
self.stop_nodes()
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ from test_framework.util import (
|
||||||
from test_framework.wallet_util import (
|
from test_framework.wallet_util import (
|
||||||
get_key,
|
get_key,
|
||||||
get_multisig,
|
get_multisig,
|
||||||
|
labels_value,
|
||||||
test_address,
|
test_address,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.test_importmulti({"scriptPubKey": key.p2pkh_script,
|
self.test_importmulti({"scriptPubKey": key.p2pkh_script,
|
||||||
"timestamp": "now",
|
"timestamp": "now",
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"label": "Example label"},
|
"label": "Unsuccessful labelling for internal addresses"},
|
||||||
success=False,
|
success=False,
|
||||||
error_code=-8,
|
error_code=-8,
|
||||||
error_message='Internal addresses should not have a label')
|
error_message='Internal addresses should not have a label')
|
||||||
|
@ -550,7 +551,7 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.log.info("Should not import a p2sh-p2wpkh address from descriptor without checksum and private key")
|
self.log.info("Should not import a p2sh-p2wpkh address from descriptor without checksum and private key")
|
||||||
self.test_importmulti({"desc": "sh(wpkh(" + key.pubkey + "))",
|
self.test_importmulti({"desc": "sh(wpkh(" + key.pubkey + "))",
|
||||||
"timestamp": "now",
|
"timestamp": "now",
|
||||||
"label": "Descriptor import test",
|
"label": "Unsuccessful P2SH-P2WPKH descriptor import",
|
||||||
"keys": [key.privkey]},
|
"keys": [key.privkey]},
|
||||||
success=False,
|
success=False,
|
||||||
error_code=-5,
|
error_code=-5,
|
||||||
|
@ -558,17 +559,19 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Test importing of a P2SH-P2WPKH address via descriptor + private key
|
# Test importing of a P2SH-P2WPKH address via descriptor + private key
|
||||||
key = get_key(self.nodes[0])
|
key = get_key(self.nodes[0])
|
||||||
|
p2sh_p2wpkh_label = "Successful P2SH-P2WPKH descriptor import"
|
||||||
self.log.info("Should import a p2sh-p2wpkh address from descriptor and private key")
|
self.log.info("Should import a p2sh-p2wpkh address from descriptor and private key")
|
||||||
self.test_importmulti({"desc": descsum_create("sh(wpkh(" + key.pubkey + "))"),
|
self.test_importmulti({"desc": descsum_create("sh(wpkh(" + key.pubkey + "))"),
|
||||||
"timestamp": "now",
|
"timestamp": "now",
|
||||||
"label": "Descriptor import test",
|
"label": p2sh_p2wpkh_label,
|
||||||
"keys": [key.privkey]},
|
"keys": [key.privkey]},
|
||||||
success=True)
|
success=True)
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
key.p2sh_p2wpkh_addr,
|
key.p2sh_p2wpkh_addr,
|
||||||
solvable=True,
|
solvable=True,
|
||||||
ismine=True,
|
ismine=True,
|
||||||
label="Descriptor import test")
|
label=p2sh_p2wpkh_label,
|
||||||
|
labels=labels_value(name=p2sh_p2wpkh_label))
|
||||||
|
|
||||||
# Test ranged descriptor fails if range is not specified
|
# Test ranged descriptor fails if range is not specified
|
||||||
xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg"
|
xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg"
|
||||||
|
@ -628,17 +631,19 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Test importing of a P2PKH address via descriptor
|
# Test importing of a P2PKH address via descriptor
|
||||||
key = get_key(self.nodes[0])
|
key = get_key(self.nodes[0])
|
||||||
|
p2pkh_label = "P2PKH descriptor import"
|
||||||
self.log.info("Should import a p2pkh address from descriptor")
|
self.log.info("Should import a p2pkh address from descriptor")
|
||||||
self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"),
|
self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"),
|
||||||
"timestamp": "now",
|
"timestamp": "now",
|
||||||
"label": "Descriptor import test"},
|
"label": p2pkh_label},
|
||||||
True,
|
True,
|
||||||
warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
|
warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
|
||||||
test_address(self.nodes[1],
|
test_address(self.nodes[1],
|
||||||
key.p2pkh_addr,
|
key.p2pkh_addr,
|
||||||
solvable=True,
|
solvable=True,
|
||||||
ismine=False,
|
ismine=False,
|
||||||
label="Descriptor import test")
|
label=p2pkh_label,
|
||||||
|
labels=labels_value(name=p2pkh_label))
|
||||||
|
|
||||||
# Test import fails if both desc and scriptPubKey are provided
|
# Test import fails if both desc and scriptPubKey are provided
|
||||||
key = get_key(self.nodes[0])
|
key = get_key(self.nodes[0])
|
||||||
|
|
|
@ -13,6 +13,10 @@ from collections import defaultdict
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error
|
from test_framework.util import assert_equal, assert_raises_rpc_error
|
||||||
|
from test_framework.wallet_util import (
|
||||||
|
labels_value,
|
||||||
|
test_address,
|
||||||
|
)
|
||||||
|
|
||||||
class WalletLabelsTest(BitcoinTestFramework):
|
class WalletLabelsTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -153,11 +157,12 @@ class Label:
|
||||||
if self.receive_address is not None:
|
if self.receive_address is not None:
|
||||||
assert self.receive_address in self.addresses
|
assert self.receive_address in self.addresses
|
||||||
for address in self.addresses:
|
for address in self.addresses:
|
||||||
assert_equal(
|
test_address(
|
||||||
node.getaddressinfo(address)['labels'][0],
|
node,
|
||||||
{"name": self.name,
|
address,
|
||||||
"purpose": self.purpose[address]})
|
label=self.name,
|
||||||
assert_equal(node.getaddressinfo(address)['label'], self.name)
|
labels=labels_value(name=self.name, purpose=self.purpose[address])
|
||||||
|
)
|
||||||
assert self.name in node.listlabels()
|
assert self.name in node.listlabels()
|
||||||
assert_equal(
|
assert_equal(
|
||||||
node.getaddressesbylabel(self.name),
|
node.getaddressesbylabel(self.name),
|
||||||
|
|
|
@ -11,6 +11,10 @@ from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import (
|
||||||
|
labels_value,
|
||||||
|
test_address,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ReceivedByTest(BitcoinTestFramework):
|
class ReceivedByTest(BitcoinTestFramework):
|
||||||
|
@ -127,7 +131,7 @@ class ReceivedByTest(BitcoinTestFramework):
|
||||||
# set pre-state
|
# set pre-state
|
||||||
label = ''
|
label = ''
|
||||||
address = self.nodes[1].getnewaddress()
|
address = self.nodes[1].getnewaddress()
|
||||||
assert_equal(self.nodes[1].getaddressinfo(address)['label'], label)
|
test_address(self.nodes[1], address, label=label, labels=labels_value(name=label))
|
||||||
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0]
|
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0]
|
||||||
balance_by_label = self.nodes[1].getreceivedbylabel(label)
|
balance_by_label = self.nodes[1].getreceivedbylabel(label)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue