Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_import_with_label.py
Show All 16 Lines | from test_framework.script import ( | ||||
OP_DUP, | OP_DUP, | ||||
OP_EQUALVERIFY, | OP_EQUALVERIFY, | ||||
OP_HASH160, | OP_HASH160, | ||||
hash160, | hash160, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import hex_str_to_bytes | from test_framework.util import hex_str_to_bytes | ||||
from test_framework.wallet_util import test_address | from test_framework.wallet_util import ( | ||||
labels_value, | |||||
test_address, | |||||
) | |||||
class ImportWithLabel(BitcoinTestFramework): | class ImportWithLabel(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
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 run_test(self): | def run_test(self): | ||||
"""Main test logic""" | """Main test logic""" | ||||
self.log.info( | self.log.info( | ||||
"Test importaddress with label and importprivkey without label." | "Test importaddress with label and importprivkey without label." | ||||
) | ) | ||||
self.log.info("Import a watch-only address with a label.") | self.log.info("Import a watch-only address with a label.") | ||||
address = self.nodes[0].getnewaddress() | address = self.nodes[0].getnewaddress() | ||||
label = "Test Label" | label = "Test Label" | ||||
self.nodes[1].importaddress(address, label) | self.nodes[1].importaddress(address, label) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
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 " | ||||
"label and the address should keep its label." | "label and the address should keep its label." | ||||
) | ) | ||||
priv_key = self.nodes[0].dumpprivkey(address) | priv_key = self.nodes[0].dumpprivkey(address) | ||||
self.nodes[1].importprivkey(priv_key) | self.nodes[1].importprivkey(priv_key) | ||||
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." | ||||
) | ) | ||||
self.log.info("Import a watch-only address without a label.") | self.log.info("Import a watch-only address without a label.") | ||||
address2 = self.nodes[0].getnewaddress() | address2 = self.nodes[0].getnewaddress() | ||||
self.nodes[1].importaddress(address2) | self.nodes[1].importaddress(address2) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
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 " | ||||
"label and the address should have its label updated." | "label and the address should have its label updated." | ||||
) | ) | ||||
priv_key2 = self.nodes[0].dumpprivkey(address2) | priv_key2 = self.nodes[0].dumpprivkey(address2) | ||||
label2 = "Test Label 2" | label2 = "Test Label 2" | ||||
self.nodes[1].importprivkey(priv_key2, label2) | self.nodes[1].importprivkey(priv_key2, label2) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
address2, | address2, | ||||
label=label2) | label=label2, | ||||
labels=labels_value(name=label2)) | |||||
self.log.info( | self.log.info( | ||||
"Test importaddress with label and importprivkey with label.") | "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.") | ||||
address3 = self.nodes[0].getnewaddress() | address3 = self.nodes[0].getnewaddress() | ||||
label3_addr = "Test Label 3 for importaddress" | label3_addr = "Test Label 3 for importaddress" | ||||
self.nodes[1].importaddress(address3, label3_addr) | self.nodes[1].importaddress(address3, label3_addr) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
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 " | ||||
"label and the address should have its label updated." | "label and the address should have its label updated." | ||||
) | ) | ||||
priv_key3 = self.nodes[0].dumpprivkey(address3) | priv_key3 = self.nodes[0].dumpprivkey(address3) | ||||
label3_priv = "Test Label 3 for importprivkey" | label3_priv = "Test Label 3 for importprivkey" | ||||
self.nodes[1].importprivkey(priv_key3, label3_priv) | self.nodes[1].importprivkey(priv_key3, label3_priv) | ||||
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 " | ||||
"label as others labeled dests for the same key." | "label as others labeled dests for the same key." | ||||
) | ) | ||||
self.log.info("Import a watch-only legacy address with a label.") | self.log.info("Import a watch-only legacy address with a label.") | ||||
address4 = self.nodes[0].getnewaddress() | address4 = self.nodes[0].getnewaddress() | ||||
label4_addr = "Test Label 4 for importaddress" | label4_addr = "Test Label 4 for importaddress" | ||||
self.nodes[1].importaddress(address4, label4_addr) | self.nodes[1].importaddress(address4, label4_addr) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
address4, | address4, | ||||
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( | ||||
"Import the watch-only address's private key without a " | "Import the watch-only address's private key without a " | ||||
"label and new destinations for the key should have an " | "label and new destinations for the key should have an " | ||||
"empty label while the 'old' destination should keep " | "empty label while the 'old' destination should keep " | ||||
"its label." | "its label." | ||||
) | ) | ||||
Show All 10 Lines | def run_test(self): | ||||
"scriptPubKey": {"address": p2shaddr4}, | "scriptPubKey": {"address": p2shaddr4}, | ||||
"timestamp": "now", | "timestamp": "now", | ||||
"redeemscript": script4.hex(), | "redeemscript": script4.hex(), | ||||
"keys": [priv_key4], | "keys": [priv_key4], | ||||
}]) | }]) | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
p2shaddr4, | p2shaddr4, | ||||
label="") | label="", | ||||
labels=labels_value()) | |||||
embedded_addr = self.nodes[1].getaddressinfo( | embedded_addr = self.nodes[1].getaddressinfo( | ||||
p2shaddr4)['embedded']['address'] | p2shaddr4)['embedded']['address'] | ||||
test_address(self.nodes[1], | test_address(self.nodes[1], | ||||
embedded_addr, | embedded_addr, | ||||
label=label4_addr) | label=label4_addr, | ||||
labels=labels_value(name=label4_addr)) | |||||
self.stop_nodes() | self.stop_nodes() | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
ImportWithLabel().main() | ImportWithLabel().main() |