@@ -159,7 +159,7 @@ pub struct Updater<O = OperationsContractClient, F = fetch::Client, T = StdTimeP
159
159
const CLIENT_ID : & str = "parity" ;
160
160
161
161
lazy_static ! {
162
- static ref CLIENT_ID_HASH : H256 = H256 :: from_slice ( CLIENT_ID . as_bytes ( ) ) ;
162
+ static ref CLIENT_ID_HASH : H256 = h256_from_str_resizing ( CLIENT_ID ) ;
163
163
}
164
164
165
165
lazy_static ! {
@@ -177,7 +177,16 @@ lazy_static! {
177
177
}
178
178
179
179
lazy_static ! {
180
- static ref PLATFORM_ID_HASH : H256 = H256 :: from_slice( PLATFORM . as_bytes( ) ) ;
180
+ static ref PLATFORM_ID_HASH : H256 = h256_from_str_resizing( & PLATFORM ) ;
181
+ }
182
+
183
+
184
+ // Pads the bytes with zeros or truncates the last bytes to H256::len_bytes()
185
+ // before the conversion to match the previous behavior.
186
+ fn h256_from_str_resizing ( s : & str ) -> H256 {
187
+ let mut bytes = s. as_bytes ( ) . to_vec ( ) ;
188
+ bytes. resize ( H256 :: len_bytes ( ) , 0 ) ;
189
+ H256 :: from_slice ( & bytes)
181
190
}
182
191
183
192
/// Client trait for getting latest release information from operations contract.
@@ -1253,4 +1262,11 @@ pub mod tests {
1253
1262
// and since our update policy requires consensus, the client should be disabled
1254
1263
assert ! ( client. is_disabled( ) ) ;
1255
1264
}
1265
+
1266
+ #[ test]
1267
+ fn static_hashes_do_not_panic ( ) {
1268
+ let client_id_hash: H256 = * CLIENT_ID_HASH ;
1269
+ assert_eq ! ( & format!( "{:x}" , client_id_hash) , "7061726974790000000000000000000000000000000000000000000000000000" ) ;
1270
+ let _: H256 = * PLATFORM_ID_HASH ;
1271
+ }
1256
1272
}
0 commit comments