Skip to content

Commit efe41ef

Browse files
committed
Deprecate geth.personal namespace methods
1 parent af0448a commit efe41ef

File tree

8 files changed

+163
-78
lines changed

8 files changed

+163
-78
lines changed

docs/web3.geth.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ GethPersonal API
173173

174174
The following methods are available on the ``web3.geth.personal`` namespace.
175175

176+
.. warning:: Deprecated: Geth has deprecated the ``personal`` namespace and
177+
has transitioned to using ``clef`` for account management. The ``personal``
178+
namespace will be removed in *web3.py* ``v7``.
179+
176180
.. py:method:: ec_recover(message, signature)
177181
178182
* Delegates to ``personal_ecRecover`` RPC Method

newsfragments/3364.deprecation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate the ``geth.personal`` namespace methods. These will be removed in *web3.py* ``v7``.

web3/_utils/decorators.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,37 @@ def wrapped(*args: Any) -> Any:
3535
return wrapped
3636

3737

38-
def deprecated_for(replace_message: str) -> Callable[..., Any]:
38+
def deprecate_method(
39+
replacement_method: str = None, deprecation_msg: str = None
40+
) -> Callable[..., Any]:
3941
"""
40-
Decorate a deprecated function, with info about what to use instead, like:
42+
Decorate a deprecated function with info on its replacement method OR a clarifying
43+
reason for the deprecation.
4144
42-
@deprecated_for("to_bytes()")
43-
def toAscii(arg):
45+
@deprecate_method("to_bytes()")
46+
def to_ascii(arg):
47+
...
48+
49+
@deprecate_method(deprecation_msg=(
50+
"This method is no longer supported and will be removed in the next release."
51+
))
52+
def some_method(arg):
4453
...
4554
"""
55+
if replacement_method is None and deprecation_msg is None:
56+
raise ValueError(
57+
"Must provide either `replacement_method` or `deprecation_msg`"
58+
)
4659

4760
def decorator(to_wrap: TFunc) -> TFunc:
4861
@functools.wraps(to_wrap)
4962
def wrapper(*args: Any, **kwargs: Any) -> Callable[..., Any]:
50-
warnings.warn(
51-
f"{to_wrap.__name__} is deprecated in favor of {replace_message}",
52-
category=DeprecationWarning,
63+
msg = (
64+
f"{to_wrap.__name__} is deprecated in favor of {replacement_method}"
65+
if replacement_method is not None
66+
else deprecation_msg
5367
)
68+
warnings.warn(msg, category=DeprecationWarning)
5469
return to_wrap(*args, **kwargs)
5570

5671
return cast(TFunc, wrapper)

web3/_utils/miner.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,22 @@
2828
mungers=[default_root_munger],
2929
)
3030

31-
make_dag = DeprecatedMethod(
32-
_make_dag, "make_dag", msg="All mining methods have been deprecated"
33-
)
31+
make_dag = DeprecatedMethod(_make_dag, msg="All mining methods have been deprecated")
3432

3533
_set_extra: Method[Callable[[str], bool]] = Method(
3634
RPC.miner_setExtra,
3735
mungers=[default_root_munger],
3836
)
3937

40-
set_extra = DeprecatedMethod(
41-
_set_extra, "set_extra", msg="All mining methods have been deprecated"
42-
)
38+
set_extra = DeprecatedMethod(_set_extra, msg="All mining methods have been deprecated")
4339

4440
_set_etherbase: Method[Callable[[ChecksumAddress], bool]] = Method(
4541
RPC.miner_setEtherbase,
4642
mungers=[default_root_munger],
4743
)
4844

4945
set_etherbase = DeprecatedMethod(
50-
_set_etherbase, "set_etherbase", msg="All mining methods have been deprecated"
46+
_set_etherbase, msg="All mining methods have been deprecated"
5147
)
5248

5349
_set_gas_price: Method[Callable[[Wei], bool]] = Method(
@@ -56,30 +52,30 @@
5652
)
5753

