Skip to content

Commit

Permalink
snake case miner
Browse files Browse the repository at this point in the history
  • Loading branch information
billbsing authored and kclowes committed Feb 20, 2020
1 parent 3696aed commit d85f579
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 35 deletions.
39 changes: 30 additions & 9 deletions docs/web3.miner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ The following methods are available on the ``web3.geth.miner`` namespace.
.. py:method:: GethMiner.makeDAG(number)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~GethMiner.make_dag(number)`
:meth:`~GethMiner.make_dag`


.. py:method:: GethMiner.setExtra(extra)
.. py:method:: GethMiner.set_extra(extra)
* Delegates to ``miner_setExtra`` RPC Method

Expand All @@ -39,10 +39,15 @@ The following methods are available on the ``web3.geth.miner`` namespace.

.. code-block:: python
>>> web3.geth.miner.setExtra('abcdefghijklmnopqrstuvwxyzABCDEF')
>>> web3.geth.miner.set_extra('abcdefghijklmnopqrstuvwxyzABCDEF')
.. py:method:: GethMiner.setExtra(extra)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~GethMiner.set_extra`

.. py:method:: GethMiner.setGasPrice(gas_price)

.. py:method:: GethMiner.set_gas_price(gas_price)
* Delegates to ``miner_setGasPrice`` RPC Method

Expand All @@ -52,7 +57,13 @@ The following methods are available on the ``web3.geth.miner`` namespace.

.. code-block:: python
>>> web3.geth.miner.setGasPrice(19999999999)
>>> web3.geth.miner.set_gas_price(19999999999)
.. py:method:: GethMiner.setGasPrice(gas_price)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~GethMiner.set_gas_price`


.. py:method:: GethMiner.start(num_threads)
Expand All @@ -77,23 +88,33 @@ The following methods are available on the ``web3.geth.miner`` namespace.
>>> web3.geth.miner.stop()
.. py:method:: GethMiner.startAutoDAG()
.. py:method:: GethMiner.start_auto_dag()
* Delegates to ``miner_startAutoDag`` RPC Method

Enable automatic DAG generation.

.. code-block:: python
>>> web3.geth.miner.startAutoDAG()
>>> web3.geth.miner.start_auto_dag()
.. py:method:: GethMiner.startAutoDag()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~GethMiner.start_auto_dag`


.. py:method:: GethMiner.stopAutoDAG()
.. py:method:: GethMiner.stop_auto_dag()
* Delegates to ``miner_stopAutoDag`` RPC Method

Disable automatic DAG generation.

