2018-07-20 14:25:35 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2018 The Bitcoin Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Test disable-privatekeys mode.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import (
|
2019-02-01 13:39:43 +01:00
|
|
|
assert_equal,
|
2018-07-20 14:25:35 +02:00
|
|
|
assert_raises_rpc_error,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class DisablePrivateKeysTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
self.setup_clean_chain = False
|
|
|
|
self.num_nodes = 1
|
|
|
|
self.supports_cli = True
|
|
|
|
|
2018-09-13 12:33:15 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2018-07-20 14:25:35 +02:00
|
|
|
def run_test(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
self.log.info("Test disableprivatekeys creation.")
|
|
|
|
self.nodes[0].createwallet('w1', True)
|
|
|
|
self.nodes[0].createwallet('w2')
|
|
|
|
w1 = node.get_wallet_rpc('w1')
|
|
|
|
w2 = node.get_wallet_rpc('w2')
|
|
|
|
assert_raises_rpc_error(-4,"Error: Private keys are disabled for this wallet", w1.getnewaddress)
|
|
|
|
assert_raises_rpc_error(-4,"Error: Private keys are disabled for this wallet", w1.getrawchangeaddress)
|
|
|
|
w1.importpubkey(w2.getaddressinfo(w2.getnewaddress())['pubkey'])
|
|
|
|
|
2019-02-01 13:39:43 +01:00
|
|
|
self.log.info('Test that private keys cannot be imported')
|
|
|
|
addr = w2.getnewaddress('')
|
|
|
|
privkey = w2.dumpprivkey(addr)
|
|
|
|
assert_raises_rpc_error(-4, 'Cannot import private keys to a wallet with private keys disabled', w1.importprivkey, privkey)
|
|
|
|
result = w1.importmulti([{'scriptPubKey': {'address': addr}, 'timestamp': 'now', 'keys': [privkey]}])
|
2021-08-27 21:03:02 +02:00
|
|
|
assert not result[0]['success']
|
|
|
|
assert 'warning' not in result[0]
|
2019-02-01 13:39:43 +01:00
|
|
|
assert_equal(result[0]['error']['code'], -4)
|
|
|
|
assert_equal(result[0]['error']['message'], 'Cannot import private keys to a wallet with private keys disabled')
|
|
|
|
|
2018-07-20 14:25:35 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
DisablePrivateKeysTest().main()
|