From 305d5d716c60d2ad1765f600e3f55ff04d482c8e Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 18 Aug 2021 19:55:40 +0300 Subject: [PATCH] Add a test for protocol.assembleAddrMessage() --- src/tests/samples.py | 9 +++++++++ src/tests/test_packets.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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:])