Skip to content

Commit

Permalink
test: add feature_asmap functional tests
Browse files Browse the repository at this point in the history
to verify node behaviour and debug log when launching bitcoind in these cases:

1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing

2. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap

3. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap

4. `bitcoind -asmap` with no file specified, and a missing default asmap file

The tests are order-independent. The slowest test (missing default asmap file)
is placed last.
  • Loading branch information
jonatack authored and furszy committed Jul 28, 2021
1 parent 4290d3f commit de39fab
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/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 bitcoind in these cases:
1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing
2. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap
3. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap
4. `bitcoind -asmap` with no file specified, and a missing default asmap file
The tests are order-independent. The slowest test (missing default asmap file)
is placed last.
"""
import os
import shutil

from test_framework.test_framework import PivxTestFramework

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(PivxTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def test_without_asmap_arg(self):
self.log.info('Test bitcoind 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_relative_path(self):
self.log.info('Test bitcoind -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 bitcoind {} (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 bitcoind -asmap with missing default map file')
self.stop_node(0)
msg = "Error: Could not find or parse specified asmap: '\"{}\"'".format(self.default_asmap)
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)

def run_test(self):
self.node = self.nodes[0]
self.datadir = os.path.join(self.node.datadir, 'regtest')
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_relative_path()
self.test_default_asmap()
#self.test_default_asmap_with_missing_file() // fixme


if __name__ == '__main__':
AsmapTest().main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
# vv Tests less than 60s vv
#'p2p_feefilter.py',
'feature_abortnode.py',
'feature_asmap.py',
'rpc_bind.py',
# vv Tests less than 30s vv
#'example_test.py',
Expand Down

0 comments on commit de39fab

Please sign in to comment.