Skip to content

Commit 5e4898d

Browse files
committed
Add smoke tests for deprecated sha3 function
1 parent cba7eec commit 5e4898d

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

tests/core/web3-module/test_sha3.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ def test_keccak_text(message, digest):
2020
assert Web3.keccak(text=message) == digest
2121

2222

23+
@pytest.mark.parametrize(
24+
'message, digest',
25+
[
26+
('cowmö', HexBytes('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8')),
27+
('', HexBytes('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')),
28+
],
29+
)
30+
def test_sha3_text(message, digest):
31+
with pytest.deprecated_call():
32+
assert Web3.sha3(text=message) == digest
33+
34+
2335
@pytest.mark.parametrize(
2436
'hexstr, digest',
2537
[
@@ -45,6 +57,32 @@ def test_keccak_hexstr(hexstr, digest):
4557
assert Web3.keccak(hexstr=hexstr) == digest
4658

4759

60+
@pytest.mark.parametrize(
61+
'hexstr, digest',
62+
[
63+
(
64+
'0x636f776dc3b6',
65+
HexBytes('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8')
66+
),
67+
(
68+
'636f776dc3b6',
69+
HexBytes('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8')
70+
),
71+
(
72+
'0x',
73+
HexBytes('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
74+
),
75+
(
76+
'',
77+
HexBytes('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')
78+
),
79+
],
80+
)
81+
def test_sha3_hexstr(hexstr, digest):
82+
with pytest.deprecated_call():
83+
assert Web3.sha3(hexstr=hexstr) == digest
84+
85+
4886
@pytest.mark.parametrize(
4987
'primitive, exception',
5088
[

web3/main.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,10 @@ def providers(self, providers):
133133
self.manager.providers = providers
134134

135135
@staticmethod
136-
@deprecated_for("This method has been renamed to web3.keccak")
136+
@deprecated_for("This method has been renamed to keccak")
137137
@apply_to_return_value(HexBytes)
138138
def sha3(primitive=None, text=None, hexstr=None):
139-
if isinstance(primitive, (bytes, int, type(None))):
140-
input_bytes = to_bytes(primitive, hexstr=hexstr, text=text)
141-
return eth_utils_keccak(input_bytes)
142-
143-
raise TypeError(
144-
"You called sha3 with first arg %r and keywords %r. You must call it with one of "
145-
"these approaches: sha3(text='txt'), sha3(hexstr='0x747874'), "
146-
"sha3(b'\\x74\\x78\\x74'), or sha3(0x747874)." % (
147-
primitive,
148-
{'text': text, 'hexstr': hexstr}
149-
)
150-
)
139+
return Web3.keccak(primitive, text, hexstr)
151140

152141
@staticmethod
153142
@apply_to_return_value(HexBytes)

0 commit comments

Comments
 (0)