Skip to content

Commit 7a91ceb

Browse files
committed
[QA] Add RPC based rescan test
1 parent c77170f commit 7a91ceb

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/functional/wallet-hd.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
connect_nodes_bi,
1111
)
1212
import shutil
13+
import os
1314

1415
class WalletHDTest(BitcoinTestFramework):
1516
def set_test_params(self):
@@ -70,9 +71,9 @@ def run_test (self):
7071
self.stop_node(1)
7172
# we need to delete the complete regtest directory
7273
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
73-
shutil.rmtree(tmpdir + "/node1/regtest/blocks")
74-
shutil.rmtree(tmpdir + "/node1/regtest/chainstate")
75-
shutil.copyfile(tmpdir + "/hd.bak", tmpdir + "/node1/regtest/wallet.dat")
74+
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/blocks"))
75+
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate"))
76+
shutil.copyfile(os.path.join(tmpdir, "hd.bak"), os.path.join(tmpdir, "node1/regtest/wallet.dat"))
7677
self.start_node(1)
7778

7879
# Assert that derivation is deterministic
@@ -91,6 +92,22 @@ def run_test (self):
9192
self.start_node(1, extra_args=self.extra_args[1] + ['-rescan'])
9293
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
9394

95+
# Try a RPC based rescan
96+
self.stop_node(1)
97+
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/blocks"))
98+
shutil.rmtree(os.path.join(tmpdir, "node1/regtest/chainstate"))
99+
shutil.copyfile(os.path.join(tmpdir, "hd.bak"), os.path.join(tmpdir, "node1/regtest/wallet.dat"))
100+
self.start_node(1, extra_args=self.extra_args[1])
101+
connect_nodes_bi(self.nodes, 0, 1)
102+
self.sync_all()
103+
out = self.nodes[1].rescanblockchain(0, 1)
104+
assert_equal(out['start_height'], 0)
105+
assert_equal(out['stop_height'], 1)
106+
out = self.nodes[1].rescanblockchain()
107+
assert_equal(out['start_height'], 0)
108+
assert_equal(out['stop_height'], self.nodes[1].getblockcount())
109+
assert_equal(self.nodes[1].getbalance(), num_hd_adds + 1)
110+
94111
# send a tx and make sure its using the internal chain for the changeoutput
95112
txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
96113
outs = self.nodes[1].decoderawtransaction(self.nodes[1].gettransaction(txid)['hex'])['vout']

0 commit comments

Comments
 (0)