Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V7 support for request batching #3370

Merged
merged 18 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ccb99d5
Add basic support of batch requests to `AsyncHTTPProvider`
dmkulazhenko Sep 20, 2023
398a6f6
Fix typing for Python<3.9
dmkulazhenko Sep 21, 2023
6cc7a7a
Initial commit for batch requests support
fselmo Nov 2, 2023
c293fcd
Batch requests async improvements; implement ``add_mapping()``:
fselmo Feb 8, 2024
72a4311
Add batch support for contract calls
fselmo Apr 29, 2024
b64a4bd
Add batch support to remaining providers:
fselmo Apr 29, 2024
d76e1da
Request information cache updates for request batching [persistent conn]
fselmo Apr 30, 2024
2c4ff79
Move batching to web3 module; Re-structure Web3Module tests:
fselmo Apr 30, 2024
0237e86
Move provider type validation to ``_batch_requests`` method.
fselmo Apr 30, 2024
eb5bc8f
Return responses sorted by response ids in each provider case
fselmo Apr 30, 2024
024d2c8
Refactor batch logic to allow for object assignment as per #832
fselmo Apr 30, 2024
3997a30
Some changes to batcher API; More tests for robustness:
fselmo May 2, 2024
cfd25cc
Make sure we sort list responses before caching
fselmo May 2, 2024
1bc0240
Clarify logic in contract call abstraction for batch requests
fselmo May 6, 2024
723940d
Refactor common ipc provider logic for making requests & batch requests.
fselmo May 6, 2024
3b9d3fb
More appropriately set batching logic on the JSONBaseProvider class
fselmo May 6, 2024
827788d
Attempt to mitigate issues in matching responses to request ids:
fselmo May 9, 2024
56adab1
changes from comments on PR #3370:
fselmo May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3370.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for request batching via ``w3.batch_requests()`` context manager (sync and async).
19 changes: 15 additions & 4 deletions tests/integration/go_ethereum/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
NetModuleTest,
Web3ModuleTest,
)
from web3._utils.module_testing.web3_module import (
AsyncWeb3ModuleTest,
)
from web3.types import (
BlockData,
)
Expand All @@ -27,7 +30,7 @@
)


class GoEthereumTest(Web3ModuleTest):
class GoEthereumWeb3ModuleTest(Web3ModuleTest):
def _check_web3_client_version(self, client_version):
assert client_version.startswith("Geth/")

Expand Down Expand Up @@ -85,12 +88,16 @@ class GoEthereumNetModuleTest(NetModuleTest):
pass


class GoEthereumAsyncNetModuleTest(AsyncNetModuleTest):
class GoEthereumAdminModuleTest(GoEthereumAdminModuleTest):
pass


class GoEthereumAdminModuleTest(GoEthereumAdminModuleTest):
pass
# --- async --- #


class GoEthereumAsyncWeb3ModuleTest(AsyncWeb3ModuleTest):
def _check_web3_client_version(self, client_version):
assert client_version.startswith("Geth/")


