@@ -16,24 +16,35 @@ async def run_test():
16
16
self .assertIn ('masterKey' , result )
17
17
self .assertIn ('keyShards' , result )
18
18
19
- # Check master key format (hex string with 0x prefix)
20
19
self .assertIsInstance (result ['masterKey' ], str )
21
20
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' ]} " )
23
28
24
- # Check key shards
25
29
self .assertEqual (len (result ['keyShards' ]), 3 )
26
30
for shard in result ['keyShards' ]:
27
31
self .assertIn ('key' , shard )
28
32
self .assertIn ('index' , shard )
29
33
30
- # Check key format (hex string with 0x prefix)
31
34
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' ]} " )
33
42
34
- # Check index format (hex string with 0x prefix)
35
43
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' ]} " )
37
48
38
49
return result
39
50
@@ -49,14 +60,26 @@ async def run_test():
49
60
50
61
self .assertEqual (len (result ['keyShards' ]), key_count )
51
62
52
- # Check all indices are present and unique
53
63
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 )
55
65
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' ]
58
78
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 } " )
60
83
61
84
return result
62
85
0 commit comments