@@ -289,3 +289,51 @@ def test_known_hex_checksum_matches(self):
289289 rarity = 5 ,
290290 )
291291 assert serialize (data ) == TOOL_HEX
292+
293+
294+ # ---------------------------------------------------------------------------
295+ # Defensive validation tests
296+ # ---------------------------------------------------------------------------
297+
298+ class TestDefensiveChecks :
299+ def test_deserialize_payload_too_long_raises (self ):
300+ """Payloads longer than 4096 hex chars must raise ValueError."""
301+ long_hex = "00" * 2049 # 4098 hex chars > 4096 limit
302+ with pytest .raises (ValueError , match = "Payload too long" ):
303+ deserialize (long_hex )
304+
305+ def test_serialize_paintwear_above_one_raises (self ):
306+ """paintwear > 1.0 must raise ValueError."""
307+ data = ItemPreviewData (defindex = 7 , paintwear = 1.1 )
308+ with pytest .raises (ValueError , match = "paintwear" ):
309+ serialize (data )
310+
311+ def test_serialize_paintwear_below_zero_raises (self ):
312+ """paintwear < 0.0 must raise ValueError."""
313+ data = ItemPreviewData (defindex = 7 , paintwear = - 0.1 )
314+ with pytest .raises (ValueError , match = "paintwear" ):
315+ serialize (data )
316+
317+ def test_serialize_paintwear_zero_is_valid (self ):
318+ """paintwear == 0.0 is a valid boundary value."""
319+ data = ItemPreviewData (defindex = 7 , paintwear = 0.0 )
320+ result = serialize (data )
321+ assert result .startswith ("00" )
322+
323+ def test_serialize_paintwear_one_is_valid (self ):
324+ """paintwear == 1.0 is a valid boundary value."""
325+ data = ItemPreviewData (defindex = 7 , paintwear = 1.0 )
326+ result = serialize (data )
327+ assert result .startswith ("00" )
328+
329+ def test_serialize_customname_101_chars_raises (self ):
330+ """customname exceeding 100 characters must raise ValueError."""
331+ data = ItemPreviewData (defindex = 7 , customname = "x" * 101 )
332+ with pytest .raises (ValueError , match = "customname" ):
333+ serialize (data )
334+
335+ def test_serialize_customname_100_chars_is_valid (self ):
336+ """customname of exactly 100 characters must be accepted."""
337+ data = ItemPreviewData (defindex = 7 , customname = "x" * 100 )
338+ result = serialize (data )
339+ assert result .startswith ("00" )
0 commit comments