Skip to content

Commit faa669c

Browse files
author
MarcoFalke
committed
qa: Premine to deterministic address with -disablewallet
1 parent 4799b09 commit faa669c

10 files changed

+122
-59
lines changed

test/functional/feature_fee_estimation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def transact_and_mine(self, numblocks, mining_node):
168168
newmem.append(utx)
169169
self.memutxo = newmem
170170

171+
def import_deterministic_coinbase_privkeys(self):
172+
self.start_nodes()
173+
super().import_deterministic_coinbase_privkeys()
174+
self.stop_nodes()
175+
171176
def run_test(self):
172177
self.log.info("This test is time consuming, please be patient")
173178
self.log.info("Splitting inputs so we can generate tx's")

test/functional/interface_zmq.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def set_test_params(self):
4040
def setup_nodes(self):
4141
skip_if_no_py3_zmq()
4242
skip_if_no_bitcoind_zmq(self)
43+
44+
# Import keys
45+
self.add_nodes(self.num_nodes)
46+
self.start_nodes()
47+
super().import_deterministic_coinbase_privkeys()
48+
self.stop_nodes()
49+
4350
import zmq
4451

4552
# Initialize ZMQ context and socket.
@@ -59,10 +66,12 @@ def setup_nodes(self):
5966
self.rawblock = ZMQSubscriber(socket, b"rawblock")
6067
self.rawtx = ZMQSubscriber(socket, b"rawtx")
6168

62-
self.extra_args = [["-zmqpub%s=%s" % (sub.topic.decode(), address) for sub in [self.hashblock, self.hashtx, self.rawblock, self.rawtx]], []]
63-
self.add_nodes(self.num_nodes, self.extra_args)
69+
self.nodes[0].extra_args = ["-zmqpub%s=%s" % (sub.topic.decode(), address) for sub in [self.hashblock, self.hashtx, self.rawblock, self.rawtx]]
6470
self.start_nodes()
6571

72+
def import_deterministic_coinbase_privkeys(self):
73+
pass
74+
6675
def run_test(self):
6776
try:
6877
self._zmq_test()

test/functional/mempool_packages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def chain_transaction(self, node, parent_txid, vout, value, fee, num_outputs):
3434
return (txid, send_value)
3535

3636
def run_test(self):
37-
''' Mine some blocks and have them mature. '''
37+
# Mine some blocks and have them mature.
3838
self.nodes[0].generate(101)
3939
utxo = self.nodes[0].listunspent(10)
4040
txid = utxo[0]['txid']

test/functional/mining_getblocktemplate_longpoll.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ def run_test(self):
7070

7171
if __name__ == '__main__':
7272
GetBlockTemplateLPTest().main()
73-

test/functional/rpc_blockchain.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
class BlockchainTest(BitcoinTestFramework):
4848
def set_test_params(self):
4949
self.num_nodes = 1
50-
self.extra_args = [['-stopatheight=207', '-prune=1']]
5150

5251
def run_test(self):
52+
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete
53+
5354
self._test_getblockchaininfo()
5455
self._test_getchaintxstats()
5556
self._test_gettxoutsetinfo()
@@ -169,7 +170,7 @@ def _test_gettxoutsetinfo(self):
169170
assert_equal(res['transactions'], 200)
170171
assert_equal(res['height'], 200)
171172
assert_equal(res['txouts'], 200)
172-
assert_equal(res['bogosize'], 17000),
173+
assert_equal(res['bogosize'], 15000),
173174
assert_equal(res['bestblock'], node.getblockhash(200))
174175
size = res['disk_size']
175176
assert size > 6400

test/functional/test_framework/test_framework.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def main(self):
158158
raise SkipTest("--usecli specified but test does not support using CLI")
159159
self.setup_chain()
160160
self.setup_network()
161+
self.import_deterministic_coinbase_privkeys()
161162
self.run_test()
162163
success = TestStatus.PASSED
163164
except JSONRPCException as e:
@@ -247,6 +248,19 @@ def setup_nodes(self):
247248
self.add_nodes(self.num_nodes, extra_args)
248249
self.start_nodes()
249250

