Skip to content

Commit

Permalink
Merge bitcoin#17812: add functional test for an empty, unparsable asmap
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Mar 9, 2021
1 parent ecadab4 commit d711e16
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
5. `dashd -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. `dashd -asmap` with an empty (unparsable) default asmap file
The tests are order-independent.
"""
import os
Expand All @@ -30,8 +31,8 @@
VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853'

def expected_messages(filename):
return ['Opened asmap file "{}" (59 bytes) from disk.'.format(filename),
'Using asmap version {} for IP bucketing.'.format(VERSION)]
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):
Expand Down Expand Up @@ -75,9 +76,18 @@ def test_default_asmap(self):
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)
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)
Expand All @@ -89,6 +99,7 @@ def run_test(self):
self.test_asmap_with_relative_path()
self.test_default_asmap()
self.test_default_asmap_with_missing_file()
self.test_empty_asmap()


if __name__ == '__main__':
Expand Down

0 comments on commit d711e16

Please sign in to comment.