Skip to content

Commit

Permalink
Add snake_case methods to Geth and Parity Personal Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tmckenzie51 authored and kclowes committed Apr 15, 2020
1 parent 363610a commit 65c2f52
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 89 deletions.
64 changes: 50 additions & 14 deletions docs/web3.geth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,25 @@ GethPersonal API

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

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

Returns the list of known accounts.

.. code-block:: python
>>> web3.geth.personal.listAccounts()
>>> web3.geth.personal.list_accounts()
['0xd3CdA913deB6f67967B99D67aCDFa1712C293601']
.. py:method:: importRawKey(self, private_key, passphrase)
.. py:method:: listAccounts()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.list_accounts()`


.. py:method:: import_raw_key(self, private_key, passphrase)
* Delegates to ``personal_importRawKey`` RPC Method

Expand All @@ -232,11 +238,17 @@ The following methods are available on the ``web3.geth.personal`` namespace.

.. code-block:: python
>>> web3.geth.personal.importRawKey(some_private_key, 'the-passphrase')
>>> web3.geth.personal.import_raw_key(some_private_key, 'the-passphrase')
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
.. py:method:: newAccount(self, password)
.. py:method:: importRawKey()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.import_raw_key()`


.. py:method:: new_account(self, password)
* Delegates to ``personal_newAccount`` RPC Method

Expand All @@ -249,41 +261,65 @@ The following methods are available on the ``web3.geth.personal`` namespace.
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
.. py:method:: lockAccount(self, account)
.. py:method:: newAccount()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.newAccount()`


.. py:method:: lock_account(self, account)
* Delegates to ``personal_lockAccount`` RPC Method

Locks the given ``account``.

.. code-block:: python
>>> web3.geth.personal.lockAccount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
>>> web3.geth.personal.lock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
.. py:method:: lockAccount()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.lockAccount()`


.. py:method:: unlock_account(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 for 300 seconds (which is current default by Geth v1.9.5),
if ``duration`` is set to ``0``, the account will remain unlocked indefinitely.
Unlocks the given ``account`` for ``duration`` seconds. If ``duration`` is
``None`` then the account will remain unlocked for 300 seconds (which is current default by Geth v1.9.5),
if ``duration`` is set to ``0``, the account will remain unlocked indefinitely.
Returns boolean as to whether the account was successfully unlocked.

.. code-block:: python
>>> web3.geth.personal.unlockAccount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'wrong-passphrase')
>>> web3.geth.personal.unlock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'wrong-passphrase')
False
>>> web3.geth.personal.unlockAccount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'the-passphrase')
>>> web3.geth.personal.unlock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'the-passphrase')
True
.. py:method:: sendTransaction(self, transaction, passphrase)
.. py:method:: unlockAccount()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.unlockAccount()`


.. py:method:: send_transaction(self, transaction, passphrase)
* Delegates to ``personal_sendTransaction`` RPC Method

Sends the transaction.


.. py:method:: sendTransaction()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.geth.personal.sendTransaction()`


.. py:module:: web3.geth.txpool
GethTxPool API
Expand Down
48 changes: 37 additions & 11 deletions docs/web3.parity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ Parity API
The ``web3.parity`` object exposes modules that enable you to interact with the JSON-RPC endpoints supported by `Parity <https://wiki.parity.io/JSONRPC>`_ that are not defined in the standard set of Ethereum JSONRPC endpoints according to `EIP 1474 <https://github.com/ethereum/EIPs/pull/1474>`_.

.. py:module:: web3.parity.personal
ParityPersonal
--------------

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

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

Returns the list of known accounts.

.. code-block:: python
>>> web3.parity.personal.listAccounts()
>>> web3.parity.personal.list_accounts()
['0xd3CdA913deB6f67967B99D67aCDFa1712C293601']
.. py:method:: listAccounts
.. py:method:: importRawKey(self, private_key, passphrase)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.list_accounts()`

.. py:method:: import_raw_key(self, private_key, passphrase)
* Delegates to ``personal_importRawKey`` RPC Method

Expand All @@ -31,11 +37,15 @@ The following methods are available on the ``web3.parity.personal`` namespace.

.. code-block:: python
>>> web3.parity.personal.importRawKey(some_private_key, 'the-passphrase')
>>> web3.parity.personal.import_raw_key(some_private_key, 'the-passphrase')
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
.. py:method:: importRawKey(self, private_key, passphrase)
.. py:method:: newAccount(self, password)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.import_raw_key()`

.. py:method:: new_account(self, password)
* Delegates to ``personal_newAccount`` RPC Method

Expand All @@ -44,11 +54,15 @@ The following methods are available on the ``web3.parity.personal`` namespace.

.. code-block:: python
>>> web3.parity.personal.newAccount('the-passphrase')
>>> web3.parity.personal.new_account('the-passphrase')
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
.. py:method:: newAccount(self, password)
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.new_account()`

.. py:method:: unlock_account(self, account, passphrase, duration=None)
* Delegates to ``personal_unlockAccount`` RPC Method

Expand All @@ -59,20 +73,28 @@ The following methods are available on the ``web3.parity.personal`` namespace.
.. code-block:: python
# Invalid call to personal_unlockAccount on Parity currently returns True, due to Parity bug
>>> web3.parity.personal.unlockAccount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'wrong-passphrase')
>>> web3.parity.personal.unlock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'wrong-passphrase')
True
>>> web3.parity.personal.unlockAccount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'the-passphrase')
>>> web3.parity.personal.unlock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'the-passphrase')
True
.. py:method:: unlockAccount(self, account, passphrase, duration=None)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.unlock_account()`

.. py:method:: sendTransaction(self, transaction, passphrase)
.. py:method:: send_transaction(self, transaction, passphrase)
* Delegates to ``personal_sendTransaction`` RPC Method

