Skip to content

Commit d46fa48

Browse files
author
Paul Robinson
committed
Merge branch 'master' into async-get-logs
2 parents 3deaeb3 + ffe59da commit d46fa48

File tree

7 files changed

+116
-45
lines changed

7 files changed

+116
-45
lines changed

docs/filters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The :meth:`web3.eth.Eth.filter` method can be used to setup filters for:
2929
3030
event_filter = mycontract.events.myEvent.createFilter(fromBlock='latest', argument_filters={'arg1':10})
3131
32-
Or built manually by supplying `valid filter params <https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter/>`_:
32+
Or built manually by supplying `valid filter params <https://github.com/ethereum/execution-apis/blob/bea0266c42919a2fb3ee524fb91e624a23bc17c5/src/schemas/filter.json#L28>`_:
3333

3434
.. code-block:: python
3535

docs/providers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ Eth
408408
- :meth:`web3.eth.block_number <web3.eth.Eth.block_number>`
409409
- :meth:`web3.eth.chain_id <web3.eth.Eth.chain_id>`
410410
- :meth:`web3.eth.coinbase <web3.eth.Eth.coinbase>`
411+
- :meth:`web3.eth.default_account <web3.eth.Eth.default_account>`
412+
- :meth:`web3.eth.default_block <web3.eth.Eth.default_block>`
411413
- :meth:`web3.eth.gas_price <web3.eth.Eth.gas_price>`
412414
- :meth:`web3.eth.hashrate <web3.eth.Eth.hashrate>`
413415
- :meth:`web3.eth.max_priority_fee <web3.eth.Eth.max_priority_fee>`

docs/web3.eth.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following properties are available on the ``web3.eth`` namespace.
4949
.. py:attribute:: Eth.default_account
5050
5151
The ethereum address that will be used as the default ``from`` address for
52-
all transactions.
52+
all transactions. Defaults to empty.
5353

5454

5555
.. py:attribute:: Eth.defaultAccount
@@ -61,7 +61,7 @@ The following properties are available on the ``web3.eth`` namespace.
6161
.. py:attribute:: Eth.default_block
6262
6363
The default block number that will be used for any RPC methods that accept
64-
a block identifier. Defaults to ``'latest'``.
64+
a block identifier. Defaults to ``'latest'``.
6565

6666

6767
.. py:attribute:: Eth.defaultBlock

newsfragments/2303.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fixed broken link to filter schema

newsfragments/2315.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add Async access to `default_account` and `default_block`

web3/_utils/module_testing/eth_module.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
HexBytes,
3636
)
3737

38+
from web3._utils.empty import (
39+
empty,
40+
)
3841
from web3._utils.ens import (
3942
ens_addresses,
4043
)
@@ -980,6 +983,41 @@ async def test_async_eth_get_logs_with_logs_none_topic_args(self, async_w3: "Web
980983
result = await async_w3.eth.get_logs(filter_params) # type: ignore
981984
assert len(result) == 0
982985

986+
def test_async_provider_default_account(
987+
self,
988+
async_w3: "Web3",
989+
unlocked_account_dual_type: ChecksumAddress
990+
) -> None:
991+
992+
# check defaults to empty
993+
default_account = async_w3.eth.default_account
994+
assert default_account is empty
995+
996+
# check setter
997+
async_w3.eth.default_account = unlocked_account_dual_type
998+
default_account = async_w3.eth.default_account
999+
assert default_account == unlocked_account_dual_type
1000+
1001+
# reset to default
1002+
async_w3.eth.default_account = empty
1003+
1004+
def test_async_provider_default_block(
1005+
self,
1006+
async_w3: "Web3",
1007+
) -> None:
1008+
1009+
# check defaults to 'latest'
1010+
default_block = async_w3.eth.default_block
1011+
assert default_block == 'latest'
1012+
1013+
# check setter
1014+
async_w3.eth.default_block = BlockNumber(12345)
1015+
default_block = async_w3.eth.default_block
1016+
assert default_block == BlockNumber(12345)
1017+
1018+
# reset to default
1019+
async_w3.eth.default_block = 'latest'
1020+
9831021

9841022
class EthModuleTest:
9851023
def test_eth_protocol_version(self, web3: "Web3") -> None:
@@ -3054,3 +3092,38 @@ def test_eth_get_raw_transaction_by_block_raises_error_block_identifier(
30543092
)
30553093
):
30563094
web3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore
3095+
3096+
def test_default_account(
3097+
self,
3098+
web3: "Web3",
3099+
unlocked_account_dual_type: ChecksumAddress
3100+
) -> None:
3101+
3102+
# check defaults to empty
3103+
default_account = web3.eth.default_account
3104+
assert default_account is empty
3105+
3106+
# check setter
3107+
web3.eth.default_account = unlocked_account_dual_type
3108+
default_account = web3.eth.default_account
3109+
assert default_account == unlocked_account_dual_type
3110+
3111+
# reset to default
3112+
web3.eth.default_account = empty
3113+
3114+
def test_default_block(
3115+
self,
3116+
web3: "Web3",
3117+
) -> None:
3118+
3119+
# check defaults to 'latest'
3120+
default_block = web3.eth.default_block
3121+
assert default_block == 'latest'
3122+
3123+
# check setter
3124+
web3.eth.default_block = BlockNumber(12345)
3125+
default_block = web3.eth.default_block
3126+
assert default_block == BlockNumber(12345)
3127+
3128+
# reset to default
3129+
web3.eth.default_block = 'latest'

