-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94fd4d0
commit ab31dd7
Showing
3 changed files
with
92 additions
and
11 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,78 @@ | ||
import json | ||
import os | ||
from glob import glob | ||
from typing import Dict, Generator, Tuple | ||
|
||
import pytest | ||
|
||
from ethereum.prague.vm.eof import validate_eof_container | ||
from ethereum.prague.vm.exceptions import InvalidEOF | ||
from ethereum.utils.hexadecimal import hex_to_bytes | ||
|
||
TEST_DIRS = ( | ||
"tests/fixtures/ethereum_tests/EOFTests/EIP3540", | ||
"tests/fixtures/ethereum_tests/EOFTests/EIP3670", | ||
"tests/fixtures/ethereum_tests/EOFTests/EIP4200", | ||
) | ||
|
||
|
||
def fetch_eof_tests(test_dirs: Tuple[str, ...]) -> Generator: | ||
for test_dir in test_dirs: | ||
all_jsons = [ | ||
y | ||
for x in os.walk(test_dir) | ||
for y in glob(os.path.join(x[0], "*.json")) | ||
] | ||
|
||
for full_path in all_jsons: | ||
# Read the json file and yield the test cases | ||
with open(full_path, "r") as file: | ||
data = json.load(file) | ||
for test in data.keys(): | ||
for key in data[test]["vectors"].keys(): | ||
yield { | ||
"test_file": full_path, | ||
"test_name": test, | ||
"test_key": key, | ||
} | ||
|
||
|
||
# Test case Identifier | ||
def idfn(test_case: Dict) -> str: | ||
if isinstance(test_case, dict): | ||
return ( | ||
test_case["test_file"] | ||
+ " - " | ||
+ test_case["test_name"] | ||
+ " - " | ||
+ test_case["test_key"] | ||
) | ||
|
||
|
||
# Run the tests | ||
@pytest.mark.parametrize( | ||
"test_case", | ||
fetch_eof_tests(TEST_DIRS), | ||
ids=idfn, | ||
) | ||
def test_eof(test_case: Dict) -> None: | ||
test_file = test_case["test_file"] | ||
test_name = test_case["test_name"] | ||
test_key = test_case["test_key"] | ||
|
||
with open(test_file, "r") as file: | ||
test_data = json.load(file) | ||
test_vector = test_data[test_name]["vectors"][test_key] | ||
|
||
# Extract the test data | ||
code = hex_to_bytes(test_vector["code"]) | ||
prague_validation = test_vector["results"]["Prague"] | ||
|
||
if "exception" in prague_validation and prague_validation["result"]: | ||
raise Exception("Test case has both exception and result") | ||
|
||
if "exception" in prague_validation: | ||
with pytest.raises(InvalidEOF): | ||
validate_eof_container(code) | ||
else: | ||
validate_eof_container(code) |
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