-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathtest_deserialize_network_address.py
71 lines (65 loc) · 2.1 KB
/
test_deserialize_network_address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from io import BytesIO
from protocol import NETWORK_I2P, NETWORK_IPV4, NETWORK_IPV6, NETWORK_TORV3, Serializer
def test_deserialize_network_address():
hex_str = "00f15365fd090c010400000000208d"
data = BytesIO(bytes.fromhex(hex_str))
assert Serializer().deserialize_network_address(
data, has_timestamp=True, version=2
) == {
"network_id": NETWORK_IPV4,
"timestamp": 1700000000,
"services": 3081,
"ipv4": "0.0.0.0",
"ipv6": "",
"onion": "",
"i2p": "",
"cjdns": "",
"port": 8333,
}
hex_str = "00f15365fd090c021000000000000000000000000000000000208d"
data = BytesIO(bytes.fromhex(hex_str))
assert Serializer().deserialize_network_address(
data, has_timestamp=True, version=2
) == {
"network_id": NETWORK_IPV6,
"timestamp": 1700000000,
"services": 3081,
"ipv4": "",
"ipv6": "::",
"onion": "",
"i2p": "",
"cjdns": "",
"port": 8333,
}
hex_str = "00f15365fd090c04200000000000000000000000000000000000000000000000000000000000000000208d"
data = BytesIO(bytes.fromhex(hex_str))
assert Serializer().deserialize_network_address(
data, has_timestamp=True, version=2
) == {
"network_id": NETWORK_TORV3,
"timestamp": 1700000000,
"services": 3081,
"ipv4": "",
"ipv6": "",
"onion": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaam2dqd.onion",
"i2p": "",
"cjdns": "",
"port": 8333,
}
hex_str = "00f15365fd090c0520e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000"
data = BytesIO(bytes.fromhex(hex_str))
assert Serializer().deserialize_network_address(
data, has_timestamp=True, version=2
) == {
"network_id": NETWORK_I2P,
"timestamp": 1700000000,
"services": 3081,
"ipv4": "",
"ipv6": "",
"onion": "",
"i2p": "4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq.b32.i2p",
"cjdns": "",
"port": 0,
}