Skip to content

Commit 4704e5f

Browse files
committed
[QA] add createwallet disableprivatekey test
1 parent c7b8f34 commit 4704e5f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,13 @@ BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup)
363363
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
364364
}
365365

366+
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
367+
{
368+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>("dummy", WalletDatabase::CreateDummy());
369+
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
370+
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
371+
CPubKey pubkey;
372+
BOOST_CHECK(!wallet->GetKeyFromPool(pubkey, false));
373+
}
374+
366375
BOOST_AUTO_TEST_SUITE_END()

test/functional/test_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
'mempool_persist.py',
9999
'wallet_multiwallet.py',
100100
'wallet_multiwallet.py --usecli',
101+
'wallet_disableprivatekeys.py',
102+
'wallet_disableprivatekeys.py --usecli',
101103
'interface_http.py',
102104
'rpc_users.py',
103105
'feature_proxy.py',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test disable-privatekeys mode.
6+
"""
7+
8+
from test_framework.test_framework import BitcoinTestFramework
9+
from test_framework.util import (
10+
assert_raises_rpc_error,
11+
)
12+
13+
14+
class DisablePrivateKeysTest(BitcoinTestFramework):
15+
def set_test_params(self):
16+
self.setup_clean_chain = False
17+
self.num_nodes = 1
18+
self.supports_cli = True
19+
20+
def run_test(self):
21+
node = self.nodes[0]
22+
self.log.info("Test disableprivatekeys creation.")
23+
self.nodes[0].createwallet('w1', True)
24+
self.nodes[0].createwallet('w2')
25+
w1 = node.get_wallet_rpc('w1')
26+
w2 = node.get_wallet_rpc('w2')
27+
assert_raises_rpc_error(-4,"Error: Private keys are disabled for this wallet", w1.getnewaddress)
28+
assert_raises_rpc_error(-4,"Error: Private keys are disabled for this wallet", w1.getrawchangeaddress)
29+
w1.importpubkey(w2.getaddressinfo(w2.getnewaddress())['pubkey'])
30+
31+
if __name__ == '__main__':
32+
DisablePrivateKeysTest().main()

0 commit comments

Comments
 (0)