File tree 3 files changed +38
-1
lines changed 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change
1
+ Add async default_chain_id and chain_id setter
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
+
3
21
4
22
def test_eth_protocol_version (w3 ):
5
23
with pytest .warns (DeprecationWarning ):
@@ -28,3 +46,14 @@ def test_set_chain_id(w3):
28
46
29
47
w3 .eth .chain_id = None
30
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 @@ -358,7 +358,14 @@ async def block_number(self) -> BlockNumber:
358
358
359
359
@property
360
360
async def chain_id (self ) -> int :
361
- return await self ._chain_id () # type: ignore
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
362
369
363
370
@property
364
371
async def coinbase (self ) -> ChecksumAddress :
You can’t perform that action at this time.
0 commit comments