Skip to content

Commit 0cb2dc0

Browse files
authored
Merge pull request #1211 from njgheorghita/relocate-personal-module
Relocate personal RPC endpoints to parity and geth class
2 parents 6467837 + d78e187 commit 0cb2dc0

File tree

17 files changed

+375
-177
lines changed

17 files changed

+375
-177
lines changed

docs/web3.personal.rst

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
Personal API
22
============
33

4-
.. py:module:: web3.personal
4+
There are 2 objects that expose methods to interact with the RPC APIS
5+
under the ``personal_`` namespace, each supporting the endpoints
6+
implemented in the respective clients.
57

6-
.. py:class:: Personal
8+
- ``web3.geth.personal``
9+
- ``web3.parity.personal``
710

8-
The ``web3.personal`` object exposes methods to interact with the RPC APIs
9-
under the ``personal_`` namespace.
1011

12+
.. py:module:: web3.geth.personal
1113
12-
Properties
13-
----------
14+
Geth Methods
15+
------------
1416

15-
The following properties are available on the ``web3.personal`` namespace.
17+
The following methods are available on the ``web3.geth.personal`` namespace.
1618

17-
.. py:attribute:: listAccounts
19+
.. py:method:: listAccounts
1820
1921
* Delegates to ``personal_listAccounts`` RPC Method
2022

2123
Returns the list of known accounts.
2224

2325
.. code-block:: python
2426
25-
>>> web3.personal.listAccounts
27+
>>> web3.geth.personal.listAccounts()
2628
['0xd3cda913deb6f67967b99d67acdfa1712c293601']
2729
2830
29-
Methods
30-
-------
31-
32-
The following methods are available on the ``web3.personal`` namespace.
33-
3431
.. py:method:: importRawKey(self, private_key, passphrase)
3532
3633
* Delegates to ``personal_importRawKey`` RPC Method
@@ -40,7 +37,7 @@ The following methods are available on the ``web3.personal`` namespace.
4037

4138
.. code-block:: python
4239
43-
>>> web3.personal.importRawKey(some_private_key, 'the-passphrase')
40+
>>> web3.geth.personal.importRawKey(some_private_key, 'the-passphrase')
4441
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
4542
4643
@@ -53,7 +50,7 @@ The following methods are available on the ``web3.personal`` namespace.
5350

5451
.. code-block:: python
5552
56-
>>> web3.personal.newAccount('the-passphrase')
53+
>>> web3.geth.personal.newAccount('the-passphrase')
5754
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
5855
5956
@@ -65,7 +62,7 @@ The following methods are available on the ``web3.personal`` namespace.
6562

6663
.. code-block:: python
6764
68-
>>> web3.personal.lockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601')
65+
>>> web3.geth.personal.lockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601')
6966
7067
7168
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
@@ -78,9 +75,77 @@ The following methods are available on the ``web3.personal`` namespace.
7875

7976
.. code-block:: python
8077
81-
>>> web3.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
78+
>>> web3.geth.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
8279
False
83-
>>> web3.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
80+
>>> web3.geth.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
81+
True
82+
83+
.. py:method:: sendTransaction(self, transaction, passphrase)
84+
85+
* Delegates to ``personal_sendTransaction`` RPC Method
86+
87+
Sends the transaction.
88+
89+
90+
.. py:module:: web3.parity.personal
91+
92+
Parity Methods
93+
--------------
94+
95+
The following methods are available on the ``web3.parity.personal`` namespace.
96+
97+
.. py:method:: listAccounts
98+
99+
* Delegates to ``personal_listAccounts`` RPC Method
100+
101+
Returns the list of known accounts.
102+
103+
.. code-block:: python
104+
105+
>>> web3.parity.personal.listAccounts()
106+
['0xd3cda913deb6f67967b99d67acdfa1712c293601']
107+
108+
109+
.. py:method:: importRawKey(self, private_key, passphrase)
110+
111+
* Delegates to ``personal_importRawKey`` RPC Method
112+
113+
Adds the given ``private_key`` to the node's keychain, encrypted with the
114+
given ``passphrase``. Returns the address of the imported account.
115+
116+
.. code-block:: python
117+
118+
>>> web3.parity.personal.importRawKey(some_private_key, 'the-passphrase')
119+
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
120+
121+
122+
.. py:method:: newAccount(self, password)
123+
124+
* Delegates to ``personal_newAccount`` RPC Method
125+
126+
Generates a new account in the node's keychain encrypted with the
127+
given ``passphrase``. Returns the address of the created account.
128+
129+
.. code-block:: python
130+
131+
>>> web3.parity.personal.newAccount('the-passphrase')
132+
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
133+
134+
135+
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
136+
137+
* Delegates to ``personal_unlockAccount`` RPC Method
138+
139+
Unlocks the given ``account`` for ``duration`` seconds. If ``duration`` is
140+
``None`` then the account will remain unlocked indefinitely. Returns
141+
boolean as to whether the account was successfully unlocked.
142+
143+
.. code-block:: python
144+
145+
# Invalid call to personal_unlockAccount on Parity currently returns True, due to Parity bug
146+
>>> web3.parity.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
147+
True
148+
>>> web3.parity.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
84149
True
85150
86151
.. py:method:: sendTransaction(self, transaction, passphrase)