Sends the transaction.

.. py:method:: sendTransaction(self, account, passphrase, duration=None)
.. py:method:: signTypedData(self, jsonMessage, account, passphrase)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.send_transaction()`

.. py:method:: sign_typed_data(self, jsonMessage, account, passphrase)
* Delegates to ``personal_signTypedData`` RPC Method

Expand All @@ -81,6 +103,10 @@ The following methods are available on the ``web3.parity.personal`` namespace.

Signs the ``Structured Data`` (or ``Typed Data``) with the passphrase of the given ``account``

.. py:method:: signTypedData(self, jsonMessage, account, passphrase)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.parity.personal.sign_typed_data()`

ParityShh
---------
Expand Down
4 changes: 2 additions & 2 deletions tests/generate_go_ethereum_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def mine_block(web3):


def deploy_contract(web3, name, factory):
web3.geth.personal.unlockAccount(web3.eth.coinbase, KEYFILE_PW)
web3.geth.personal.unlock_account(web3.eth.coinbase, KEYFILE_PW)
deploy_txn_hash = factory.constructor().transact({'from': web3.eth.coinbase})
print('{0}_CONTRACT_DEPLOY_HASH: '.format(name.upper()), deploy_txn_hash)
deploy_receipt = mine_transaction_hash(web3, deploy_txn_hash)
Expand Down Expand Up @@ -376,7 +376,7 @@ def setup_chain_state(web3):
#
# Block with Transaction
#
web3.geth.personal.unlockAccount(coinbase, KEYFILE_PW)
web3.geth.personal.unlock_account(coinbase, KEYFILE_PW)
web3.geth.miner.start(1)
mined_txn_hash = web3.eth.sendTransaction({
'from': coinbase,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/generate_fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def mine_transaction_hash(web3, txn_hash):


def deploy_contract(web3, name, factory):
web3.geth.personal.unlockAccount(web3.eth.coinbase, KEYFILE_PW)
web3.geth.personal.unlock_account(web3.eth.coinbase, KEYFILE_PW)
deploy_txn_hash = factory.constructor().transact({'from': web3.eth.coinbase})
print('{0}_CONTRACT_DEPLOY_HASH: '.format(name.upper()), deploy_txn_hash)
deploy_receipt = mine_transaction_hash(web3, deploy_txn_hash)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/generate_fixtures/go_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def setup_chain_state(web3):
#
# Block with Transaction
#
web3.geth.personal.unlockAccount(coinbase, common.KEYFILE_PW)
web3.geth.personal.unlock_account(coinbase, common.KEYFILE_PW)
web3.geth.miner.start(1)
mined_txn_hash = web3.eth.sendTransaction({
'from': coinbase,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/go_ethereum/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@ def test_shh_post_deprecated(self, web3):

class GoEthereumAdminModuleTest(GoEthereumAdminModuleTest):
pass


class GoEthereumPersonalModuleTest(GoEthereumPersonalModuleTest):
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 @@ -170,9 +170,9 @@ def emitter_contract_address(emitter_contract, address_conversion_func):

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


@pytest.fixture(scope='module')
Expand All @@ -192,9 +192,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.geth.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
web3.geth.personal.unlock_account(unlockable_account_dual_type, unlockable_account_pw)
yield unlockable_account_dual_type
web3.geth.personal.lockAccount(unlockable_account_dual_type)
web3.geth.personal.lock_account(unlockable_account_dual_type)


@pytest.fixture(scope="module")
Expand Down
32 changes: 21 additions & 11 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
EthereumTesterProvider,
)

pytestmark = pytest.mark.filterwarnings("ignore:implicit cast from 'char *'")


@pytest.fixture(scope="module")
def eth_tester():
Expand Down Expand Up @@ -147,7 +145,7 @@ def unlockable_account_pw(web3):

@pytest.fixture(scope='module')
def unlockable_account(web3, unlockable_account_pw):
account = web3.geth.personal.importRawKey(UNLOCKABLE_PRIVATE_KEY, unlockable_account_pw)
account = web3.geth.personal.import_raw_key(UNLOCKABLE_PRIVATE_KEY, unlockable_account_pw)
web3.eth.sendTransaction({
'from': web3.eth.coinbase,
'to': account,
Expand All @@ -158,9 +156,9 @@ def unlockable_account(web3, unlockable_account_pw):

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


@pytest.fixture()
Expand All @@ -170,9 +168,9 @@ def unlockable_account_dual_type(unlockable_account, address_conversion_func):

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


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -317,10 +315,22 @@ class TestEthereumTesterPersonalModule(GoEthereumPersonalModuleTest):
GoEthereumPersonalModuleTest.test_personal_sign_and_ecrecover,
ValueError,
)
test_personal_sign_and_ecrecover_deprecated = not_implemented(
GoEthereumPersonalModuleTest.test_personal_sign_and_ecrecover,
ValueError,
)

# Test overridden here since eth-tester returns False rather than None for failed unlock
def test_personal_unlockAccount_failure(self,
web3,
unlockable_account_dual_type):
result = web3.geth.personal.unlockAccount(unlockable_account_dual_type, 'bad-password')
def test_personal_unlock_account_failure(self,
web3,
unlockable_account_dual_type):
result = web3.geth.personal.unlock_account(unlockable_account_dual_type, 'bad-password')
assert result is False

def test_personal_unlockAccount_failure_deprecated(self,
web3,
unlockable_account_dual_type):
with pytest.warns(DeprecationWarning,
match="unlockAccount is deprecated in favor of unlock_account"):
result = web3.geth.personal.unlockAccount(unlockable_account_dual_type, 'bad-password')
assert result is False
Loading

0 comments on commit 65c2f52

Please sign in to comment.