apply PR suggestions from djrtwo
This commit is contained in:
parent
bc685133ec
commit
3a5243cc89
|
@ -103,7 +103,7 @@ def get_random_basic_value(rng: Random, typ: str) -> Any:
|
|||
return rng.choice((True, False))
|
||||
if typ[:4] == 'uint':
|
||||
size = int(typ[4:])
|
||||
assert size in (8, 16, 32, 64, 128, 256)
|
||||
assert size in UINT_SIZES
|
||||
return rng.randint(0, 2**size - 1)
|
||||
if typ == 'byte':
|
||||
return rng.randint(0, 8)
|
||||
|
@ -116,7 +116,7 @@ def get_min_basic_value(typ: str) -> Any:
|
|||
return False
|
||||
if typ[:4] == 'uint':
|
||||
size = int(typ[4:])
|
||||
assert size in (8, 16, 32, 64, 128, 256)
|
||||
assert size in UINT_SIZES
|
||||
return 0
|
||||
if typ == 'byte':
|
||||
return 0x00
|
||||
|
@ -129,7 +129,7 @@ def get_max_basic_value(typ: str) -> Any:
|
|||
return True
|
||||
if typ[:4] == 'uint':
|
||||
size = int(typ[4:])
|
||||
assert size in (8, 16, 32, 64, 128, 256)
|
||||
assert size in UINT_SIZES
|
||||
return 2**size - 1
|
||||
if typ == 'byte':
|
||||
return 0xff
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from .hash_function import hash
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .hash_function import hash
|
||||
|
||||
BYTES_PER_CHUNK = 32
|
||||
BYTES_PER_LENGTH_PREFIX = 4
|
||||
ZERO_CHUNK = b'\x00' * BYTES_PER_CHUNK
|
||||
|
@ -17,10 +17,7 @@ def SSZType(fields):
|
|||
setattr(self, f, kwargs[f])
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
self.fields == other.fields and
|
||||
self.serialize() == other.serialize()
|
||||
)
|
||||
return self.fields == other.fields and self.serialize() == other.serialize()
|
||||
|
||||
def __hash__(self):
|
||||
return int.from_bytes(self.hash_tree_root(), byteorder="little")
|
||||
|
@ -262,6 +259,7 @@ def infer_type(value):
|
|||
else:
|
||||
raise Exception("Failed to infer type")
|
||||
|
||||
|
||||
def hash_tree_root(value, typ=None):
|
||||
if typ is None:
|
||||
typ = infer_type(value)
|
||||
|
|
Loading…
Reference in New Issue