5854
set_gas_price = DeprecatedMethod(
59-
_set_gas_price, "set_gas_price", msg="All mining methods have been deprecated"
55+
_set_gas_price, msg="All mining methods have been deprecated"
6056
)
6157

6258
_start: Method[Callable[[int], bool]] = Method(
6359
RPC.miner_start,
6460
mungers=[default_root_munger],
6561
)
6662

67-
start = DeprecatedMethod(_start, "start", msg="All mining methods have been deprecated")
63+
start = DeprecatedMethod(_start, msg="All mining methods have been deprecated")
6864

6965
_stop: Method[Callable[[], bool]] = Method(
7066
RPC.miner_stop,
7167
is_property=True,
7268
)
7369

74-
stop = DeprecatedMethod(_stop, "stop", msg="All mining methods have been deprecated")
70+
stop = DeprecatedMethod(_stop, msg="All mining methods have been deprecated")
7571

7672
_start_auto_dag: Method[Callable[[], bool]] = Method(
7773
RPC.miner_startAutoDag,
7874
is_property=True,
7975
)
8076

8177
start_auto_dag = DeprecatedMethod(
82-
_start_auto_dag, "start_auto_dag", msg="All mining methods have been deprecated"
78+
_start_auto_dag, msg="All mining methods have been deprecated"
8379
)
8480

8581
_stop_auto_dag: Method[Callable[[], bool]] = Method(
@@ -88,5 +84,5 @@
8884
)
8985

9086
stop_auto_dag = DeprecatedMethod(
91-
_stop_auto_dag, "stop_auto_dag", msg="All mining methods have been deprecated"
87+
_stop_auto_dag, msg="All mining methods have been deprecated"
9288
)

web3/_utils/module_testing/go_ethereum_personal_module.py

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@
5555

5656
class GoEthereumPersonalModuleTest:
5757
def test_personal_import_raw_key(self, w3: "Web3") -> None:
58-
actual = w3.geth.personal.import_raw_key(PRIVATE_KEY_HEX, PASSWORD)
58+
with pytest.warns(DeprecationWarning):
59+
actual = w3.geth.personal.import_raw_key(PRIVATE_KEY_HEX, PASSWORD)
5960
assert actual == ADDRESS
6061

6162
def test_personal_list_accounts(self, w3: "Web3") -> None:
62-
accounts = w3.geth.personal.list_accounts()
63+
with pytest.warns(DeprecationWarning):
64+
accounts = w3.geth.personal.list_accounts()
6365
assert is_list_like(accounts)
6466
assert len(accounts) > 0
6567
assert all((is_checksum_address(item) for item in accounts))
6668

6769
def test_personal_list_wallets(self, w3: "Web3") -> None:
68-
wallets = w3.geth.personal.list_wallets()
70+
with pytest.warns(DeprecationWarning):
71+
wallets = w3.geth.personal.list_wallets()
6972
assert is_list_like(wallets)
7073
assert len(wallets) > 0
7174
assert is_checksum_address(wallets[0]["accounts"][0]["address"])
@@ -76,18 +79,19 @@ def test_personal_list_wallets(self, w3: "Web3") -> None:
7679
def test_personal_lock_account(
7780
self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress
7881
) -> None:
79-
# TODO: how do we test this better?
80-
w3.geth.personal.lock_account(unlockable_account_dual_type)
82+
with pytest.warns(DeprecationWarning):
83+
w3.geth.personal.lock_account(unlockable_account_dual_type)
8184

8285
def test_personal_unlock_account_success(
8386
self,
8487
w3: "Web3",
8588
unlockable_account_dual_type: ChecksumAddress,
8689
unlockable_account_pw: str,
8790
) -> None:
88-
result = w3.geth.personal.unlock_account(
89-
unlockable_account_dual_type, unlockable_account_pw
90-
)
91+
with pytest.warns(DeprecationWarning):
92+
result = w3.geth.personal.unlock_account(
93+
unlockable_account_dual_type, unlockable_account_pw
94+
)
9195
assert result is True
9296

