2016-06-16 16:57:48 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-07-27 00:36:45 +02:00
|
|
|
# Copyright (c) 2014-2018 The Bitcoin Core developers
|
2016-06-16 16:57:48 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2017-01-18 00:34:40 +01:00
|
|
|
"""Test the importmulti RPC."""
|
2018-12-06 00:28:32 +01:00
|
|
|
from collections import namedtuple
|
2016-11-28 23:19:27 +01:00
|
|
|
|
2018-12-06 00:28:32 +01:00
|
|
|
from test_framework.address import (
|
|
|
|
key_to_p2pkh,
|
|
|
|
key_to_p2sh_p2wpkh,
|
|
|
|
key_to_p2wpkh,
|
|
|
|
)
|
2018-11-30 23:49:03 +01:00
|
|
|
from test_framework.messages import sha256
|
|
|
|
from test_framework.script import (
|
|
|
|
CScript,
|
|
|
|
OP_0,
|
2018-12-06 00:28:32 +01:00
|
|
|
OP_CHECKSIG,
|
|
|
|
OP_DUP,
|
|
|
|
OP_EQUAL,
|
|
|
|
OP_EQUALVERIFY,
|
|
|
|
OP_HASH160,
|
2018-11-30 23:49:03 +01:00
|
|
|
OP_NOP,
|
2018-12-06 00:28:32 +01:00
|
|
|
hash160,
|
2018-11-30 23:49:03 +01:00
|
|
|
)
|
2016-06-16 16:57:48 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2018-09-10 19:08:13 +02:00
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
|
|
|
assert_greater_than,
|
|
|
|
assert_raises_rpc_error,
|
|
|
|
bytes_to_hex_str,
|
2018-10-09 07:43:20 +02:00
|
|
|
hex_str_to_bytes
|
2018-09-10 19:08:13 +02:00
|
|
|
)
|
|
|
|
|
2018-12-06 00:28:32 +01:00
|
|
|
Key = namedtuple('Key', ['privkey',
|
|
|
|
'pubkey',
|
|
|
|
'p2pkh_script',
|
|
|
|
'p2pkh_addr',
|
|
|
|
'p2wpkh_script',
|
|
|
|
'p2wpkh_addr',
|
|
|
|
'p2sh_p2wpkh_script',
|
|
|
|
'p2sh_p2wpkh_redeem_script',
|
|
|
|
'p2sh_p2wpkh_addr'])
|
|
|
|
|
2018-09-10 19:08:13 +02:00
|
|
|
class ImportMultiTest(BitcoinTestFramework):
|
2017-06-10 00:21:21 +02:00
|
|
|
def set_test_params(self):
|
2016-06-16 16:57:48 +02:00
|
|
|
self.num_nodes = 2
|
2017-12-01 01:49:11 +01:00
|
|
|
self.extra_args = [["-addresstype=legacy"], ["-addresstype=legacy"]]
|
2016-06-16 16:57:48 +02:00
|
|
|
self.setup_clean_chain = True
|
|
|
|
|
2018-09-09 19:32:37 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2017-04-03 15:34:04 +02:00
|
|
|
def setup_network(self):
|
|
|
|
self.setup_nodes()
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-12-06 00:28:32 +01:00
|
|
|
def get_key(self):
|
|
|
|
"""Generate a fresh key on node0
|
|
|
|
|
|
|
|
Returns a named tuple of privkey, pubkey and all address and scripts."""
|
|
|
|
addr = self.nodes[0].getnewaddress()
|
|
|
|
pubkey = self.nodes[0].getaddressinfo(addr)['pubkey']
|
|
|
|
pkh = hash160(hex_str_to_bytes(pubkey))
|
|
|
|
return Key(self.nodes[0].dumpprivkey(addr),
|
|
|
|
pubkey,
|
|
|
|
CScript([OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), # p2pkh
|
|
|
|
key_to_p2pkh(pubkey), # p2pkh addr
|
|
|
|
CScript([OP_0, pkh]).hex(), # p2wpkh
|
|
|
|
key_to_p2wpkh(pubkey), # p2wpkh addr
|
|
|
|
CScript([OP_HASH160, hash160(CScript([OP_0, pkh])), OP_EQUAL]).hex(), # p2sh-p2wpkh
|
|
|
|
CScript([OP_0, pkh]).hex(), # p2sh-p2wpkh redeem script
|
|
|
|
key_to_p2sh_p2wpkh(pubkey)) # p2sh-p2wpkh addr
|
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
def run_test(self):
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Mining blocks...")
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-02-09 17:12:27 +01:00
|
|
|
node0_address1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
# Check only one address
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(node0_address1['ismine'], True)
|
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
# Node 1 sync test
|
|
|
|
assert_equal(self.nodes[1].getblockcount(), 1)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
# Address Test - before import
|
2018-02-09 17:12:27 +01:00
|
|
|
address_info = self.nodes[1].getaddressinfo(node0_address1['address'])
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_info['iswatchonly'], False)
|
|
|
|
assert_equal(address_info['ismine'], False)
|
|
|
|
|
|
|
|
# RPC importmulti -----------------------------------------------
|
|
|
|
|
2018-11-07 17:24:34 +01:00
|
|
|
# Bitcoin Address (implicit non-internal)
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import an address")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2017-02-03 22:23:13 +01:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2018-11-07 17:24:34 +01:00
|
|
|
assert_equal(address_assert['ischange'], False)
|
2018-12-06 00:28:32 +01:00
|
|
|
watchonly_address = address
|
2016-11-08 22:55:02 +01:00
|
|
|
watchonly_timestamp = timestamp
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import an invalid address")
|
2017-02-13 23:54:51 +01:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": "not valid address",
|
|
|
|
},
|
|
|
|
"timestamp": "now",
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Invalid address')
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
# ScriptPubKey + internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a scriptPubKey with internal flag")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"internal": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(key.p2pkh_addr)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2018-11-07 17:24:34 +01:00
|
|
|
assert_equal(address_assert['ischange'], True)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-10-09 07:43:20 +02:00
|
|
|
# ScriptPubKey + internal + label
|
|
|
|
self.log.info("Should not allow a label to be specified when internal is true")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
2018-10-09 07:43:20 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2018-10-09 07:43:20 +02:00
|
|
|
"timestamp": "now",
|
|
|
|
"internal": True,
|
|
|
|
"label": "Example label"
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Internal addresses should not have a label')
|
|
|
|
|
2016-11-28 23:19:27 +01:00
|
|
|
# Nonstandard scriptPubKey + !internal
|
|
|
|
self.log.info("Should not import a nonstandard scriptPubKey without internal flag")
|
2018-12-06 00:28:32 +01:00
|
|
|
nonstandardScriptPubKey = key.p2pkh_script + bytes_to_hex_str(CScript([OP_NOP]))
|
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2016-11-28 23:19:27 +01:00
|
|
|
"scriptPubKey": nonstandardScriptPubKey,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
2016-11-28 23:19:27 +01:00
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set to true for nonstandard scriptPubKey imports.')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-11-07 17:24:34 +01:00
|
|
|
# Address + Public key + !Internal(explicit)
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import an address with public key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2016-06-16 16:57:48 +02:00
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [key.pubkey],
|
2018-11-07 17:24:34 +01:00
|
|
|
"internal": False
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
# ScriptPubKey + Public key + internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a scriptPubKey with internal and with public key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
request = [{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [key.pubkey],
|
2016-06-16 16:57:48 +02:00
|
|
|
"internal": True
|
2017-01-20 22:55:26 +01:00
|
|
|
}]
|
2018-11-13 19:42:36 +01:00
|
|
|
result = self.nodes[1].importmulti(requests=request)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2016-11-28 23:19:27 +01:00
|
|
|
# Nonstandard scriptPubKey + Public key + !internal
|
|
|
|
self.log.info("Should not import a nonstandard scriptPubKey without internal and with public key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
request = [{
|
2016-11-28 23:19:27 +01:00
|
|
|
"scriptPubKey": nonstandardScriptPubKey,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [key.pubkey]
|
2017-01-20 22:55:26 +01:00
|
|
|
}]
|
2018-11-13 19:42:36 +01:00
|
|
|
result = self.nodes[1].importmulti(requests=request)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
2016-11-28 23:19:27 +01:00
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set to true for nonstandard scriptPubKey imports.')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
# Address + Private key + !watchonly
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import an address with private key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2016-06-16 16:57:48 +02:00
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey]
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], True)
|
2017-02-06 17:13:05 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-10-11 12:12:59 +02:00
|
|
|
self.log.info("Should not import an address with private key if is already imported")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2017-10-11 12:12:59 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey]
|
2017-10-11 12:12:59 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -4)
|
|
|
|
assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')
|
|
|
|
|
2016-06-16 16:57:48 +02:00
|
|
|
# Address + Private key + watchonly
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import an address with private key and with watchonly")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2016-06-16 16:57:48 +02:00
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey],
|
2016-06-16 16:57:48 +02:00
|
|
|
"watchonly": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Watch-only addresses should not include private keys')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
# ScriptPubKey + Private key + internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a scriptPubKey with internal and with private key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey],
|
2016-06-16 16:57:48 +02:00
|
|
|
"internal": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], True)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2016-11-28 23:19:27 +01:00
|
|
|
# Nonstandard scriptPubKey + Private key + !internal
|
|
|
|
self.log.info("Should not import a nonstandard scriptPubKey without internal and with private key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2016-11-28 23:19:27 +01:00
|
|
|
"scriptPubKey": nonstandardScriptPubKey,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey]
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
2016-11-28 23:19:27 +01:00
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set to true for nonstandard scriptPubKey imports.')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
# P2SH address
|
2018-02-09 17:12:27 +01:00
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
2017-09-29 06:21:28 +02:00
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(100)
|
2018-03-29 17:47:06 +02:00
|
|
|
self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a p2sh")
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
2017-02-03 22:23:13 +01:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-02-09 17:12:27 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(address_assert['isscript'], True)
|
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2018-11-30 23:47:46 +01:00
|
|
|
p2shunspent = self.nodes[1].listunspent(0, 999999, [multi_sig_script['address']])[0]
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], False)
|
|
|
|
|
|
|
|
# P2SH + Redeem script
|
2018-02-09 17:12:27 +01:00
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
2017-09-29 06:21:28 +02:00
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(100)
|
2018-03-29 17:47:06 +02:00
|
|
|
self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a p2sh with respective redeem script")
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"redeemscript": multi_sig_script['redeemScript']
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-02-09 17:12:27 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
p2shunspent = self.nodes[1].listunspent(0, 999999, [multi_sig_script['address']])[0]
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], True)
|
|
|
|
|
|
|
|
# P2SH + Redeem script + Private Keys + !Watchonly
|
2018-02-09 17:12:27 +01:00
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
2017-09-29 06:21:28 +02:00
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(100)
|
2018-03-29 17:47:06 +02:00
|
|
|
self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"redeemscript": multi_sig_script['redeemScript'],
|
2018-11-30 23:47:46 +01:00
|
|
|
"keys": [self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-02-09 17:12:27 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2018-11-30 23:47:46 +01:00
|
|
|
p2shunspent = self.nodes[1].listunspent(0, 999999, [multi_sig_script['address']])[0]
|
2016-06-16 16:57:48 +02:00
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], True)
|
|
|
|
|
|
|
|
# P2SH + Redeem script + Private Keys + Watchonly
|
2018-02-09 17:12:27 +01:00
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
2017-09-29 06:21:28 +02:00
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(100)
|
2018-03-29 17:47:06 +02:00
|
|
|
self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
2016-06-16 16:57:48 +02:00
|
|
|
self.nodes[1].generate(1)
|
2017-02-21 16:53:07 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"redeemscript": multi_sig_script['redeemScript'],
|
2018-11-30 23:47:46 +01:00
|
|
|
"keys": [self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])],
|
2016-06-16 16:57:48 +02:00
|
|
|
"watchonly": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Watch-only addresses should not include private keys')
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2016-10-19 16:17:42 +02:00
|
|
|
# Address + Public key + !Internal + Wrong pubkey
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import an address with a wrong public key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
|
|
|
wrong_key = self.get_key().pubkey
|
2016-10-19 16:17:42 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2016-10-19 16:17:42 +02:00
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [wrong_key]
|
2016-10-19 16:17:42 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Key does not match address destination')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-10-19 16:17:42 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-10-19 16:17:42 +02:00
|
|
|
|
|
|
|
# ScriptPubKey + Public key + internal + Wrong pubkey
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import a scriptPubKey with internal and with a wrong public key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
|
|
|
wrong_key = self.get_key().pubkey
|
2016-10-19 16:17:42 +02:00
|
|
|
request = [{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [wrong_key],
|
2016-10-19 16:17:42 +02:00
|
|
|
"internal": True
|
2017-01-20 22:55:26 +01:00
|
|
|
}]
|
2016-10-19 16:17:42 +02:00
|
|
|
result = self.nodes[1].importmulti(request)
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Key does not match address destination')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-10-19 16:17:42 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
2016-10-19 16:17:42 +02:00
|
|
|
# Address + Private key + !watchonly + Wrong private key
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import an address with a wrong private key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
|
|
|
wrong_privkey = self.get_key().privkey
|
2016-10-19 16:17:42 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2016-10-19 16:17:42 +02:00
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [wrong_privkey]
|
2016-10-19 16:17:42 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Key does not match address destination')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-10-19 16:17:42 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
2016-10-19 16:17:42 +02:00
|
|
|
|
|
|
|
# ScriptPubKey + Private key + internal + Wrong private key
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import a scriptPubKey with internal and with a wrong private key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2pkh_addr
|
|
|
|
wrong_privkey = self.get_key().privkey
|
2016-10-19 16:17:42 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [wrong_privkey],
|
2016-10-19 16:17:42 +02:00
|
|
|
"internal": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
2018-10-09 06:29:27 +02:00
|
|
|
assert_equal(result[0]['error']['message'], 'Key does not match address destination')
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2016-10-19 16:17:42 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal('timestamp' in address_assert, False)
|
|
|
|
|
2017-02-21 16:53:07 +01:00
|
|
|
# Importing existing watch only address with new timestamp should replace saved timestamp.
|
|
|
|
assert_greater_than(timestamp, watchonly_timestamp)
|
2017-03-17 23:04:13 +01:00
|
|
|
self.log.info("Should replace previously saved watch only timestamp.")
|
2017-02-21 16:53:07 +01:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": watchonly_address,
|
|
|
|
},
|
|
|
|
"timestamp": "now",
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-02-09 17:12:27 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(watchonly_address)
|
2017-02-21 16:53:07 +01:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
|
|
|
watchonly_timestamp = timestamp
|
|
|
|
|
2016-11-08 22:55:02 +01:00
|
|
|
# restart nodes to check for proper serialization/deserialization of watch only address
|
2017-03-24 04:56:31 +01:00
|
|
|
self.stop_nodes()
|
2017-06-09 22:35:17 +02:00
|
|
|
self.start_nodes()
|
2018-02-09 17:12:27 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(watchonly_address)
|
2016-11-08 22:55:02 +01:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
2017-03-28 15:19:19 +02:00
|
|
|
assert_equal(address_assert['timestamp'], watchonly_timestamp)
|
2016-10-19 16:17:42 +02:00
|
|
|
|
2017-02-03 22:23:13 +01:00
|
|
|
# Bad or missing timestamps
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should throw on invalid or missing timestamp values")
|
2017-07-12 16:33:46 +02:00
|
|
|
assert_raises_rpc_error(-3, 'Missing required timestamp field for key',
|
2018-12-06 00:28:32 +01:00
|
|
|
self.nodes[1].importmulti, [{"scriptPubKey": key.p2pkh_script}])
|
2017-07-12 16:33:46 +02:00
|
|
|
assert_raises_rpc_error(-3, 'Expected number or "now" timestamp value for key. got type string',
|
2018-11-30 23:47:46 +01:00
|
|
|
self.nodes[1].importmulti, [{
|
2018-12-06 00:28:32 +01:00
|
|
|
"scriptPubKey": key.p2pkh_script,
|
2018-11-30 23:47:46 +01:00
|
|
|
"timestamp": ""
|
|
|
|
}])
|
2017-02-03 22:23:13 +01:00
|
|
|
|
2018-10-09 07:43:20 +02:00
|
|
|
# Import P2WPKH address as watch only
|
|
|
|
self.log.info("Should import a P2WPKH address as watch only")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2wpkh_addr
|
2018-10-09 07:43:20 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], True)
|
|
|
|
assert_equal(address_assert['solvable'], False)
|
|
|
|
|
|
|
|
# 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")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2wpkh_addr
|
2018-10-09 07:43:20 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"pubkeys": [key.pubkey]
|
2018-10-09 07:43:20 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['ismine'], False)
|
|
|
|
assert_equal(address_assert['solvable'], True)
|
|
|
|
|
|
|
|
# Import P2WPKH address with key and check it is spendable
|
|
|
|
self.log.info("Should import a P2WPKH address with key")
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2wpkh_addr
|
2018-10-09 07:43:20 +02:00
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"keys": [key.privkey]
|
2018-10-09 07:43:20 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['iswatchonly'], False)
|
|
|
|
assert_equal(address_assert['ismine'], True)
|
|
|
|
|
|
|
|
# P2WSH multisig address without scripts or keys
|
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].addmultisigaddress(2, [sig_address_1['pubkey'], sig_address_2['pubkey']], "", "bech32")
|
|
|
|
self.log.info("Should import a p2wsh multisig as watch only without respective redeem script and private keys")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
|
|
|
"timestamp": "now"
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
|
|
|
assert_equal(address_assert['solvable'], False)
|
|
|
|
|
|
|
|
# Same P2WSH multisig address as above, but now with witnessscript + private keys
|
|
|
|
self.log.info("Should import a p2wsh with respective redeem script and private keys")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
|
|
|
"timestamp": "now",
|
|
|
|
"witnessscript": multi_sig_script['redeemScript'],
|
2018-11-30 23:47:46 +01:00
|
|
|
"keys": [self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]
|
2018-10-09 07:43:20 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
|
|
|
assert_equal(address_assert['solvable'], True)
|
|
|
|
assert_equal(address_assert['ismine'], True)
|
|
|
|
assert_equal(address_assert['sigsrequired'], 2)
|
|
|
|
|
|
|
|
# P2SH-P2WPKH address with no redeemscript or public or private key
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2sh_p2wpkh_addr
|
2018-10-09 07:43:20 +02:00
|
|
|
self.log.info("Should import a p2sh-p2wpkh without redeem script or keys")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now"
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['solvable'], False)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
|
|
|
|
|
|
|
# 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")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"redeemscript": key.p2sh_p2wpkh_redeem_script,
|
|
|
|
"pubkeys": [key.pubkey]
|
2018-10-09 07:43:20 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['solvable'], True)
|
|
|
|
assert_equal(address_assert['ismine'], False)
|
|
|
|
|
|
|
|
# P2SH-P2WPKH address + redeemscript + private key
|
2018-12-06 00:28:32 +01:00
|
|
|
key = self.get_key()
|
|
|
|
address = key.p2sh_p2wpkh_addr
|
2018-10-09 07:43:20 +02:00
|
|
|
self.log.info("Should import a p2sh-p2wpkh with respective redeem script and private keys")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
2018-12-06 00:28:32 +01:00
|
|
|
"address": address
|
2018-10-09 07:43:20 +02:00
|
|
|
},
|
|
|
|
"timestamp": "now",
|
2018-12-06 00:28:32 +01:00
|
|
|
"redeemscript": key.p2sh_p2wpkh_redeem_script,
|
|
|
|
"keys": [key.privkey]
|
2018-10-09 07:43:20 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2018-12-06 00:28:32 +01:00
|
|
|
address_assert = self.nodes[1].getaddressinfo(address)
|
2018-10-09 07:43:20 +02:00
|
|
|
assert_equal(address_assert['solvable'], True)
|
|
|
|
assert_equal(address_assert['ismine'], True)
|
|
|
|
|
|
|
|
# P2SH-P2WSH 1-of-1 multisig + redeemscript with no private key
|
|
|
|
sig_address_1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].addmultisigaddress(1, [sig_address_1['pubkey']], "", "p2sh-segwit")
|
|
|
|
scripthash = sha256(hex_str_to_bytes(multi_sig_script['redeemScript']))
|
|
|
|
redeem_script = CScript([OP_0, scripthash])
|
|
|
|
self.log.info("Should import a p2sh-p2wsh with respective redeem script but no private key")
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": multi_sig_script['address']
|
|
|
|
},
|
|
|
|
"timestamp": "now",
|
|
|
|
"redeemscript": bytes_to_hex_str(redeem_script),
|
|
|
|
"witnessscript": multi_sig_script['redeemScript']
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].getaddressinfo(multi_sig_script['address'])
|
|
|
|
assert_equal(address_assert['solvable'], True)
|
2017-02-03 22:23:13 +01:00
|
|
|
|
2016-06-16 16:57:48 +02:00
|
|
|
if __name__ == '__main__':
|
2018-11-30 23:47:46 +01:00
|
|
|
ImportMultiTest().main()
|