diff --git a/src/tests/samples.py b/src/tests/samples.py index 426bd4c1..7a9870a9 100644 --- a/src/tests/samples.py +++ b/src/tests/samples.py @@ -5,6 +5,15 @@ from binascii import unhexlify magic = 0xE9BEB4D9 +# 500 identical peers: +# 1626611891, 1, 1, 127.0.0.1, 8444 +sample_addr_data = unhexlify( + 'fd01f4' + ( + '0000000060f420b30000000' + '1000000000000000100000000000000000000ffff7f00000120fc' + ) * 500 +) + # These keys are from addresses test script sample_pubsigningkey = unhexlify( '044a367f049ec16cb6b6118eb734a9962d10b8db59c890cd08f210c43ff08bdf09d' diff --git a/src/tests/test_packets.py b/src/tests/test_packets.py index 3a0c43e9..115f1edc 100644 --- a/src/tests/test_packets.py +++ b/src/tests/test_packets.py @@ -5,7 +5,7 @@ from struct import pack from pybitmessage import addresses, protocol -from .samples import magic +from .samples import magic, sample_addr_data from .test_protocol import TestSocketInet @@ -67,3 +67,12 @@ class TestSerialize(TestSocketInet): self.assertEqual( protocol.encodeHost('quzwelsuziwqgpt2.onion'), unhexlify('fd87d87eeb438533622e54ca2d033e7a')) + + def test_assemble_addr(self): + """Assemble addr packet and compare it to pregenerated sample""" + self.assertEqual( + sample_addr_data, + protocol.assembleAddrMessage([ + (1, protocol.Peer('127.0.0.1', 8444), 1626611891) + for _ in range(500) + ])[protocol.Header.size:])