Skip to content

Commit 92b2f53

Browse files
committed
test: add dumptxoutset RPC test
1 parent c1ccbc3 commit 92b2f53

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

test/functional/rpc_dumptxoutset.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import hashlib
11+
from pathlib import Path
12+
13+
14+
class DumptxoutsetTest(BitcoinTestFramework):
15+
def set_test_params(self):
16+
self.setup_clean_chain = True
17+
self.num_nodes = 1
18+
19+
def run_test(self):
20+
"""Test a trivial usage of the dumptxoutset RPC command."""
21+
node = self.nodes[0]
22+
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
23+
node.setmocktime(mocktime)
24+
node.generate(100)
25+
26+
FILENAME = 'txoutset.dat'
27+
out = node.dumptxoutset(FILENAME)
28+
expected_path = Path(node.datadir) / 'regtest' / FILENAME
29+
30+
assert expected_path.is_file()
31+
32+
assert_equal(out['coins_written'], 100)
33+
assert_equal(out['base_height'], 100)
34+
assert_equal(out['path'], str(expected_path))
35+
# Blockhash should be deterministic based on mocked time.
36+
assert_equal(
37+
out['base_hash'],
38+
'6fd417acba2a8738b06fee43330c50d58e6a725046c3d843c8dd7e51d46d1ed6')
39+
40+
with open(str(expected_path), 'rb') as f:
41+
digest = hashlib.sha256(f.read()).hexdigest()
42+
# UTXO snapshot hash should be deterministic based on mocked time.
43+
assert_equal(
44+
digest, 'be032e5f248264ba08e11099ac09dbd001f6f87ffc68bf0f87043d8146d50664')
45+
46+
# Specifying a path to an existing file will fail.
47+
assert_raises_rpc_error(
48+
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
49+
50+
if __name__ == '__main__':
51+
DumptxoutsetTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
'rpc_uptime.py',
191191
'wallet_resendwallettransactions.py',
192192
'wallet_fallbackfee.py',
193+
'rpc_dumptxoutset.py',
193194
'feature_minchainwork.py',
194195
'rpc_getblockstats.py',
195196
'wallet_create_tx.py',

0 commit comments

Comments
 (0)