11"""Unit tests for crypto_utils module."""
2+
23from cryptography .hazmat .primitives .asymmetric import ec
34import pytest
45
1516def test_keccak256 ():
1617 """Test keccak256 hashing."""
1718 # Known vector: empty string -> c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
18- assert keccak256 (b"" ).hex () == "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
19+ assert (
20+ keccak256 (b"" ).hex ()
21+ == "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
22+ )
1923
2024 # "hello" -> 1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8
21- assert keccak256 (b"hello" ).hex () == "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
25+ assert (
26+ keccak256 (b"hello" ).hex ()
27+ == "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
28+ )
2229
2330 # "Transfer" -> 461a29a8a7db848c0827103038dd4776114eb182e0717208d0a793574936353d
24- assert keccak256 (b"Transfer" ).hex () == "f099cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
31+ assert (
32+ keccak256 (b"Transfer" ).hex ()
33+ == "f099cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"
34+ )
2535
2636
2737def test_compress_point_unchecked ():
@@ -57,19 +67,19 @@ def test_decompress_point():
5767 assert y == nums .y
5868
5969 # Test uncompressed 65-byte format (0x04 + x + y)
60- uncompressed = b' \x04 ' + nums .x .to_bytes (32 , ' big' ) + nums .y .to_bytes (32 , ' big' )
70+ uncompressed = b" \x04 " + nums .x .to_bytes (32 , " big" ) + nums .y .to_bytes (32 , " big" )
6171 x2 , y2 = decompress_point (uncompressed )
6272 assert x2 == nums .x
6373 assert y2 == nums .y
6474
6575 # Test invalid length
6676 with pytest .raises (ValueError , match = "Not recognized" ):
67- decompress_point (b' \x04 ' * 10 )
77+ decompress_point (b" \x04 " * 10 )
6878
6979 # Test invalid prefix
7080 with pytest .raises (ValueError , match = "Not recognized" ):
7181 # 0x05 is invalid prefix for 33-byte point
72- invalid_point = b' \x05 ' + nums .x .to_bytes (32 , ' big' )
82+ invalid_point = b" \x05 " + nums .x .to_bytes (32 , " big" )
7383 decompress_point (invalid_point )
7484
7585
@@ -80,7 +90,7 @@ def test_compress_with_cryptography():
8090 nums = pub .public_numbers ()
8191
8292 # Create uncompressed
83- uncompressed = b' \x04 ' + nums .x .to_bytes (32 , ' big' ) + nums .y .to_bytes (32 , ' big' )
93+ uncompressed = b" \x04 " + nums .x .to_bytes (32 , " big" ) + nums .y .to_bytes (32 , " big" )
8494
8595 compressed_via_lib = compress_with_cryptography (uncompressed )
8696 compressed_manual = compress_point_unchecked (nums .x , nums .y )
0 commit comments