.. code-block:: python
>>> web3.geth.miner.stopAutoDAG()
>>> web3.geth.miner.stop_auto_dag()
.. py:method:: GethMiner.stopAutoDag()
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~GethMiner.stop_auto_dag`
13 changes: 0 additions & 13 deletions tests/core/mining-module/test_miner_makeDag.py

This file was deleted.

27 changes: 26 additions & 1 deletion tests/core/mining-module/test_miner_setExtra.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import random

from eth_utils import (
Expand All @@ -13,7 +14,7 @@


@flaky(max_runs=3)
def test_miner_setExtra(web3_empty, wait_for_block):
def test_miner_set_extra(web3_empty, wait_for_block):
web3 = web3_empty

initial_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
Expand All @@ -35,3 +36,27 @@ def test_miner_setExtra(web3_empty, wait_for_block):
after_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])

assert after_extra == new_extra_data


@flaky(max_runs=3)
def test_miner_setExtra(web3_empty, wait_for_block):
web3 = web3_empty

initial_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])

new_extra_data = b'-this-is-32-bytes-of-extra-data-'

# sanity
assert initial_extra != new_extra_data

with pytest.warns(DeprecationWarning):
web3.geth.miner.setExtra(new_extra_data)
with Timeout(60) as timeout:
while True:
extra_data = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
if extra_data == new_extra_data:
break
timeout.sleep(random.random())

after_extra = decode_hex(web3.eth.getBlock(web3.eth.blockNumber)['extraData'])
assert after_extra == new_extra_data
25 changes: 23 additions & 2 deletions tests/core/mining-module/test_miner_setGasPrice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import random

from flaky import (
Expand All @@ -10,15 +11,35 @@


@flaky(max_runs=3)
def test_miner_setGasPrice(web3_empty, wait_for_block):
def test_miner_set_gas_price(web3_empty, wait_for_block):
web3 = web3_empty

initial_gas_price = web3.eth.gasPrice

# sanity check
assert web3.eth.gasPrice > 1000

web3.geth.miner.setGasPrice(initial_gas_price // 2)
web3.geth.miner.set_gas_price(initial_gas_price // 2)

with Timeout(60) as timeout:
while web3.eth.gasPrice == initial_gas_price:
timeout.sleep(random.random())

after_gas_price = web3.eth.gasPrice
assert after_gas_price < initial_gas_price


@flaky(max_runs=3)
def test_miner_setGasPrice(web3_empty, wait_for_block):
web3 = web3_empty

initial_gas_price = web3.eth.gasPrice
assert web3.eth.gasPrice > 1000

# sanity check

with pytest.warns(DeprecationWarning):
web3.geth.miner.setGasPrice(initial_gas_price // 2)

with Timeout(60) as timeout:
while web3.eth.gasPrice == initial_gas_price:
Expand Down
13 changes: 12 additions & 1 deletion tests/core/mining-module/test_setEtherBase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import pytest


def test_miner_set_etherbase(web3_empty):
web3 = web3_empty
assert web3.eth.coinbase == web3.eth.accounts[0]
new_account = web3.personal.newAccount('this-is-a-password')
web3.geth.miner.set_etherbase(new_account)
assert web3.eth.coinbase == new_account


def test_miner_setEtherbase(web3_empty):
web3 = web3_empty
assert web3.eth.coinbase == web3.eth.accounts[0]
new_account = web3.personal.newAccount('this-is-a-password')
web3.geth.miner.setEtherBase(new_account)
with pytest.warns(DeprecationWarning):
web3.geth.miner.setEtherbase(new_account)
assert web3.eth.coinbase == new_account
15 changes: 10 additions & 5 deletions web3/_utils/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
)


setExtra: Method[Callable[[str], bool]] = Method(
set_extra: Method[Callable[[str], bool]] = Method(
RPC.miner_setExtra,
mungers=[default_root_munger],
)


setEtherbase: Method[Callable[[ChecksumAddress], bool]] = Method(
set_etherbase: Method[Callable[[ChecksumAddress], bool]] = Method(
RPC.miner_setEtherbase,
mungers=[default_root_munger],
)


setGasPrice: Method[Callable[[Wei], bool]] = Method(
set_gas_price: Method[Callable[[Wei], bool]] = Method(
RPC.miner_setGasPrice,
mungers=[default_root_munger],
)
Expand All @@ -55,13 +55,13 @@
)


startAutoDag: Method[Callable[[], bool]] = Method(
start_auto_dag: Method[Callable[[], bool]] = Method(
RPC.miner_startAutoDag,
mungers=None,
)


stopAutoDag: Method[Callable[[], bool]] = Method(
stop_auto_dag: Method[Callable[[], bool]] = Method(
RPC.miner_stopAutoDag,
mungers=None,
)
Expand All @@ -71,3 +71,8 @@
# Deprecated Methods
#
makeDag = DeprecatedMethod(make_dag, 'makeDag', 'make_dag')
setExtra = DeprecatedMethod(set_extra, 'setExtra', 'set_extra')
setEtherbase = DeprecatedMethod(set_etherbase, 'setEtherbase', 'set_etherbase')
setGasPrice = DeprecatedMethod(set_gas_price, 'setGasPrice', 'set_gas_price')
startAutoDag = DeprecatedMethod(start_auto_dag, 'startAutoDag', 'start_auto_dag')
stopAutoDag = DeprecatedMethod(stop_auto_dag, 'stopAutoDag', 'stop_auto_dag')
14 changes: 12 additions & 2 deletions web3/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
from web3._utils.miner import (
make_dag,
makeDag,
set_etherbase,
set_extra,
set_gas_price,
setEtherbase,
setExtra,
setGasPrice,
start,
start_auto_dag,
startAutoDag,
stop,
stop_auto_dag,
stopAutoDag,
)
from web3._utils.personal import (
Expand Down Expand Up @@ -100,13 +105,18 @@ class GethMiner(ModuleV2):
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner
"""
make_dag = make_dag
set_extra = set_extra
set_etherbase = set_etherbase
set_gas_price = set_gas_price
start = start
stop = stop
start_auto_dag = start_auto_dag
stop_auto_dag = stop_auto_dag
# deprecated
makeDag = makeDag
setExtra = setExtra
setEtherbase = setEtherbase
setGasPrice = setGasPrice
start = start
stop = stop
startAutoDag = startAutoDag
stopAutoDag = stopAutoDag

Expand Down
10 changes: 8 additions & 2 deletions web3/providers/eth_tester/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,18 @@ def personal_send_transaction(eth_tester: "EthereumTester", params: Any) -> HexS
'writeMemProfile': not_implemented,
},
'miner': {
'make_dag': not_implemented,
'set_extra': not_implemented,
'set_gas_price': not_implemented,
'start': not_implemented,
'stop': not_implemented,
'start_auto_dag': not_implemented,
'stop_auto_dag': not_implemented,
# deprecated
'makeDAG': not_implemented,
'setExtra': not_implemented,
'setGasPrice': not_implemented,
'start': not_implemented,
'startAutoDAG': not_implemented,
'stop': not_implemented,
'stopAutoDAG': not_implemented,
},
'personal': {
Expand Down

0 comments on commit d85f579

Please sign in to comment.