Skip to content

Commit 73d7882

Browse files
committed
Updates to test suite after running for EELS backend
1 parent 4735bf9 commit 73d7882

34 files changed

+242
-120
lines changed

Diff for: conftest.py

+4-7
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

Diff for: docs/contributing.rst

+3-2
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

Diff for: setup.py

+5-2
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",

Diff for: tests/conftest.py

+47-1
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

Diff for: tests/core/conftest.py

+4-8
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]

Diff for: tests/core/contracts/test_contract_attributes.py

+1-1
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

Diff for: tests/core/contracts/test_contract_caller_interface.py

+2-2
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,

Diff for: tests/core/contracts/test_contract_example.py

+9-4
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

Diff for: tests/core/contracts/test_contract_init.py

+1-1
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(

Diff for: tests/core/contracts/test_extracting_event_data.py

+1-1
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

Diff for: tests/core/contracts/test_extracting_event_data_old.py

+1-1
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,

Diff for: tests/core/eth-module/test_accounts.py

+11-6
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")

Diff for: tests/core/eth-module/test_eth_filter.py

+8-5
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

Diff for: tests/core/eth-module/test_eth_properties.py

+11-4
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+
)

Diff for: tests/core/filtering/conftest.py

+4-4
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

Diff for: tests/core/filtering/test_contract_data_filters.py

+4-4
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")

0 commit comments

Comments
 (0)