mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
6acda4b00b
ffd09281fe
rpc: various fixups for dumptxoutset (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11) (parent PR: #15606) --- A few fixes to make this RPC actually useful when generating snapshots. - Generate an assumeutxo hash and display it (sort of a bugfix) - Add nchaintx to output (necessary for use in chainparams entry) - Add path of serialized UTXO file to output ACKs for top commit: laanwj: Code review ACKffd09281fe
Tree-SHA512: b0b5fd5138dea0e21258b1b18ab75bf3fd1628522cc1dbafa81af9cb9fa96562a1c39124fdb31057f256bfc560f462f907e9fe5e209b577b3f57afae2b7be826
58 lines
2.1 KiB
Python
Executable File
58 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2019-2021 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test the generation of UTXO snapshots using `dumptxoutset`.
|
|
"""
|
|
|
|
from test_framework.blocktools import COINBASE_MATURITY
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, assert_raises_rpc_error
|
|
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
|
|
class DumptxoutsetTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 1
|
|
|
|
def run_test(self):
|
|
"""Test a trivial usage of the dumptxoutset RPC command."""
|
|
node = self.nodes[0]
|
|
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
|
|
node.setmocktime(mocktime)
|
|
self.generate(node, COINBASE_MATURITY)
|
|
|
|
FILENAME = 'txoutset.dat'
|
|
out = node.dumptxoutset(FILENAME)
|
|
expected_path = Path(node.datadir) / self.chain / FILENAME
|
|
|
|
assert expected_path.is_file()
|
|
|
|
assert_equal(out['coins_written'], 100)
|
|
assert_equal(out['base_height'], 100)
|
|
assert_equal(out['path'], str(expected_path))
|
|
# Blockhash should be deterministic based on mocked time.
|
|
assert_equal(
|
|
out['base_hash'],
|
|
'6fd417acba2a8738b06fee43330c50d58e6a725046c3d843c8dd7e51d46d1ed6')
|
|
|
|
with open(str(expected_path), 'rb') as f:
|
|
digest = hashlib.sha256(f.read()).hexdigest()
|
|
# UTXO snapshot hash should be deterministic based on mocked time.
|
|
assert_equal(
|
|
digest, '7ae82c986fa5445678d2a21453bb1c86d39e47af13da137640c2b1cf8093691c')
|
|
|
|
assert_equal(
|
|
out['txoutset_hash'], 'd4b614f476b99a6e569973bf1c0120d88b1a168076f8ce25691fb41dd1cef149')
|
|
assert_equal(out['nchaintx'], 101)
|
|
|
|
# Specifying a path to an existing file will fail.
|
|
assert_raises_rpc_error(
|
|
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
|
|
|
|
if __name__ == '__main__':
|
|
DumptxoutsetTest().main()
|