File tree 7 files changed +16
-58
lines changed 7 files changed +16
-58
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,18 @@ The following properties are available on the ``web3.eth`` namespace.
216
216
>> > web3.eth.chain_id
217
217
61
218
218
219
+ .. note ::
220
+
221
+ This property gets called frequently in validation middleware,
222
+ but `chain_id ` is added to the ``simple_cache_middleware `` by default.
223
+ Add the :meth: `simple_cache_middleware<web3.middleware.construct_simple_cache_middleware> `
224
+ to the ``middleware_onion `` to increase performance:
225
+
226
+ .. code-block :: python
227
+
228
+ >> > from web3.middleware import simple_cache_middleware
229
+ >> > w3.middleware_onion.add(simple_cache_middleare)
230
+
219
231
220
232
.. py :attribute :: Eth.chainId
221
233
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ Add sync chain_id to ``simple_middleware_cache ``
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
3
- from web3 import Web3
4
- from web3 .eth import (
5
- AsyncEth ,
6
- )
7
- from web3 .providers .eth_tester .main import (
8
- AsyncEthereumTesterProvider ,
9
- )
10
-
11
-
12
- @pytest .fixture
13
- def async_w3 ():
14
- return Web3 (
15
- AsyncEthereumTesterProvider (),
16
- middlewares = [],
17
- modules = {
18
- 'eth' : (AsyncEth ,),
19
- })
20
-
21
3
22
4
def test_eth_protocol_version (w3 ):
23
5
with pytest .warns (DeprecationWarning ):
@@ -36,24 +18,3 @@ def test_eth_chain_id(w3):
36
18
def test_eth_chainId (w3 ):
37
19
with pytest .warns (DeprecationWarning ):
38
20
assert w3 .eth .chainId == 131277322940537
39
-
40
-
41
- def test_set_chain_id (w3 ):
42
- assert w3 .eth .chain_id == 131277322940537
43
-
44
- w3 .eth .chain_id = 72
45
- assert w3 .eth .chain_id == 72
46
-
47
- w3 .eth .chain_id = None
48
- assert w3 .eth .chain_id == 131277322940537
49
-
50
-
51
- @pytest .mark .asyncio
52
- async def test_async_set_chain_id (async_w3 ):
53
- assert await async_w3 .eth .chain_id == 131277322940537
54
-
55
- async_w3 .eth .chain_id = 72
56
- assert await async_w3 .eth .chain_id == 72
57
-
58
- async_w3 .eth .chain_id = None
59
- assert await async_w3 .eth .chain_id == 131277322940537
Original file line number Diff line number Diff line change 116
116
class BaseEth (Module ):
117
117
_default_account : Union [ChecksumAddress , Empty ] = empty
118
118
_default_block : BlockIdentifier = "latest"
119
- _default_chain_id : Optional [int ] = None
120
119
gasPriceStrategy = None
121
120
defaultContractFactory : Any = None
122
121
@@ -386,14 +385,7 @@ async def block_number(self) -> BlockNumber:
386
385
387
386
@property
388
387
async def chain_id (self ) -> int :
389
- if self ._default_chain_id is None :
390
- return await self ._chain_id () # type: ignore
391
- else :
392
- return self ._default_chain_id
393
-
394
- @chain_id .setter
395
- def chain_id (self , value : int ) -> None :
396
- self ._default_chain_id = value
388
+ return await self ._chain_id () # type: ignore
397
389
398
390
@property
399
391
async def coinbase (self ) -> ChecksumAddress :
@@ -665,14 +657,7 @@ def blockNumber(self) -> BlockNumber:
665
657
666
658
@property
667
659
def chain_id (self ) -> int :
668
- if self ._default_chain_id is None :
669
- return self ._chain_id ()
670
- else :
671
- return self ._default_chain_id
672
-
673
- @chain_id .setter
674
- def chain_id (self , value : int ) -> None :
675
- self ._default_chain_id = value
660
+ return self ._chain_id ()
676
661
677
662
@property
678
663
def chainId (self ) -> int :
Original file line number Diff line number Diff line change 82
82
# 'eth_getWork',
83
83
# 'eth_submitWork',
84
84
# 'eth_submitHashrate',
85
+ 'eth_chainId' ,
85
86
})
86
87
87
88
You can’t perform that action at this time.
0 commit comments