Skip to content

Commit

Permalink
Update get_default_modules structure to cleaner format
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Mar 11, 2019
1 parent 7ca37c2 commit a770663
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
3 changes: 2 additions & 1 deletion docs/web3.personal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ 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')
False
True
>>> web3.parity.personal.unlockAccount('0xd3cda913deb6f67967b99d67acdfa1712c293601', 'the-passphrase')
True
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=[{'name': 'fake', 'module': 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=[
{"name": "blocking_version", "module": BlockingVersion},
{"name": "legacy_version", "module": Version},
{"blocking_version": (BlockingVersion,)},
{"legacy_version": (Version,)},
])


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


Expand Down
1 change: 1 addition & 0 deletions web3/_utils/module_testing/personal_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def test_personal_unlockAccount_success(self,
)
assert result is True

# Seems to be an issue with Parity since this should return False
def test_personal_unlockAccount_failure(self,
web3,
unlockable_account_dual_type):
Expand Down
35 changes: 20 additions & 15 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@


def get_default_modules():
return [
{"name": "eth", "module": Eth},
{"name": "net", "module": Net},
{"name": "version", "module": Version},
{"name": "txpool", "module": TxPool},
{"name": "miner", "module": Miner},
{"name": "admin", "module": Admin},
{"name": "parity", "module": Parity, 'submodules': {'personal': ParityPersonal}},
{"name": "geth", "module": Geth, 'submodules': {'personal': GethPersonal}},
{"name": "testing", "module": Testing},
]
return {
"eth": (Eth,),
"net": (Net,),
"version": (Version,),
"txpool": (TxPool,),
"miner": (Miner,),
"admin": (Admin,),
"parity": (Parity, {
"personal": (ParityPersonal,)
}),
"geth": (Geth, {
"personal": (GethPersonal,)
}),
"testing": (Testing,),
}


class Web3:
Expand Down Expand Up @@ -133,10 +137,11 @@ def __init__(self, provider=None, middlewares=None, modules=None, ens=empty):
modules = get_default_modules()

for module in modules:
module['module'].attach(self, module['name'])
if 'submodules' in module:
for subname, submodule in module['submodules'].items():
submodule.attach(getattr(self, module['name']), subname)
module_class, *submodules = modules[module]
module_class.attach(self, module)
if submodules:
for subname, subclasses in submodules[0].items():
subclasses[0].attach(getattr(self, module), subname)

self.ens = ens

Expand Down
8 changes: 0 additions & 8 deletions web3/personal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,53 @@ def importRawKey():
return Method(
"personal_importRawKey",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def newAccount():
return Method(
"personal_newAccount",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def listAccounts():
return Method(
"personal_listAccounts",
mungers=None,
formatter_lookup_fn=None,
)


def sendTransaction():
return Method(
"personal_sendTransaction",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def lockAccount():
return Method(
"personal_lockAccount",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def unlockAccount():
return Method(
"personal_unlockAccount",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def sign():
return Method(
"personal_sign",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)


def ecRecover():
return Method(
"personal_ecRecover",
mungers=[default_root_munger],
formatter_lookup_fn=None,
)

0 comments on commit a770663

Please sign in to comment.