Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 73d7882

Browse files
committedAug 22, 2024
Updates to test suite after running for EELS backend
1 parent 4735bf9 commit 73d7882

34 files changed

+242
-120
lines changed
 

‎conftest.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import warnings
44

55
from eth_tester import (
6-
EELSBackend,
76
EthereumTester,
87
)
98
import pytest_asyncio
@@ -75,17 +74,15 @@ def _wait_for_transaction(w3, txn_hash, timeout=120):
7574

7675

7776
@pytest.fixture
78-
def w3():
79-
t = EthereumTester(backend=EELSBackend("cancun"))
80-
w3 = Web3(EthereumTesterProvider(t))
77+
def w3(backend_class):
78+
w3 = Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
8179
w3.eth.default_account = w3.eth.accounts[0]
8280
return w3
8381

8482

8583
@pytest.fixture(scope="module")
86-
def w3_non_strict_abi():
87-
t = EthereumTester(backend=EELSBackend("cancun"))
88-
w3 = Web3(EthereumTesterProvider(t))
84+
def w3_non_strict_abi(backend_class):
85+
w3 = Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
8986
w3.eth.default_account = w3.eth.accounts[0]
9087
w3.strict_bytes_type_checking = False
9188
return w3

‎docs/contributing.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ Typically, you'll just want to run a subset instead, like:
160160
$ pytest tests/core/eth-module/test_accounts.py
161161
162162
163-
You can use ``tox`` to run all the tests for a given version of Python:
163+
You can use ``tox`` to run all the core tests for a given version of Python. You must
164+
an available backend for eth-tester to use (currently {'pyevm', 'eels'}).
164165

165166
.. code:: sh
166167
167-
$ tox -e py38-core
168+
$ tox -e py38-core --backend=pyevm
168169
169170
170171
Linting is also performed by the CI. You can save yourself some time by checking for

‎setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
setup,
55
)
66

