-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow eth.filter to return appropriate sync/async filter types (#2645)
* update method_formatters.py to select the appropriate sync/async filter type
- Loading branch information
Paul Robinson
committed
Dec 19, 2022
1 parent
cc17153
commit 0844ff8
Showing
3 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
import pytest_asyncio | ||
|
||
from web3 import Web3 | ||
from web3._utils.filters import ( | ||
AsyncBlockFilter, | ||
AsyncLogFilter, | ||
AsyncTransactionFilter, | ||
BlockFilter, | ||
LogFilter, | ||
TransactionFilter, | ||
) | ||
from web3.eth import ( | ||
AsyncEth, | ||
) | ||
from web3.providers.eth_tester.main import ( | ||
AsyncEthereumTesterProvider, | ||
) | ||
|
||
|
||
def test_Eth_filter_creates_correct_filter_type(w3): | ||
filter1 = w3.eth.filter("latest") | ||
assert isinstance(filter1, BlockFilter) | ||
filter2 = w3.eth.filter("pending") | ||
assert isinstance(filter2, TransactionFilter) | ||
filter3 = w3.eth.filter({}) | ||
assert isinstance(filter3, LogFilter) | ||
|
||
|
||
# --- async --- # | ||
|
||
|
||
@pytest_asyncio.fixture() | ||
async def async_w3(): | ||
provider = AsyncEthereumTesterProvider() | ||
w3 = Web3(provider, modules={"eth": [AsyncEth]}, middlewares=[]) | ||
return w3 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_AsyncEth_filter_creates_correct_filter_type(async_w3): | ||
|
||
filter1 = await async_w3.eth.filter("latest") | ||
assert isinstance(filter1, AsyncBlockFilter) | ||
filter2 = await async_w3.eth.filter("pending") | ||
assert isinstance(filter2, AsyncTransactionFilter) | ||
filter3 = await async_w3.eth.filter({}) | ||
assert isinstance(filter3, AsyncLogFilter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters