Finish test_address() using a sample data, generated with pybitmessage

This commit is contained in:
Lee Miller 2023-08-14 04:21:00 +03:00
parent dd2b0b89af
commit 4f1e14da2a
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -6,6 +6,14 @@ from binascii import unhexlify
from minode import structure
# host pregenerated by pybitmessage.protocol.encodeHost()
# for one of bootstrap servers, port 8080,
# everything else is like in test_message: 1626611891, 1, 1
sample_addr_data = unhexlify(
'0000000060f420b3000000010000000000000001'
'260753000201300000000000000057ae1f90')
class TestStructure(unittest.TestCase):
"""Testing structures serializing and deserializing"""
@ -68,3 +76,12 @@ class TestStructure(unittest.TestCase):
self.assertEqual(
addr.to_bytes()[8:24],
unhexlify('0102030405060708090a0b0c0d0e0f10'))
addr = structure.NetAddr.from_bytes(sample_addr_data)
self.assertEqual(addr.host, '2607:5300:201:3000::57ae')
self.assertEqual(addr.port, 8080)
self.assertEqual(addr.stream, 1)
self.assertEqual(addr.services, 1)
addr = structure.NetAddr(1, '2607:5300:201:3000::57ae', 8080, 1)
self.assertEqual(addr.to_bytes()[8:], sample_addr_data[8:])