7+
CUSTOM_ETH_TESTER_BRANCH = " @ git+https://github.com/fselmo/eth-tester@eels-backend"
8+
79
extras_require = {
810
"dev": [
911
"build>=0.9.0",
@@ -30,8 +32,9 @@
3032
"test": [
3133
# Note: ethereum-maintained libraries in this list should be added to the
3234
# `install_pre_releases.py` script.
33-
"eth-tester[py-evm]>=0.11.0b1,<0.13.0b1",
34-
"py-geth>=5.0.0",
35+
f"eth-tester[py-evm]{CUSTOM_ETH_TESTER_BRANCH}",
36+
# if python version >= 3.10, install the eels backend:
37+
f"eth-tester[eels]{CUSTOM_ETH_TESTER_BRANCH} ; python_version >= '3.10'",
3538
"pytest-asyncio>=0.18.1,<0.23",
3639
"pytest-mock>=1.10",
3740
"pytest-xdist>=2.4.0",

‎tests/conftest.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Type,
44
)
55

6+
from eth_tester import (
7+
PyEVMBackend,
8+
)
69
from eth_utils import (
710
event_signature_to_log_topic,
811
to_bytes,
@@ -23,20 +26,63 @@
2326
get_open_port,
2427
)
2528

29+
SUPPORTED_ETH_TESTER_BACKENDS = {"pyevm", "eels"}
30+
2631

2732
@pytest.fixture(scope="module", params=[lambda x: to_bytes(hexstr=x), identity])
2833
def address_conversion_func(request):
2934
return request.param
3035

3136

32-
@pytest.fixture()
37+
@pytest.fixture
3338
def open_port():
3439
return get_open_port()
3540

3641

3742
# --- session-scoped constants --- #
3843

3944

45+
def pytest_addoption(parser):
46+
parser.addoption(
47+
"--backend",
48+
action="store",
49+
default=None,
50+
help="Specify the backend for `EthereumTester` to use.",
51+
)
52+
53+
54+
def pytest_collection_modifyitems(config, items):
55+
backend_required_for_tests = any(
56+
"backend_class" in item.fixturenames for item in items
57+
)
58+
if backend_required_for_tests:
59+
backend = config.getoption("--backend")
60+
if not backend:
61+
raise pytest.UsageError(
62+
"This test run requires a specified a backend via the `--backend` "
63+
"command line option. Supported backends are: "
64+
f"{SUPPORTED_ETH_TESTER_BACKENDS}"
65+
)
66+
elif backend not in SUPPORTED_ETH_TESTER_BACKENDS:
67+
raise pytest.UsageError(f"Unsupported backend: `{backend}`.")
68+
69+
70+
@pytest.fixture(scope="session")
71+
def backend_class(request):
72+
backend = request.config.getoption("--backend")
73+
if backend == "pyevm":
74+
return PyEVMBackend
75+
elif backend == "eels":
76+
# conditionally import since eels is only supported on python >= 3.10
77+
from eth_tester.backends.eels import (
78+
EELSBackend,
79+
)
80+
81+
return EELSBackend
82+
else:
83+
raise ValueError("Invariant: Unreachable code path.")
84+
85+
4086
@pytest.fixture(scope="session")
4187
def emitter_contract_data():
4288
return EMITTER_CONTRACT_DATA

‎tests/core/conftest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from eth_tester import (
4-
EELSBackend,
54
EthereumTester,
65
)
76
import pytest_asyncio
@@ -121,19 +120,16 @@ def __init__(self, a, b):
121120

122121

123122
@pytest_asyncio.fixture
124-
async def async_w3():
125-
t = EthereumTester(backend=EELSBackend("cancun"))
126-
provider = AsyncEthereumTesterProvider()
127-
provider.ethereum_tester = t
128-
w3 = AsyncWeb3(provider)
123+
async def async_w3(backend_class):
124+
w3 = AsyncWeb3(AsyncEthereumTesterProvider(EthereumTester(backend=backend_class())))
129125
accounts = await w3.eth.accounts
130126
w3.eth.default_account = accounts[0]
131127
return w3
132128

133129

134130
@pytest_asyncio.fixture
135-
async def async_w3_non_strict_abi():
136-
w3 = AsyncWeb3(AsyncEthereumTesterProvider())
131+
async def async_w3_non_strict_abi(backend_class):
132+
w3 = AsyncWeb3(AsyncEthereumTesterProvider(EthereumTester(backend=backend_class())))
137133
w3.strict_bytes_type_checking = False
138134
accounts = await w3.eth.accounts
139135
w3.eth.default_account = accounts[0]

‎tests/core/contracts/test_contract_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
)
77

88

9-
@pytest.fixture()
9+
@pytest.fixture
1010
def abi():
1111
return """[{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"function"}, {"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"event"}]""" # noqa: E501
1212

‎tests/core/contracts/test_contract_caller_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
)
99

1010

11-
@pytest.fixture()
11+
@pytest.fixture
1212
def address(w3):
1313
return w3.eth.accounts[1]
1414

1515

