From 68bea10ab7cecf12e1509da73acda8a56f0a35f1 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Mon, 8 Jul 2024 01:17:19 +0300 Subject: [PATCH] Add a test for addr with host 127.0.0.1 --- minode/tests/test_network.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/minode/tests/test_network.py b/minode/tests/test_network.py index c8cdd31..dbf5bc3 100644 --- a/minode/tests/test_network.py +++ b/minode/tests/test_network.py @@ -142,9 +142,12 @@ class TestNetwork(unittest.TestCase): time_offset_connections(nodes, -4000) -class TestListener(TestProcessProto): - """A separate test case for Listener with a process with --trusted-peer""" - _process_cmd = ['minode', '--trusted-peer', '127.0.0.1'] +class TestConnection(TestProcessProto): + """ + A base class for test cases using a process with --trusted-peer + to connect to a listener instance. + """ + _process_cmd = ['minode', '--trusted-peer', '127.0.0.1', '-p', '8448'] def setUp(self): shared.shutting_down = False @@ -154,6 +157,10 @@ class TestListener(TestProcessProto): super().tearDownClass() shared.shutting_down = False + +class TestListener(TestConnection): + """A separate test case for Listener""" + def test_listener(self): """Start Listener and try to connect""" with run_listener() as listener: @@ -215,3 +222,16 @@ class TestListener(TestProcessProto): if c.status == 'fully_established': self.fail('Established a connection') time.sleep(0.5) + + +class TestBehavior(TestConnection): + """Test behavior of the process with --trusted-peer""" + + def test_advertisement(self): + """Ensure it doesn't advertise 127.0.0.1""" + started = time.time() + with run_listener() as _: + while time.time() - started < 30: + if ('127.0.0.1', 8448) in shared.unchecked_node_pool: + self.fail('Got 127.0.0.1 in an addr message') + time.sleep(1)