Skip to content

Commit

Permalink
test: add functional test for an empty, unparsable asmap
Browse files Browse the repository at this point in the history
This is now testable after separating the asmap finding and parsing checks in the previous commit.
  • Loading branch information
jonatack authored and furszy committed Jul 28, 2021
1 parent 6545656 commit 0c9efb8
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
# 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:
Verify node behaviour and debug log when launching pivxd in these cases:
1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing
1. `pivxd` with no -asmap arg, using /16 prefix for IP bucketing
2. `bitcoind -asmap=<absolute path>`, using the unit test skeleton asmap
2. `pivxd -asmap=<absolute path>`, using the unit test skeleton asmap
3. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap
3. `pivxd -asmap=<relative path>`, using the unit test skeleton asmap
4. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap
4. `pivxd -asmap/-asmap=` with no file specified, using the default asmap
5. `bitcoind -asmap` with no file specified and a missing default asmap file
5. `pivxd -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.
6. `pivxd -asmap` with an empty (unparsable) default asmap file
The tests are order-independent. The slowest tests (missing default asmap and
empty asmap) are placed last.
"""
import os
Expand All @@ -35,17 +37,16 @@ def expected_messages(filename):

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.log.info('Test pivxd 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 bitcoind -asmap=<absolute path>')
self.log.info('Test pivxd -asmap=<absolute path>')
self.stop_node(0)
filename = os.path.join(self.datadir, 'my-map-file.map')
shutil.copyfile(self.asmap_raw, filename)
Expand All @@ -54,7 +55,7 @@ def test_asmap_with_absolute_path(self):
os.remove(filename)

def test_asmap_with_relative_path(self):
self.log.info('Test bitcoind -asmap=<relative path>')
self.log.info('Test pivxd -asmap=<relative path>')
self.stop_node(0)
name = 'ASN_map'
filename = os.path.join(self.datadir, name)
Expand All @@ -66,17 +67,26 @@ def test_asmap_with_relative_path(self):
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.log.info('Test pivxd {} (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.log.info('Test pivxd -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)
self.assert_start_raises_init_error(0, extra_args=['-asmap'], expected_msg=msg)

def test_empty_asmap(self):
self.log.info('Test pivxd -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.assert_start_raises_init_error(0, extra_args=['-asmap'], expected_msg=msg)
os.remove(self.default_asmap)

def run_test(self):
self.node = self.nodes[0]
Expand All @@ -88,7 +98,8 @@ def run_test(self):
self.test_asmap_with_absolute_path()
self.test_asmap_with_relative_path()
self.test_default_asmap()
#self.test_default_asmap_with_missing_file() // fixme
self.test_default_asmap_with_missing_file()
self.test_empty_asmap()


if __name__ == '__main__':
Expand Down

0 comments on commit 0c9efb8

Please sign in to comment.