16-
@pytest.fixture()
16+
@pytest.fixture
1717
def transaction_dict(w3, address):
1818
return {
1919
"from": address,

‎tests/core/contracts/test_contract_example.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# of how to write unit tests with web3.py
33
import pytest
44

5+
from eth_tester import (
6+
EthereumTester,
7+
)
58
import pytest_asyncio
69

710
from web3 import (
@@ -15,8 +18,8 @@
1518

1619

1720
@pytest.fixture
18-
def tester_provider():
19-
return EthereumTesterProvider()
21+
def tester_provider(backend_class):
22+
return EthereumTesterProvider(EthereumTester(backend=backend_class()))
2023

2124

2225
@pytest.fixture
@@ -118,8 +121,10 @@ def async_eth_tester():
118121

119122

120123
@pytest_asyncio.fixture()
121-
async def async_w3():
122-
async_w3 = AsyncWeb3(AsyncEthereumTesterProvider())
124+
async def async_w3(backend_class):
125+
async_w3 = AsyncWeb3(
126+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
127+
)
123128
accounts = await async_w3.eth.accounts
124129
async_w3.eth.default_account = accounts[0]
125130
return async_w3

‎tests/core/contracts/test_contract_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111

1212

13-
@pytest.fixture()
13+
@pytest.fixture
1414
def math_addr(math_contract_factory, address_conversion_func):
1515
w3 = math_contract_factory.w3
1616
deploy_txn = math_contract_factory.constructor().transact(

‎tests/core/contracts/test_extracting_event_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030

31-
@pytest.fixture()
31+
@pytest.fixture
3232
def dup_txn_receipt(w3, indexed_event_contract, wait_for_transaction, event_contract):
3333
emitter_fn = indexed_event_contract.functions.logTwoEvents
3434

‎tests/core/contracts/test_extracting_event_data_old.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010

1111

12-
@pytest.fixture()
12+
@pytest.fixture
1313
def emitter(
1414
w3,
1515
emitter_contract_data,

‎tests/core/eth-module/test_accounts.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from eth_account.signers.local import (
1010
LocalAccount,
1111
)
12+
from eth_tester import (
13+
EthereumTester,
14+
)
1215
from eth_utils import (
1316
is_bytes,
1417
is_checksum_address,
@@ -98,9 +101,9 @@ def acct(request, w3):
98101
raise Exception("Unreachable!")
99102

100103

101-
@pytest.fixture()
102-
def w3():
103-
return Web3(EthereumTesterProvider())
104+
@pytest.fixture
105+
def w3(backend_class):
106+
return Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
104107

105108

106109
def test_eth_default_account_is_empty_by_default(w3):
@@ -560,9 +563,11 @@ def test_eth_account_sign_and_send_EIP155_transaction_to_eth_tester(
560563
# -- async -- #
561564

562565

563-
@pytest.fixture()
564-
def async_w3():
565-
return AsyncWeb3(AsyncEthereumTesterProvider())
566+
@pytest.fixture
567+
def async_w3(backend_class):
568+
return AsyncWeb3(
569+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
570+
)
566571

567572

568573
@patch("web3.eth.BaseEth.account", "wired via BaseEth")

‎tests/core/eth-module/test_eth_filter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22

3+
from eth_tester import (
4+
EthereumTester,
5+
)
36
import pytest_asyncio
47

58
from web3 import (
@@ -30,11 +33,11 @@ def test_eth_filter_creates_correct_filter_type(w3):
3033
# --- async --- #
3134

3235

33-
@pytest_asyncio.fixture()
34-
async def async_w3():
35-
provider = AsyncEthereumTesterProvider()
36-
w3 = AsyncWeb3(provider)
37-
return w3
36+
@pytest_asyncio.fixture
37+
async def async_w3(backend_class):
38+
return AsyncWeb3(
39+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
40+
)
3841

3942

4043
@pytest.mark.asyncio
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
22

3+
from eth_tester import (
4+
EthereumTester,
5+
)
6+
37
from web3 import (
48
AsyncWeb3,
59
)
@@ -9,16 +13,19 @@
913

1014

1115
@pytest.fixture
12-
def async_w3():
16+
def async_w3(backend_class):
1317
return AsyncWeb3(
14-
AsyncEthereumTesterProvider(),
18+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class())),
1519
)
1620

1721

1822
def test_eth_chain_id(w3):
19-
assert w3.eth.chain_id == w3.provider.eth_tester.chain_id
23+
assert w3.eth.chain_id == w3.provider.ethereum_tester.backend.chain.chain_id
2024

2125

2226
@pytest.mark.asyncio
2327
async def test_async_eth_chain_id(async_w3):
24-
assert await async_w3.eth.chain_id == async_w3.provider.eth_tester.chain_id
28+
assert (
29+
await async_w3.eth.chain_id
30+
== async_w3.provider.ethereum_tester.backend.chain.chain_id
31+
)

‎tests/core/filtering/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
params=[True, False],
2323
ids=["LocalFilterMiddleware", "node_based_filter"],
2424
)
25-
def w3(request):
26-
return _w3_fixture_logic(request)
25+
def w3(request, backend_class):
26+
return _w3_fixture_logic(request, backend_class)
2727

2828

2929
@pytest.fixture
@@ -69,8 +69,8 @@ def create_filter(request):
6969
params=[True, False],
7070
ids=["LocalFilterMiddleware", "node_based_filter"],
7171
)
72-
async def async_w3(request):
73-
return await _async_w3_fixture_logic(request)
72+
async def async_w3(request, backend_class):
73+
return await _async_w3_fixture_logic(request, backend_class)
7474

7575

7676
@pytest.fixture

‎tests/core/filtering/test_contract_data_filters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def array_values(draw):
8181
params=[True, False],
8282
ids=["LocalFilterMiddleware", "node_based_filter"],
8383
)
84-
def w3(request):
85-
return _w3_fixture_logic(request)
84+
def w3(request, backend_class):
85+
return _w3_fixture_logic(request, backend_class)
8686

8787

8888
@pytest.fixture(scope="module")
@@ -284,8 +284,8 @@ def event_loop():
284284
params=[True, False],
285285
ids=["LocalFilterMiddleware", "node_based_filter"],
286286
)
287-
async def async_w3(request):
288-
return await _async_w3_fixture_logic(request)
287+
async def async_w3(request, backend_class):
288+
return await _async_w3_fixture_logic(request, backend_class)
289289

290290

291291
@pytest.fixture(scope="module")

‎tests/core/filtering/test_contract_topic_filters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def array_values(draw):
8181
params=[True, False],
8282
ids=["LocalFilterMiddleware", "node_based_filter"],
8383
)
84-
def w3(request):
85-
return _w3_fixture_logic(request)
84+
def w3(request, backend_class):
85+
return _w3_fixture_logic(request, backend_class)
8686

