Skip to content

Commit 6cba60a

Browse files
committed
speed up wallet_hd.py and clarify/augment checks
1 parent 3cf76c2 commit 6cba60a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/functional/wallet_hd.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def run_test(self):
4848
# Also send funds to each add
4949
self.nodes[0].generate(101)
5050
hd_add = None
51-
num_hd_adds = 300
52-
for i in range(num_hd_adds):
51+
NUM_HD_ADDS = 10
52+
for i in range(NUM_HD_ADDS):
5353
hd_add = self.nodes[1].getnewaddress()
5454
hd_info = self.nodes[1].getaddressinfo(hd_add)
5555
assert_equal(hd_info["hdkeypath"], "m/0'/0'/"+str(i)+"'")
@@ -65,7 +65,7 @@ def run_test(self):
6565
assert_equal(change_addrV["hdkeypath"], "m/0'/1'/1'") #second internal child key
6666

6767
self.sync_all()
68-
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
68+
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
6969

7070
self.log.info("Restore backup ...")
7171
self.stop_node(1)
@@ -78,10 +78,10 @@ def run_test(self):
7878

7979
# Assert that derivation is deterministic
8080
hd_add_2 = None
81-
for _ in range(num_hd_adds):
81+
for i in range(NUM_HD_ADDS):
8282
hd_add_2 = self.nodes[1].getnewaddress()
8383
hd_info_2 = self.nodes[1].getaddressinfo(hd_add_2)
84-
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(_)+"'")
84+
assert_equal(hd_info_2["hdkeypath"], "m/0'/0'/"+str(i)+"'")
8585
assert_equal(hd_info_2["hdmasterkeyid"], masterkeyid)
8686
assert_equal(hd_add, hd_add_2)
8787
connect_nodes_bi(self.nodes, 0, 1)
@@ -90,7 +90,7 @@ def run_test(self):
9090
# Needs rescan
9191
self.stop_node(1)
9292
self.start_node(1, extra_args=self.extra_args[1] + ['-rescan'])
93-
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
93+
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
9494

9595
# Try a RPC based rescan
9696
self.stop_node(1)
@@ -100,13 +100,15 @@ def run_test(self):
100100
self.start_node(1, extra_args=self.extra_args[1])
101101
connect_nodes_bi(self.nodes, 0, 1)
102102
self.sync_all()
103+
# Wallet automatically scans blocks older than key on startup
104+
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
103105
out = self.nodes[1].rescanblockchain(0, 1)
104106
assert_equal(out['start_height'], 0)
105107
assert_equal(out['stop_height'], 1)
106108
out = self.nodes[1].rescanblockchain()
107109
assert_equal(out['start_height'], 0)
108110
assert_equal(out['stop_height'], self.nodes[1].getblockcount())
109-
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
111+
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
110112

111113
# send a tx and make sure its using the internal chain for the changeoutput
112114
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)

0 commit comments

Comments
 (0)