Skip to content

Commit

Permalink
Implement eth_submitHashrate and integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Mar 14, 2019
1 parent e4f46cf commit 32017cf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,17 @@ with the filtering API.
:meth:`~Eth.filter` for details on allowed filter parameters.


.. py:method:: Eth.submitHashrate(hashrate, nodeid)
* Delegates to ``eth_submitHashrate`` RPC Method.

.. code-block:: python
>>> node_id = '59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
>>> web3.eth.submitHashrate(5000, node_id)
True
Contracts
---------

Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def func_wrapper(self, eth_tester, *args, **kwargs):

class TestEthereumTesterEthModule(EthModuleTest):
test_eth_sign = not_implemented(EthModuleTest.test_eth_sign, ValueError)
test_eth_submitHashrate = not_implemented(EthModuleTest.test_eth_submitHashrate, ValueError)

@disable_auto_mine
def test_eth_getTransactionReceipt_unmined(self, eth_tester, web3, unlocked_account):
Expand Down
5 changes: 5 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,8 @@ def test_eth_getTransactionFromBlock_deprecation(self, web3, block_with_txn):
def test_eth_getCompilers_deprecation(self, web3):
with pytest.raises(DeprecationWarning):
web3.eth.getCompilers()

def test_eth_submitHashrate(self, web3):
node_id = '59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
result = web3.eth.submitHashrate(5000, node_id)
assert result is True
1 change: 1 addition & 0 deletions web3/_utils/rpc_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'eth_sendRawTransaction': ['bytes'],
'eth_sendTransaction': TRANSACTION_PARAMS_ABIS,
'eth_sign': ['address', 'bytes'],
'eth_submitHashrate': ['uint', None],
# personal
'personal_sendTransaction': TRANSACTION_PARAMS_ABIS,
'personal_lockAccount': ['address'],
Expand Down
5 changes: 5 additions & 0 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ def getLogs(self, filter_params):
"eth_getLogs", [filter_params],
)

def submitHashrate(self, hashrate, node_id):
return self.web3.manager.request_blocking(
"eth_submitHashrate", [hashrate, node_id],
)

def uninstallFilter(self, filter_id):
return self.web3.manager.request_blocking(
"eth_uninstallFilter", [filter_id],
Expand Down
1 change: 1 addition & 0 deletions web3/middleware/pythonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
(estimate_gas_with_block_id, is_length(2)),
)),
'eth_sendTransaction': apply_formatter_at_index(transaction_param_formatter, 0),
'eth_submitHashrate': apply_formatter_at_index(hexstr_if_str(to_hex), 1),
# personal
'personal_importRawKey': apply_formatter_at_index(
compose(remove_0x_prefix, hexstr_if_str(to_hex)),
Expand Down

0 comments on commit 32017cf

Please sign in to comment.