Skip to content

Commit 8426850

Browse files
committed
test: Test for dumptxoutset at specific height
1 parent 993cafe commit 8426850

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
assert_approx,
2323
assert_equal,
2424
assert_raises_rpc_error,
25+
sha256sum_file,
2526
)
2627
from test_framework.wallet import (
2728
getnewdestination,
@@ -320,12 +321,16 @@ def run_test(self):
320321
for n in self.nodes:
321322
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
322323

323-
assert_equal(
324-
dump_output['txoutset_hash'],
325-
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")
326-
assert_equal(dump_output["nchaintx"], blocks[SNAPSHOT_BASE_HEIGHT].chain_tx)
327324
assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
328325

326+
def check_dump_output(output):
327+
assert_equal(
328+
output['txoutset_hash'],
329+
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")
330+
assert_equal(output["nchaintx"], blocks[SNAPSHOT_BASE_HEIGHT].chain_tx)
331+
332+
check_dump_output(dump_output)
333+
329334
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
330335
# will allow us to test n1's sync-to-tip on top of a snapshot.
331336
self.generate(n0, nblocks=100, sync_fun=self.no_op)
@@ -335,6 +340,39 @@ def run_test(self):
335340

336341
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
337342

343+
self.log.info(f"Check that dumptxoutset works for past block heights")
344+
# rollback defaults to the snapshot base height
345+
dump_output2 = n0.dumptxoutset('utxos2.dat', "rollback")
346+
check_dump_output(dump_output2)
347+
assert_equal(sha256sum_file(dump_output['path']), sha256sum_file(dump_output2['path']))
348+
349+
# Rollback with specific height
350+
dump_output3 = n0.dumptxoutset('utxos3.dat', rollback=SNAPSHOT_BASE_HEIGHT)
351+
check_dump_output(dump_output3)
352+
assert_equal(sha256sum_file(dump_output['path']), sha256sum_file(dump_output3['path']))
353+
354+
# Specified height that is not a snapshot height
355+
prev_snap_height = SNAPSHOT_BASE_HEIGHT - 1
356+
dump_output4 = n0.dumptxoutset(path='utxos4.dat', rollback=prev_snap_height)
357+
assert_equal(
358+
dump_output4['txoutset_hash'],
359+
"8a1db0d6e958ce0d7c963bc6fc91ead596c027129bacec68acc40351037b09d7")
360+
assert sha256sum_file(dump_output['path']) != sha256sum_file(dump_output4['path'])
361+
362+
# Use a hash instead of a height
363+
prev_snap_hash = n0.getblockhash(prev_snap_height)
364+
dump_output5 = n0.dumptxoutset('utxos5.dat', rollback=prev_snap_hash)
365+
assert_equal(sha256sum_file(dump_output4['path']), sha256sum_file(dump_output5['path']))
366+
367+
# TODO: This is a hack to set m_best_header to the correct value after
368+
# dumptxoutset/reconsiderblock. Otherwise the wrong error messages are
369+
# returned in following tests. It can be removed once this bug is
370+
# fixed. See also https://github.com/bitcoin/bitcoin/issues/26245
371+
self.restart_node(0, ["-reindex"])
372+
373+
# Ensure n0 is back at the tip
374+
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
375+
338376
self.test_snapshot_with_less_work(dump_output['path'])
339377
self.test_invalid_mempool_state(dump_output['path'])
340378
self.test_invalid_snapshot_scenarios(dump_output['path'])

test/functional/rpc_dumptxoutset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def run_test(self):
5656
assert_raises_rpc_error(
5757
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path, "latest")
5858

59+
self.log.info(f"Test that dumptxoutset with unknown dump type fails")
60+
assert_raises_rpc_error(
61+
-8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus")
62+
5963

6064
if __name__ == '__main__':
6165
DumptxoutsetTest(__file__).main()

0 commit comments

Comments
 (0)