8787

8888
@pytest.fixture(scope="module")
@@ -265,8 +265,8 @@ def event_loop():
265265
params=[True, False],
266266
ids=["LocalFilterMiddleware", "node_based_filter"],
267267
)
268-
async def async_w3(request):
269-
return await _async_w3_fixture_logic(request)
268+
async def async_w3(request, backend_class):
269+
return await _async_w3_fixture_logic(request, backend_class)
270270

271271

272272
@pytest_asyncio.fixture(scope="module")

‎tests/core/filtering/test_existing_filter_instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
)
88

99

10-
@pytest.fixture()
10+
@pytest.fixture
1111
def filter_id(w3):
1212
block_filter = w3.eth.filter("latest")
1313
return block_filter.filter_id

‎tests/core/filtering/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from eth_tester import (
2+
EthereumTester,
3+
)
4+
15
from web3 import (
26
AsyncWeb3,
37
Web3,
@@ -11,10 +15,9 @@
1115
)
1216

1317

14-
def _w3_fixture_logic(request):
18+
def _w3_fixture_logic(request, backend_class):
1519
use_filter_middleware = request.param
16-
provider = EthereumTesterProvider()
17-
w3 = Web3(provider)
20+
w3 = Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
1821
w3.eth.default_account = w3.eth.accounts[0]
1922
if use_filter_middleware:
2023
w3.middleware_onion.add(LocalFilterMiddleware)
@@ -43,10 +46,11 @@ def _emitter_fixture_logic(
4346
# --- async --- #
4447

4548

46-
async def _async_w3_fixture_logic(request):
49+
async def _async_w3_fixture_logic(request, backend_class):
4750
use_filter_middleware = request.param
48-
provider = AsyncEthereumTesterProvider()
49-
async_w3 = AsyncWeb3(provider)
51+
async_w3 = AsyncWeb3(
52+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
53+
)
5054

5155
accounts = await async_w3.eth.accounts
5256
async_w3.eth.default_account = accounts[0]

‎tests/core/middleware/test_name_to_address_middleware.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22

3+
from eth_tester import (
4+
EthereumTester,
5+
)
36
import pytest_asyncio
47

58
from web3 import (
@@ -30,8 +33,11 @@ def address(self, name):
3033

3134

3235
@pytest.fixture
33-
def _w3_setup():
34-
return Web3(provider=EthereumTesterProvider(), middleware=[])
36+
def _w3_setup(backend_class):
37+
return Web3(
38+
provider=EthereumTesterProvider(EthereumTester(backend=backend_class())),
39+
middleware=[],
40+
)
3541

3642

3743
@pytest.fixture

‎tests/core/middleware/test_transaction_signing.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
LocalAccount,
88
)
99
import eth_keys
10+
from eth_tester import (
11+
EthereumTester,
12+
)
1013
from eth_tester.exceptions import (
1114
ValidationError,
1215
)
1316
from eth_utils import (
14-
ValidationError as EthUtilsValidationError,
1517
is_hexstr,
1618
to_bytes,
1719
to_hex,
@@ -221,7 +223,7 @@ def hex_to_bytes(s):
221223
),
222224
(
223225
{"gas": 21000, "gasPrice": 0, "value": 1},
224-
EthUtilsValidationError,
226+
Exception,
225227
MIXED_KEY_MIXED_TYPE,
226228
ADDRESS_1,
227229
),
@@ -239,7 +241,7 @@ def hex_to_bytes(s):
239241
(
240242
{
241243
"value": 22,
242-
"maxFeePerGas": 20**9,
244+
"maxFeePerGas": 10**9,
243245
"maxPriorityFeePerGas": 10**9,
244246
},
245247
-1,
@@ -303,9 +305,9 @@ def assert_method_and_txn_signed(actual, expected):
303305
assert is_hexstr(raw_txn)
304306

305307

306-
@pytest.fixture()
307-
def w3():
308-
_w3 = Web3(EthereumTesterProvider())
308+
@pytest.fixture
309+
def w3(backend_class):
310+
_w3 = Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
309311
_w3.eth.default_account = _w3.eth.accounts[0]
310312
return _w3
311313

@@ -442,8 +444,10 @@ async def async_w3_dummy(request_mocker):
442444

443445

444446
@pytest_asyncio.fixture
445-
async def async_w3():
446-
_async_w3 = AsyncWeb3(AsyncEthereumTesterProvider())
447+
async def async_w3(backend_class):
448+
_async_w3 = AsyncWeb3(
449+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
450+
)
447451
accounts = await _async_w3.eth.accounts
448452
_async_w3.eth.default_account = accounts[0]
449453
return _async_w3

‎tests/core/module-class/test_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_attach_methods_to_module(web3_with_external_modules):
3737
}
3838
)
3939

