Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show First 20 Lines • Show All 2,112 Lines • ▼ Show 20 Lines | class msg_getavaaddr: | ||||
def serialize(self): | def serialize(self): | ||||
return b"" | return b"" | ||||
def __repr__(self): | def __repr__(self): | ||||
return "msg_getavaaddr()" | return "msg_getavaaddr()" | ||||
class msg_getavaproofs: | |||||
__slots__ = () | |||||
msgtype = b"getavaproofs" | |||||
def __init__(self): | |||||
pass | |||||
def deserialize(self, f): | |||||
pass | |||||
def serialize(self): | |||||
return b"" | |||||
def __repr__(self): | |||||
return "msg_getavaproofs()" | |||||
class msg_avaproofs: | |||||
__slots__ = ("key0", "key1", "shortids") | |||||
msgtype = b"avaproofs" | |||||
def __init__(self): | |||||
self.key0 = 0 | |||||
self.key1 = 0 | |||||
self.shortids = [] | |||||
def deserialize(self, f): | |||||
self.key0 = struct.unpack("<Q", f.read(8))[0] | |||||
self.key1 = struct.unpack("<Q", f.read(8))[0] | |||||
shortids_length = deser_compact_size(f) | |||||
for _ in range(shortids_length): | |||||
# shortids are defined to be 6 bytes in the spec, so append | |||||
# two zero bytes and read it in as an 8-byte number | |||||
self.shortids.append( | |||||
struct.unpack("<Q", f.read(6) + b'\x00\x00')[0]) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += struct.pack("<Q", self.key0) | |||||
r += struct.pack("<Q", self.key1) | |||||
r += ser_compact_size(len(self.shortids)) | |||||
for shortid in self.shortids: | |||||
# We only want the first 6 bytes | |||||
r += struct.pack("<Q", shortid)[0:6] | |||||
return r | |||||
def __repr__(self): | |||||
return "msg_avaproofs(key0={}, key1={}, len(shortids)={}, shortids={})".format( | |||||
self.key0, self.key1, len(self.shortids), self.shortids) | |||||
class TestFrameworkMessages(unittest.TestCase): | class TestFrameworkMessages(unittest.TestCase): | ||||
def test_legacy_avalanche_proof_serialization_round_trip(self): | def test_legacy_avalanche_proof_serialization_round_trip(self): | ||||
"""Verify that a LegacyAvalancheProof object is unchanged after a | """Verify that a LegacyAvalancheProof object is unchanged after a | ||||
round-trip of deserialization-serialization. | round-trip of deserialization-serialization. | ||||
""" | """ | ||||
proof_hex = ( | proof_hex = ( | ||||
"2a00000000000000fff053650000000021030b4c866585dd868a9d62348a9cd00" | "2a00000000000000fff053650000000021030b4c866585dd868a9d62348a9cd00" | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |