From 73ba419d640920a1427c357e487625ba70ae87b4 Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 18 Jun 2019 02:04:10 +0200 Subject: [PATCH] check virtual lengths, fix imports --- test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 7662971c4..efcb8f207 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -268,7 +268,7 @@ class Elements(ParamsBase, metaclass=ElementsType): @classmethod def value_check(cls, value): - return all(isinstance(v, cls.elem_type) for v in value) + return all(isinstance(v, cls.elem_type) for v in value) and len(value) <= cls.length @classmethod def extract_args(cls, *args): @@ -316,6 +316,7 @@ class Vector(Elements): @classmethod def value_check(cls, value): + # check length limit strictly return len(value) == cls.length and super().value_check(value) @classmethod @@ -350,7 +351,8 @@ class BytesLike(Elements, metaclass=BytesType): @classmethod def value_check(cls, value): - return isinstance(value, bytes) + # check type and virtual length limit + return isinstance(value, bytes) and len(value) <= cls.length def __str__(self): cls = self.__class__ @@ -376,6 +378,7 @@ class BytesN(BytesLike): @classmethod def value_check(cls, value): + # check length limit strictly return len(value) == cls.length and super().value_check(value) @classmethod