40-
configured_chain_id = w3.provider.eth_tester.chain_id
40+
configured_chain_id = w3.provider.ethereum_tester.backend.chain.chain_id
4141
assert w3.eth.chain_id == configured_chain_id
4242
assert w3.module1.property1 == configured_chain_id
4343

‎tests/core/utilities/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
22

3+
from eth_tester import (
4+
EthereumTester,
5+
)
6+
37
from web3.main import (
48
Web3,
59
)
@@ -9,6 +13,5 @@
913

1014

1115
@pytest.fixture(scope="module")
12-
def w3():
13-
provider = EthereumTesterProvider()
14-
return Web3(provider)
16+
def w3(backend_class):
17+
return Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))

‎tests/core/utilities/test_abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
ABI_ERROR = ABIError({"type": "error", "name": "error"})
169169

170170

171-
@pytest.fixture()
171+
@pytest.fixture
172172
def contract_abi() -> ABI:
173173
return CONTRACT_ABI
174174

‎tests/core/web3-module/test_web3_inheritance.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ class InheritsFromWeb3(Web3):
99
pass
1010

1111
inherited_w3 = InheritsFromWeb3(EthereumTesterProvider())
12-
assert inherited_w3.eth.chain_id == inherited_w3.provider.eth_tester.chain_id
12+
assert (
13+
inherited_w3.eth.chain_id
14+
== inherited_w3.provider.ethereum_tester.backend.chain.chain_id
15+
)

