Skip to content

Commit 2fa2a18

Browse files
committed
Add support for the --fork flag, enable BC/GeneralStateTests
1 parent 65e6f4d commit 2fa2a18

File tree

1 file changed

+89
-9
lines changed

1 file changed

+89
-9
lines changed

tests/json-fixtures/test_blockchain.py

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

55
from eth_utils import (
6+
to_tuple,
67
ValidationError,
78
)
89

@@ -34,6 +35,62 @@
3435
BASE_FIXTURE_PATH = os.path.join(ROOT_PROJECT_DIR, 'fixtures', 'BlockchainTests')
3536

3637

38+
# These are the slowest 50 tests from the full statetest run. This list should
39+
# be regenerated occasionally using `--durations 50`.
40+
SLOWEST_TESTS = {
41+
('stStaticCall/static_Call50000_sha256.json', 'static_Call50000_sha256'),
42+
('stStaticCall/static_Call50000_rip160.json', 'static_Call50000_rip160'),
43+
('stStaticCall/static_Call50000_sha256.json', 'static_Call50000_sha256'),
44+
('stStaticCall/static_Call50000.json', 'static_Call50000'),
45+
('stStaticCall/static_Call50000_ecrec.json', 'static_Call50000_ecrec'),
46+
('stStaticCall/static_Call50000_rip160.json', 'static_Call50000_rip160'),
47+
('stStaticCall/static_LoopCallsThenRevert.json', 'static_LoopCallsThenRevert'),
48+
('stStaticCall/static_Call50000_identity2.json', 'static_Call50000_identity2'),
49+
('stStaticCall/static_Call50000_identity.json', 'static_Call50000_identity'),
50+
('stStaticCall/static_Return50000_2.json', 'static_Return50000_2'),
51+
('stCallCreateCallCodeTest/Call1024PreCalls.json', 'Call1024PreCalls'),
52+
('stChangedEIP150/Call1024PreCalls.json', 'Call1024PreCalls'),
53+
('stDelegatecallTestHomestead/Call1024PreCalls.json', 'Call1024PreCalls'),
54+
('stStaticCall/static_Call50000.json', 'static_Call50000'),
55+
('stStaticCall/static_Call50000_ecrec.json', 'static_Call50000_ecrec'),
56+
('stStaticCall/static_Call1024PreCalls2.json', 'static_Call1024PreCalls2'),
57+
('stStaticCall/static_Call50000_identity.json', 'static_Call50000_identity'),
58+
('stStaticCall/static_Call50000_identity2.json', 'static_Call50000_identity2'),
59+
('stStaticCall/static_LoopCallsThenRevert.json', 'static_LoopCallsThenRevert'),
60+
('stCallCreateCallCodeTest/Call1024BalanceTooLow.json', 'Call1024BalanceTooLow'), # noqa: E501
61+
('stChangedEIP150/Call1024BalanceTooLow.json', 'Call1024BalanceTooLow'),
62+
('stCallCreateCallCodeTest/Callcode1024BalanceTooLow.json', 'Callcode1024BalanceTooLow'), # noqa: E501
63+
('stChangedEIP150/Callcode1024BalanceTooLow.json', 'Callcode1024BalanceTooLow'), # noqa: E501
64+
('stSystemOperationsTest/CallRecursiveBomb0_OOG_atMaxCallDepth.json', 'CallRecursiveBomb0_OOG_atMaxCallDepth'), # noqa: E501
65+
('stRevertTest/LoopCallsDepthThenRevert2.json', 'LoopCallsDepthThenRevert2'),
66+
('stRevertTest/LoopCallsDepthThenRevert3.json', 'LoopCallsDepthThenRevert3'),
67+
('stDelegatecallTestHomestead/CallRecursiveBombPreCall.json', 'CallRecursiveBombPreCall'), # noqa: E501
68+
('stRevertTest/LoopCallsThenRevert.json', 'LoopCallsThenRevert'),
69+
('stCallCreateCallCodeTest/CallRecursiveBombPreCall.json', 'CallRecursiveBombPreCall'), # noqa: E501
70+
('stStaticCall/static_Call50000bytesContract50_1.json', 'static_Call50000bytesContract50_1'), # noqa: E501
71+
('stStaticCall/static_Call1024PreCalls.json', 'static_Call1024PreCalls'),
72+
('stDelegatecallTestHomestead/Call1024BalanceTooLow.json', 'Call1024BalanceTooLow'), # noqa: E501
73+
('stDelegatecallTestHomestead/Delegatecall1024.json', 'Delegatecall1024'),
74+
('stRevertTest/LoopCallsThenRevert.json', 'LoopCallsThenRevert'),
75+
('stStaticCall/static_Call50000bytesContract50_2.json', 'static_Call50000bytesContract50_2'), # noqa: E501
76+
('stStaticCall/static_Call1024PreCalls2.json', 'static_Call1024PreCalls2'),
77+
('stRandom/randomStatetest636.json', 'randomStatetest636'),
78+
('stStaticCall/static_Call1024PreCalls3.json', 'static_Call1024PreCalls3'),
79+
('stRandom/randomStatetest467.json', 'randomStatetest467'),
80+
('stRandom/randomStatetest458.json', 'randomStatetest458'),
81+
('stRandom/randomStatetest150.json', 'randomStatetest150'),
82+
('stRandom/randomStatetest639.json', 'randomStatetest639'),
83+
('stStaticCall/static_LoopCallsDepthThenRevert2.json', 'static_LoopCallsDepthThenRevert2'), # noqa: E501
84+
('stRandom/randomStatetest154.json', 'randomStatetest154'),
85+
('stRecursiveCreate/recursiveCreateReturnValue.json', 'recursiveCreateReturnValue'), # noqa: E501
86+
('stStaticCall/static_LoopCallsDepthThenRevert3.json', 'static_LoopCallsDepthThenRevert3'), # noqa: E501
87+
('stSystemOperationsTest/ABAcalls1.json', 'ABAcalls1'),
88+
('stSpecialTest/failed_tx_xcf416c53.json', 'failed_tx_xcf416c53'),
89+
('stRandom/randomStatetest159.json', 'randomStatetest159'),
90+
('stRandom/randomStatetest554.json', 'randomStatetest554'),
91+
}
92+
93+
3794
# These are tests that are thought to be incorrect or buggy upstream,
3895
# at the commit currently checked out in submodule `fixtures`.
3996
# Ideally, this list should be empty.
@@ -48,37 +105,60 @@
48105
}
49106

