|
4 | 4 | ClientSession, |
5 | 5 | ) |
6 | 6 |
|
| 7 | +from web3 import Web3 |
7 | 8 | from web3._utils import ( |
8 | 9 | request, |
9 | 10 | ) |
| 11 | +from web3.eth import ( |
| 12 | + AsyncEth, |
| 13 | +) |
| 14 | +from web3.geth import ( |
| 15 | + AsyncGethAdmin, |
| 16 | + AsyncGethPersonal, |
| 17 | + AsyncGethTxPool, |
| 18 | + Geth, |
| 19 | +) |
| 20 | +from web3.middleware import ( |
| 21 | + async_buffered_gas_estimate_middleware, |
| 22 | + async_gas_price_strategy_middleware, |
| 23 | + async_validation_middleware, |
| 24 | +) |
| 25 | +from web3.net import ( |
| 26 | + AsyncNet, |
| 27 | +) |
10 | 28 | from web3.providers.async_rpc import ( |
11 | 29 | AsyncHTTPProvider, |
12 | 30 | ) |
13 | 31 |
|
| 32 | +URI = "http://mynode.local:8545" |
| 33 | + |
| 34 | + |
| 35 | +def test_no_args(): |
| 36 | + provider = AsyncHTTPProvider() |
| 37 | + w3 = Web3(provider) |
| 38 | + assert w3.manager.provider == provider |
| 39 | + assert w3.manager.provider.is_async |
| 40 | + |
| 41 | + |
| 42 | +def test_init_kwargs(): |
| 43 | + provider = AsyncHTTPProvider(endpoint_uri=URI, request_kwargs={"timeout": 60}) |
| 44 | + w3 = Web3(provider) |
| 45 | + assert w3.manager.provider == provider |
| 46 | + |
| 47 | + |
| 48 | +def test_web3_with_async_http_provider_has_default_middlewares_and_modules() -> None: |
| 49 | + async_w3 = Web3(AsyncHTTPProvider(endpoint_uri="http://mynode.local:8545")) |
| 50 | + |
| 51 | + # assert default modules |
| 52 | + |
| 53 | + assert isinstance(async_w3.eth, AsyncEth) |
| 54 | + assert isinstance(async_w3.geth, Geth) |
| 55 | + assert isinstance(async_w3.async_net, AsyncNet) |
| 56 | + assert isinstance(async_w3.geth.admin, AsyncGethAdmin) |
| 57 | + assert isinstance(async_w3.geth.personal, AsyncGethPersonal) |
| 58 | + assert isinstance(async_w3.geth.txpool, AsyncGethTxPool) |
| 59 | + |
| 60 | + # assert default middleware |
| 61 | + |
| 62 | + # the following length check should fail and will need to be added to once more |
| 63 | + # async middlewares are added to the defaults |
| 64 | + assert len(async_w3.middleware_onion.middlewares) == 3 |
| 65 | + |
| 66 | + assert ( |
| 67 | + async_w3.middleware_onion.get("gas_price_strategy") |
| 68 | + == async_gas_price_strategy_middleware |
| 69 | + ) |
| 70 | + assert async_w3.middleware_onion.get("validation") == async_validation_middleware |
| 71 | + assert ( |
| 72 | + async_w3.middleware_onion.get("gas_estimate") |
| 73 | + == async_buffered_gas_estimate_middleware |
| 74 | + ) |
| 75 | + |
14 | 76 |
|
15 | 77 | @pytest.mark.asyncio |
16 | 78 | async def test_user_provided_session() -> None: |
17 | 79 | session = ClientSession() |
18 | | - provider = AsyncHTTPProvider(endpoint_uri="http://mynode.local:8545") |
| 80 | + provider = AsyncHTTPProvider(endpoint_uri=URI) |
19 | 81 | cached_session = await provider.cache_async_session(session) |
20 | 82 | assert len(request._async_session_cache) == 1 |
21 | 83 | assert cached_session == session |
0 commit comments