Skip to content

Commit

Permalink
Merge pull request #1211 from njgheorghita/relocate-personal-module
Browse files Browse the repository at this point in the history
Relocate personal RPC endpoints to parity and geth class
  • Loading branch information
njgheorghita authored Mar 12, 2019
2 parents 6467837 + d78e187 commit 0cb2dc0
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 177 deletions.
103 changes: 84 additions & 19 deletions docs/web3.personal.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
Personal API
============

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

.. py:class:: Personal
- ``web3.geth.personal``
- ``web3.parity.personal``

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

.. py:module:: web3.geth.personal
Properties
----------
Geth Methods
------------

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

.. py:attribute:: listAccounts
.. py:method:: listAccounts
* Delegates to ``personal_listAccounts`` RPC Method

Returns the list of known accounts.

.. code-block:: python
>>> web3.personal.listAccounts
>>> web3.geth.personal.listAccounts()
['0xd3cda913deb6f67967b99d67acdfa1712c293601']
Methods
-------

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

.. py:method:: importRawKey(self, private_key, passphrase)
* Delegates to ``personal_importRawKey`` RPC Method
Expand All @@ -40,7 +37,7 @@ The following methods are available on the ``web3.personal`` namespace.

.. code-block:: python
>>> web3.personal.importRawKey(some_private_key, 'the-passphrase')
>>> web3.geth.personal.importRawKey(some_private_key, 'the-passphrase')
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
Expand All @@ -53,7 +50,7 @@ The following methods are available on the ``web3.personal`` namespace.

.. code-block:: python
>>> web3.personal.newAccount('the-passphrase')
>>> web3.geth.personal.newAccount('the-passphrase')
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
Expand All @@ -65,7 +62,7 @@ The following methods are available on the ``web3.personal`` namespace.

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

.. code-block:: python
>>> web3.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
>>> web3.geth.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
False
>>> web3.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
>>> web3.geth.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
True
.. py:method:: sendTransaction(self, transaction, passphrase)
* Delegates to ``personal_sendTransaction`` RPC Method

Sends the transaction.


.. py:module:: web3.parity.personal
Parity Methods
--------------

The following methods are available on the ``web3.parity.personal`` namespace.

.. py:method:: listAccounts
* Delegates to ``personal_listAccounts`` RPC Method

Returns the list of known accounts.

.. code-block:: python
>>> web3.parity.personal.listAccounts()
['0xd3cda913deb6f67967b99d67acdfa1712c293601']
.. py:method:: importRawKey(self, private_key, passphrase)
* Delegates to ``personal_importRawKey`` RPC Method

Adds the given ``private_key`` to the node's keychain, encrypted with the
given ``passphrase``. Returns the address of the imported account.

.. code-block:: python
>>> web3.parity.personal.importRawKey(some_private_key, 'the-passphrase')
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
.. py:method:: newAccount(self, password)
* Delegates to ``personal_newAccount`` RPC Method

Generates a new account in the node's keychain encrypted with the
given ``passphrase``. Returns the address of the created account.

.. code-block:: python
>>> web3.parity.personal.newAccount('the-passphrase')
'0xd3cda913deb6f67967b99d67acdfa1712c293601'
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
* Delegates to ``personal_unlockAccount`` RPC Method

Unlocks the given ``account`` for ``duration`` seconds. If ``duration`` is
``None`` then the account will remain unlocked indefinitely. Returns
boolean as to whether the account was successfully unlocked.

.. code-block:: python
# Invalid call to personal_unlockAccount on Parity currently returns True, due to Parity bug
>>> web3.parity.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'wrong-passphrase')
True
>>> web3.parity.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
True
.. py:method:: sendTransaction(self, transaction, passphrase)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/method-class/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class FakeModule(ModuleV2):
def dummy_w3():
return Web3(
EthereumTesterProvider(),
modules={'fake': FakeModule},
modules={'fake': (FakeModule,)},
middlewares=[])


Expand Down
6 changes: 3 additions & 3 deletions tests/core/version-module/test_version_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def blocking_w3():
return Web3(
EthereumTesterProvider(),
modules={
'blocking_version': BlockingVersion,
'legacy_version': Version
"blocking_version": (BlockingVersion,),
"legacy_version": (Version,),
})


Expand All @@ -30,7 +30,7 @@ def async_w3():
AsyncEthereumTesterProvider(),
middlewares=[],
modules={
'async_version': AsyncVersion,
'async_version': (AsyncVersion,),
})