9397
def test_personal_unlock_account_failure(
@@ -99,7 +103,8 @@ def test_personal_unlock_account_failure(
99103
)
100104

101105
def test_personal_new_account(self, w3: "Web3") -> None:
102-
new_account = w3.geth.personal.new_account(PASSWORD)
106+
with pytest.warns(DeprecationWarning):
107+
new_account = w3.geth.personal.new_account(PASSWORD)
103108
assert is_checksum_address(new_account)
104109

105110
def test_personal_send_transaction(
@@ -118,7 +123,10 @@ def test_personal_send_transaction(
118123
"value": Wei(1),
119124
"gasPrice": w3.to_wei(1, "gwei"),
120125
}
121-
txn_hash = w3.geth.personal.send_transaction(txn_params, unlockable_account_pw)
126+
with pytest.warns(DeprecationWarning):
127+
txn_hash = w3.geth.personal.send_transaction(
128+
txn_params, unlockable_account_pw
129+
)
122130
assert txn_hash
123131
transaction = w3.eth.get_transaction(txn_hash)
124132

@@ -139,10 +147,13 @@ def test_personal_sign_and_ecrecover(
139147
unlockable_account_pw: str,
140148
) -> None:
141149
message = "test-web3-geth-personal-sign"
142-
signature = w3.geth.personal.sign(
143-
message, unlockable_account_dual_type, unlockable_account_pw
144-
)
145-
signer = w3.geth.personal.ec_recover(message, signature)
150+
with pytest.warns(DeprecationWarning):
151+
signature = w3.geth.personal.sign(
152+
message, unlockable_account_dual_type, unlockable_account_pw
153+
)
154+
155+
with pytest.warns(DeprecationWarning):
156+
signer = w3.geth.personal.ec_recover(message, signature)
146157
assert is_same_address(signer, unlockable_account_dual_type)
147158

148159
@pytest.mark.xfail(
@@ -193,13 +204,14 @@ def test_personal_sign_typed_data(
193204
}
194205
}
195206
"""
196-
signature = HexBytes(
197-
w3.geth.personal.sign_typed_data(
198-
json.loads(typed_message),
199-
unlockable_account_dual_type,
200-
unlockable_account_pw,
207+
with pytest.warns(DeprecationWarning):
208+
signature = HexBytes(
209+
w3.geth.personal.sign_typed_data(
210+
json.loads(typed_message),
211+
unlockable_account_dual_type,
212+
unlockable_account_pw,
213+
)
201214
)
202-
)
203215

204216
expected_signature = HexBytes(
205217
"0xc8b56aaeefd10ab4005c2455daf28d9082af661ac347cd"
@@ -219,33 +231,38 @@ async def test_async_sign_and_ec_recover(
219231
unlockable_account_pw: str,
220232
) -> None:
221233
message = "This is a test"
222-
signature = await async_w3.geth.personal.sign(
223-
message, async_unlockable_account_dual_type, unlockable_account_pw
224-
)
234+
with pytest.warns(DeprecationWarning):
235+
signature = await async_w3.geth.personal.sign(
236+
message, async_unlockable_account_dual_type, unlockable_account_pw
237+
)
225238
address = await async_w3.geth.personal.ec_recover(message, signature)
226239
assert is_same_address(async_unlockable_account_dual_type, address)
227240

228241
@pytest.mark.asyncio
229242
async def test_async_import_key(self, async_w3: "AsyncWeb3") -> None:
230-
address = await async_w3.geth.personal.import_raw_key(
231-
THIRD_PRIVATE_KEY_HEX, "Testing"
232-
)
243+
with pytest.warns(DeprecationWarning):
244+
address = await async_w3.geth.personal.import_raw_key(
245+
THIRD_PRIVATE_KEY_HEX, "Testing"
246+
)
233247
assert address is not None
234248

235249
@pytest.mark.asyncio
236250
async def test_async_list_accounts(self, async_w3: "AsyncWeb3") -> None:
237-
accounts = await async_w3.geth.personal.list_accounts()
251+
with pytest.warns(DeprecationWarning):
252+
accounts = await async_w3.geth.personal.list_accounts()
238253
assert len(accounts) > 0
239254

240255
@pytest.mark.asyncio
241256
async def test_async_list_wallets(self, async_w3: "AsyncWeb3") -> None:
242-
wallets = await async_w3.geth.personal.list_wallets()
257+
with pytest.warns(DeprecationWarning):
258+
wallets = await async_w3.geth.personal.list_wallets()
243259
assert isinstance(wallets[0], AttributeDict)
244260

245261
@pytest.mark.asyncio
246262
async def test_async_new_account(self, async_w3: "AsyncWeb3") -> None:
247263
passphrase = "Create New Account"
248-
account = await async_w3.geth.personal.new_account(passphrase)
264+
with pytest.warns(DeprecationWarning):
265+
account = await async_w3.geth.personal.new_account(passphrase)
249266
assert is_checksum_address(account)
250267

251268
@pytest.mark.asyncio
@@ -255,13 +272,16 @@ async def test_async_unlock_lock_account(
255272
async_unlockable_account_dual_type: ChecksumAddress,
256273
unlockable_account_pw: str,
257274
) -> None:
258-
unlocked = await async_w3.geth.personal.unlock_account(
259-
async_unlockable_account_dual_type, unlockable_account_pw
260-
)
275+
with pytest.warns(DeprecationWarning):
276+
unlocked = await async_w3.geth.personal.unlock_account(
277+
async_unlockable_account_dual_type, unlockable_account_pw
278+
)
261279
assert unlocked is True
262-
locked = await async_w3.geth.personal.lock_account(
263-
async_unlockable_account_dual_type
264-
)
280+
281+
with pytest.warns(DeprecationWarning):
282+
locked = await async_w3.geth.personal.lock_account(
283+
async_unlockable_account_dual_type
284+
)
265285
assert locked is True
266286

267287
@pytest.mark.asyncio
@@ -275,9 +295,10 @@ async def test_async_send_transaction(
275295
tx_params["to"] = async_unlockable_account_dual_type
276296
tx_params["from"] = async_unlockable_account_dual_type
277297
tx_params["value"] = Wei(123)
278-
response = await async_w3.geth.personal.send_transaction(
279-
tx_params, unlockable_account_pw
280-
)
298+
with pytest.warns(DeprecationWarning):
299+
response = await async_w3.geth.personal.send_transaction(
300+
tx_params, unlockable_account_pw
301+
)
281302
assert response is not None
282303

283304
@pytest.mark.xfail(
@@ -291,10 +312,12 @@ async def test_async_sign_typed_data(
291312
unlockable_account_pw: str,
292313
) -> None:
293314
message = {"message": "This is a test"}
294-
signature = await async_w3.geth.personal.sign_typed_data(
295-
message, async_unlockable_account_dual_type, unlockable_account_pw
296-
)
297-
address = await async_w3.geth.personal.ec_recover(
298-
json.dumps(message), signature
299-
)
315+
with pytest.warns(DeprecationWarning):
316+
signature = await async_w3.geth.personal.sign_typed_data(
317+
message, async_unlockable_account_dual_type, unlockable_account_pw
318+
)
319+
with pytest.warns(DeprecationWarning):
320+
address = await async_w3.geth.personal.ec_recover(
321+
json.dumps(message), signature
322+
)
300323
assert is_same_address(async_unlockable_account_dual_type, address)

web3/contract/base_contract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
PropertyCheckingFactory,
5858
)
5959
from web3._utils.decorators import (
60-
deprecated_for,
60+
deprecate_method,
6161
)
6262
from web3._utils.empty import (
6363
empty,
@@ -727,7 +727,7 @@ class BaseContract:
727727
# Public API
728728
#
729729
@combomethod
730-
@deprecated_for("encode_abi()")
730+
@deprecate_method("encode_abi()")
731731
def encodeABI(
732732
cls,
733733
fn_name: str,

0 commit comments

Comments
 (0)