Add a test for protocol.assembleAddrMessage()

This commit is contained in:
Dmitri Bogomolov 2021-08-18 19:55:40 +03:00 committed by Lee Miller
parent 7f376b0203
commit 305d5d716c
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 19 additions and 1 deletions

View File

@ -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'

View File

@ -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:])