mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
ac01dbee63
e6c58d3b014ab8ef5cca4be68764af4b79685fcb Do not import private keys to wallets with private keys disabled (Andrew Chow) b5c5021b644731d14a6ef04961320a99466f035a Refactor importwallet to extract data from the file and then import (Andrew Chow) 1f77f6754ce724493b0cb084ae0b35107d58605f tests: unify RPC argument to cli argument conversion and handle dicts and lists (Andrew Chow) Pull request description: Fixes a bug where private keys could be imported to wallets with private keys disabled. Now every RPC which can import private keys checks for whether the wallet has private keys are disabled and errors if it is. Also added an belt-and-suspenders check to `AddKeyPubkeyWithDB` to have it assert that the wallet has private keys enabled. Tree-SHA512: 5cd04febce9aa2bd9bfd02f312c6ff8705e37278cae59efd3895f6d6e2f1b477aefd297e2dd0860791bdd3d4f3cad8eb1a404f8f3d4e2035b91314ad2c1028ae dash changes
44 lines
1.8 KiB
Python
Executable File
44 lines
1.8 KiB
Python
Executable File
#!/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 (
|
|
assert_equal,
|
|
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
|
|
|
|
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'])
|
|
|
|
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]}])
|
|
assert(not result[0]['success'])
|
|
assert('warning' not in result[0])
|
|
assert_equal(result[0]['error']['code'], -4)
|
|
assert_equal(result[0]['error']['message'], 'Cannot import private keys to a wallet with private keys disabled')
|
|
|
|
if __name__ == '__main__':
|
|
DisablePrivateKeysTest().main()
|