Expand Down
8 changes: 2 additions & 6 deletions tests/integration/go_ethereum/common.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from web3._utils.module_testing import (
from web3._utils.module_testing import ( # noqa: F401
EthModuleTest,
GoEthereumPersonalModuleTest,
NetModuleTest,
PersonalModuleTest,
VersionModuleTest,
Web3ModuleTest,
)
Expand Down Expand Up @@ -66,7 +66,3 @@ class GoEthereumVersionModuleTest(VersionModuleTest):

class GoEthereumNetModuleTest(NetModuleTest):
pass


class GoEthereumPersonalModuleTest(PersonalModuleTest):
pass
8 changes: 4 additions & 4 deletions tests/integration/go_ethereum/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def emitter_contract_address(emitter_contract, address_conversion_func):

@pytest.fixture
def unlocked_account(web3, unlockable_account, unlockable_account_pw):
web3.personal.unlockAccount(unlockable_account, unlockable_account_pw)
web3.geth.personal.unlockAccount(unlockable_account, unlockable_account_pw)
yield unlockable_account
web3.personal.lockAccount(unlockable_account)
web3.geth.personal.lockAccount(unlockable_account)


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

@pytest.yield_fixture
def unlocked_account_dual_type(web3, unlockable_account_dual_type, unlockable_account_pw):
web3.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
web3.geth.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
yield unlockable_account_dual_type
web3.personal.lockAccount(unlockable_account_dual_type)
web3.geth.personal.lockAccount(unlockable_account_dual_type)


@pytest.fixture(scope="module")
Expand Down
52 changes: 2 additions & 50 deletions tests/integration/parity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
flaky,
)

from web3._utils.module_testing import (
from web3._utils.module_testing import ( # noqa: F401
EthModuleTest,
ParityModuleTest as TraceModuleTest,
PersonalModuleTest,
ParityPersonalModuleTest,
Web3ModuleTest,
)

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


class ParityPersonalModuleTest(PersonalModuleTest):
def test_personal_importRawKey(self, web3):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_importRawKey(web3)

def test_personal_listAccounts(self, web3):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_listAccounts(web3)

def test_personal_lockAccount(self, web3, unlocked_account):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_lockAccount(web3, unlocked_account)

def test_personal_unlockAccount_success(self, web3):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_unlockAccount_success(web3)

def test_personal_unlockAccount_failure(self, web3, unlockable_account):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_unlockAccount_failure(web3, unlockable_account)

def test_personal_newAccount(self, web3):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_newAccount(web3)

def test_personal_sendTransaction(
self,
web3,
unlockable_account,
unlockable_account_pw):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_sendTransaction(
web3,
unlockable_account,
unlockable_account_pw)

def test_personal_sign_and_ecrecover(
self,
web3,
unlockable_account,
unlockable_account_pw):
pytest.xfail('this non-standard json-rpc method is not implemented on parity')
super().test_personal_sign_and_ecrecover(
web3,
unlockable_account,
unlockable_account_pw)


class ParityTraceModuleTest(TraceModuleTest):
def test_list_storage_keys_no_support(self, web3, emitter_contract_address):
super().test_list_storage_keys_no_support(web3, emitter_contract_address)
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/parity/test_parity_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def parity_command_arguments(
'--unlock', author,
'--password', passwordfile,
'--jsonrpc-port', rpc_port,
'--jsonrpc-apis', 'all',
'--no-ipc',
'--no-ws',
)
Expand All @@ -61,6 +62,7 @@ def parity_import_blocks_command(parity_binary, rpc_port, datadir, passwordfile)
'--base-path', datadir,
'--password', passwordfile,
'--jsonrpc-port', str(rpc_port),
'--jsonrpc-apis', 'all',
'--no-ipc',
'--no-ws',
'--tracing', 'on',
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/parity/test_parity_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def parity_command_arguments(
'--base-path', datadir,
'--unlock', author,
'--password', passwordfile,
'--ipc-apis', 'all',
'--no-jsonrpc',
'--no-ws',
)
Expand All @@ -59,6 +60,7 @@ def parity_import_blocks_command(parity_binary, ipc_path, datadir, passwordfile)
'--ipc-path', ipc_path,
'--base-path', datadir,
'--password', passwordfile,
'--ipc-apis', 'all',
'--no-jsonrpc',
'--no-ws',
'--tracing', 'on',
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/parity/test_parity_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def parity_command_arguments(
'--password', passwordfile,
'--ws-port', ws_port,
'--ws-origins', '*',
'--ws-apis', 'all',
'--no-ipc',
'--no-jsonrpc',
)
Expand All @@ -64,6 +65,7 @@ def parity_import_blocks_command(parity_binary, ws_port, datadir, passwordfile):
'--password', passwordfile,
'--ws-port', str(ws_port),
'--ws-origins', '*',
'--ws-apis', 'all',
'--no-ipc',
'--no-jsonrpc',
'--tracing', 'on',
Expand Down
Loading

0 comments on commit 0cb2dc0

Please sign in to comment.