mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
00b3dbd877
33f5fc32e5bfbe1e89c4d20ce455bcc6dc194151 test: add rpc getaddressinfo labels test coverage (Jon Atack) 0f3539ac6d772fc646b5f184fa1efe77bf632f6a test: add listlabels test in wallet_labels.py (Jon Atack) 1388de83900eaced906d369fe9e8887ae74b2dcf rpc: add getaddressinfo code documentation (Jon Atack) 2ee0cb3330ccf70f0540cb42370796e32eff1569 rpc: update getaddressinfo RPCExamples to bech32 (Jon Atack) 8d1ed0c263f8cdff7189f02040b5d02238d93da0 rpc: clarify label vs labels in getaddressinfo RPCHelpman (Jon Atack) 5a0ed850700dfb19167d40b38f80313bd5e427ca rpc: improve getaddressinfo RPCHelpman content (Jon Atack) 70cda342cd20d0e0cd9f28405457544036968f2d rpc: improve getaddressinfo RPCHelpman formatting (Jon Atack) Pull request description: This PR is a continuation of the work in https://github.com/bitcoin/bitcoin/pull/12892. Main motivations: - There is currently no test coverage for the getaddressinfo `labels` response. Coverage here is a prerequisite before deprecating the `label` response or adding multiple labels per address. - `bitcoin-cli help getaddressinfo` returns a few content errors, difficult-to-read formatting, and no explanation why it returns both `label` and `labels` and how they relate, which can be confusing for application developers. Changes by order of commits: - [x] improve/fix getaddressinfo RPCHelpman layout formatting - [x] improve/fix getaddressinfo RPCHelpman content - [x] clarify the `label` and `labels` fields in getaddressinfo RPCHelpman - [x] update getaddressinfo RPCExamples addresses to bech32 - [x] add getaddressinfo code docs - [x] add a `listlabels` test assertion in wallet_labels.py - [x] add missing getaddressinfo `labels` test coverage and improve the existing `label` tests Here are gists of the CLI help output: [`bitcoin-cli help getaddressinfo` before this PR](https://gist.github.com/jonatack/022af5221a85c069780359a22643c810) [`bitcoin-cli help getaddressinfo` after this PR](https://gist.github.com/jonatack/4ee5f6abc62a3d99269570206a5f90ba) It seems we ought to begin a deprecation process for the getaddressinfo `label` field? If yes, I have a follow-up ready. _--> EDIT: Deprecation follow-ups #17578 and #17585 now build on this PR._ ACKs for top commit: fjahr: Re-ACK 33f5fc32e5bfbe1e89c4d20ce455bcc6dc194151 jnewbery: ACK 33f5fc32e5bfbe1e89c4d20ce455bcc6dc194151. Tree-SHA512: a001aa863090ec2566a31059477945b1c303ebeb430b33472f8b150e420fa5742fc33bca9d95571746395b607f43f6078dd5b53e238ac1f3fc648b51c8f79a07
141 lines
5.0 KiB
Python
Executable File
141 lines
5.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2018 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test the behavior of RPC importprivkey on set and unset labels of
|
|
addresses.
|
|
|
|
It tests different cases in which an address is imported with importaddress
|
|
with or without a label and then its private key is imported with importprivkey
|
|
with and without a label.
|
|
"""
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.wallet_util import (
|
|
labels_value,
|
|
test_address,
|
|
)
|
|
|
|
|
|
class ImportWithLabel(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 2
|
|
self.setup_clean_chain = True
|
|
|
|
def skip_test_if_missing_module(self):
|
|
self.skip_if_no_wallet()
|
|
|
|
def run_test(self):
|
|
"""Main test logic"""
|
|
|
|
self.log.info(
|
|
"Test importaddress with label and importprivkey without label."
|
|
)
|
|
self.log.info("Import a watch-only address with a label.")
|
|
address = self.nodes[0].getnewaddress()
|
|
label = "Test Label"
|
|
self.nodes[1].importaddress(address, label)
|
|
test_address(self.nodes[1],
|
|
address,
|
|
iswatchonly=True,
|
|
ismine=False,
|
|
label=label,
|
|
labels=labels_value(name=label))
|
|
|
|
self.log.info(
|
|
"Import the watch-only address's private key without a "
|
|
"label and the address should keep its label."
|
|
)
|
|
priv_key = self.nodes[0].dumpprivkey(address)
|
|
self.nodes[1].importprivkey(priv_key)
|
|
|
|
test_address(self.nodes[1],
|
|
address,
|
|
label=label,
|
|
labels=labels_value(name=label))
|
|
|
|
self.log.info(
|
|
"Test importaddress without label and importprivkey with label."
|
|
)
|
|
self.log.info("Import a watch-only address without a label.")
|
|
address2 = self.nodes[0].getnewaddress()
|
|
self.nodes[1].importaddress(address2)
|
|
test_address(self.nodes[1],
|
|
address2,
|
|
iswatchonly=True,
|
|
ismine=False,
|
|
label="",
|
|
labels=labels_value())
|
|
|
|
self.log.info(
|
|
"Import the watch-only address's private key with a "
|
|
"label and the address should have its label updated."
|
|
)
|
|
priv_key2 = self.nodes[0].dumpprivkey(address2)
|
|
label2 = "Test Label 2"
|
|
self.nodes[1].importprivkey(priv_key2, label2)
|
|
|
|
test_address(self.nodes[1],
|
|
address2,
|
|
label=label2,
|
|
labels=labels_value(name=label2))
|
|
|
|
self.log.info("Test importaddress with label and importprivkey with label.")
|
|
self.log.info("Import a watch-only address with a label.")
|
|
address3 = self.nodes[0].getnewaddress()
|
|
label3_addr = "Test Label 3 for importaddress"
|
|
self.nodes[1].importaddress(address3, label3_addr)
|
|
test_address(self.nodes[1],
|
|
address3,
|
|
iswatchonly=True,
|
|
ismine=False,
|
|
label=label3_addr,
|
|
labels=labels_value(name=label3_addr))
|
|
|
|
self.log.info(
|
|
"Import the watch-only address's private key with a "
|
|
"label and the address should have its label updated."
|
|
)
|
|
priv_key3 = self.nodes[0].dumpprivkey(address3)
|
|
label3_priv = "Test Label 3 for importprivkey"
|
|
self.nodes[1].importprivkey(priv_key3, label3_priv)
|
|
|
|
test_address(self.nodes[1],
|
|
address3,
|
|
label=label3_priv,
|
|
labels=labels_value(name=label3_priv))
|
|
|
|
self.log.info(
|
|
"Test importprivkey won't label new dests with the same "
|
|
"label as others labeled dests for the same key."
|
|
)
|
|
self.log.info("Import a watch-only legacy address with a label.")
|
|
address4 = self.nodes[0].getnewaddress()
|
|
label4_addr = "Test Label 4 for importaddress"
|
|
self.nodes[1].importaddress(address4, label4_addr)
|
|
test_address(self.nodes[1],
|
|
address4,
|
|
iswatchonly=True,
|
|
ismine=False,
|
|
label=label4_addr,
|
|
labels=labels_value(name=label4_addr))
|
|
|
|
self.log.info(
|
|
"Import the watch-only address's private key without a "
|
|
"label and new destinations for the key should have an "
|
|
"empty label while the 'old' destination should keep "
|
|
"its label."
|
|
)
|
|
priv_key4 = self.nodes[0].dumpprivkey(address4)
|
|
self.nodes[1].importprivkey(priv_key4)
|
|
test_address(self.nodes[1],
|
|
address4,
|
|
label=label4_addr,
|
|
labels=labels_value(name=label4_addr))
|
|
|
|
self.stop_nodes()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ImportWithLabel().main()
|