class GoEthereumAsyncEthModuleTest(AsyncEthModuleTest):
Expand All @@ -111,3 +118,7 @@ async def test_invalid_eth_sign_typed_data(
await super().test_invalid_eth_sign_typed_data(
async_w3, keyfile_account_address_dual_type, async_skip_if_testrpc
)


class GoEthereumAsyncNetModuleTest(AsyncNetModuleTest):
pass
9 changes: 7 additions & 2 deletions tests/integration/go_ethereum/test_goethereum_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
GoEthereumAsyncEthModuleTest,
GoEthereumAsyncNetModuleTest,
GoEthereumAsyncTxPoolModuleTest,
GoEthereumAsyncWeb3ModuleTest,
GoEthereumEthModuleTest,
GoEthereumNetModuleTest,
GoEthereumTest,
GoEthereumTxPoolModuleTest,
GoEthereumWeb3ModuleTest,
)
from .utils import (
wait_for_aiohttp,
Expand Down Expand Up @@ -70,7 +71,7 @@ def w3(geth_process, endpoint_uri):
return Web3(Web3.HTTPProvider(endpoint_uri))


class TestGoEthereumTest(GoEthereumTest):
class TestGoEthereumWeb3ModuleTest(GoEthereumWeb3ModuleTest):
fselmo marked this conversation as resolved.
Show resolved Hide resolved
pass


Expand Down Expand Up @@ -116,6 +117,10 @@ async def async_w3(geth_process, endpoint_uri):
return _w3


class TestGoEthereumAsyncWeb3ModuleTest(GoEthereumAsyncWeb3ModuleTest):
pass


class TestGoEthereumAsyncAdminModuleTest(GoEthereumAsyncAdminModuleTest):
@pytest.mark.asyncio
@pytest.mark.xfail(
Expand Down
35 changes: 25 additions & 10 deletions tests/integration/go_ethereum/test_goethereum_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
AsyncWeb3,
Web3,
)
from web3._utils.module_testing.persistent_connection_provider import (
PersistentConnectionProviderTest,
)

from .common import (
GoEthereumAdminModuleTest,
GoEthereumAsyncEthModuleTest,
GoEthereumAsyncNetModuleTest,
GoEthereumAsyncWeb3ModuleTest,
GoEthereumEthModuleTest,
GoEthereumNetModuleTest,
GoEthereumTest,
GoEthereumWeb3ModuleTest,
)
from .utils import (
wait_for_async_socket,
Expand Down Expand Up @@ -53,14 +57,15 @@ def w3(geth_process, geth_ipc_path):
return Web3(Web3.IPCProvider(geth_ipc_path, timeout=30))


@pytest_asyncio.fixture(scope="module")
async def async_w3(geth_process, geth_ipc_path):
await wait_for_async_socket(geth_ipc_path)
async with AsyncWeb3(AsyncIPCProvider(geth_ipc_path)) as _aw3:
yield _aw3
class TestGoEthereumWeb3ModuleTest(GoEthereumWeb3ModuleTest):
pass


class TestGoEthereumTest(GoEthereumTest):
class TestGoEthereumEthModuleTest(GoEthereumEthModuleTest):
pass


class TestGoEthereumNetModuleTest(GoEthereumNetModuleTest):
pass


Expand All @@ -84,17 +89,27 @@ def test_admin_start_stop_ws(self, w3: "Web3") -> None:
super().test_admin_start_stop_ws(w3)


class TestGoEthereumEthModuleTest(GoEthereumEthModuleTest):
# -- async -- #


@pytest_asyncio.fixture(scope="module")
async def async_w3(geth_process, geth_ipc_path):
await wait_for_async_socket(geth_ipc_path)
async with AsyncWeb3(AsyncIPCProvider(geth_ipc_path)) as _aw3:
yield _aw3


class TestGoEthereumAsyncWeb3ModuleTest(GoEthereumAsyncWeb3ModuleTest):
pass


class TestGoEthereumAsyncEthModuleTest(GoEthereumAsyncEthModuleTest):
pass


class TestGoEthereumNetModuleTest(GoEthereumNetModuleTest):
class TestGoEthereumAsyncNetModuleTest(GoEthereumAsyncNetModuleTest):
pass


class TestGoEthereumAsyncNetModuleTest(GoEthereumAsyncNetModuleTest):
class TestPersistentConnectionProviderTest(PersistentConnectionProviderTest):
pass
4 changes: 2 additions & 2 deletions tests/integration/go_ethereum/test_goethereum_legacy_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
GoEthereumAdminModuleTest,
GoEthereumEthModuleTest,
GoEthereumNetModuleTest,
GoEthereumTest,
GoEthereumWeb3ModuleTest,
)


Expand Down Expand Up @@ -70,7 +70,7 @@ def w3(geth_process, endpoint_uri):
return _w3


class TestGoEthereumTest(GoEthereumTest):
class TestGoEthereumWeb3ModuleTest(GoEthereumWeb3ModuleTest):
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..common import (
GoEthereumAsyncEthModuleTest,
GoEthereumAsyncNetModuleTest,
GoEthereumAsyncWeb3ModuleTest,
)
from ..utils import (
wait_for_aiohttp,
Expand All @@ -30,6 +31,10 @@ async def async_w3(geth_process, endpoint_uri):
return await AsyncWeb3(WebSocketProvider(endpoint_uri))


class TestGoEthereumAsyncWeb3ModuleTest(GoEthereumAsyncWeb3ModuleTest):
pass


class TestGoEthereumAsyncAdminModuleTest(GoEthereumAsyncAdminModuleTest):
@pytest.mark.asyncio
@pytest.mark.xfail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..common import (
GoEthereumAsyncEthModuleTest,
GoEthereumAsyncNetModuleTest,
GoEthereumAsyncWeb3ModuleTest,
)
from ..utils import (
wait_for_aiohttp,
Expand All @@ -31,6 +32,10 @@ async def async_w3(geth_process, endpoint_uri):
yield w3


class TestGoEthereumAsyncWeb3ModuleTest(GoEthereumAsyncWeb3ModuleTest):
pass


class TestGoEthereumAsyncAdminModuleTest(GoEthereumAsyncAdminModuleTest):
@pytest.mark.asyncio
@pytest.mark.xfail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..common import (
GoEthereumAsyncEthModuleTest,
GoEthereumAsyncNetModuleTest,
GoEthereumAsyncWeb3ModuleTest,
)
from ..utils import (
wait_for_aiohttp,
Expand All @@ -31,6 +32,10 @@ async def async_w3(geth_process, endpoint_uri):
return w3


class TestGoEthereumAsyncWeb3ModuleTest(GoEthereumAsyncWeb3ModuleTest):
pass


class TestGoEthereumAsyncAdminModuleTest(GoEthereumAsyncAdminModuleTest):
@pytest.mark.asyncio
@pytest.mark.xfail(
Expand Down
28 changes: 23 additions & 5 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
)
from web3.exceptions import (
MethodUnavailable,
Web3TypeError,
)
from web3.providers.eth_tester import (
EthereumTesterProvider,
Expand Down Expand Up @@ -221,11 +222,6 @@ def keyfile_account_address_dual_type(keyfile_account_address, address_conversio
yield keyfile_account_address


class TestEthereumTesterWeb3Module(Web3ModuleTest):
def _check_web3_client_version(self, client_version):
assert client_version.startswith("EthereumTester/")


def not_implemented(method, exc_type=NotImplementedError):
@functools.wraps(method)
def inner(*args, **kwargs):
Expand All @@ -250,6 +246,28 @@ def func_wrapper(self, eth_tester, *args, **kwargs):
return func_wrapper


class TestEthereumTesterWeb3Module(Web3ModuleTest):
def _check_web3_client_version(self, client_version):
assert client_version.startswith("EthereumTester/")

test_batch_requests = not_implemented(
Web3ModuleTest.test_batch_requests, Web3TypeError
)
test_batch_requests_raises_for_common_unsupported_methods = not_implemented(
Web3ModuleTest.test_batch_requests_raises_for_common_unsupported_methods,
Web3TypeError,
)
test_batch_requests_initialized_as_object = not_implemented(
Web3ModuleTest.test_batch_requests_initialized_as_object, Web3TypeError
)
test_batch_requests_cancel = not_implemented(
Web3ModuleTest.test_batch_requests_cancel, Web3TypeError
)
test_batch_requests_clear = not_implemented(
Web3ModuleTest.test_batch_requests_clear, Web3TypeError
)


class TestEthereumTesterEthModule(EthModuleTest):
test_eth_sign = not_implemented(EthModuleTest.test_eth_sign, MethodUnavailable)
test_eth_sign_ens_names = not_implemented(
Expand Down
Loading