File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -343,7 +343,18 @@ def to_primitive(self) -> bytes:
343
343
return bytes (self )
344
344
345
345
@classmethod
346
- def from_primitive (cls : Type [Address ], value : Union [bytes , str ]) -> Address :
346
+ def from_primitive (cls : Type [Address ], value : Primitive ) -> Address :
347
+ if not isinstance (
348
+ value ,
349
+ (
350
+ bytes ,
351
+ str ,
352
+ ),
353
+ ):
354
+ raise DeserializeException (
355
+ f"A bytes or a string value is required for deserialization: { value } "
356
+ )
357
+
347
358
if isinstance (value , str ):
348
359
value = bytes (decode (value ))
349
360
header = value [0 ]
Original file line number Diff line number Diff line change @@ -24,3 +24,21 @@ class PointerAddressTest(TestCase):
24
24
def test_from_primitive_invalid_value (self ):
25
25
with self .assertRaises (DeserializeException ):
26
26
PointerAddress .from_primitive (1 )
27
+
28
+ with self .assertRaises (DeserializeException ):
29
+ PointerAddress .from_primitive ([])
30
+
31
+ with self .assertRaises (DeserializeException ):
32
+ PointerAddress .from_primitive ({})
33
+
34
+
35
+ class AddressTest (TestCase ):
36
+ def test_from_primitive_invalid_value (self ):
37
+ with self .assertRaises (DeserializeException ):
38
+ Address .from_primitive (1 )
39
+
40
+ with self .assertRaises (DeserializeException ):
41
+ Address .from_primitive ([])
42
+
43
+ with self .assertRaises (DeserializeException ):
44
+ Address .from_primitive ({})
You can’t perform that action at this time.
0 commit comments