251+
def import_deterministic_coinbase_privkeys(self):
252+
if self.setup_clean_chain:
253+
return
254+
255+
for n in self.nodes:
256+
try:
257+
n.getwalletinfo()
258+
except JSONRPCException as e:
259+
assert str(e).startswith('Method not found')
260+
continue
261+
262+
n.importprivkey(n.get_deterministic_priv_key()[1])
263+
250264
def run_test(self):
251265
"""Tests must override this method to define test logic"""
252266
raise NotImplementedError
@@ -415,7 +429,7 @@ def _initialize_chain(self):
415429
# Create cache directories, run bitcoinds:
416430
for i in range(MAX_NODES):
417431
datadir = initialize_datadir(self.options.cachedir, i)
418-
args = [self.options.bitcoind, "-datadir=" + datadir]
432+
args = [self.options.bitcoind, "-datadir=" + datadir, '-disablewallet']
419433
if i > 0:
420434
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
421435
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[], rpchost=None, timewait=self.rpc_timewait, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None))
@@ -439,7 +453,7 @@ def _initialize_chain(self):
439453
for peer in range(4):
440454
for j in range(25):
441455
set_node_times(self.nodes, block_time)
442-
self.nodes[peer].generate(1)
456+
self.nodes[peer].generatetoaddress(1, self.nodes[peer].get_deterministic_priv_key()[0])
443457
block_time += 10 * 60
444458
# Must sync before next peer starts generating blocks
445459
sync_blocks(self.nodes)
@@ -453,8 +467,9 @@ def cache_path(n, *paths):
453467
return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths)
454468

455469
for i in range(MAX_NODES):
470+
os.rmdir(cache_path(i, 'wallets')) # Remove empty wallets dir
456471
for entry in os.listdir(cache_path(i)):
457-
if entry not in ['wallets', 'chainstate', 'blocks']:
472+
if entry not in ['chainstate', 'blocks']:
458473
os.remove(cache_path(i, entry))
459474

460475
for i in range(self.num_nodes):

test/functional/test_framework/test_node.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mock
9797

9898
self.p2ps = []
9999

100+
def get_deterministic_priv_key(self):
101+
"""Return a deterministic priv key in base58, that only depends on the node's index"""
102+
PRIV_KEYS = [
103+
# adress , privkey
104+
('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'),
105+
('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'),
106+
('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'),
107+
('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'),
108+
('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'),
109+
('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'),
110+
('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'),
111+
('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'),
112+
('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'),
113+
]
114+
return PRIV_KEYS[self.index]
115+
100116
def _node_msg(self, msg: str) -> str:
101117
"""Return a modified msg that identifies this node by its index as a debugging aid."""
102118
return "[node %d] %s" % (self.index, msg)

test/functional/wallet_dump.py

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,54 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
2929
# only read non comment lines
3030
if line[0] != "#" and len(line) > 10:
3131
# split out some data
32-
key_label, comment = line.split("#")
33-
# key = key_label.split(" ")[0]
34-
keytype = key_label.split(" ")[2]
35-
if len(comment) > 1:
36-
addr_keypath = comment.split(" addr=")[1]
37-
addr = addr_keypath.split(" ")[0]
32+
key_date_label, comment = line.split("#")
33+
key_date_label = key_date_label.split(" ")
34+
# key = key_date_label[0]
35+
date = key_date_label[1]
36+
keytype = key_date_label[2]
37+
if not len(comment) or date.startswith('1970'):
38+
continue
39+
40+
addr_keypath = comment.split(" addr=")[1]
41+
addr = addr_keypath.split(" ")[0]
42+
keypath = None
43+
if keytype == "inactivehdseed=1":
44+
# ensure the old master is still available
45+
assert (hd_master_addr_old == addr)
46+
elif keytype == "hdseed=1":
47+
# ensure we have generated a new hd master key
48+
assert (hd_master_addr_old != addr)
49+
hd_master_addr_ret = addr
50+
elif keytype == "script=1":
51+
# scripts don't have keypaths
3852
keypath = None
39-
if keytype == "inactivehdseed=1":
40-
# ensure the old master is still available
41-
assert(hd_master_addr_old == addr)
42-
elif keytype == "hdseed=1":
43-
# ensure we have generated a new hd master key
44-
assert(hd_master_addr_old != addr)
45-
hd_master_addr_ret = addr
46-
elif keytype == "script=1":
47-
# scripts don't have keypaths
48-
keypath = None
49-
else:
50-
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
51-
52-
# count key types
53-
for addrObj in addrs:
54-
if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
55-
# a labeled entry in the wallet should contain both a native address
56-
# and the p2sh-p2wpkh address that was added at wallet setup
57-
if len(addr.split(",")) == 2:
58-
addr_list = addr.split(",")
59-
# the entry should be of the first key in the wallet
60-
assert_equal(addrs[0]['address'], addr_list[0])
61-
witness_addr_ret = addr_list[1]
62-
found_addr += 1
63-
break
64-
elif keytype == "change=1":
65-
found_addr_chg += 1
66-
break
67-
elif keytype == "reserve=1":
68-
found_addr_rsv += 1
69-
break
70-
71-
# count scripts
72-
for script_addr in script_addrs:
73-
if script_addr == addr.rstrip() and keytype == "script=1":
74-
found_script_addr += 1
75-
break
53+
else:
54+
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
55+
56+
# count key types
57+
for addrObj in addrs:
58+
if addrObj['address'] == addr.split(",")[0] and addrObj['hdkeypath'] == keypath and keytype == "label=":
59+
# a labeled entry in the wallet should contain both a native address
60+
# and the p2sh-p2wpkh address that was added at wallet setup
61+
if len(addr.split(",")) == 2:
62+
addr_list = addr.split(",")
63+
# the entry should be of the first key in the wallet
64+
assert_equal(addrs[0]['address'], addr_list[0])
65+
witness_addr_ret = addr_list[1]
66+
found_addr += 1
67+
break
68+
elif keytype == "change=1":
69+
found_addr_chg += 1
70+
break
71+
elif keytype == "reserve=1":
72+
found_addr_rsv += 1
73+
break
74+
75+
# count scripts
76+
for script_addr in script_addrs:
77+
if script_addr == addr.rstrip() and keytype == "script=1":
78+
found_script_addr += 1
79+
break
7680

