mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
00d2d7fac3
590bda79e876d9b959083105b8c7c41dd87706eb scripted-diff: Remove setup_clean_chain if default is not changed (Fabian Jahr) 98892f39e3d079c73bff7f2a5d5420fa95270497 doc: Improve setup_clean_chain documentation (Fabian Jahr) Pull request description: The first commit improves documentation on setup_clean_chain which is misunderstood quite frequently. Most importantly it fixes the TestShell docs which are simply incorrect. The second commit removes the instances of `setup_clean_clain` in functional tests where it is not changing the default. This used to be part of #19168 which also sought to rename`setup_clean_chain`. ACKs for top commit: jonatack: ACK 590bda79e876d9b959083105b8c7c41dd87706eb Tree-SHA512: a7881186e65d31160b8f84107fb185973b37c6e50f190a85c6e2906a13a7472bb4efa9440bd37fe0a9ac5cd2d1e8559870a7e4380632d9a249eca8980b945f3e
106 lines
4.1 KiB
Python
Executable File
106 lines
4.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020 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 asmap config argument for ASN-based IP bucketing.
|
|
|
|
Verify node behaviour and debug log when launching dashd in these cases:
|
|
|
|
1. `dashd` with no -asmap arg, using /16 prefix for IP bucketing
|
|
|
|
2. `dashd -asmap=<absolute path>`, using the unit test skeleton asmap
|
|
|
|
3. `dashd -asmap=<relative path>`, using the unit test skeleton asmap
|
|
|
|
4. `dashd -asmap/-asmap=` with no file specified, using the default asmap
|
|
|
|
5. `dashd -asmap` with no file specified and a missing default asmap file
|
|
|
|
6. `dashd -asmap` with an empty (unparsable) default asmap file
|
|
|
|
The tests are order-independent.
|
|
|
|
"""
|
|
import os
|
|
import shutil
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
DEFAULT_ASMAP_FILENAME = 'ip_asn.map' # defined in src/init.cpp
|
|
ASMAP = '../../src/test/data/asmap.raw' # path to unit test skeleton asmap
|
|
VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853'
|
|
|
|
def expected_messages(filename):
|
|
return ['Opened asmap file "{}" (59 bytes) from disk'.format(filename),
|
|
'Using asmap version {} for IP bucketing'.format(VERSION)]
|
|
|
|
class AsmapTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 1
|
|
|
|
def test_without_asmap_arg(self):
|
|
self.log.info('Test dashd with no -asmap arg passed')
|
|
self.stop_node(0)
|
|
with self.node.assert_debug_log(['Using /16 prefix for IP bucketing']):
|
|
self.start_node(0)
|
|
|
|
def test_asmap_with_absolute_path(self):
|
|
self.log.info('Test dashd -asmap=<absolute path>')
|
|
self.stop_node(0)
|
|
filename = os.path.join(self.datadir, 'my-map-file.map')
|
|
shutil.copyfile(self.asmap_raw, filename)
|
|
with self.node.assert_debug_log(expected_messages(filename)):
|
|
self.start_node(0, ['-asmap={}'.format(filename)])
|
|
os.remove(filename)
|
|
|
|
def test_asmap_with_relative_path(self):
|
|
self.log.info('Test dashd -asmap=<relative path>')
|
|
self.stop_node(0)
|
|
name = 'ASN_map'
|
|
filename = os.path.join(self.datadir, name)
|
|
shutil.copyfile(self.asmap_raw, filename)
|
|
with self.node.assert_debug_log(expected_messages(filename)):
|
|
self.start_node(0, ['-asmap={}'.format(name)])
|
|
os.remove(filename)
|
|
|
|
def test_default_asmap(self):
|
|
shutil.copyfile(self.asmap_raw, self.default_asmap)
|
|
for arg in ['-asmap', '-asmap=']:
|
|
self.log.info('Test dashd {} (using default map file)'.format(arg))
|
|
self.stop_node(0)
|
|
with self.node.assert_debug_log(expected_messages(self.default_asmap)):
|
|
self.start_node(0, [arg])
|
|
os.remove(self.default_asmap)
|
|
|
|
def test_default_asmap_with_missing_file(self):
|
|
self.log.info('Test dashd -asmap with missing default map file')
|
|
self.stop_node(0)
|
|
msg = "Error: Could not find asmap file \"{}\"".format(self.default_asmap)
|
|
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
|
|
|
|
def test_empty_asmap(self):
|
|
self.log.info('Test dashd -asmap with empty map file')
|
|
self.stop_node(0)
|
|
with open(self.default_asmap, "w", encoding="utf-8") as f:
|
|
f.write("")
|
|
msg = "Error: Could not parse asmap file \"{}\"".format(self.default_asmap)
|
|
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
|
|
os.remove(self.default_asmap)
|
|
|
|
def run_test(self):
|
|
self.node = self.nodes[0]
|
|
self.datadir = os.path.join(self.node.datadir, self.chain)
|
|
self.default_asmap = os.path.join(self.datadir, DEFAULT_ASMAP_FILENAME)
|
|
self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP)
|
|
|
|
self.test_without_asmap_arg()
|
|
self.test_asmap_with_absolute_path()
|
|
self.test_asmap_with_relative_path()
|
|
self.test_default_asmap()
|
|
self.test_default_asmap_with_missing_file()
|
|
self.test_empty_asmap()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
AsmapTest().main()
|