tests/core/method-class/test_method.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class FakeModule(ModuleV2):
265265
def dummy_w3():
266266
return Web3(
267267
EthereumTesterProvider(),
268-
modules={'fake': FakeModule},
268+
modules={'fake': (FakeModule,)},
269269
middlewares=[])
270270

271271

tests/core/version-module/test_version_module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def blocking_w3():
1919
return Web3(
2020
EthereumTesterProvider(),
2121
modules={
22-
'blocking_version': BlockingVersion,
23-
'legacy_version': Version
22+
"blocking_version": (BlockingVersion,),
23+
"legacy_version": (Version,),
2424
})
2525

2626

@@ -30,7 +30,7 @@ def async_w3():
3030
AsyncEthereumTesterProvider(),
3131
middlewares=[],
3232
modules={
33-
'async_version': AsyncVersion,
33+
'async_version': (AsyncVersion,),
3434
})
3535

3636

tests/integration/go_ethereum/common.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
22

3-
from web3._utils.module_testing import (
3+
from web3._utils.module_testing import ( # noqa: F401
44
EthModuleTest,
5+
GoEthereumPersonalModuleTest,
56
NetModuleTest,
6-
PersonalModuleTest,
77
VersionModuleTest,
88
Web3ModuleTest,
99
)
@@ -66,7 +66,3 @@ class GoEthereumVersionModuleTest(VersionModuleTest):
6666

6767
class GoEthereumNetModuleTest(NetModuleTest):
6868
pass
69-
70-
71-
class GoEthereumPersonalModuleTest(PersonalModuleTest):
72-
pass

tests/integration/go_ethereum/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ def emitter_contract_address(emitter_contract, address_conversion_func):
184184

185185
@pytest.fixture
186186
def unlocked_account(web3, unlockable_account, unlockable_account_pw):
187-
web3.personal.unlockAccount(unlockable_account, unlockable_account_pw)
187+
web3.geth.personal.unlockAccount(unlockable_account, unlockable_account_pw)
188188
yield unlockable_account
189-
web3.personal.lockAccount(unlockable_account)
189+
web3.geth.personal.lockAccount(unlockable_account)
190190

191191

192192
@pytest.fixture(scope='module')
@@ -206,9 +206,9 @@ def unlockable_account_dual_type(unlockable_account, address_conversion_func):
206206

207207
@pytest.yield_fixture
208208
def unlocked_account_dual_type(web3, unlockable_account_dual_type, unlockable_account_pw):
209-
web3.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
209+
web3.geth.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
210210
yield unlockable_account_dual_type
211-
web3.personal.lockAccount(unlockable_account_dual_type)
211+
web3.geth.personal.lockAccount(unlockable_account_dual_type)
212212

213213

214214
@pytest.fixture(scope="module")

tests/integration/parity/common.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
flaky,
55
)
66