‎tests/ens/conftest.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def ens(ens_setup, mocker):
163163

164164
# session scope for performance
165165
@pytest.fixture(scope="session")
166-
def ens_setup():
167-
w3 = Web3(EthereumTesterProvider(EthereumTester()))
166+
def ens_setup(backend_class):
167+
w3 = Web3(EthereumTesterProvider(EthereumTester(backend=backend_class())))
168168

169169
# ** Set up ENS contracts **
170170

@@ -355,7 +355,7 @@ def ens_setup():
355355
return ENS.from_web3(w3, ens_contract.address)
356356

357357

358-
@pytest.fixture()
358+
@pytest.fixture
359359
def TEST_ADDRESS(address_conversion_func):
360360
return address_conversion_func("0x000000000000000000000000000000000000dEaD")
361361

@@ -364,8 +364,10 @@ def TEST_ADDRESS(address_conversion_func):
364364

365365

366366
@pytest_asyncio.fixture(scope="session")
367-
def async_w3():
368-
_async_w3 = AsyncWeb3(AsyncEthereumTesterProvider())
367+
def async_w3(backend_class):
368+
_async_w3 = AsyncWeb3(
369+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
370+
)
369371
return _async_w3
370372

371373

@@ -461,8 +463,11 @@ def event_loop():
461463

462464
# add session scope with above session-scoped `event_loop` for better performance
463465
@pytest_asyncio.fixture(scope="session")
464-
async def async_ens_setup(async_w3):
466+
async def async_ens_setup(backend_class):
465467
# ** Set up ENS contracts **
468+
async_w3 = AsyncWeb3(
469+
AsyncEthereumTesterProvider(EthereumTester(backend=backend_class()))
470+
)
466471

467472
# remove account that creates ENS, so test transactions don't have write access
468473
accounts = await async_w3.eth.accounts
@@ -479,7 +484,7 @@ async def async_ens_setup(async_w3):
479484
)
480485
reverse_tld_namehash = bytes32(
481486
0xA097F6721CE401E757D1223A763FEF49B8B5F90BB18567DDB86FD205DFF71D34
482-
) # noqa: E501
487+
)
483488
reverser_namehash = bytes32(
484489
0x91D1777781884D03A6757A803996E38DE2A42967FB37EEACA72729271025A9E2
485490
)

