From 3a5243cc898c42c777060aeab724f1bc09bec230 Mon Sep 17 00:00:00 2001 From: protolambda Date: Fri, 19 Apr 2019 12:09:30 +1000 Subject: [PATCH] apply PR suggestions from djrtwo --- test_libs/pyspec/eth2spec/debug/random_value.py | 6 +++--- test_libs/pyspec/eth2spec/utils/minimal_ssz.py | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test_libs/pyspec/eth2spec/debug/random_value.py b/test_libs/pyspec/eth2spec/debug/random_value.py index 59ed5b54b..a853d2328 100644 --- a/test_libs/pyspec/eth2spec/debug/random_value.py +++ b/test_libs/pyspec/eth2spec/debug/random_value.py @@ -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 diff --git a/test_libs/pyspec/eth2spec/utils/minimal_ssz.py b/test_libs/pyspec/eth2spec/utils/minimal_ssz.py index ff7ab6027..dbe9d1359 100644 --- a/test_libs/pyspec/eth2spec/utils/minimal_ssz.py +++ b/test_libs/pyspec/eth2spec/utils/minimal_ssz.py @@ -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)