7-
from web3._utils.module_testing import (
7+
from web3._utils.module_testing import ( # noqa: F401
88
EthModuleTest,
99
ParityModuleTest as TraceModuleTest,
10-
PersonalModuleTest,
10+
ParityPersonalModuleTest,
1111
Web3ModuleTest,
1212
)
1313

@@ -120,54 +120,6 @@ def test_eth_call_old_contract_state(self, web3, math_contract, unlocked_account
120120
raise AssertionError("pending call result was %d!" % pending_call_result)
121121

122122

123-
class ParityPersonalModuleTest(PersonalModuleTest):
124-
def test_personal_importRawKey(self, web3):
125-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
126-
super().test_personal_importRawKey(web3)
127-
128-
def test_personal_listAccounts(self, web3):
129-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
130-
super().test_personal_listAccounts(web3)
131-
132-
def test_personal_lockAccount(self, web3, unlocked_account):
133-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
134-
super().test_personal_lockAccount(web3, unlocked_account)
135-
136-
def test_personal_unlockAccount_success(self, web3):
137-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
138-
super().test_personal_unlockAccount_success(web3)
139-
140-
def test_personal_unlockAccount_failure(self, web3, unlockable_account):
141-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
142-
super().test_personal_unlockAccount_failure(web3, unlockable_account)
143-
144-
def test_personal_newAccount(self, web3):
145-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
146-
super().test_personal_newAccount(web3)
147-
148-
def test_personal_sendTransaction(
149-
self,
150-
web3,
151-
unlockable_account,
152-
unlockable_account_pw):
153-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
154-
super().test_personal_sendTransaction(
155-
web3,
156-
unlockable_account,
157-
unlockable_account_pw)
158-
159-
def test_personal_sign_and_ecrecover(
160-
self,
161-
web3,
162-
unlockable_account,
163-
unlockable_account_pw):
164-
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
165-
super().test_personal_sign_and_ecrecover(
166-
web3,
167-
unlockable_account,
168-
unlockable_account_pw)
169-
170-
171123
class ParityTraceModuleTest(TraceModuleTest):
172124
def test_list_storage_keys_no_support(self, web3, emitter_contract_address):
173125
super().test_list_storage_keys_no_support(web3, emitter_contract_address)

tests/integration/parity/test_parity_http.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def parity_command_arguments(
4747
'--unlock', author,
4848
'--password', passwordfile,
4949
'--jsonrpc-port', rpc_port,
50+
'--jsonrpc-apis', 'all',
5051
'--no-ipc',
5152
'--no-ws',
5253
)
@@ -61,6 +62,7 @@ def parity_import_blocks_command(parity_binary, rpc_port, datadir, passwordfile)
6162
'--base-path', datadir,
6263
'--password', passwordfile,
6364
'--jsonrpc-port', str(rpc_port),
65+
'--jsonrpc-apis', 'all',
6466
'--no-ipc',
6567
'--no-ws',
6668
'--tracing', 'on',

tests/integration/parity/test_parity_ipc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def parity_command_arguments(
4545
'--base-path', datadir,
4646
'--unlock', author,
4747
'--password', passwordfile,
48+
'--ipc-apis', 'all',
4849
'--no-jsonrpc',
4950
'--no-ws',
5051
)
@@ -59,6 +60,7 @@ def parity_import_blocks_command(parity_binary, ipc_path, datadir, passwordfile)
5960
'--ipc-path', ipc_path,
6061
'--base-path', datadir,
6162
'--password', passwordfile,
63+
'--ipc-apis', 'all',
6264
'--no-jsonrpc',
6365
'--no-ws',
6466
'--tracing', 'on',

tests/integration/parity/test_parity_ws.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def parity_command_arguments(
4949
'--password', passwordfile,
5050
'--ws-port', ws_port,
5151
'--ws-origins', '*',
52+
'--ws-apis', 'all',
5253
'--no-ipc',
5354
'--no-jsonrpc',
5455
)
@@ -64,6 +65,7 @@ def parity_import_blocks_command(parity_binary, ws_port, datadir, passwordfile):
6465
'--password', passwordfile,
6566
'--ws-port', str(ws_port),
6667
'--ws-origins', '*',
68+
'--ws-apis', 'all',
6769
'--no-ipc',
6870
'--no-jsonrpc',
6971
'--tracing', 'on',

0 commit comments

Comments
 (0)