|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2019 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Test the generation of UTXO snapshots using `dumptxoutset`. |
| 6 | +""" |
| 7 | +from test_framework.test_framework import BitcoinTestFramework |
| 8 | +from test_framework.util import assert_equal, assert_raises_rpc_error |
| 9 | + |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | + |
| 13 | +class DumptxoutsetTest(BitcoinTestFramework): |
| 14 | + def set_test_params(self): |
| 15 | + self.setup_clean_chain = True |
| 16 | + self.num_nodes = 1 |
| 17 | + |
| 18 | + def run_test(self): |
| 19 | + """Test a trivial usage of the dumptxoutset RPC command.""" |
| 20 | + node = self.nodes[0] |
| 21 | + node.generate(100) |
| 22 | + |
| 23 | + FILENAME = 'txoutset.dat' |
| 24 | + out = node.dumptxoutset(FILENAME) |
| 25 | + expected_path = Path(node.datadir) / 'regtest' / FILENAME |
| 26 | + |
| 27 | + assert expected_path.is_file() |
| 28 | + |
| 29 | + assert_equal(out['coins_written'], 100) |
| 30 | + assert_equal(out['base_height'], 100) |
| 31 | + assert_equal(out['path'], str(expected_path)) |
| 32 | + assert out['base_hash'] |
| 33 | + |
| 34 | + # TODO I'd like to make assertions about the contents of the file |
| 35 | + # (ideally its hash), but because we can't get a deterministic block |
| 36 | + # header (we'd need to mock time) and we have no way of deserializing |
| 37 | + # the file (yet), we can't really do anything in this department. |
| 38 | + |
| 39 | + # Specifying a path to an existing file will fail. |
| 40 | + assert_raises_rpc_error( |
| 41 | + -8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME) |
| 42 | + |
| 43 | +if __name__ == '__main__': |
| 44 | + DumptxoutsetTest().main() |
0 commit comments