2016-06-16 16:57:48 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
|
|
|
# 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."""
|
2016-06-16 16:57:48 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import *
|
|
|
|
|
|
|
|
class ImportMultiTest (BitcoinTestFramework):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.num_nodes = 2
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
|
|
|
|
def setup_network(self, split=False):
|
|
|
|
self.nodes = start_nodes(2, self.options.tmpdir)
|
|
|
|
self.is_network_split=False
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
# keyword definition
|
|
|
|
PRIV_KEY = 'privkey'
|
|
|
|
PUB_KEY = 'pubkey'
|
|
|
|
ADDRESS_KEY = 'address'
|
|
|
|
SCRIPT_KEY = 'script'
|
|
|
|
|
|
|
|
|
|
|
|
node0_address1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
node0_address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
node0_address3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
|
|
|
|
#Check only one address
|
|
|
|
assert_equal(node0_address1['ismine'], True)
|
|
|
|
|
|
|
|
#Node 1 sync test
|
|
|
|
assert_equal(self.nodes[1].getblockcount(),1)
|
|
|
|
|
|
|
|
#Address Test - before import
|
|
|
|
address_info = self.nodes[1].validateaddress(node0_address1['address'])
|
|
|
|
assert_equal(address_info['iswatchonly'], False)
|
|
|
|
assert_equal(address_info['ismine'], False)
|
|
|
|
|
|
|
|
|
|
|
|
# RPC importmulti -----------------------------------------------
|
|
|
|
|
|
|
|
# Bitcoin Address
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import an address")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": 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)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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)
|
|
|
|
watchonly_address = address['address']
|
|
|
|
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")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
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)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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 + !internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import a scriptPubKey without internal flag")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
2017-02-03 22:23:13 +01:00
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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 + Public key + !Internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should import an address with public key")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": address['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"pubkeys": [ address['pubkey'] ]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
request = [{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"pubkeys": [ address['pubkey'] ],
|
|
|
|
"internal": True
|
2017-01-20 22:55:26 +01:00
|
|
|
}]
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti(request)
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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 not import a scriptPubKey without internal and with public key")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
request = [{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"pubkeys": [ address['pubkey'] ]
|
2017-01-20 22:55:26 +01:00
|
|
|
}]
|
2016-06-16 16:57:48 +02:00
|
|
|
result = self.nodes[1].importmulti(request)
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": address['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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
|
|
|
|
|
|
|
# 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")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": address['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address['address']) ],
|
|
|
|
"watchonly": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address['address']) ],
|
|
|
|
"internal": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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
|
|
|
|
|
|
|
# ScriptPubKey + Private key + !internal
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Should not import a scriptPubKey without internal and with private key")
|
2016-06-16 16:57:48 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-06-16 16:57:48 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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
|
|
|
|
sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
|
|
|
|
self.nodes[1].generate(100)
|
|
|
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2017-01-20 22:55:26 +01:00
|
|
|
transaction = self.nodes[1].gettransaction(transactionid)
|
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)
|
|
|
|
address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
|
|
|
|
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)
|
2016-06-16 16:57:48 +02:00
|
|
|
p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]
|
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], False)
|
|
|
|
|
|
|
|
|
|
|
|
# P2SH + Redeem script
|
|
|
|
sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
|
|
|
|
self.nodes[1].generate(100)
|
|
|
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2017-01-20 22:55:26 +01:00
|
|
|
transaction = self.nodes[1].gettransaction(transactionid)
|
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)
|
2016-11-08 22:55:02 +01:00
|
|
|
address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
|
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]
|
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], True)
|
|
|
|
|
|
|
|
|
|
|
|
# P2SH + Redeem script + Private Keys + !Watchonly
|
|
|
|
sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
|
|
|
|
self.nodes[1].generate(100)
|
|
|
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
|
|
|
self.nodes[1].generate(1)
|
2016-11-08 22:55:02 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2017-01-20 22:55:26 +01:00
|
|
|
transaction = self.nodes[1].gettransaction(transactionid)
|
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'],
|
|
|
|
"keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], True)
|
2016-11-08 22:55:02 +01:00
|
|
|
address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
|
|
|
|
assert_equal(address_assert['timestamp'], timestamp)
|
2016-06-16 16:57:48 +02:00
|
|
|
|
|
|
|
p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]
|
|
|
|
assert_equal(p2shunspent['spendable'], False)
|
|
|
|
assert_equal(p2shunspent['solvable'], True)
|
|
|
|
|
|
|
|
# P2SH + Redeem script + Private Keys + Watchonly
|
|
|
|
sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])
|
|
|
|
self.nodes[1].generate(100)
|
|
|
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
|
|
|
self.nodes[1].generate(1)
|
2017-02-21 16:53:07 +01:00
|
|
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
2017-01-20 22:55:26 +01:00
|
|
|
transaction = self.nodes[1].gettransaction(transactionid)
|
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'],
|
|
|
|
"keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])],
|
|
|
|
"watchonly": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -8)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')
|
|
|
|
|
|
|
|
|
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")
|
2016-10-19 16:17:42 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": address['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-10-19 16:17:42 +02:00
|
|
|
"pubkeys": [ address2['pubkey'] ]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Consistency check failed')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-10-19 16:17:42 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
request = [{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-10-19 16:17:42 +02:00
|
|
|
"pubkeys": [ address2['pubkey'] ],
|
|
|
|
"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)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Consistency check failed')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-10-19 16:17:42 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": {
|
|
|
|
"address": address['address']
|
|
|
|
},
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-10-19 16:17:42 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address2['address']) ]
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Consistency check failed')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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")
|
2016-10-19 16:17:42 +02:00
|
|
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
|
|
|
result = self.nodes[1].importmulti([{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
2017-02-03 22:23:13 +01:00
|
|
|
"timestamp": "now",
|
2016-10-19 16:17:42 +02:00
|
|
|
"keys": [ self.nodes[0].dumpprivkey(address2['address']) ],
|
|
|
|
"internal": True
|
|
|
|
}])
|
|
|
|
assert_equal(result[0]['success'], False)
|
|
|
|
assert_equal(result[0]['error']['code'], -5)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Consistency check failed')
|
|
|
|
address_assert = self.nodes[1].validateaddress(address['address'])
|
|
|
|
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)
|
|
|
|
address_assert = self.nodes[1].validateaddress(watchonly_address)
|
|
|
|
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
|
|
|
|
stop_nodes(self.nodes)
|
|
|
|
self.nodes = start_nodes(2, self.options.tmpdir)
|
|
|
|
address_assert = self.nodes[1].validateaddress(watchonly_address)
|
|
|
|
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-02-03 22:23:13 +01:00
|
|
|
assert_raises_message(JSONRPCException, 'Missing required timestamp field for key',
|
|
|
|
self.nodes[1].importmulti, [{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
|
|
|
}])
|
|
|
|
assert_raises_message(JSONRPCException, 'Expected number or "now" timestamp value for key. got type string',
|
|
|
|
self.nodes[1].importmulti, [{
|
|
|
|
"scriptPubKey": address['scriptPubKey'],
|
|
|
|
"timestamp": "",
|
|
|
|
}])
|
|
|
|
|
|
|
|
|
2016-06-16 16:57:48 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
ImportMultiTest ().main ()
|