99from web3 import Web3
1010
1111
12+ @pytest .mark .parametrize (
13+ 'message, digest' ,
14+ [
15+ ('cowmö' , HexBytes ('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8' )),
16+ ('' , HexBytes ('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' )),
17+ ],
18+ )
19+ def test_keccak_text (message , digest ):
20+ assert Web3 .keccak (text = message ) == digest
21+
22+
1223@pytest .mark .parametrize (
1324 'message, digest' ,
1425 [
1728 ],
1829)
1930def test_sha3_text (message , digest ):
20- assert Web3 .sha3 (text = message ) == digest
31+ with pytest .deprecated_call ():
32+ assert Web3 .sha3 (text = message ) == digest
33+
34+
35+ @pytest .mark .parametrize (
36+ 'hexstr, digest' ,
37+ [
38+ (
39+ '0x636f776dc3b6' ,
40+ HexBytes ('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8' )
41+ ),
42+ (
43+ '636f776dc3b6' ,
44+ HexBytes ('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8' )
45+ ),
46+ (
47+ '0x' ,
48+ HexBytes ('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' )
49+ ),
50+ (
51+ '' ,
52+ HexBytes ('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' )
53+ ),
54+ ],
55+ )
56+ def test_keccak_hexstr (hexstr , digest ):
57+ assert Web3 .keccak (hexstr = hexstr ) == digest
2158
2259
2360@pytest .mark .parametrize (
@@ -42,7 +79,8 @@ def test_sha3_text(message, digest):
4279 ],
4380)
4481def test_sha3_hexstr (hexstr , digest ):
45- assert Web3 .sha3 (hexstr = hexstr ) == digest
82+ with pytest .deprecated_call ():
83+ assert Web3 .sha3 (hexstr = hexstr ) == digest
4684
4785
4886@pytest .mark .parametrize (
@@ -53,9 +91,9 @@ def test_sha3_hexstr(hexstr, digest):
5391 (- 1 , ValueError ),
5492 ],
5593)
56- def test_sha3_primitive_invalid (primitive , exception ):
94+ def test_keccak_primitive_invalid (primitive , exception ):
5795 with pytest .raises (exception ):
58- Web3 .sha3 (primitive )
96+ Web3 .keccak (primitive )
5997
6098
6199@pytest .mark .parametrize (
@@ -71,8 +109,8 @@ def test_sha3_primitive_invalid(primitive, exception):
71109 ),
72110 ],
73111)
74- def test_sha3_primitive (primitive , digest ):
75- assert Web3 .sha3 (primitive ) == digest
112+ def test_keccak_primitive (primitive , digest ):
113+ assert Web3 .keccak (primitive ) == digest
76114
77115
78116@pytest .mark .parametrize (
@@ -83,17 +121,17 @@ def test_sha3_primitive(primitive, digest):
83121 {'text' : '' , 'hexstr' : '0x' },
84122 ],
85123)
86- def test_sha3_raise_if_primitive_and (kwargs ):
124+ def test_keccak_raise_if_primitive_and (kwargs ):
87125 # must not set more than one input
88126 with pytest .raises (TypeError ):
89- Web3 .sha3 ('' , ** kwargs )
127+ Web3 .keccak ('' , ** kwargs )
90128
91129
92- def test_sha3_raise_if_hexstr_and_text ():
130+ def test_keccak_raise_if_hexstr_and_text ():
93131 with pytest .raises (TypeError ):
94- Web3 .sha3 (hexstr = '0x' , text = '' )
132+ Web3 .keccak (hexstr = '0x' , text = '' )
95133
96134
97- def test_sha3_raise_if_no_args ():
135+ def test_keccak_raise_if_no_args ():
98136 with pytest .raises (TypeError ):
99- Web3 .sha3 ()
137+ Web3 .keccak ()
0 commit comments