web3/eth.py

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class BaseEth(Module):
117117
mungers=None,
118118
)
119119

120-
""" property default_block """
121120
@property
122121
def default_block(self) -> BlockIdentifier:
123122
return self._default_block
@@ -126,10 +125,46 @@ def default_block(self) -> BlockIdentifier:
126125
def default_block(self, value: BlockIdentifier) -> None:
127126
self._default_block = value
128127

128+
@property
129+
def defaultBlock(self) -> BlockIdentifier:
130+
warnings.warn(
131+
'defaultBlock is deprecated in favor of default_block',
132+
category=DeprecationWarning,
133+
)
134+
return self._default_block
135+
136+
@defaultBlock.setter
137+
def defaultBlock(self, value: BlockIdentifier) -> None:
138+
warnings.warn(
139+
'defaultBlock is deprecated in favor of default_block',
140+
category=DeprecationWarning,
141+
)
142+
self._default_block = value
143+
129144
@property
130145
def default_account(self) -> Union[ChecksumAddress, Empty]:
131146
return self._default_account
132147

148+
@default_account.setter
149+
def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
150+
self._default_account = account
151+
152+
@property
153+
def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
154+
warnings.warn(
155+
'defaultAccount is deprecated in favor of default_account',
156+
category=DeprecationWarning,
157+
)
158+
return self._default_account
159+
160+
@defaultAccount.setter
161+
def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
162+
warnings.warn(
163+
'defaultAccount is deprecated in favor of default_account',
164+
category=DeprecationWarning,
165+
)
166+
self._default_account = account
167+
133168
def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
134169
if 'from' not in transaction and is_checksum_address(self.default_account):
135170
transaction = assoc(transaction, 'from', self.default_account)
@@ -562,52 +597,11 @@ def chainId(self) -> int:
562597
)
563598
return self.chain_id
564599

565-
""" property default_account """
566-
@property
567-
def default_account(self) -> Union[ChecksumAddress, Empty]:
568-
return self._default_account
569-
570-
@default_account.setter
571-
def default_account(self, account: Union[ChecksumAddress, Empty]) -> None:
572-
self._default_account = account
573-
574-
@property
575-
def defaultAccount(self) -> Union[ChecksumAddress, Empty]:
576-
warnings.warn(
577-
'defaultAccount is deprecated in favor of default_account',
578-
category=DeprecationWarning,
579-
)
580-
return self._default_account
581-
582-
@defaultAccount.setter
583-
def defaultAccount(self, account: Union[ChecksumAddress, Empty]) -> None:
584-
warnings.warn(
585-
'defaultAccount is deprecated in favor of default_account',
586-
category=DeprecationWarning,
587-
)
588-
self._default_account = account
589-
590600
get_balance: Method[Callable[..., Wei]] = Method(
591601
RPC.eth_getBalance,
592602
mungers=[BaseEth.block_id_munger],
593603
)
594604

595-
@property
596-
def defaultBlock(self) -> BlockIdentifier:
597-
warnings.warn(
598-
'defaultBlock is deprecated in favor of default_block',
599-
category=DeprecationWarning,
600-
)
601-
return self._default_block
602-
603-
@defaultBlock.setter
604-
def defaultBlock(self, value: BlockIdentifier) -> None:
605-
warnings.warn(
606-
'defaultBlock is deprecated in favor of default_block',
607-
category=DeprecationWarning,
608-
)
609-
self._default_block = value
610-
611605
@property
612606
def max_priority_fee(self) -> Wei:
613607
return self._max_priority_fee()

0 commit comments

Comments
 (0)