@@ -189,6 +189,7 @@ class AcceptsHexStrEncoder(encoding.BaseEncoder):
189
189
is_strict : bool = None
190
190
is_big_endian : bool = False
191
191
data_byte_size : int = None
192
+ value_bit_size : int = None
192
193
193
194
def __init__ (
194
195
self ,
@@ -280,11 +281,22 @@ class ExactLengthBytesEncoder(BytesEncoder):
280
281
281
282
def validate (self ) -> None :
282
283
super ().validate ()
284
+ if self .value_bit_size is None :
285
+ raise ValueError ("`value_bit_size` may not be none" )
283
286
if self .data_byte_size is None :
284
287
raise ValueError ("`data_byte_size` may not be none" )
285
288
if self .is_big_endian is None :
286
289
raise ValueError ("`is_big_endian` may not be none" )
287
290
291
+ if self .value_bit_size % 8 != 0 :
292
+ raise ValueError (
293
+ f"Invalid value bit size: { self .value_bit_size } . "
294
+ "Must be a multiple of 8"
295
+ )
296
+
297
+ if self .value_bit_size > self .data_byte_size * 8 :
298
+ raise ValueError ("Value byte size exceeds data size" )
299
+
288
300
@parse_type_str ("bytes" )
289
301
def from_type_str (cls , abi_type : BasicType , registry : ABIRegistry ) -> bytes :
290
302
subencoder_cls = cls .get_subencoder_class ()
@@ -298,6 +310,7 @@ def from_type_str(cls, abi_type: BasicType, registry: ABIRegistry) -> bytes:
298
310
# Unexpected keyword argument "value_bit_size" for "__call__" of "BaseEncoder"
299
311
return cls ( # type: ignore
300
312
subencoder ,
313
+ value_bit_size = abi_type .sub * 8 ,
301
314
data_byte_size = abi_type .sub ,
302
315
)
303
316
0 commit comments