Skip to content

Commit 4d26312

Browse files
author
MarcoFalke
committed
Merge #18597: test: Extend wallet_dump test to cover comments
555567a test: Extend wallet_dump test to cover comments (MarcoFalke) Pull request description: ACKs for top commit: ryanofsky: Code review ACK 555567a. Nice new checks in this test. I confirmed this catches the missing FormatISO8601DateTime call you discovered in bitcoin/bitcoin#17954 (comment) Tree-SHA512: 71aa23dd039f3bcdee642b01151edd1a0d44f48cedd070f5858148c8cb8abd6f5edfd212daeba38e35c843da5ea6c799e5a952105fdecedac355a5a843c05a84
2 parents c49971f + 555567a commit 4d26312

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

test/functional/wallet_dump.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the dumpwallet RPC."""
6+
import datetime
67
import os
8+
import time
79

810
from test_framework.test_framework import BitcoinTestFramework
911
from test_framework.util import (
@@ -18,6 +20,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
1820
Also check that the old hd_master is inactive
1921
"""
2022
with open(file_name, encoding='utf8') as inputfile:
23+
found_comments = []
2124
found_legacy_addr = 0
2225
found_p2sh_segwit_addr = 0
2326
found_bech32_addr = 0
@@ -26,8 +29,12 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
2629
found_addr_rsv = 0
2730
hd_master_addr_ret = None
2831
for line in inputfile:
29-
# only read non comment lines
30-
if line[0] != "#" and len(line) > 10:
32+
line = line.strip()
33+
if not line:
34+
continue
35+
if line[0] == '#':
36+
found_comments.append(line)
37+
else:
3138
# split out some data
3239
key_date_label, comment = line.split("#")
3340
key_date_label = key_date_label.split(" ")
@@ -82,7 +89,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
8289
found_script_addr += 1
8390
break
8491

85-
return found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
92+
return found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_ret
8693

8794

8895
class WalletDumpTest(BitcoinTestFramework):
@@ -122,12 +129,36 @@ def run_test(self):
122129
# its capacity
123130
self.nodes[0].keypoolrefill()
124131

125-
# dump unencrypted wallet
132+
self.log.info('Mine a block one second before the wallet is dumped')
133+
dump_time = int(time.time())
134+
self.nodes[0].setmocktime(dump_time - 1)
135+
self.nodes[0].generate(1)
136+
self.nodes[0].setmocktime(dump_time)
137+
dump_time_str = '# * Created on {}Z'.format(
138+
datetime.datetime.fromtimestamp(
139+
dump_time,
140+
tz=datetime.timezone.utc,
141+
).replace(tzinfo=None).isoformat())
142+
dump_best_block_1 = '# * Best block at time of backup was {} ({}),'.format(
143+
self.nodes[0].getblockcount(),
144+
self.nodes[0].getbestblockhash(),
145+
)
146+
dump_best_block_2 = '# mined on {}Z'.format(
147+
datetime.datetime.fromtimestamp(
148+
dump_time - 1,
149+
tz=datetime.timezone.utc,
150+
).replace(tzinfo=None).isoformat())
151+
152+
self.log.info('Dump unencrypted wallet')
126153
result = self.nodes[0].dumpwallet(wallet_unenc_dump)
127154
assert_equal(result['filename'], wallet_unenc_dump)
128155

129-
found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
156+
found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
130157
read_dump(wallet_unenc_dump, addrs, [multisig_addr], None)
158+
assert '# End of dump' in found_comments # Check that file is not corrupt
159+
assert_equal(dump_time_str, next(c for c in found_comments if c.startswith('# * Created on')))
160+
assert_equal(dump_best_block_1, next(c for c in found_comments if c.startswith('# * Best block')))
161+
assert_equal(dump_best_block_2, next(c for c in found_comments if c.startswith('# mined on')))
131162
assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
132163
assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
133164
assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump
@@ -142,8 +173,12 @@ def run_test(self):
142173
self.nodes[0].keypoolrefill()
143174
self.nodes[0].dumpwallet(wallet_enc_dump)
144175

145-
found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
176+
found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, _ = \
146177
read_dump(wallet_enc_dump, addrs, [multisig_addr], hd_master_addr_unenc)
178+
assert '# End of dump' in found_comments # Check that file is not corrupt
179+
assert_equal(dump_time_str, next(c for c in found_comments if c.startswith('# * Created on')))
180+
assert_equal(dump_best_block_1, next(c for c in found_comments if c.startswith('# * Best block')))
181+
assert_equal(dump_best_block_2, next(c for c in found_comments if c.startswith('# mined on')))
147182
assert_equal(found_legacy_addr, test_addr_count) # all keys must be in the dump
148183
assert_equal(found_p2sh_segwit_addr, test_addr_count) # all keys must be in the dump
149184
assert_equal(found_bech32_addr, test_addr_count) # all keys must be in the dump

0 commit comments

Comments
 (0)