Skip to content

Commit

Permalink
Relocate personal RPC endpoints to parity and geth class
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Jan 15, 2019
1 parent 92463a2 commit 5c3fc71
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
20 changes: 10 additions & 10 deletions web3/_utils/module_testing/personal_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

class PersonalModuleTest:
def test_personal_importRawKey(self, web3):
actual = web3.personal.importRawKey(PRIVATE_KEY_HEX, PASSWORD)
actual = web3.geth.personal.importRawKey(PRIVATE_KEY_HEX, PASSWORD)
assert actual == ADDRESS

def test_personal_listAccounts(self, web3):
accounts = web3.personal.listAccounts
accounts = web3.geth.personal.listAccounts
assert is_list_like(accounts)
assert len(accounts) > 0
assert all((
Expand All @@ -30,23 +30,23 @@ def test_personal_listAccounts(self, web3):

def test_personal_lockAccount(self, web3, unlockable_account_dual_type):
# TODO: how do we test this better?
web3.personal.lockAccount(unlockable_account_dual_type)
web3.geth.personal.lockAccount(unlockable_account_dual_type)

def test_personal_unlockAccount_success(self,
web3,
unlockable_account_dual_type,
unlockable_account_pw):
result = web3.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
result = web3.geth.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
assert result is True

def test_personal_unlockAccount_failure(self,
web3,
unlockable_account_dual_type):
result = web3.personal.unlockAccount(unlockable_account_dual_type, 'bad-password')
result = web3.geth.personal.unlockAccount(unlockable_account_dual_type, 'bad-password')
assert result is False

def test_personal_newAccount(self, web3):
new_account = web3.personal.newAccount(PASSWORD)
new_account = web3.geth.personal.newAccount(PASSWORD)
assert is_checksum_address(new_account)

def test_personal_sendTransaction(self,
Expand All @@ -61,7 +61,7 @@ def test_personal_sendTransaction(self,
'value': 1,
'gasPrice': web3.toWei(1, 'gwei'),
}
txn_hash = web3.personal.sendTransaction(txn_params, unlockable_account_pw)
txn_hash = web3.geth.personal.sendTransaction(txn_params, unlockable_account_pw)
assert txn_hash
transaction = web3.eth.getTransaction(txn_hash)

Expand All @@ -75,7 +75,7 @@ def test_personal_sign_and_ecrecover(self,
web3,
unlockable_account_dual_type,
unlockable_account_pw):
message = 'test-web3-personal-sign'
signature = web3.personal.sign(message, unlockable_account_dual_type, unlockable_account_pw)
signer = web3.personal.ecRecover(message, signature)
message = 'test-web3-geth-personal-sign'
signature = web3.geth.personal.sign(message, unlockable_account_dual_type, unlockable_account_pw)
signer = web3.geth.personal.ecRecover(message, signature)
assert is_same_address(signer, unlockable_account_dual_type)
20 changes: 20 additions & 0 deletions web3/geth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from web3.module import (
Module,
)
from web3.personal import (
Personal,
)


class GethPersonal(Personal):
"""
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal
"""
def __init__(self, w3):
self.w3 = w3


class Geth(Module):
@property
def personal(self):
return GethPersonal(self.web3)
8 changes: 4 additions & 4 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
from web3.eth import (
Eth,
)
from web3.geth import (
Geth,
)
from web3.iban import (
Iban,
)
Expand All @@ -55,9 +58,6 @@
from web3.parity import (
Parity,
)
from web3.personal import (
Personal,
)
from web3.providers.eth_tester import (
EthereumTesterProvider,
)
Expand Down Expand Up @@ -85,12 +85,12 @@ def get_default_modules():
return {
"eth": Eth,
"net": Net,
"personal": Personal,
"version": Version,
"txpool": TxPool,
"miner": Miner,
"admin": Admin,
"parity": Parity,
"geth": Geth,
"testing": Testing,
}

Expand Down
25 changes: 25 additions & 0 deletions web3/parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,42 @@
from web3._utils.toolz import (
assoc,
)
from web3.personal import (
Personal,
)
from web3.module import (
Module,
)


class ParityPersonal(Personal):
"""
https://wiki.parity.io/JSONRPC-personal-module
"""
def __init__(self, w3):
self.w3 = w3

def importRawKey(self, private_key, passphrase):
raise NotImplementedError(
"personal_importRawKey RPC-endpoint is not supported by the Parity client."
)

def lockAccount(self, account):
raise NotImplementedError(
"personal_lockAccount RPC-endpoint is not supported by the Parity client."
)


class Parity(Module):
"""
https://paritytech.github.io/wiki/JSONRPC-parity-module
"""
defaultBlock = "latest"

@property
def personal(self):
return ParityPersonal(self.web3)

def enode(self):
return self.web3.manager.request_blocking(
"parity_enode",
Expand Down
13 changes: 6 additions & 7 deletions web3/personal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from web3.module import (
Module,
)


class Personal(Module):
class Personal():
"""
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal
This API is not automatically available on a `web3` instance, rather it should be accessed
through `web3.geth.personal` or `web3.parity.personal`.
All RPC endpoints under the personal namespace should be added here, and NotImplementedErrors
should be raised in subclasses if the endpoints are not supported by the respective client.
"""
def importRawKey(self, private_key, passphrase):
return self.web3.manager.request_blocking(
Expand Down

0 comments on commit 5c3fc71

Please sign in to comment.