mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
test: Test for dumptxoutset at specific height
This commit is contained in:
parent
993cafe7e4
commit
8426850352
2 changed files with 46 additions and 4 deletions
|
@ -22,6 +22,7 @@ from test_framework.util import (
|
||||||
assert_approx,
|
assert_approx,
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
|
sha256sum_file,
|
||||||
)
|
)
|
||||||
from test_framework.wallet import (
|
from test_framework.wallet import (
|
||||||
getnewdestination,
|
getnewdestination,
|
||||||
|
@ -320,12 +321,16 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||||
for n in self.nodes:
|
for n in self.nodes:
|
||||||
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
|
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
|
||||||
|
|
||||||
assert_equal(
|
|
||||||
dump_output['txoutset_hash'],
|
|
||||||
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")
|
|
||||||
assert_equal(dump_output["nchaintx"], blocks[SNAPSHOT_BASE_HEIGHT].chain_tx)
|
|
||||||
assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
|
assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
|
||||||
|
|
||||||
|
def check_dump_output(output):
|
||||||
|
assert_equal(
|
||||||
|
output['txoutset_hash'],
|
||||||
|
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")
|
||||||
|
assert_equal(output["nchaintx"], blocks[SNAPSHOT_BASE_HEIGHT].chain_tx)
|
||||||
|
|
||||||
|
check_dump_output(dump_output)
|
||||||
|
|
||||||
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
|
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
|
||||||
# will allow us to test n1's sync-to-tip on top of a snapshot.
|
# will allow us to test n1's sync-to-tip on top of a snapshot.
|
||||||
self.generate(n0, nblocks=100, sync_fun=self.no_op)
|
self.generate(n0, nblocks=100, sync_fun=self.no_op)
|
||||||
|
@ -335,6 +340,39 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||||
|
|
||||||
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
|
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
|
||||||
|
|
||||||
|
self.log.info(f"Check that dumptxoutset works for past block heights")
|
||||||
|
# rollback defaults to the snapshot base height
|
||||||
|
dump_output2 = n0.dumptxoutset('utxos2.dat', "rollback")
|
||||||
|
check_dump_output(dump_output2)
|
||||||
|
assert_equal(sha256sum_file(dump_output['path']), sha256sum_file(dump_output2['path']))
|
||||||
|
|
||||||
|
# Rollback with specific height
|
||||||
|
dump_output3 = n0.dumptxoutset('utxos3.dat', rollback=SNAPSHOT_BASE_HEIGHT)
|
||||||
|
check_dump_output(dump_output3)
|
||||||
|
assert_equal(sha256sum_file(dump_output['path']), sha256sum_file(dump_output3['path']))
|
||||||
|
|
||||||
|
# Specified height that is not a snapshot height
|
||||||
|
prev_snap_height = SNAPSHOT_BASE_HEIGHT - 1
|
||||||
|
dump_output4 = n0.dumptxoutset(path='utxos4.dat', rollback=prev_snap_height)
|
||||||
|
assert_equal(
|
||||||
|
dump_output4['txoutset_hash'],
|
||||||
|
"8a1db0d6e958ce0d7c963bc6fc91ead596c027129bacec68acc40351037b09d7")
|
||||||
|
assert sha256sum_file(dump_output['path']) != sha256sum_file(dump_output4['path'])
|
||||||
|
|
||||||
|
# Use a hash instead of a height
|
||||||
|
prev_snap_hash = n0.getblockhash(prev_snap_height)
|
||||||
|
dump_output5 = n0.dumptxoutset('utxos5.dat', rollback=prev_snap_hash)
|
||||||
|
assert_equal(sha256sum_file(dump_output4['path']), sha256sum_file(dump_output5['path']))
|
||||||
|
|
||||||
|
# TODO: This is a hack to set m_best_header to the correct value after
|
||||||
|
# dumptxoutset/reconsiderblock. Otherwise the wrong error messages are
|
||||||
|
# returned in following tests. It can be removed once this bug is
|
||||||
|
# fixed. See also https://github.com/bitcoin/bitcoin/issues/26245
|
||||||
|
self.restart_node(0, ["-reindex"])
|
||||||
|
|
||||||
|
# Ensure n0 is back at the tip
|
||||||
|
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
|
||||||
|
|
||||||
self.test_snapshot_with_less_work(dump_output['path'])
|
self.test_snapshot_with_less_work(dump_output['path'])
|
||||||
self.test_invalid_mempool_state(dump_output['path'])
|
self.test_invalid_mempool_state(dump_output['path'])
|
||||||
self.test_invalid_snapshot_scenarios(dump_output['path'])
|
self.test_invalid_snapshot_scenarios(dump_output['path'])
|
||||||
|
|
|
@ -56,6 +56,10 @@ class DumptxoutsetTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(
|
assert_raises_rpc_error(
|
||||||
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path, "latest")
|
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path, "latest")
|
||||||
|
|
||||||
|
self.log.info(f"Test that dumptxoutset with unknown dump type fails")
|
||||||
|
assert_raises_rpc_error(
|
||||||
|
-8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
DumptxoutsetTest(__file__).main()
|
DumptxoutsetTest(__file__).main()
|
||||||
|
|
Loading…
Reference in a new issue