|
5 | 5 | from twisted.internet.protocol import Protocol
|
6 | 6 | from twisted.python.failure import Failure
|
7 | 7 |
|
| 8 | +from hathor.p2p.entrypoint import Entrypoint |
8 | 9 | from hathor.p2p.peer_id import PeerId
|
9 | 10 | from hathor.p2p.protocol import HathorLineReceiver, HathorProtocol
|
10 | 11 | from hathor.simulator import FakeConnection
|
11 |
| -from hathor.util import json_dumps |
| 12 | +from hathor.util import json_dumps, json_loadb |
12 | 13 | from tests import unittest
|
13 | 14 |
|
14 | 15 |
|
@@ -69,6 +70,25 @@ def _check_cmd_and_value(self, result: bytes, expected: tuple[bytes, bytes]) ->
|
69 | 70 | def test_on_connect(self) -> None:
|
70 | 71 | self._check_result_only_cmd(self.conn.peek_tr1_value(), b'HELLO')
|
71 | 72 |
|
| 73 | + def test_peer_id_with_entrypoint(self) -> None: |
| 74 | + entrypoint_str = 'tcp://192.168.1.1:54321' |
| 75 | + entrypoint = Entrypoint.parse(entrypoint_str) |
| 76 | + self.peer_id1.entrypoints.append(entrypoint) |
| 77 | + self.peer_id2.entrypoints.append(entrypoint) |
| 78 | + self.conn.run_one_step() # HELLO |
| 79 | + |
| 80 | + msg1 = self.conn.peek_tr1_value() |
| 81 | + cmd1, val1 = msg1.split(b' ', 1) |
| 82 | + data1 = json_loadb(val1) |
| 83 | + self.assertEqual(cmd1, b'PEER-ID') |
| 84 | + self.assertEqual(data1['entrypoints'], [entrypoint_str]) |
| 85 | + |
| 86 | + msg2 = self.conn.peek_tr2_value() |
| 87 | + cmd2, val2 = msg2.split(b' ', 1) |
| 88 | + data2 = json_loadb(val2) |
| 89 | + self.assertEqual(cmd2, b'PEER-ID') |
| 90 | + self.assertEqual(data2['entrypoints'], [entrypoint_str]) |
| 91 | + |
72 | 92 | def test_invalid_command(self) -> None:
|
73 | 93 | self._send_cmd(self.conn.proto1, 'INVALID-CMD')
|
74 | 94 | self.conn.proto1.state.handle_error('')
|
|
0 commit comments