Add a test for addr with own IP

This commit is contained in:
Lee Miller 2024-06-25 00:19:53 +03:00
parent af5a8acd21
commit 6146c6ccd6
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -142,8 +142,11 @@ class TestNetwork(unittest.TestCase):
time_offset_connections(nodes, -4000)
class TestListener(TestProcessProto):
"""A separate test case for Listener with a process with --trusted-peer"""
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']
def setUp(self):
@ -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 the behavior of the process with --trusted-peer"""
def test_advertisement(self):
"""Ensure it doesn't advertise to connected peers their own IPs"""
started = time.time()
with run_listener() as _:
while time.time() - started < 30:
if ('127.0.0.1', 8444) in shared.unchecked_node_pool:
self.fail('Got own IP in an addr message')
time.sleep(1)