[tests] tidy up wallet_importmulti.py

Fixes review comments from PR 14886.
This commit is contained in:
John Newbery 2018-12-13 12:32:50 -05:00 committed by Amiti Uttarwar
parent fe5a70b9fe
commit 6be64ef02c

View file

@ -87,18 +87,18 @@ class ImportMultiTest(BitcoinTestFramework):
addr = self.nodes[0].getnewaddress() addr = self.nodes[0].getnewaddress()
pubkey = self.nodes[0].getaddressinfo(addr)['pubkey'] pubkey = self.nodes[0].getaddressinfo(addr)['pubkey']
pkh = hash160(hex_str_to_bytes(pubkey)) pkh = hash160(hex_str_to_bytes(pubkey))
return Key(self.nodes[0].dumpprivkey(addr), return Key(privkey=self.nodes[0].dumpprivkey(addr),
pubkey, pubkey=pubkey,
CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), # p2pkh p2pkh_script=CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(),
key_to_p2pkh(pubkey), # p2pkh addr p2pkh_addr=key_to_p2pkh(pubkey),
CScript([OP_0, pkh]).hex(), # p2wpkh p2wpkh_script=CScript([OP_0, pkh]).hex(),
key_to_p2wpkh(pubkey), # p2wpkh addr p2wpkh_addr=key_to_p2wpkh(pubkey),
CScript([OP_HASH160, hash160(CScript([OP_0, pkh])), OP_EQUAL]).hex(), # p2sh-p2wpkh p2sh_p2wpkh_script=CScript([OP_HASH160, hash160(CScript([OP_0, pkh])), OP_EQUAL]).hex(),
CScript([OP_0, pkh]).hex(), # p2sh-p2wpkh redeem script p2sh_p2wpkh_redeem_script=CScript([OP_0, pkh]).hex(),
key_to_p2sh_p2wpkh(pubkey)) # p2sh-p2wpkh addr p2sh_p2wpkh_addr=key_to_p2sh_p2wpkh(pubkey))
def get_multisig(self): def get_multisig(self):
"""Generate a fresh multisig on node0 """Generate a fresh 2-of-3 multisig on node0
Returns a named tuple of privkeys, pubkeys and all address and scripts.""" Returns a named tuple of privkeys, pubkeys and all address and scripts."""
addrs = [] addrs = []
@ -109,15 +109,15 @@ class ImportMultiTest(BitcoinTestFramework):
pubkeys.append(addr['pubkey']) pubkeys.append(addr['pubkey'])
script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG]) script_code = CScript([OP_2] + [hex_str_to_bytes(pubkey) for pubkey in pubkeys] + [OP_3, OP_CHECKMULTISIG])
witness_script = CScript([OP_0, sha256(script_code)]) witness_script = CScript([OP_0, sha256(script_code)])
return Multisig([self.nodes[0].dumpprivkey(addr) for addr in addrs], return Multisig(privkeys=[self.nodes[0].dumpprivkey(addr) for addr in addrs],
pubkeys, pubkeys=pubkeys,
CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(), # p2sh p2sh_script=CScript([OP_HASH160, hash160(script_code), OP_EQUAL]).hex(),
script_to_p2sh(script_code), # p2sh addr p2sh_addr=script_to_p2sh(script_code),
script_code.hex(), # redeem script redeem_script=script_code.hex(),
witness_script.hex(), # p2wsh p2wsh_script=witness_script.hex(),
script_to_p2wsh(script_code), # p2wsh addr p2wsh_addr=script_to_p2wsh(script_code),
CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(), # p2sh-p2wsh p2sh_p2wsh_script=CScript([OP_HASH160, witness_script, OP_EQUAL]).hex(),
script_to_p2sh_p2wsh(script_code)) # p2sh-p2wsh addr p2sh_p2wsh_addr=script_to_p2sh_p2wsh(script_code))
def test_importmulti(self, req, success, error_code=None, error_message=None, warnings=[]): def test_importmulti(self, req, success, error_code=None, error_message=None, warnings=[]):
"""Run importmulti and assert success""" """Run importmulti and assert success"""
@ -165,22 +165,21 @@ class ImportMultiTest(BitcoinTestFramework):
# Bitcoin Address (implicit non-internal) # Bitcoin Address (implicit non-internal)
self.log.info("Should import an address") self.log.info("Should import an address")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
timestamp=timestamp, timestamp=timestamp,
ischange=False) ischange=False)
watchonly_address = address watchonly_address = key.p2pkh_addr
watchonly_timestamp = timestamp watchonly_timestamp = timestamp
self.log.info("Should not import an invalid address") self.log.info("Should not import an invalid address")
self.test_importmulti({"scriptPubKey": {"address": "not valid address"}, self.test_importmulti({"scriptPubKey": {"address": "not valid address"},
"timestamp": "now"}, "timestamp": "now"},
False, success=False,
error_code=-5, error_code=-5,
error_message='Invalid address \"not valid address\"') error_message='Invalid address \"not valid address\"')
@ -190,7 +189,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},
True) success=True)
self.test_address(key.p2pkh_addr, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
@ -204,7 +203,7 @@ class ImportMultiTest(BitcoinTestFramework):
"timestamp": "now", "timestamp": "now",
"internal": True, "internal": True,
"label": "Example label"}, "label": "Example label"},
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')
@ -212,13 +211,12 @@ class ImportMultiTest(BitcoinTestFramework):
self.log.info("Should not import a nonstandard scriptPubKey without internal flag") self.log.info("Should not import a nonstandard scriptPubKey without internal flag")
nonstandardScriptPubKey = key.p2pkh_script + bytes_to_hex_str(CScript([OP_NOP])) nonstandardScriptPubKey = key.p2pkh_script + bytes_to_hex_str(CScript([OP_NOP]))
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey, self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey,
"timestamp": "now"}, "timestamp": "now"},
False, success=False,
error_code=-8, error_code=-8,
error_message='Internal must be set to true for nonstandard scriptPubKey imports.') error_message='Internal must be set to true for nonstandard scriptPubKey imports.')
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=False, ismine=False,
timestamp=None) timestamp=None)
@ -226,14 +224,13 @@ class ImportMultiTest(BitcoinTestFramework):
# Address + Public key + !Internal(explicit) # Address + Public key + !Internal(explicit)
self.log.info("Should import an address with public key") self.log.info("Should import an address with public key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now", "timestamp": "now",
"pubkeys": [key.pubkey], "pubkeys": [key.pubkey],
"internal": False}, "internal": False},
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."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
timestamp=timestamp) timestamp=timestamp)
@ -241,14 +238,13 @@ class ImportMultiTest(BitcoinTestFramework):
# ScriptPubKey + Public key + internal # ScriptPubKey + Public key + internal
self.log.info("Should import a scriptPubKey with internal and with public key") self.log.info("Should import a scriptPubKey with internal and with public key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
self.test_importmulti({"scriptPubKey": key.p2pkh_script, self.test_importmulti({"scriptPubKey": key.p2pkh_script,
"timestamp": "now", "timestamp": "now",
"pubkeys": [key.pubkey], "pubkeys": [key.pubkey],
"internal": True}, "internal": True},
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."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
timestamp=timestamp) timestamp=timestamp)
@ -256,14 +252,13 @@ class ImportMultiTest(BitcoinTestFramework):
# Nonstandard scriptPubKey + Public key + !internal # Nonstandard scriptPubKey + Public key + !internal
self.log.info("Should not import a nonstandard scriptPubKey without internal and with public key") self.log.info("Should not import a nonstandard scriptPubKey without internal and with public key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey, self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey,
"timestamp": "now", "timestamp": "now",
"pubkeys": [key.pubkey]}, "pubkeys": [key.pubkey]},
False, success=False,
error_code=-8, error_code=-8,
error_message='Internal must be set to true for nonstandard scriptPubKey imports.') error_message='Internal must be set to true for nonstandard scriptPubKey imports.')
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=False, ismine=False,
timestamp=None) timestamp=None)
@ -271,35 +266,33 @@ class ImportMultiTest(BitcoinTestFramework):
# Address + Private key + !watchonly # Address + Private key + !watchonly
self.log.info("Should import an address with private key") self.log.info("Should import an address with private key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey]}, "keys": [key.privkey]},
True) success=True)
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=True, ismine=True,
timestamp=timestamp) timestamp=timestamp)
self.log.info("Should not import an address with private key if is already imported") self.log.info("Should not import an address with private key if is already imported")
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey]}, "keys": [key.privkey]},
False, success=False,
error_code=-4, error_code=-4,
error_message='The wallet already contains the private key for this address or script') error_message='The wallet already contains the private key for this address or script')
# Address + Private key + watchonly # Address + Private key + watchonly
self.log.info("Should import an address with private key and with watchonly") self.log.info("Should import an address with private key and with watchonly")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey], "keys": [key.privkey],
"watchonly": True}, "watchonly": True},
True, success=True,
warnings=["All private keys are provided, outputs will be considered spendable. If this is intentional, do not specify the watchonly flag."]) warnings=["All private keys are provided, outputs will be considered spendable. If this is intentional, do not specify the watchonly flag."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=True, ismine=True,
timestamp=timestamp) timestamp=timestamp)
@ -307,13 +300,12 @@ class ImportMultiTest(BitcoinTestFramework):
# ScriptPubKey + Private key + internal # ScriptPubKey + Private key + internal
self.log.info("Should import a scriptPubKey with internal and with private key") self.log.info("Should import a scriptPubKey with internal and with private key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
self.test_importmulti({"scriptPubKey": key.p2pkh_script, self.test_importmulti({"scriptPubKey": key.p2pkh_script,
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey], "keys": [key.privkey],
"internal": True}, "internal": True},
True) success=True)
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=True, ismine=True,
timestamp=timestamp) timestamp=timestamp)
@ -321,14 +313,13 @@ class ImportMultiTest(BitcoinTestFramework):
# Nonstandard scriptPubKey + Private key + !internal # Nonstandard scriptPubKey + Private key + !internal
self.log.info("Should not import a nonstandard scriptPubKey without internal and with private key") self.log.info("Should not import a nonstandard scriptPubKey without internal and with private key")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey, self.test_importmulti({"scriptPubKey": nonstandardScriptPubKey,
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey]}, "keys": [key.privkey]},
False, success=False,
error_code=-8, error_code=-8,
error_message='Internal must be set to true for nonstandard scriptPubKey imports.') error_message='Internal must be set to true for nonstandard scriptPubKey imports.')
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=False, ismine=False,
timestamp=None) timestamp=None)
@ -343,7 +334,7 @@ class ImportMultiTest(BitcoinTestFramework):
self.log.info("Should import a p2sh") self.log.info("Should import a p2sh")
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr}, self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(multisig.p2sh_addr, self.test_address(multisig.p2sh_addr,
isscript=True, isscript=True,
iswatchonly=True, iswatchonly=True,
@ -363,7 +354,7 @@ class ImportMultiTest(BitcoinTestFramework):
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr}, self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
"timestamp": "now", "timestamp": "now",
"redeemscript": multisig.redeem_script}, "redeemscript": multisig.redeem_script},
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."])
self.test_address(multisig.p2sh_addr, timestamp=timestamp, iswatchonly=True, ismine=False, solvable=True) self.test_address(multisig.p2sh_addr, timestamp=timestamp, iswatchonly=True, ismine=False, solvable=True)
@ -383,7 +374,7 @@ class ImportMultiTest(BitcoinTestFramework):
"timestamp": "now", "timestamp": "now",
"redeemscript": multisig.redeem_script, "redeemscript": multisig.redeem_script,
"keys": multisig.privkeys[0:2]}, "keys": multisig.privkeys[0:2]},
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."])
self.test_address(multisig.p2sh_addr, self.test_address(multisig.p2sh_addr,
timestamp=timestamp, timestamp=timestamp,
@ -408,7 +399,7 @@ class ImportMultiTest(BitcoinTestFramework):
"redeemscript": multisig.redeem_script, "redeemscript": multisig.redeem_script,
"keys": multisig.privkeys[0:2], "keys": multisig.privkeys[0:2],
"watchonly": True}, "watchonly": True},
True) success=True)
self.test_address(multisig.p2sh_addr, self.test_address(multisig.p2sh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
@ -418,14 +409,13 @@ class ImportMultiTest(BitcoinTestFramework):
# Address + Public key + !Internal + Wrong pubkey # Address + Public key + !Internal + Wrong pubkey
self.log.info("Should not import an address with the wrong public key as non-solvable") self.log.info("Should not import an address with the wrong public key as non-solvable")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
wrong_key = self.get_key().pubkey wrong_key = self.get_key().pubkey
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
"timestamp": "now", "timestamp": "now",
"pubkeys": [wrong_key]}, "pubkeys": [wrong_key]},
True, success=True,
warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."]) warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
solvable=False, solvable=False,
@ -434,15 +424,14 @@ class ImportMultiTest(BitcoinTestFramework):
# ScriptPubKey + Public key + internal + Wrong pubkey # ScriptPubKey + Public key + internal + Wrong pubkey
self.log.info("Should import a scriptPubKey with internal and with a wrong public key as non-solvable") self.log.info("Should import a scriptPubKey with internal and with a wrong public key as non-solvable")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
wrong_key = self.get_key().pubkey wrong_key = self.get_key().pubkey
self.test_importmulti({"scriptPubKey": key.p2pkh_script, self.test_importmulti({"scriptPubKey": key.p2pkh_script,
"timestamp": "now", "timestamp": "now",
"pubkeys": [wrong_key], "pubkeys": [wrong_key],
"internal": True}, "internal": True},
True, success=True,
warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."]) warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
solvable=False, solvable=False,
@ -451,14 +440,13 @@ class ImportMultiTest(BitcoinTestFramework):
# Address + Private key + !watchonly + Wrong private key # Address + Private key + !watchonly + Wrong private key
self.log.info("Should import an address with a wrong private key as non-solvable") self.log.info("Should import an address with a wrong private key as non-solvable")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
wrong_privkey = self.get_key().privkey wrong_privkey = self.get_key().privkey
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2pkh_addr},
"timestamp": "now", "timestamp": "now",
"keys": [wrong_privkey]}, "keys": [wrong_privkey]},
True, success=True,
warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."]) warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
solvable=False, solvable=False,
@ -467,15 +455,14 @@ class ImportMultiTest(BitcoinTestFramework):
# ScriptPubKey + Private key + internal + Wrong private key # ScriptPubKey + Private key + internal + Wrong private key
self.log.info("Should import a scriptPubKey with internal and with a wrong private key as non-solvable") self.log.info("Should import a scriptPubKey with internal and with a wrong private key as non-solvable")
key = self.get_key() key = self.get_key()
address = key.p2pkh_addr
wrong_privkey = self.get_key().privkey wrong_privkey = self.get_key().privkey
self.test_importmulti({"scriptPubKey": key.p2pkh_script, self.test_importmulti({"scriptPubKey": key.p2pkh_script,
"timestamp": "now", "timestamp": "now",
"keys": [wrong_privkey], "keys": [wrong_privkey],
"internal": True}, "internal": True},
True, success=True,
warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."]) warnings=["Importing as non-solvable: some required keys are missing. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript.", "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."])
self.test_address(address, self.test_address(key.p2pkh_addr,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
solvable=False, solvable=False,
@ -486,7 +473,7 @@ class ImportMultiTest(BitcoinTestFramework):
self.log.info("Should replace previously saved watch only timestamp.") self.log.info("Should replace previously saved watch only timestamp.")
self.test_importmulti({"scriptPubKey": {"address": watchonly_address}, self.test_importmulti({"scriptPubKey": {"address": watchonly_address},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(watchonly_address, self.test_address(watchonly_address,
iswatchonly=True, iswatchonly=True,
ismine=False, ismine=False,
@ -514,36 +501,33 @@ class ImportMultiTest(BitcoinTestFramework):
# Import P2WPKH address as watch only # Import P2WPKH address as watch only
self.log.info("Should import a P2WPKH address as watch only") self.log.info("Should import a P2WPKH address as watch only")
key = self.get_key() key = self.get_key()
address = key.p2wpkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2wpkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(address, self.test_address(key.p2wpkh_addr,
iswatchonly=True, iswatchonly=True,
solvable=False) solvable=False)
# Import P2WPKH address with public key but no private key # Import P2WPKH address with public key but no private key
self.log.info("Should import a P2WPKH address and public key as solvable but not spendable") self.log.info("Should import a P2WPKH address and public key as solvable but not spendable")
key = self.get_key() key = self.get_key()
address = key.p2wpkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2wpkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now", "timestamp": "now",
"pubkeys": [key.pubkey]}, "pubkeys": [key.pubkey]},
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."])
self.test_address(address, self.test_address(key.p2wpkh_addr,
ismine=False, ismine=False,
solvable=True) solvable=True)
# Import P2WPKH address with key and check it is spendable # Import P2WPKH address with key and check it is spendable
self.log.info("Should import a P2WPKH address with key") self.log.info("Should import a P2WPKH address with key")
key = self.get_key() key = self.get_key()
address = key.p2wpkh_addr self.test_importmulti({"scriptPubKey": {"address": key.p2wpkh_addr},
self.test_importmulti({"scriptPubKey": {"address": address},
"timestamp": "now", "timestamp": "now",
"keys": [key.privkey]}, "keys": [key.privkey]},
True) success=True)
self.test_address(address, self.test_address(key.p2wpkh_addr,
iswatchonly=False, iswatchonly=False,
ismine=True) ismine=True)
@ -552,7 +536,7 @@ class ImportMultiTest(BitcoinTestFramework):
self.log.info("Should import a p2wsh multisig as watch only without respective redeem script and private keys") self.log.info("Should import a p2wsh multisig as watch only without respective redeem script and private keys")
self.test_importmulti({"scriptPubKey": {"address": multisig.p2wsh_addr}, self.test_importmulti({"scriptPubKey": {"address": multisig.p2wsh_addr},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(multisig.p2sh_addr, self.test_address(multisig.p2sh_addr,
solvable=False) solvable=False)
@ -562,7 +546,7 @@ class ImportMultiTest(BitcoinTestFramework):
"timestamp": "now", "timestamp": "now",
"witnessscript": multisig.redeem_script, "witnessscript": multisig.redeem_script,
"keys": multisig.privkeys}, "keys": multisig.privkeys},
True) success=True)
self.test_address(multisig.p2sh_addr, self.test_address(multisig.p2sh_addr,
solvable=True, solvable=True,
ismine=True, ismine=True,
@ -570,51 +554,48 @@ class ImportMultiTest(BitcoinTestFramework):
# P2SH-P2WPKH address with no redeemscript or public or private key # P2SH-P2WPKH address with no redeemscript or public or private key
key = self.get_key() key = self.get_key()
address = key.p2sh_p2wpkh_addr
self.log.info("Should import a p2sh-p2wpkh without redeem script or keys") self.log.info("Should import a p2sh-p2wpkh without redeem script or keys")
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2sh_p2wpkh_addr},
"timestamp": "now"}, "timestamp": "now"},
True) success=True)
self.test_address(address, self.test_address(key.p2sh_p2wpkh_addr,
solvable=False, solvable=False,
ismine=False) ismine=False)
# P2SH-P2WPKH address + redeemscript + public key with no private key # P2SH-P2WPKH address + redeemscript + public key with no private key
self.log.info("Should import a p2sh-p2wpkh with respective redeem script and pubkey as solvable") self.log.info("Should import a p2sh-p2wpkh with respective redeem script and pubkey as solvable")
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2sh_p2wpkh_addr},
"timestamp": "now", "timestamp": "now",
"redeemscript": key.p2sh_p2wpkh_redeem_script, "redeemscript": key.p2sh_p2wpkh_redeem_script,
"pubkeys": [key.pubkey]}, "pubkeys": [key.pubkey]},
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."])
self.test_address(address, self.test_address(key.p2sh_p2wpkh_addr,
solvable=True, solvable=True,
ismine=False) ismine=False)
# P2SH-P2WPKH address + redeemscript + private key # P2SH-P2WPKH address + redeemscript + private key
key = self.get_key() key = self.get_key()
address = key.p2sh_p2wpkh_addr
self.log.info("Should import a p2sh-p2wpkh with respective redeem script and private keys") self.log.info("Should import a p2sh-p2wpkh with respective redeem script and private keys")
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": key.p2sh_p2wpkh_addr},
"timestamp": "now", "timestamp": "now",
"redeemscript": key.p2sh_p2wpkh_redeem_script, "redeemscript": key.p2sh_p2wpkh_redeem_script,
"keys": [key.privkey]}, "keys": [key.privkey]},
True) success=True)
self.test_address(address, self.test_address(key.p2sh_p2wpkh_addr,
solvable=True, solvable=True,
ismine=True) ismine=True)
# P2SH-P2WSH multisig + redeemscript with no private key # P2SH-P2WSH multisig + redeemscript with no private key
multisig = self.get_multisig() multisig = self.get_multisig()
address = multisig.p2sh_p2wsh_addr
self.log.info("Should import a p2sh-p2wsh with respective redeem script but no private key") self.log.info("Should import a p2sh-p2wsh with respective redeem script but no private key")
self.test_importmulti({"scriptPubKey": {"address": address}, self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_p2wsh_addr},
"timestamp": "now", "timestamp": "now",
"redeemscript": multisig.p2wsh_script, "redeemscript": multisig.p2wsh_script,
"witnessscript": multisig.redeem_script}, "witnessscript": multisig.redeem_script},
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."])
self.test_address(address, self.test_address(multisig.p2sh_p2wsh_addr,
solvable=True, solvable=True,
ismine=False) ismine=False)