Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_importmulti.py
Show First 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"Should fail to import a p2pkh address from descriptor with no checksum") | "Should fail to import a p2pkh address from descriptor with no checksum") | ||||
self.test_importmulti({"desc": "pkh(" + key.pubkey + ")", | self.test_importmulti({"desc": "pkh(" + key.pubkey + ")", | ||||
"timestamp": "now", | "timestamp": "now", | ||||
"label": "Descriptor import test"}, | "label": "Descriptor import test"}, | ||||
success=False, | success=False, | ||||
error_code=-5, | error_code=-5, | ||||
error_message='Missing checksum') | error_message='Missing checksum') | ||||
# Test ranged descriptor fails if range is not specified | |||||
xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg" | xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg" | ||||
# hdkeypath=m/0'/0'/0' and 1' | # hdkeypath=m/0'/0'/0' and 1' | ||||
addresses = [ | addresses = [ | ||||
"2N7yv4p8G8yEaPddJxY41kPihnWvs39qCMf", | "bchreg:prvn9ycvgr5atuyh49sua3mapskh2mnnzg34lqtyst", | ||||
"2MsHxyb2JS3pAySeNUsJ7mNnurtpeenDzLA"] | "bchreg:pp3n087yx0njv2e5wcvltahfxqst7l66ruyuaun8qt"] | ||||
desc = "pkh(" + xpriv + "/0'/0'/*'" + ")" | # pkh subscripts corresponding to the above addresses | ||||
addresses += [ | |||||
"bchreg:qqdkxd2xnzftq2p8wr3sqqyw8lntap7tncl2076yur", | |||||
"bchreg:qpyryy83jfaec5u0gpzldk6teadsuq8zly0fwmm3pq", | |||||
] | |||||
desc = "sh(pkh(" + xpriv + "/0'/0'/*'" + "))" | |||||
self.log.info( | self.log.info( | ||||
"Ranged descriptor import should fail without a specified range") | "Ranged descriptor import should fail without a specified range") | ||||
self.test_importmulti({"desc": descsum_create(desc), | self.test_importmulti({"desc": descsum_create(desc), | ||||
"timestamp": "now"}, | "timestamp": "now"}, | ||||
success=False, | success=False, | ||||
error_code=-8, | error_code=-8, | ||||
error_message='Descriptor is ranged, please specify the range') | error_message='Descriptor is ranged, please specify the range') | ||||
# Test importing of a ranged descriptor without keys | # Test importing of a ranged descriptor with xpriv | ||||
self.log.info( | self.log.info( | ||||
"Should import the ranged descriptor with specified range as solvable") | "Should import the ranged descriptor with specified range as solvable") | ||||
self.test_importmulti({"desc": descsum_create(desc), | self.test_importmulti({"desc": descsum_create(desc), | ||||
"timestamp": "now", | "timestamp": "now", | ||||
"range": 1}, | "range": 1}, | ||||
success=True, | success=True) | ||||
warnings=["Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."]) | |||||
for address in addresses: | for address in addresses: | ||||
# P2PKH are not considered solvable. | test_address(self.nodes[1], address, solvable=True, ismine=True) | ||||
test_address(self.nodes[1], key.p2pkh_addr, solvable=False) | |||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": -1}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": -1}, | ||||
success=False, error_code=-8, error_message='End of range is too high') | success=False, error_code=-8, error_message='End of range is too high') | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [-1, 10]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [-1, 10]}, | ||||
success=False, error_code=-8, error_message='Range should be greater or equal than 0') | success=False, error_code=-8, error_message='Range should be greater or equal than 0') | ||||
self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [(2 << 31 + 1) - 1000000, (2 << 31 + 1)]}, | self.test_importmulti({"desc": descsum_create(desc), "timestamp": "now", "range": [(2 << 31 + 1) - 1000000, (2 << 31 + 1)]}, | ||||
success=False, error_code=-8, error_message='End of range is too high') | success=False, error_code=-8, error_message='End of range is too high') | ||||
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 a descriptor containing a WIF private key | |||||
wif_priv = "cTe1f5rdT8A8DFgVWTjyPwACsDPJM9ff4QngFxUixCSvvbg1x6sh" | |||||
# Note: in Core's test, this address refers to the sh(wpkh()) address. | |||||
# For a sh(pkh()) this does not refer to a key, so we use the subscript | |||||
# address instead, which returns the same privkey. | |||||
address = "bchreg:qzh6rch6st3wjvp0h2ud87gn7xnxvf6h8yvgavjk6t" | |||||
desc = "sh(pkh(" + wif_priv + "))" | |||||
self.log.info( | |||||
"Should import a descriptor with a WIF private key as spendable") | |||||
self.test_importmulti({"desc": descsum_create(desc), | |||||
"timestamp": "now"}, | |||||
success=True) | |||||
test_address(self.nodes[1], | |||||
address, | |||||
solvable=True, | |||||
ismine=True) | |||||
# dump the private key to ensure it matches what was imported | |||||
privkey = self.nodes[1].dumpprivkey(address) | |||||
assert_equal(privkey, wif_priv) | |||||
# 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" | 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": p2pkh_label}, | "label": p2pkh_label}, | ||||
success=True, | success=True, | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |