Skip to content

Commit

Permalink
Merge pull request #629 from gurukamath/tests_update
Browse files Browse the repository at this point in the history
Update tests - `NoPostState` and `bigmem`
  • Loading branch information
gurukamath authored Oct 27, 2022
2 parents 34476ed + 92f2252 commit c8fbb41
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 49 deletions.
18 changes: 13 additions & 5 deletions tests/berlin/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ethereum.exceptions import InvalidBlock
from tests.helpers.load_state_tests import (
Load,
NoPostState,
fetch_state_test_files,
idfn,
run_blockchain_st_test,
Expand Down Expand Up @@ -53,7 +54,14 @@
)

# All tests that recursively create a large number of frames (50000)
BIG_MEMORY_TESTS = ("50000_",)
GENERAL_STATE_BIG_MEMORY_TESTS = (
"50000_",
"/stQuadraticComplexityTest/",
"/stRandom2/",
"/stRandom/",
"/stSpecialTest/",
"stTimeConsuming/",
)


@pytest.mark.parametrize(
Expand All @@ -62,14 +70,14 @@
test_dir,
ignore_list=INCORRECT_UPSTREAM_STATE_TESTS,
slow_list=GENERAL_STATE_SLOW_TESTS,
big_memory_list=BIG_MEMORY_TESTS,
big_memory_list=GENERAL_STATE_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_general_state_tests(test_case: Dict) -> None:
try:
run_berlin_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand Down Expand Up @@ -101,7 +109,7 @@ def test_general_state_tests(test_case: Dict) -> None:
def test_valid_block_tests(test_case: Dict) -> None:
try:
run_berlin_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand Down Expand Up @@ -147,7 +155,7 @@ def test_invalid_block_tests(test_case: Dict) -> None:
else:
with pytest.raises(InvalidBlock):
run_berlin_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(
"{} doesn't have post state".format(test_case["test_key"])
Expand Down
22 changes: 15 additions & 7 deletions tests/byzantium/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ethereum.exceptions import InvalidBlock
from tests.helpers.load_state_tests import (
Load,
NoPostState,
fetch_state_test_files,
idfn,
run_blockchain_st_test,
Expand Down Expand Up @@ -38,22 +39,29 @@
)

# All tests that recursively create a large number of frames (50000)
BIG_MEMORY_TESTS = ("50000_",)
GENERAL_STATE_BIG_MEMORY_TESTS = (
"50000_",
"/stQuadraticComplexityTest/",
"/stRandom2/",
"/stRandom/",
"/stSpecialTest/",
"stTimeConsuming/",
)


@pytest.mark.parametrize(
"test_case",
fetch_byzantium_tests(
test_dir,
ignore_list=INCORRECT_UPSTREAM_STATE_TESTS,
big_memory_list=BIG_MEMORY_TESTS,
big_memory_list=GENERAL_STATE_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_general_state_tests(test_case: Dict) -> None:
try:
run_byzantium_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand All @@ -74,7 +82,7 @@ def test_general_state_tests(test_case: Dict) -> None:
# hence they've been marked as slow
SLOW_TESTS = ("bcExploitTest/DelegateCallSpam.json",)

BIG_MEMORY_TESTS = ("randomStatetest94_",)
VALID_BLOCKS_BIG_MEMORY_TESTS = ("randomStatetest94_",)


@pytest.mark.parametrize(
Expand All @@ -83,14 +91,14 @@ def test_general_state_tests(test_case: Dict) -> None:
test_dir,
ignore_list=IGNORE_LIST,
slow_list=SLOW_TESTS,
big_memory_list=BIG_MEMORY_TESTS,
big_memory_list=VALID_BLOCKS_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_valid_block_tests(test_case: Dict) -> None:
try:
run_byzantium_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand Down Expand Up @@ -119,7 +127,7 @@ def test_invalid_block_tests(test_case: Dict) -> None:
else:
with pytest.raises(InvalidBlock):
run_byzantium_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(
"{} doesn't have post state".format(test_case["test_key"])
Expand Down
22 changes: 15 additions & 7 deletions tests/constantinople/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ethereum.exceptions import InvalidBlock
from tests.helpers.load_state_tests import (
Load,
NoPostState,
fetch_state_test_files,
idfn,
run_blockchain_st_test,
Expand Down Expand Up @@ -56,22 +57,29 @@
)

# All tests that recursively create a large number of frames (50000)
BIG_MEMORY_TESTS = ("50000_",)
GENERAL_STATE_BIG_MEMORY_TESTS = (
"50000_",
"/stQuadraticComplexityTest/",
"/stRandom2/",
"/stRandom/",
"/stSpecialTest/",
"stTimeConsuming/",
)


@pytest.mark.parametrize(
"test_case",
fetch_constantinople_tests(
test_dir,
ignore_list=INCORRECT_UPSTREAM_STATE_TESTS,
big_memory_list=BIG_MEMORY_TESTS,
big_memory_list=GENERAL_STATE_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_general_state_tests(test_case: Dict) -> None:
try:
run_constantinople_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand All @@ -92,7 +100,7 @@ def test_general_state_tests(test_case: Dict) -> None:
# hence they've been marked as slow
SLOW_TESTS = ("bcExploitTest/DelegateCallSpam.json",)

BIG_MEMORY_TESTS = ("randomStatetest94_",)
VALID_BLOCKS_BIG_MEMORY_TESTS = ("randomStatetest94_",)


@pytest.mark.parametrize(
Expand All @@ -101,14 +109,14 @@ def test_general_state_tests(test_case: Dict) -> None:
test_dir,
ignore_list=IGNORE_LIST,
slow_list=SLOW_TESTS,
big_memory_list=BIG_MEMORY_TESTS,
big_memory_list=VALID_BLOCKS_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_valid_block_tests(test_case: Dict) -> None:
try:
run_constantinople_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand Down Expand Up @@ -137,7 +145,7 @@ def test_invalid_block_tests(test_case: Dict) -> None:
else:
with pytest.raises(InvalidBlock):
run_constantinople_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(
"{} doesn't have post state".format(test_case["test_key"])
Expand Down
20 changes: 16 additions & 4 deletions tests/frontier/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ethereum.exceptions import InvalidBlock
from tests.helpers.load_state_tests import (
Load,
NoPostState,
fetch_state_test_files,
idfn,
run_blockchain_st_test,
Expand All @@ -29,16 +30,26 @@
"GeneralStateTests/"
)

GENERAL_STATE_BIG_MEMORY_TESTS = (
"/stQuadraticComplexityTest/",
"/stRandom2/",
"/stRandom/",
"/stSpecialTest/",
)


@pytest.mark.parametrize(
"test_case",
fetch_frontier_tests(test_dir),
fetch_frontier_tests(
test_dir,
big_memory_list=GENERAL_STATE_BIG_MEMORY_TESTS,
),
ids=idfn,
)
def test_general_state_tests(test_case: Dict) -> None:
try:
run_frontier_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand All @@ -53,6 +64,7 @@ def test_general_state_tests(test_case: Dict) -> None:
"bcGasPricerTest/RPC_API_Test.json",
"bcMultiChainTest/",
"bcTotalDifficultyTest/",
"stTimeConsuming/",
)


Expand All @@ -67,7 +79,7 @@ def test_general_state_tests(test_case: Dict) -> None:
def test_valid_block_tests(test_case: Dict) -> None:
try:
run_frontier_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_case} doesn't have post state")

Expand Down Expand Up @@ -96,7 +108,7 @@ def test_invalid_block_tests(test_case: Dict) -> None:
else:
with pytest.raises(InvalidBlock):
run_frontier_blockchain_st_tests(test_case)
except KeyError:
except NoPostState:
# FIXME: Handle tests that don't have post state
pytest.xfail(
"{} doesn't have post state".format(test_case["test_key"])
Expand Down
25 changes: 22 additions & 3 deletions tests/helpers/load_state_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
)


class NoTestsFound(Exception):
"""
An exception thrown when the test for a particular fork isn't
available in the json fixture
"""


class NoPostState(Exception):
"""
An exception thrown when the test does not have a postState defined.
"""


class BaseLoad(ABC):
@property
@abstractmethod
Expand Down Expand Up @@ -335,6 +348,12 @@ def load_test(test_case: Dict, load: BaseLoad) -> Dict:
json_data["blocks"]
)

try:
raw_post_state = json_data["postState"]
except KeyError:
raise NoPostState
post_state = load.json_to_state(raw_post_state)

return {
"test_file": test_case["test_file"],
"test_key": test_case["test_key"],
Expand All @@ -346,7 +365,7 @@ def load_test(test_case: Dict, load: BaseLoad) -> Dict:
"genesis_block_rlp": hex_to_bytes(json_data["genesisRLP"]),
"last_block_hash": hex_to_bytes(json_data["lastblockhash"]),
"pre_state": load.json_to_state(json_data["pre"]),
"expected_post_state": load.json_to_state(json_data["postState"]),
"expected_post_state": post_state,
"blocks": blocks,
"block_header_hashes": block_header_hashes,
"block_rlps": block_rlps,
Expand Down Expand Up @@ -428,7 +447,7 @@ def load_json_fixture(test_file: str, network: str) -> Generator:
found_keys = list(filter(keys_to_search.match, data.keys()))

if not any(found_keys):
raise KeyError
raise NoTestsFound

for _key in found_keys:
yield {
Expand Down Expand Up @@ -493,7 +512,7 @@ def fetch_state_test_files(
yield pytest.param(_test_case, marks=pytest.mark.bigmem)
else:
yield _test_case
except KeyError:
except NoTestsFound:
# file doesn't contain tests for the given fork
continue

Expand Down
Loading

0 comments on commit c8fbb41

Please sign in to comment.