Skip to content

Commit

Permalink
Merge branch 'master' into async-get-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Robinson authored Jan 25, 2022
2 parents 3deaeb3 + ffe59da commit aacc056
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 46 deletions.
2 changes: 1 addition & 1 deletion docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The :meth:`web3.eth.Eth.filter` method can be used to setup filters for:
event_filter = mycontract.events.myEvent.createFilter(fromBlock='latest', argument_filters={'arg1':10})
Or built manually by supplying `valid filter params <https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter/>`_:
Or built manually by supplying `valid filter params <https://github.com/ethereum/execution-apis/blob/bea0266c42919a2fb3ee524fb91e624a23bc17c5/src/schemas/filter.json#L28>`_:

.. code-block:: python
Expand Down
2 changes: 2 additions & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ Eth
- :meth:`web3.eth.block_number <web3.eth.Eth.block_number>`
- :meth:`web3.eth.chain_id <web3.eth.Eth.chain_id>`
- :meth:`web3.eth.coinbase <web3.eth.Eth.coinbase>`
- :meth:`web3.eth.default_account <web3.eth.Eth.default_account>`
- :meth:`web3.eth.default_block <web3.eth.Eth.default_block>`
- :meth:`web3.eth.gas_price <web3.eth.Eth.gas_price>`
- :meth:`web3.eth.hashrate <web3.eth.Eth.hashrate>`
- :meth:`web3.eth.max_priority_fee <web3.eth.Eth.max_priority_fee>`
Expand Down
4 changes: 2 additions & 2 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The following properties are available on the ``web3.eth`` namespace.
.. py:attribute:: Eth.default_account
The ethereum address that will be used as the default ``from`` address for
all transactions.
all transactions. Defaults to empty.


.. py:attribute:: Eth.defaultAccount
Expand All @@ -61,7 +61,7 @@ The following properties are available on the ``web3.eth`` namespace.
.. 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'``.
a block identifier. Defaults to ``'latest'``.


.. py:attribute:: Eth.defaultBlock
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2303.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed broken link to filter schema
1 change: 1 addition & 0 deletions newsfragments/2315.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add Async access to `default_account` and `default_block`
75 changes: 74 additions & 1 deletion web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
HexBytes,
)

from web3._utils.empty import (
empty,
)
from web3._utils.ens import (
ens_addresses,
)
Expand Down Expand Up @@ -844,7 +847,7 @@ async def test_async_eth_accounts(self, async_w3: "Web3") -> None:
in accounts
))
assert await async_w3.eth.coinbase in accounts # type: ignore

@pytest.mark.asyncio
async def test_async_eth_get_logs_without_logs(
self, async_w3: "Web3", block_with_txn_with_log: BlockData
Expand Down Expand Up @@ -979,6 +982,41 @@ async def test_async_eth_get_logs_with_logs_none_topic_args(self, async_w3: "Web

result = await async_w3.eth.get_logs(filter_params) # type: ignore
assert len(result) == 0

def test_async_provider_default_account(
self,
async_w3: "Web3",
unlocked_account_dual_type: ChecksumAddress
) -> None:

# check defaults to empty
default_account = async_w3.eth.default_account
assert default_account is empty

# check setter
async_w3.eth.default_account = unlocked_account_dual_type
default_account = async_w3.eth.default_account
assert default_account == unlocked_account_dual_type

# reset to default
async_w3.eth.default_account = empty

def test_async_provider_default_block(
self,
async_w3: "Web3",
) -> None:

# check defaults to 'latest'
default_block = async_w3.eth.default_block
assert default_block == 'latest'

# check setter
async_w3.eth.default_block = BlockNumber(12345)
default_block = async_w3.eth.default_block
assert default_block == BlockNumber(12345)

# reset to default
async_w3.eth.default_block = 'latest'


class EthModuleTest:
Expand Down Expand Up @@ -3054,3 +3092,38 @@ def test_eth_get_raw_transaction_by_block_raises_error_block_identifier(
)
):
web3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore

def test_default_account(
self,
web3: "Web3",
unlocked_account_dual_type: ChecksumAddress
) -> None:

# check defaults to empty
default_account = web3.eth.default_account
assert default_account is empty

# check setter
web3.eth.default_account = unlocked_account_dual_type
default_account = web3.eth.default_account
assert default_account == unlocked_account_dual_type

# reset to default
web3.eth.default_account = empty

def test_default_block(
self,
web3: "Web3",
) -> None:

# check defaults to 'latest'
default_block = web3.eth.default_block
assert default_block == 'latest'

# check setter
web3.eth.default_block = BlockNumber(12345)
default_block = web3.eth.default_block
assert default_block == BlockNumber(12345)

# reset to default
web3.eth.default_block = 'latest'
78 changes: 36 additions & 42 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class BaseEth(Module):
mungers=None,
)

""" property default_block """
@property
def default_block(self) -> BlockIdentifier:
return self._default_block
Expand All @@ -126,10 +125,46 @@ def default_block(self) -> BlockIdentifier:
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

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

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

@property
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[ChecksumAddress, Empty]) -> None:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
self._default_account = account

def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
if 'from' not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, 'from', self.default_account)
Expand Down Expand Up @@ -562,52 +597,11 @@ def chainId(self) -> int:
)
return self.chain_id

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

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

@property
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[ChecksumAddress, Empty]) -> None:
warnings.warn(
'defaultAccount is deprecated in favor of default_account',
category=DeprecationWarning,
)
self._default_account = account

get_balance: Method[Callable[..., Wei]] = Method(
RPC.eth_getBalance,
mungers=[BaseEth.block_id_munger],
)

@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

@property
def max_priority_fee(self) -> Wei:
return self._max_priority_fee()
Expand Down

0 comments on commit aacc056

Please sign in to comment.