Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_importmulti.py
Show All 23 Lines | |||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
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, | ||||
) | ) | ||||
class ImportMultiTest(BitcoinTestFramework): | class ImportMultiTest(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 | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# ScriptPubKey + internal + label | # ScriptPubKey + internal + label | ||||
self.log.info( | self.log.info( | ||||
"Should not allow a label to be specified when internal is true") | "Should not allow a label to be specified when internal is true") | ||||
key = get_key(self.nodes[0]) | key = get_key(self.nodes[0]) | ||||
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') | ||||
# Nonstandard scriptPubKey + !internal | # Nonstandard scriptPubKey + !internal | ||||
self.log.info( | self.log.info( | ||||
"Should not import a nonstandard scriptPubKey without internal flag") | "Should not import a nonstandard scriptPubKey without internal flag") | ||||
nonstandardScriptPubKey = key.p2pkh_script + CScript([OP_NOP]).hex() | nonstandardScriptPubKey = key.p2pkh_script + CScript([OP_NOP]).hex() | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [2, 1]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [2, 1]}, | ||||
success=False, error_code=-8, error_message='Range specified as [begin,end] must not have begin after end') | success=False, error_code=-8, error_message='Range specified as [begin,end] must not have begin after end') | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [0, 1000001]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [0, 1000001]}, | ||||
success=False, error_code=-8, error_message='Range is too large') | success=False, error_code=-8, error_message='Range is too large') | ||||
# 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}, | ||||
success=True, | success=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]) | ||||
self.log.info( | self.log.info( | ||||
"Import should fail if both scriptPubKey and desc are provided") | "Import should fail if both scriptPubKey and desc are provided") | ||||
self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"), | self.test_importmulti({"desc": descsum_create("pkh(" + key.pubkey + ")"), | ||||
"scriptPubKey": {"address": key.p2pkh_addr}, | "scriptPubKey": {"address": key.p2pkh_addr}, | ||||
"timestamp": "now"}, | "timestamp": "now"}, | ||||
▲ Show 20 Lines • Show All 218 Lines • Show Last 20 Lines |