Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show First 20 Lines • Show All 908 Lines • ▼ Show 20 Lines | def __init__(self, sequence=0, expiration=0, | ||||
self.proofid: int = self.compute_proof_id() | self.proofid: int = self.compute_proof_id() | ||||
def compute_proof_id(self) -> int: | def compute_proof_id(self) -> int: | ||||
"""Return Bitcoin's 256-bit hash (double SHA-256) of the | """Return Bitcoin's 256-bit hash (double SHA-256) of the | ||||
serialized proof data. | serialized proof data. | ||||
:return: bytes of length 32 | :return: bytes of length 32 | ||||
""" | """ | ||||
ss = struct.pack("<Qq", self.sequence, self.expiration) | ss = struct.pack("<Qq", self.sequence, self.expiration) | ||||
ss += ser_string(self.master) | |||||
ss += ser_compact_size(len(self.stakes)) | ss += ser_compact_size(len(self.stakes)) | ||||
# Use unsigned stakes | # Use unsigned stakes | ||||
for s in self.stakes: | for s in self.stakes: | ||||
ss += s.stake.serialize() | ss += s.stake.serialize() | ||||
h = hash256(ss) | h = hash256(ss) | ||||
h += ser_string(self.master) | |||||
h = hash256(h) | |||||
# make it an int, for comparing with Delegation.proofid | # make it an int, for comparing with Delegation.proofid | ||||
return uint256_from_str(h) | return uint256_from_str(h) | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
self.sequence = struct.unpack("<Q", f.read(8))[0] | self.sequence = struct.unpack("<Q", f.read(8))[0] | ||||
self.expiration = struct.unpack("<q", f.read(8))[0] | self.expiration = struct.unpack("<q", f.read(8))[0] | ||||
self.master = deser_string(f) | self.master = deser_string(f) | ||||
self.stakes = deser_vector(f, AvalancheSignedStake) | self.stakes = deser_vector(f, AvalancheSignedStake) | ||||
▲ Show 20 Lines • Show All 1,094 Lines • ▼ Show 20 Lines | def test_serialization_round_trip(self): | ||||
"8cb0ac3052d58da74de7404e84ebe2940ed2b0fe85578d8230788d8387aeaa618" | "8cb0ac3052d58da74de7404e84ebe2940ed2b0fe85578d8230788d8387aeaa618" | ||||
"274b0f2edc73679fd398f60e6315258c9ec348df7fcc09340ae1af37d009719b0" | "274b0f2edc73679fd398f60e6315258c9ec348df7fcc09340ae1af37d009719b0" | ||||
"665" | "665" | ||||
) | ) | ||||
avaproof = FromHex(AvalancheProof(), proof_hex) | avaproof = FromHex(AvalancheProof(), proof_hex) | ||||
self.assertEqual(ToHex(avaproof), proof_hex) | self.assertEqual(ToHex(avaproof), proof_hex) | ||||
self.assertEqual(f"{avaproof.proofid:x}", | self.assertEqual( | ||||
"8ab9e9db85055cea7f541d464a84bd4fabaf284cc2815394868741bbe09b4735" | f"{avaproof.proofid:0{64}x}", | ||||
"cb33d7fac9092089f0d473c13befa012e6ee4d19abf9a42248f731d5e59e74a2" | |||||
) | ) | ||||
self.assertEqual(avaproof.sequence, 42) | self.assertEqual(avaproof.sequence, 42) | ||||
self.assertEqual(avaproof.expiration, 1699999999) | self.assertEqual(avaproof.expiration, 1699999999) | ||||
# The master key is extracted from the key_tests.cpp. | # The master key is extracted from the key_tests.cpp. | ||||
# Associated privkey: | # Associated privkey: | ||||
# hex: 12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747 | # hex: 12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747 | ||||
# WIF: cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN | # WIF: cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN | ||||
self.assertEqual(avaproof.master, bytes.fromhex( | self.assertEqual(avaproof.master, bytes.fromhex( | ||||
"030b4c866585dd868a9d62348a9cd008d6a312937048fff31670e7e920cfc7a744" | "030b4c866585dd868a9d62348a9cd008d6a312937048fff31670e7e920cfc7a744" | ||||
Show All 21 Lines |