‎tests/ens/test_get_text.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3-
from eth_utils import (
4-
ValidationError as EthUtilsValidationError,
3+
from eth_tester.exceptions import (
4+
ValidationError as EthTesterValidationError,
55
)
66

77
from ens.exceptions import (
@@ -31,9 +31,14 @@ def test_set_text_fails_with_bad_address(ens):
3131
address = ens.w3.eth.accounts[2]
3232
ens.setup_address("tester.eth", address)
3333
zero_address = "0x" + "00" * 20
34-
with pytest.raises(EthUtilsValidationError):
34+
with pytest.raises(EthTesterValidationError):
3535
ens.set_text(
36-
"tester.eth", "url", "http://example.com", transact={"from": zero_address}
36+
"tester.eth",
37+
"url",
38+
"http://example.com",
39+
# add gas so we don't call eth_estimateGas which can fail the transaction
40+
# in a different way
41+
transact={"from": zero_address, "gas": 222_222},
3742
)
3843

3944
# teardown
@@ -49,8 +54,8 @@ def test_set_text_pass_in_transaction_dict(ens):
4954
"avatar",
5055
"example.jpeg",
5156
transact={
52-
"maxFeePerGas": Web3.to_wei(100, "gwei"),
53-
"maxPriorityFeePerGas": Web3.to_wei(100, "gwei"),
57+
"maxFeePerGas": Web3.to_wei(1, "gwei"),
58+
"maxPriorityFeePerGas": Web3.to_wei(1, "gwei"),
5459
},
5560
)
5661
assert ens.get_text("tester.eth", "url") == "http://example.com"
@@ -102,9 +107,14 @@ async def test_async_set_text_fails_with_bad_address(async_ens):
102107
address = accounts[2]
103108
await async_ens.setup_address("tester.eth", address)
104109
zero_address = "0x" + "00" * 20
105-
with pytest.raises(EthUtilsValidationError):
110+
with pytest.raises(EthTesterValidationError):
106111
await async_ens.set_text(
107-
"tester.eth", "url", "http://example.com", transact={"from": zero_address}
112+
"tester.eth",
113+
"url",
114+
"http://example.com",
115+
# add gas so we don't call eth_estimateGas which can fail the transaction
116+
# in a different way
117+
transact={"from": zero_address, "gas": 222_222},
108118
)
109119

110120
# teardown
@@ -125,8 +135,8 @@ async def async_test_set_text_pass_in_transaction_dict(async_ens):
125135
"avatar",
126136
"example.jpeg",
127137
transact={
128-
"maxFeePerGas": Web3.to_wei(100, "gwei"),
129-
"maxPriorityFeePerGas": Web3.to_wei(100, "gwei"),
138+
"maxFeePerGas": Web3.to_wei(1, "gwei"),
139+
"maxPriorityFeePerGas": Web3.to_wei(1, "gwei"),
130140
},
131141
)
132142
assert await async_ens.get_text("tester.eth", "url") == "http://example.com"

‎tests/ens/test_setup_name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_setup_name_default_address(ens):
9292
assert not ens.name(new_resolution)
9393
assert ens.owner(name) == owner
9494
assert ens.address(name) == new_resolution
95-
ens.setup_name(name)
95+
ens.setup_name(name, transact={"gas": 222_222})
9696
assert ens.name(new_resolution) == name
9797
ens.setup_name(None, new_resolution)
9898

@@ -190,7 +190,7 @@ async def test_async_setup_name_default_address(async_ens):
190190
assert not await async_ens.name(new_resolution)
191191
assert await async_ens.owner(name) == owner
192192
assert await async_ens.address(name) == new_resolution
193-
await async_ens.setup_name(name)
193+
await async_ens.setup_name(name, transact={"gas": 222_222})
194194
assert await async_ens.name(new_resolution) == name
195195
await async_ens.setup_name(None, new_resolution)
196196

‎tests/integration/ethereum_tester/common.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,6 @@ def test_eth_call_old_contract_state(
277277
w3, math_contract, keyfile_account_address
278278
)
279279

