Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth.defaultBlock -> eth.default_block #1849

Merged
merged 3 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ The following properties are available on the ``web3.eth`` namespace.
The ethereum address that will be used as the default ``from`` address for
all transactions.


.. py:attribute:: Eth.defaultAccount

.. warning:: Deprecated: This property is deprecated in favor of
:attr:`~web3.eth.Eth.default_account`


.. py:attribute:: Eth.defaultBlock
.. py:attribute:: Eth.default_block

The default block number that will be used for any RPC methods that accept
a block identifier. Defaults to ``'latest'``.


.. py:attribute:: Eth.defaultBlock

.. warning:: Deprecated: This property is deprecated in favor of
:attr:`~web3.eth.Eth.default_block`


.. py:attribute:: Eth.syncing

* Delegates to ``eth_syncing`` RPC Method
Expand Down Expand Up @@ -176,7 +183,7 @@ Methods
The following methods are available on the ``web3.eth`` namespace.


.. py:method:: Eth.get_balance(account, block_identifier=eth.defaultBlock)
.. py:method:: Eth.get_balance(account, block_identifier=eth.default_block)

* Delegates to ``eth_getBalance`` RPC Method

Expand All @@ -191,13 +198,13 @@ The following methods are available on the ``web3.eth`` namespace.
77320681768999138915


.. py:method:: Eth.getBalance(account, block_identifier=eth.defaultBlock)
.. py:method:: Eth.getBalance(account, block_identifier=eth.default_block)

.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.get_balance()`


.. py:method:: Eth.get_storage_at(account, position, block_identifier=eth.defaultBlock)
.. py:method:: Eth.get_storage_at(account, position, block_identifier=eth.default_block)

* Delegates to ``eth_getStorageAt`` RPC Method

Expand All @@ -212,13 +219,13 @@ The following methods are available on the ``web3.eth`` namespace.
'0x00000000000000000000000000000000000000000000000000120a0b063499d4'


.. py:method:: Eth.getStorageAt(account, position, block_identifier=eth.defaultBlock)
.. py:method:: Eth.getStorageAt(account, position, block_identifier=eth.default_block)

.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_storage_at`


.. py:method:: Eth.getProof(account, positions, block_identifier=eth.defaultBlock)
.. py:method:: Eth.getProof(account, positions, block_identifier=eth.default_block)

* Delegates to ``eth_getProof`` RPC Method

Expand Down Expand Up @@ -319,7 +326,7 @@ The following methods are available on the ``web3.eth`` namespace.
assert verify_eth_getProof(proof, block.stateRoot)


.. py:method:: Eth.getCode(account, block_identifier=eth.defaultBlock)
.. py:method:: Eth.getCode(account, block_identifier=eth.default_block)

* Delegates to ``eth_getCode`` RPC Method

Expand All @@ -338,7 +345,7 @@ The following methods are available on the ``web3.eth`` namespace.
'0x'


.. py:method:: Eth.get_block(block_identifier=eth.defaultBlock, full_transactions=False)
.. py:method:: Eth.get_block(block_identifier=eth.default_block, full_transactions=False)

* Delegates to ``eth_getBlockByNumber`` or ``eth_getBlockByHash`` RPC Methods

Expand Down Expand Up @@ -376,7 +383,7 @@ The following methods are available on the ``web3.eth`` namespace.
'uncles': [],
})

.. py:method:: Eth.getBlock(block_identifier=eth.defaultBlock, full_transactions=False)
.. py:method:: Eth.getBlock(block_identifier=eth.default_block, full_transactions=False)