50107

51-
def blockchain_fixture_mark_fn(fixture_path, fixture_name):
108+
def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
109+
fixture_id = (fixture_path, fixture_name)
110+
52111
if fixture_path.startswith('bcExploitTest'):
53112
return pytest.mark.skip("Exploit tests are slow")
54113
elif fixture_path == 'bcWalletTest/walletReorganizeOwners.json':
55114
return pytest.mark.skip("Wallet owner reorganization tests are slow")
56-
elif (fixture_path, fixture_name) in INCORRECT_UPSTREAM_TESTS:
115+
elif fixture_id in INCORRECT_UPSTREAM_TESTS:
57116
return pytest.mark.xfail(reason="Listed in INCORRECT_UPSTREAM_TESTS.")
117+
elif 'stTransactionTest/zeroSigTransa' in fixture_path:
118+
return pytest.mark.skip("EIP-86 not supported.")
119+
elif fixture_id in SLOWEST_TESTS:
120+
if should_run_slow_tests():
121+
return
122+
else:
123+
return pytest.mark.skip("Skipping slow test")
124+
elif 'stQuadraticComplexityTest' in fixture_path:
125+
return pytest.mark.skip("Skipping slow test")
126+
127+
128+
def generate_ignore_fn_for_fork(passed_fork):
129+
if passed_fork:
130+
passed_fork = passed_fork.lower()
131+
132+
def ignore_fn(fixture_path, fixture_key, fixture_fork):
133+
return fixture_fork.lower() != passed_fork
134+
135+
return ignore_fn
58136

59137

60-
def blockchain_fixture_ignore_fn(fixture_path, fixture_name):
61-
if fixture_path.startswith('GeneralStateTests'):
62-
# General state tests are also exported as blockchain tests. We
63-
# skip them here so we don't run them twice
64-
return True
138+
@to_tuple
139+
def expand_fixtures_forks(all_fixtures):
140+
for fixture_path, fixture_key in all_fixtures:
141+
fixture = load_fixture(fixture_path, fixture_key)
142+
yield fixture_path, fixture_key, fixture['network']
65143

66144

67145
def pytest_generate_tests(metafunc):
146+
fork = metafunc.config.getoption('fork')
68147
generate_fixture_tests(
69148
metafunc=metafunc,
70149
base_fixture_path=BASE_FIXTURE_PATH,
150+
preprocess_fn=expand_fixtures_forks,
71151
filter_fn=filter_fixtures(
72152
fixtures_base_dir=BASE_FIXTURE_PATH,
73153
mark_fn=blockchain_fixture_mark_fn,
74-
ignore_fn=blockchain_fixture_ignore_fn,
154+
ignore_fn=generate_ignore_fn_for_fork(fork)
75155
),
76156
)
77157

78158

79159
@pytest.fixture
80160
def fixture(fixture_data):
81-
fixture_path, fixture_key = fixture_data
161+
fixture_path, fixture_key, fixture_fork = fixture_data
82162
fixture = load_fixture(
83163
fixture_path,
84164
fixture_key,

0 commit comments

Comments
 (0)