mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
8db2aabee0
bfa9309ad606102f24c9bd3c33dfe78949f09418 Use COINBASE_MATURITY constant in functional tests. (Kiminuo) 525448df9dc2ab6b7e960ff138956ae3e2efdf60 Move COINBASE_MATURITY from `feature_nulldummy` test to `blocktools`. (Kiminuo) Pull request description: `COINBASE_MATURITY` constant was added to `feature_nulldummy` test in #21373. This PR moves the constant to `blocktools.py` file and uses the constant in more tests as suggested [here](https://github.com/bitcoin/bitcoin/pull/21373#discussion_r605418462). Edit: Goal of this PR is to replace integer constants with `COINBASE_MATURITY` but not necessarily in *all* cases because that would mean to read and fully understand all tests. That's out of my time constraints. Any reports where `COINBASE_MATURITY` should be used are welcome though! ACKs for top commit: theStack: ACK bfa9309ad606102f24c9bd3c33dfe78949f09418 🌇 Tree-SHA512: 01f04645f05a39028681f355cf3d42dd63ea3303f76d93c430e0fdce441934358a2d847a54e6068d61932f1b75e1d406f51859b057b3e4b569f7083915cb317f
54 lines
1.9 KiB
Python
Executable File
54 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2019 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)
|
|
node.generate(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'],
|
|
'0266fa3cd96867c40f2f3056da3b66daf8fb4c83ec4f3f5344fd3fe9755794b5')
|
|
|
|
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, '83ec62f0b9d9f2cdfe4514e8996d5ba0a6aa4cf74517988670d912db83bc0318')
|
|
|
|
# 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()
|