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 == 61
39
-
40
-
41
- def test_set_chain_id (w3 ):
42
- assert w3 .eth .chain_id == 61
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 == 61
49
-
50
-
51
- @pytest .mark .asyncio
52
- async def test_async_set_chain_id (async_w3 ):
53
- assert await async_w3 .eth .chain_id == 61
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 == 61
Original file line number Diff line number Diff line change 114
114
class BaseEth (Module ):
115
115
_default_account : Union [ChecksumAddress , Empty ] = empty
116
116
_default_block : BlockIdentifier = "latest"
117
- _default_chain_id : Optional [int ] = None
118
117
gasPriceStrategy = None
119
118
120
119
_gas_price : Method [Callable [[], Wei ]] = Method (
@@ -358,14 +357,7 @@ async def block_number(self) -> BlockNumber:
358
357
359
358
@property
360
359
async def chain_id (self ) -> int :
361
- if self ._default_chain_id is None :
362
- return await self ._chain_id () # type: ignore
363
- else :
364
- return self ._default_chain_id
365
-
366
- @chain_id .setter
367
- def chain_id (self , value : int ) -> None :
368
- self ._default_chain_id = value
360
+ return await self ._chain_id () # type: ignore
369
361
370
362
@property
371
363
async def coinbase (self ) -> ChecksumAddress :
@@ -637,14 +629,7 @@ def blockNumber(self) -> BlockNumber:
637
629
638
630
@property
639
631
def chain_id (self ) -> int :
640
- if self ._default_chain_id is None :
641
- return self ._chain_id ()
642
- else :
643
- return self ._default_chain_id
644
-
645
- @chain_id .setter
646
- def chain_id (self , value : int ) -> None :
647
- self ._default_chain_id = value
632
+ return self ._chain_id ()
648
633
649
634
@property
650
635
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