280-
def test_eth_chain_id(self, w3):
281-
chain_id = w3.eth.chain_id
282-
assert is_integer(chain_id)
283-
assert chain_id == w3.provider.eth_tester.chain_id
284-
285280
@disable_auto_mine
286281
def test_eth_wait_for_transaction_receipt_unmined(
287282
self, eth_tester, w3, keyfile_account_address_dual_type

‎tests/integration/ethereum_tester/test_eels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _eth_tester_state_setup(w3, keyfile_account_address, keyfile_account_pkey):
4646

4747
@pytest.fixture(scope="module")
4848
def eth_tester():
49-
return EthereumTester(backend=EELSBackend(debug_mode=True))
49+
return EthereumTester(backend=EELSBackend())
5050

5151

5252
@pytest.fixture(scope="module")

‎tests/integration/ethereum_tester/test_pyevm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class TestEthereumTesterWeb3Module(EthereumTesterWeb3Module):
6565

6666

6767
class TestEthereumTesterEthModule(EthereumTesterEthModule):
68-
pass
68+
def test_eth_chain_id(self, w3):
69+
chain_id = w3.eth.chain_id
70+
assert chain_id == 131277322940537
6971

7072

7173
class TestEthereumTesterNetModule(EthereumTesterNetModule):

‎tests/integration/go_ethereum/test_goethereum_ws/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
from tests.utils import (
77
get_open_port,
88
)
9+
from web3 import (
10+
AsyncWeb3,
11+
WebSocketProvider,
12+
)
13+
14+
15+
@pytest.fixture(scope="module")
16+
def w3():
17+
"""
18+
Defined for the sake of overriding the `w3` in the `AsyncWeb3ModuleTest` test cases.
19+
"""
20+
return AsyncWeb3(WebSocketProvider())
921

1022

1123
@pytest.fixture(scope="module")

‎tox.ini

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[tox]
22
envlist=
3-
py{38,39,310,311,312}-{ens,core,lint,wheel}
3+
py{38,39,310,311,312}-{ens,core,lint,wheel}-pyevm
4+
py{310,311,312}-{ens,core}-eels
45
py{38,39,310,311,312}-integration-{goethereum,ethtester}
6+
py{310,311,312}-integration-ethtester-eels
57
docs
68
benchmark
79
windows-wheel
@@ -20,9 +22,12 @@ allowlist_externals=make,pre-commit
2022
install_command=python -m pip install {opts} {packages}
2123
usedevelop=True
2224
commands=
23-
core: pytest {posargs:tests/core -m "not asyncio"}
24-
core_async: pytest {posargs:tests/core -m asyncio}
25-
ens: pytest {posargs:tests/ens --ignore=tests/ens/normalization/test_normalize_name_ensip15.py}
25+
core-pyevm: pytest {posargs:tests/core -m "not asyncio" --backend=pyevm}
26+
core-pyevm_async: pytest {posargs:tests/core -m asyncio --backend=pyevm}
27+
core-eels: pytest {posargs:tests/core -m "not asyncio" --backend=eels}
28+
core-eels_async: pytest {posargs:tests/core -m asyncio --backend=eels}
29+
ens-pyevm: pytest {posargs:tests/ens --ignore=tests/ens/normalization/test_normalize_name_ensip15.py --backend=pyevm}
30+
ens-eels: pytest {posargs:tests/ens --ignore=tests/ens/normalization/test_normalize_name_ensip15.py --backend=eels}
2631
ensip15: pytest {posargs:tests/ens/normalization/test_normalize_name_ensip15.py -q}
2732
integration-goethereum-ipc: pytest {posargs:tests/integration/go_ethereum/test_goethereum_ipc.py -k "not Async"}
2833
integration-goethereum-ipc_async: pytest {posargs:tests/integration/go_ethereum/test_goethereum_ipc.py -k Async}

‎web3/providers/eth_tester/main.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,30 @@ class AsyncEthereumTesterProvider(AsyncBaseProvider):
6666
ethereum_tester_middleware,
6767
)
6868

69-
def __init__(self) -> None:
69+
def __init__(
70+
self,
71+
ethereum_tester: Optional["EthereumTester"] = None,
72+
api_endpoints: Optional[
73+
Dict[str, Dict[str, Callable[..., RPCResponse]]]
74+
] = None,
75+
) -> None:
7076
super().__init__()
77+
if not ethereum_tester:
78+
from eth_tester import (
79+
EthereumTester,
80+
)
7181

72-
# do not import eth_tester until runtime, it is not a default dependency
73-
from eth_tester import (
74-
EthereumTester,
75-
)
82+
ethereum_tester = EthereumTester()
7683

77-
from web3.providers.eth_tester.defaults import (
78-
API_ENDPOINTS,
79-
)
84+
if not api_endpoints:
85+
from web3.providers.eth_tester.defaults import (
86+
API_ENDPOINTS,
87+
)
88+
89+
api_endpoints = API_ENDPOINTS
8090

81-
self.ethereum_tester = EthereumTester()
82-
self.api_endpoints = API_ENDPOINTS
91+
self.ethereum_tester = ethereum_tester
92+
self.api_endpoints = api_endpoints
8393

8494
async def request_func(
8595
self, async_w3: "AsyncWeb3", middleware_onion: "MiddlewareOnion"

0 commit comments

Comments
 (0)
Please sign in to comment.