You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
452 lines
21 KiB
452 lines
21 KiB
9 years ago
|
#!/usr/bin/env python3
|
||
7 years ago
|
# Copyright (c) 2014-2017 The Bitcoin Core developers
|
||
9 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
8 years ago
|
"""Test the importmulti RPC."""
|
||
9 years ago
|
from test_framework.test_framework import BitcoinTestFramework
|
||
|
from test_framework.util import *
|
||
|
|
||
|
class ImportMultiTest (BitcoinTestFramework):
|
||
8 years ago
|
def set_test_params(self):
|
||
9 years ago
|
self.num_nodes = 2
|
||
7 years ago
|
self.extra_args = [["-addresstype=legacy"], ["-addresstype=legacy"]]
|
||
9 years ago
|
self.setup_clean_chain = True
|
||
|
|
||
8 years ago
|
def setup_network(self):
|
||
|
self.setup_nodes()
|
||
9 years ago
|
|
||
|
def run_test (self):
|
||
8 years ago
|
self.log.info("Mining blocks...")
|
||
9 years ago
|
self.nodes[0].generate(1)
|
||
|
self.nodes[1].generate(1)
|
||
8 years ago
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||
9 years ago
|
|
||
|
node0_address1 = 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
|
||
8 years ago
|
self.log.info("Should import an address")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": address['address']
|
||
8 years ago
|
},
|
||
|
"timestamp": "now",
|
||
9 years ago
|
}])
|
||
|
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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
|
watchonly_address = address['address']
|
||
|
watchonly_timestamp = timestamp
|
||
9 years ago
|
|
||
8 years ago
|
self.log.info("Should not import an invalid address")
|
||
8 years ago
|
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')
|
||
9 years ago
|
|
||
|
# ScriptPubKey + internal
|
||
8 years ago
|
self.log.info("Should import a scriptPubKey with internal flag")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
# ScriptPubKey + !internal
|
||
8 years ago
|
self.log.info("Should not import a scriptPubKey without internal flag")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
8 years ago
|
"scriptPubKey": address['scriptPubKey'],
|
||
|
"timestamp": "now",
|
||
9 years ago
|
}])
|
||
|
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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
9 years ago
|
|
||
|
|
||
|
# Address + Public key + !Internal
|
||
8 years ago
|
self.log.info("Should import an address with public key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": address['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
|
||
|
# ScriptPubKey + Public key + internal
|
||
8 years ago
|
self.log.info("Should import a scriptPubKey with internal and with public key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
request = [{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"pubkeys": [ address['pubkey'] ],
|
||
|
"internal": True
|
||
8 years ago
|
}]
|
||
9 years ago
|
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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
# ScriptPubKey + Public key + !internal
|
||
8 years ago
|
self.log.info("Should not import a scriptPubKey without internal and with public key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
request = [{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"pubkeys": [ address['pubkey'] ]
|
||
8 years ago
|
}]
|
||
9 years ago
|
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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
9 years ago
|
|
||
|
# Address + Private key + !watchonly
|
||
8 years ago
|
self.log.info("Should import an address with private key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": address['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
7 years ago
|
self.log.info("Should not import an address with private key if is already imported")
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": address['address']
|
||
|
},
|
||
|
"timestamp": "now",
|
||
|
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
|
||
|
}])
|
||
|
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')
|
||
|
|
||
9 years ago
|
# Address + Private key + watchonly
|
||
8 years ago
|
self.log.info("Should not import an address with private key and with watchonly")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": address['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
9 years ago
|
|
||
|
# ScriptPubKey + Private key + internal
|
||
8 years ago
|
self.log.info("Should import a scriptPubKey with internal and with private key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
# ScriptPubKey + Private key + !internal
|
||
8 years ago
|
self.log.info("Should not import a scriptPubKey without internal and with private key")
|
||
9 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
9 years ago
|
|
||
|
|
||
|
# 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())
|
||
7 years ago
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
||
9 years ago
|
self.nodes[1].generate(100)
|
||
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
||
|
self.nodes[1].generate(1)
|
||
8 years ago
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||
9 years ago
|
|
||
8 years ago
|
self.log.info("Should import a p2sh")
|
||
9 years ago
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": multi_sig_script['address']
|
||
8 years ago
|
},
|
||
|
"timestamp": "now",
|
||
9 years ago
|
}])
|
||
|
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)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
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())
|
||
7 years ago
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
||
9 years ago
|
self.nodes[1].generate(100)
|
||
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
||
|
self.nodes[1].generate(1)
|
||
8 years ago
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||
9 years ago
|
|
||
8 years ago
|
self.log.info("Should import a p2sh with respective redeem script")
|
||
9 years ago
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": multi_sig_script['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"redeemscript": multi_sig_script['redeemScript']
|
||
|
}])
|
||
|
assert_equal(result[0]['success'], True)
|
||
8 years ago
|
address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
|
||
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
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())
|
||
7 years ago
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
||
9 years ago
|
self.nodes[1].generate(100)
|
||
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
||
|
self.nodes[1].generate(1)
|
||
8 years ago
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||
9 years ago
|
|
||
8 years ago
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
||
9 years ago
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": multi_sig_script['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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)
|
||
8 years ago
|
address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])
|
||
|
assert_equal(address_assert['timestamp'], timestamp)
|
||
9 years ago
|
|
||
|
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())
|
||
7 years ago
|
multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])
|
||
9 years ago
|
self.nodes[1].generate(100)
|
||
|
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
|
||
|
self.nodes[1].generate(1)
|
||
8 years ago
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||
9 years ago
|
|
||
8 years ago
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
||
9 years ago
|
result = self.nodes[1].importmulti([{
|
||
|
"scriptPubKey": {
|
||
|
"address": multi_sig_script['address']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
9 years ago
|
"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')
|
||
|
|
||
|
|
||
8 years ago
|
# Address + Public key + !Internal + Wrong pubkey
|
||
8 years ago
|
self.log.info("Should not import an address with a wrong public key")
|
||
8 years ago
|
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']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
8 years ago
|
"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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
8 years ago
|
|
||
|
|
||
|
# ScriptPubKey + Public key + internal + Wrong pubkey
|
||
8 years ago
|
self.log.info("Should not import a scriptPubKey with internal and with a wrong public key")
|
||
8 years ago
|
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())
|
||
|
request = [{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
8 years ago
|
"timestamp": "now",
|
||
8 years ago
|
"pubkeys": [ address2['pubkey'] ],
|
||
|
"internal": True
|
||
8 years ago
|
}]
|
||
8 years ago
|
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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
9 years ago
|
|
||
|
|
||
8 years ago
|
# Address + Private key + !watchonly + Wrong private key
|
||
8 years ago
|
self.log.info("Should not import an address with a wrong private key")
|
||
8 years ago
|
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']
|
||
|
},
|
||
8 years ago
|
"timestamp": "now",
|
||
8 years ago
|
"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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
8 years ago
|
|
||
|
|
||
|
# ScriptPubKey + Private key + internal + Wrong private key
|
||
8 years ago
|
self.log.info("Should not import a scriptPubKey with internal and with a wrong private key")
|
||
8 years ago
|
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'],
|
||
8 years ago
|
"timestamp": "now",
|
||
8 years ago
|
"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)
|
||
8 years ago
|
assert_equal('timestamp' in address_assert, False)
|
||
|
|
||
8 years ago
|
|
||
|
# Importing existing watch only address with new timestamp should replace saved timestamp.
|
||
|
assert_greater_than(timestamp, watchonly_timestamp)
|
||
8 years ago
|
self.log.info("Should replace previously saved watch only timestamp.")
|
||
8 years ago
|
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
|
||
|
|
||
|
|
||
8 years ago
|
# restart nodes to check for proper serialization/deserialization of watch only address
|
||
8 years ago
|
self.stop_nodes()
|
||
8 years ago
|
self.start_nodes()
|
||
8 years ago
|
address_assert = self.nodes[1].validateaddress(watchonly_address)
|
||
|
assert_equal(address_assert['iswatchonly'], True)
|
||
|
assert_equal(address_assert['ismine'], False)
|
||
8 years ago
|
assert_equal(address_assert['timestamp'], watchonly_timestamp)
|
||
8 years ago
|
|
||
8 years ago
|
# Bad or missing timestamps
|
||
8 years ago
|
self.log.info("Should throw on invalid or missing timestamp values")
|
||
7 years ago
|
assert_raises_rpc_error(-3, 'Missing required timestamp field for key',
|
||
8 years ago
|
self.nodes[1].importmulti, [{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
|
}])
|
||
7 years ago
|
assert_raises_rpc_error(-3, 'Expected number or "now" timestamp value for key. got type string',
|
||
8 years ago
|
self.nodes[1].importmulti, [{
|
||
|
"scriptPubKey": address['scriptPubKey'],
|
||
|
"timestamp": "",
|
||
|
}])
|
||
|
|
||
|
|
||
9 years ago
|
if __name__ == '__main__':
|
||
|
ImportMultiTest ().main ()
|