.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_block`
Expand Down Expand Up @@ -612,7 +619,7 @@ The following methods are available on the ``web3.eth`` namespace.
})


.. py:method:: Eth.getTransactionCount(account, block_identifier=web3.eth.defaultBlock)
.. py:method:: Eth.getTransactionCount(account, block_identifier=web3.eth.default_block)

* Delegates to ``eth_getTransactionCount`` RPC Method

Expand Down Expand Up @@ -819,7 +826,7 @@ The following methods are available on the ``web3.eth`` namespace.
``account`` may be a checksum address or an ENS name


.. py:method:: Eth.call(transaction, block_identifier=web3.eth.defaultBlock)
.. py:method:: Eth.call(transaction, block_identifier=web3.eth.default_block)

* Delegates to ``eth_call`` RPC Method

Expand Down
2 changes: 2 additions & 0 deletions newsfragments/1849.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``eth.default_block``, deprecate ``eth.defaultBlock``.
Also adds ``parity.default_block``, and deprecates ``parity.defaultBlock``.
6 changes: 6 additions & 0 deletions tests/core/eth-module/test_default_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def test_uses_defaultAccount_when_set_with_warning(web3, extra_accounts,
wait_for_transaction):
with pytest.warns(DeprecationWarning):
web3.eth.defaultAccount = extra_accounts[2]

with pytest.warns(DeprecationWarning):
assert web3.eth.defaultAccount == extra_accounts[2]

txn_hash = web3.eth.sendTransaction({
Expand Down Expand Up @@ -58,6 +60,10 @@ def test_uses_given_from_address_when_provided_with_warning(web3, extra_accounts
wait_for_transaction):
with pytest.warns(DeprecationWarning):
web3.eth.defaultAccount = extra_accounts[2]

with pytest.warns(DeprecationWarning):
assert web3.eth.defaultAccount == extra_accounts[2]

txn_hash = web3.eth.sendTransaction({
"from": extra_accounts[5],
"to": extra_accounts[1],
Expand Down
25 changes: 25 additions & 0 deletions tests/core/eth-module/test_default_block_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest


@pytest.fixture(autouse=True)
def wait_for_first_block(web3, wait_for_block):
wait_for_block(web3)


def test_uses_default_block(web3, extra_accounts,
wait_for_transaction):
assert(web3.eth.default_block == 'latest')
web3.eth.default_block = web3.eth.blockNumber
assert(web3.eth.default_block == web3.eth.blockNumber)


def test_uses_default_block_with_warning(web3, extra_accounts,
wait_for_transaction):
with pytest.warns(DeprecationWarning):
assert web3.eth.defaultBlock == 'latest'

with pytest.warns(DeprecationWarning):
web3.eth.defaultBlock = web3.eth.blockNumber

with pytest.warns(DeprecationWarning):
assert web3.eth.defaultBlock == web3.eth.blockNumber
51 changes: 38 additions & 13 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
from web3._utils.blocks import (
select_method_for_block_identifier,
)
from web3._utils.compat import (
Literal,
)
from web3._utils.empty import (
Empty,
empty,
Expand Down Expand Up @@ -106,8 +103,8 @@

class Eth(ModuleV2, Module):
account = Account()
_default_account: Union[Empty, ChecksumAddress] = empty
defaultBlock: Literal["latest"] = "latest" # noqa: E704
_default_account: Union[ChecksumAddress, Empty] = empty
_default_block: BlockIdentifier = "latest"
defaultContractFactory: Type[Union[Contract, ConciseContract, ContractCaller]] = Contract # noqa: E704,E501
iban = Iban
gasPriceStrategy = None
Expand Down Expand Up @@ -199,37 +196,65 @@ def blockNumber(self) -> BlockNumber:
def chainId(self) -> int:
return self.web3.manager.request_blocking(RPC.eth_chainId, [])

""" property default_account """

@property
def default_account(self) -> Union[Empty, ChecksumAddress]:
def default_account(self) -> Union[ChecksumAddress, Empty]:
return self._default_account

@default_account.setter
def default_account(self, account: Union[Empty, ChecksumAddress]) -> None:
def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
self._default_account = account

@property
def defaultAccount(self) -> Union[Empty, ChecksumAddress]:
def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
return self._default_account

@defaultAccount.setter
def defaultAccount(self, account: Union[Empty, ChecksumAddress]) -> None:
def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
self._default_account = account

""" property default_block """

@property
def default_block(self) -> BlockIdentifier:
return self._default_block

@default_block.setter
def default_block(self, value: BlockIdentifier) -> None:
self._default_block = value

@property
def defaultBlock(self) -> BlockIdentifier:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
return self._default_block

@defaultBlock.setter
def defaultBlock(self, value: BlockIdentifier) -> None:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
self._default_block = value

def block_id_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], BlockIdentifier]:
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block
return (account, block_identifier)

get_balance: Method[Callable[..., Wei]] = Method(
Expand All @@ -244,7 +269,7 @@ def get_storage_at_munger(
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block
return (account, position, block_identifier)

get_storage_at: Method[Callable[..., HexBytes]] = Method(
Expand All @@ -259,7 +284,7 @@ def get_proof_munger(
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], Sequence[int], Optional[BlockIdentifier]]:
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block
return (account, positions, block_identifier)

getProof: Method[
Expand Down Expand Up @@ -455,7 +480,7 @@ def call_munger(

# TODO: move to middleware
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block

return (transaction, block_identifier)

Expand Down
36 changes: 30 additions & 6 deletions web3/parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Tuple,
Union,
)
import warnings

from eth_typing import (
Address,
Expand All @@ -19,9 +20,6 @@
assoc,
)

from web3._utils.compat import (
Literal,
)
from web3._utils.personal import (
ec_recover,
ecRecover,
Expand Down Expand Up @@ -90,14 +88,40 @@ class Parity(ModuleV2):
"""
https://paritytech.github.io/wiki/JSONRPC-parity-module
"""
defaultBlock: Literal["latest"] = "latest" # noqa: E704
_default_block: BlockIdentifier = "latest"
personal: ParityPersonal

enode: Method[Callable[[], str]] = Method(
RPC.parity_enode,
mungers=None,
)

""" property default_block """

@property
def default_block(self) -> BlockIdentifier:
return self._default_block

@default_block.setter
def default_block(self, value: BlockIdentifier) -> None:
self._default_block = value

@property
def defaultBlock(self) -> BlockIdentifier:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
return self._default_block

@defaultBlock.setter
def defaultBlock(self, value: BlockIdentifier) -> None:
warnings.warn(
'defaultBlock is deprecated in favor of default_block',
category=DeprecationWarning,
)
self._default_block = value

def list_storage_keys_munger(
self,
address: Union[Address, ChecksumAddress, ENS, Hash32],
Expand All @@ -106,7 +130,7 @@ def list_storage_keys_munger(
block_identifier: Optional[BlockIdentifier] = None,
) -> Tuple[Union[Address, ChecksumAddress, ENS, Hash32], int, Hash32, BlockIdentifier]:
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block
return (address, quantity, hash_, block_identifier)

listStorageKeys: Method[Callable[..., List[Hash32]]] = Method(
Expand Down Expand Up @@ -166,7 +190,7 @@ def trace_call_munger(

# TODO: move to middleware
if block_identifier is None:
block_identifier = self.defaultBlock
block_identifier = self.default_block

return (transaction, mode, block_identifier)

Expand Down