A test for encoding and decoding of onion peer object
This commit is contained in:
parent
c385b43a09
commit
638f613c03
|
@ -23,6 +23,9 @@ sample_addr_data = unhexlify(
|
||||||
sample_object_data = unhexlify(
|
sample_object_data = unhexlify(
|
||||||
'000000000000000000000000652724030000002a010248454c4c4f')
|
'000000000000000000000000652724030000002a010248454c4c4f')
|
||||||
|
|
||||||
|
sample_onion_host = \
|
||||||
|
'bmtestlmgmvpbsg7kzmrxu47chs3cdou2tj4t5iloocgujzsf3e7rbqd.onion'
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=shared.log_level,
|
level=shared.log_level,
|
||||||
format='[%(asctime)s] [%(levelname)s] %(message)s')
|
format='[%(asctime)s] [%(levelname)s] %(message)s')
|
||||||
|
@ -192,3 +195,21 @@ class TestStructure(unittest.TestCase):
|
||||||
nonce, obj.expires_time, obj.object_type, obj.version,
|
nonce, obj.expires_time, obj.object_type, obj.version,
|
||||||
obj.stream_number, obj.object_payload)
|
obj.stream_number, obj.object_payload)
|
||||||
self.assertTrue(obj.is_valid())
|
self.assertTrue(obj.is_valid())
|
||||||
|
|
||||||
|
def test_onion_peer(self):
|
||||||
|
"""Make an onion peer object and decode it back"""
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
onion_peer = structure.OnionPeer('testing2')
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
onion_peer = structure.OnionPeer('testing.onion')
|
||||||
|
onion_peer = structure.OnionPeer(sample_onion_host)
|
||||||
|
self.assertEqual(onion_peer.stream, shared.stream)
|
||||||
|
obj = onion_peer.to_object()
|
||||||
|
self.assertEqual(obj.object_type, shared.onion_obj_type)
|
||||||
|
self.assertEqual(obj.version, shared.onion_obj_version)
|
||||||
|
decoded = structure.OnionPeer.from_object(obj)
|
||||||
|
self.assertEqual(decoded.dest_pub, onion_peer.dest_pub)
|
||||||
|
self.assertEqual(decoded.port, onion_peer.port)
|
||||||
|
obj.object_payload = obj.object_payload[0:1] + obj.object_payload[2:]
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
structure.OnionPeer.from_object(obj)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user