Skip to content

Commit

Permalink
Fix Bitvector
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Jul 4, 2019
1 parent 03896e4 commit 9c72b93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ssz/sedes/bitvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, size: int) -> None:
is_fixed_sized = True

def get_fixed_size(self):
return self.size
return (self.size + 7) // 8

#
# Serialization
Expand All @@ -50,7 +50,7 @@ def serialize(self, value: BytesOrByteArray) -> bytes:
# Deserialization
#
def deserialize(self, data: bytes) -> bytes:
if len(data) >= self.size:
if len(data) > self.size:
raise DeserializationError(
f"Cannot deserialize length {len(data)} data as bytes{self.size}"
)
Expand Down
6 changes: 3 additions & 3 deletions tests/sedes/test_bitvector_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(16, (0b1,) * 16, b'\xff\xff'),
),
)
def test_bytes_serialize_values(size, value, expected):
def test_bitvector_serialize_values(size, value, expected):
Foo = Bitvector(size)
assert encode(value, Foo) == expected
assert Foo.serialize(bytearray(value)) == expected
Expand All @@ -33,7 +33,7 @@ def test_bytes_serialize_values(size, value, expected):
(16, b'\xff\xff', (0b1,) * 16),
),
)
def test_bytes_deserialize_values(size, value, expected):
def test_bitvector_deserialize_values(size, value, expected):
Foo = Bitvector(size)
assert Foo.deserialize(value) == expected

Expand All @@ -44,6 +44,6 @@ def test_bytes_deserialize_values(size, value, expected):
(16, (0b1,) + (0b0,) * 15),
),
)
def test_bytes_round_trip_no_sedes(size, value):
def test_bitvector_round_trip_no_sedes(size, value):
Foo = Bitvector(size)
assert decode(encode(value, Foo), Foo) == value

0 comments on commit 9c72b93

Please sign in to comment.