Skip to content

Commit ebdc552

Browse files
committed
Fixup the walletdump command and python test
1 parent 37b29c7 commit ebdc552

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

src/rpcdump.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
380380

381381
EnsureWalletIsUnlocked();
382382

383+
boost::filesystem::path filepath = params[0].get_str().c_str();
384+
filepath = boost::filesystem::absolute(filepath);
385+
383386
ofstream file;
384387
file.open(params[0].get_str().c_str());
385388
if (!file.is_open())
@@ -422,7 +425,11 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
422425
file << "\n";
423426
file << "# End of dump\n";
424427
file.close();
425-
return NullUniValue;
428+
429+
UniValue reply(UniValue::VOBJ);
430+
reply.push_back(Pair("filename", filepath.string()));
431+
432+
return reply;
426433
}
427434

428435
UniValue bip38encrypt(const UniValue& params, bool fHelp)

test/functional/wallet_dump.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,15 @@ def read_dump(file_name, addrs, hd_master_addr_old):
2727
key_label, comment = line.split("#")
2828
# key = key_label.split(" ")[0]
2929
keytype = key_label.split(" ")[2]
30-
if len(comment) > 1:
31-
addr_keypath = comment.split(" addr=")[1]
32-
addr = addr_keypath.split(" ")[0]
33-
keypath = None
34-
if keytype == "inactivehdmaster=1":
35-
# ensure the old master is still available
36-
assert(hd_master_addr_old == addr)
37-
elif keytype == "hdmaster=1":
38-
# ensure we have generated a new hd master key
39-
assert(hd_master_addr_old != addr)
40-
hd_master_addr_ret = addr
41-
else:
42-
keypath = addr_keypath.rstrip().split("hdkeypath=")[1]
30+
addr = comment.split(" addr=")[1].strip()
4331

44-
# count key types
45-
for addrObj in addrs:
46-
if addrObj['address'] == addr and addrObj['hdkeypath'] == keypath and keytype == "label=":
47-
found_addr += 1
48-
break
49-
elif keytype == "change=1":
50-
found_addr_chg += 1
51-
break
52-
elif keytype == "reserve=1":
53-
found_addr_rsv += 1
54-
break
32+
# count key types
33+
if addr in addrs:
34+
found_addr += 1
35+
elif keytype == "change=1":
36+
found_addr_chg += 1
37+
elif keytype == "reserve=1":
38+
found_addr_rsv += 1
5539
return found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
5640

5741

@@ -76,8 +60,8 @@ def run_test (self):
7660
addrs = []
7761
for i in range(0,test_addr_count):
7862
addr = self.nodes[0].getnewaddress()
79-
vaddr= self.nodes[0].validateaddress(addr) #required to get hd keypath
80-
addrs.append(vaddr)
63+
#vaddr= self.nodes[0].validateaddress(addr) #required to get hd keypath
64+
addrs.append(addr)
8165
# Should be a no-op:
8266
self.nodes[0].keypoolrefill()
8367

@@ -88,13 +72,12 @@ def run_test (self):
8872
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
8973
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
9074
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
91-
assert_equal(found_addr_chg, 50) # 50 blocks where mined
75+
assert_equal(found_addr_chg, 0) # 0 blocks where mined
9276
assert_equal(found_addr_rsv, 90 + 1) # keypool size (TODO: fix off-by-one)
9377

9478
#encrypt wallet, restart, unlock and dump
95-
self.nodes[0].encryptwallet('test')
96-
bitcoind_processes[0].wait()
97-
self.nodes[0] = start_node(0, self.options.tmpdir, self.extra_args[0])
79+
self.nodes[0].node_encrypt_wallet('test')
80+
self.start_node(0)
9881
self.nodes[0].walletpassphrase('test', 10)
9982
# Should be a no-op:
10083
self.nodes[0].keypoolrefill()
@@ -103,7 +86,7 @@ def run_test (self):
10386
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_enc = \
10487
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
10588
assert_equal(found_addr, test_addr_count)
106-
assert_equal(found_addr_chg, 90 + 1 + 50) # old reserve keys are marked as change now
89+
assert_equal(found_addr_chg, 90 + 1) # old reserve keys are marked as change now
10790
assert_equal(found_addr_rsv, 90 + 1) # keypool size (TODO: fix off-by-one)
10891

10992
if __name__ == '__main__':

0 commit comments

Comments
 (0)