@@ -16,24 +16,35 @@ async def run_test():
1616 self .assertIn ('masterKey' , result )
1717 self .assertIn ('keyShards' , result )
1818
19- # Check master key format (hex string with 0x prefix)
2019 self .assertIsInstance (result ['masterKey' ], str )
2120 self .assertTrue (result ['masterKey' ].startswith ('0x' ))
22- self .assertTrue (all (c in '0123456789abcdef' for c in result ['masterKey' ][2 :]))
21+ hex_str = result ['masterKey' ][2 :]
22+ if len (hex_str ) % 2 != 0 :
23+ hex_str = '0' + hex_str
24+ try :
25+ bytes .fromhex (hex_str )
26+ except ValueError :
27+ self .fail (f"Invalid hex string: { result ['masterKey' ]} " )
2328
24- # Check key shards
2529 self .assertEqual (len (result ['keyShards' ]), 3 )
2630 for shard in result ['keyShards' ]:
2731 self .assertIn ('key' , shard )
2832 self .assertIn ('index' , shard )
2933
30- # Check key format (hex string with 0x prefix)
3134 self .assertTrue (shard ['key' ].startswith ('0x' ))
32- self .assertTrue (all (c in '0123456789abcdef' for c in shard ['key' ][2 :]))
35+ hex_str = shard ['key' ][2 :]
36+ if len (hex_str ) % 2 != 0 :
37+ hex_str = '0' + hex_str
38+ try :
39+ bytes .fromhex (hex_str )
40+ except ValueError :
41+ self .fail (f"Invalid hex string in key: { shard ['key' ]} " )
3342
34- # Check index format (hex string with 0x prefix)
3543 self .assertTrue (shard ['index' ].startswith ('0x' ))
36- self .assertTrue (all (c in '0123456789abcdef' for c in shard ['index' ][2 :]))
44+ try :
45+ int (shard ['index' ], 16 )
46+ except ValueError :
47+ self .fail (f"Invalid index format (not a valid hex number): { shard ['index' ]} " )
3748
3849 return result
3950
@@ -49,14 +60,26 @@ async def run_test():
4960
5061 self .assertEqual (len (result ['keyShards' ]), key_count )
5162
52- # Check all indices are present and unique
5363 indices = [shard ['index' ] for shard in result ['keyShards' ]]
54- self .assertEqual (len (set (indices )), key_count ) # All unique
64+ self .assertEqual (len (set (indices )), key_count )
5565
56- # Verify all indices are valid hex strings with 0x prefix
57- for index in indices :
66+ for shard in result ['keyShards' ]:
67+ self .assertTrue (shard ['key' ].startswith ('0x' ))
68+ key_hex = shard ['key' ][2 :]
69+ if len (key_hex ) % 2 != 0 :
70+ key_hex = '0' + key_hex
71+ try :
72+ bytes .fromhex (key_hex )
73+ except ValueError :
74+ self .fail (f"Invalid hex string in key: { shard ['key' ]} " )
75+
76+
77+ index = shard ['index' ]
5878 self .assertTrue (index .startswith ('0x' ))
59- self .assertTrue (all (c in '0123456789abcdef' for c in index [2 :]))
79+ try :
80+ int (index , 16 )
81+ except ValueError :
82+ self .fail (f"Invalid index format (not a valid hex number): { index } " )
6083
6184 return result
6285
0 commit comments