7781
return found_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret, witness_addr_ret
7882

@@ -116,9 +120,9 @@ def run_test(self):
116120
read_dump(wallet_unenc_dump, addrs, script_addrs, None)
117121
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
118122
assert_equal(found_script_addr, 2) # all scripts must be in the dump
119-
assert_equal(found_addr_chg, 50) # 50 blocks where mined
120-
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
121-
assert_equal(witness_addr_ret, witness_addr) # p2sh-p2wsh address added to the first key
123+
assert_equal(found_addr_chg, 0) # 0 blocks where mined
124+
assert_equal(found_addr_rsv, 90 * 2) # 90 keys plus 100% internal keys
125+
assert_equal(witness_addr_ret, witness_addr) # p2sh-p2wsh address added to the first key
122126

123127
#encrypt wallet, restart, unlock and dump
124128
self.nodes[0].node_encrypt_wallet('test')
@@ -132,8 +136,8 @@ def run_test(self):
132136
read_dump(wallet_enc_dump, addrs, script_addrs, hd_master_addr_unenc)
133137
assert_equal(found_addr, test_addr_count)
134138
assert_equal(found_script_addr, 2)
135-
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
136-
assert_equal(found_addr_rsv, 90*2)
139+
assert_equal(found_addr_chg, 90 * 2) # old reserve keys are marked as change now
140+
assert_equal(found_addr_rsv, 90 * 2)
137141
assert_equal(witness_addr_ret, witness_addr)
138142

139143
# Overwriting should fail

test/functional/wallet_import_rescan.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,19 @@ def setup_network(self):
116116
extra_args[i] += ["-prune=1"]
117117

118118
self.add_nodes(self.num_nodes, extra_args=extra_args)
119+
120+
# Import keys
121+
self.start_nodes(extra_args=[[]] * self.num_nodes)
122+
super().import_deterministic_coinbase_privkeys()
123+
self.stop_nodes()
124+
119125
self.start_nodes()
120126
for i in range(1, self.num_nodes):
121127
connect_nodes(self.nodes[i], 0)
122128

129+
def import_deterministic_coinbase_privkeys(self):
130+
pass
131+
123132
def run_test(self):
124133
# Create one transaction on node 0 with a unique amount for
125134
# each possible type of wallet import RPC.

test/functional/wallet_listreceivedby.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class ReceivedByTest(BitcoinTestFramework):
1818
def set_test_params(self):
1919
self.num_nodes = 2
2020

21+
def import_deterministic_coinbase_privkeys(self):
22+
assert_equal(0, len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True)))
23+
super().import_deterministic_coinbase_privkeys()
24+
self.num_cb_reward_addresses = len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True))
25+
2126
def run_test(self):
2227
# Generate block to get out of IBD
2328
self.nodes[0].generate(1)
@@ -64,7 +69,7 @@ def run_test(self):
6469
assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, include_empty=True, include_watchonly=True, address_filter="bamboozling")
6570
# Another address receive money
6671
res = self.nodes[1].listreceivedbyaddress(0, True, True)
67-
assert_equal(len(res), 2) # Right now 2 entries
72+
assert_equal(len(res), 2 + self.num_cb_reward_addresses) # Right now 2 entries
6873
other_addr = self.nodes[1].getnewaddress()
6974
txid2 = self.nodes[0].sendtoaddress(other_addr, 0.1)
7075
self.nodes[0].generate(1)
@@ -81,7 +86,7 @@ def run_test(self):
8186
assert_equal(len(res), 1)
8287
# Should be two entries though without filter
8388
res = self.nodes[1].listreceivedbyaddress(0, True, True)
84-
assert_equal(len(res), 3) # Became 3 entries
89+
assert_equal(len(res), 3 + self.num_cb_reward_addresses) # Became 3 entries
8590

8691
# Not on random addr
8792
other_addr = self.nodes[0].getnewaddress() # note on node[0]! just a random addr

0 commit comments

Comments
 (0)