Skip to content

Commit

Permalink
Merge pull request #462 from gurukamath/missing_tests_415
Browse files Browse the repository at this point in the history
Add BlockChainTests that were accidentally removed
  • Loading branch information
SamWilsn committed Feb 28, 2022
2 parents eedbbd1 + 564f26d commit fd10aa4
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 36 deletions.
78 changes: 78 additions & 0 deletions tests/byzantium/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import pytest

from ethereum.utils.ensure import EnsureError
from tests.byzantium.blockchain_st_test_helpers import (
FIXTURES_LOADER,
run_byzantium_blockchain_st_tests,
)
from tests.helpers.load_state_tests import fetch_state_test_files

# Run legacy general state tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/"
"GeneralStateTests/"
Expand Down Expand Up @@ -1493,3 +1495,79 @@ def test_general_state_tests(test_file: str) -> None:
except KeyError:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_file} doesn't have post state")


# Run legacy valid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/ValidBlocks/"
)

run_valid_block_test = partial(
run_byzantium_blockchain_st_tests,
test_dir,
)


@pytest.mark.parametrize(
"test_file_uncle_correctness",
[
"bcUncleTest/oneUncle.json",
"bcUncleTest/oneUncleGeneration2.json",
"bcUncleTest/oneUncleGeneration3.json",
"bcUncleTest/oneUncleGeneration4.json",
"bcUncleTest/oneUncleGeneration5.json",
"bcUncleTest/oneUncleGeneration6.json",
"bcUncleTest/twoUncle.json",
],
)
def test_uncles_correctness(test_file_uncle_correctness: str) -> None:
run_valid_block_test(test_file_uncle_correctness)


# Run legacy invalid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks"
)

run_invalid_block_test = partial(
run_byzantium_blockchain_st_tests,
test_dir,
)


@pytest.mark.parametrize(
"test_file", fetch_state_test_files(test_dir, (), FIXTURES_LOADER)
)
def test_invalid_block_tests(test_file: str) -> None:
try:
# Ideally correct.json should not have been in the InvalidBlocks folder
if test_file == "bcUncleHeaderValidity/correct.json":
run_invalid_block_test(test_file)
else:
with pytest.raises((EnsureError, AssertionError, ValueError)):
run_invalid_block_test(test_file)
except KeyError:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_file} doesn't have post state")


# Run Non-Legacy GeneralStateTests
run_general_state_tests_new = partial(
run_byzantium_blockchain_st_tests,
"tests/fixtures/BlockchainTests/GeneralStateTests/",
)


@pytest.mark.parametrize(
"test_file_new",
[
"stCreateTest/CREATE_HighNonce.json",
"stCreateTest/CREATE_HighNonceMinus1.json",
],
)
def test_general_state_tests_new(test_file_new: str) -> None:
try:
run_general_state_tests_new(test_file_new)
except KeyError:
# KeyError is raised when a test_file has no tests for frontier
raise pytest.skip(f"{test_file_new} has no tests for frontier")
57 changes: 48 additions & 9 deletions tests/frontier/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from tests.helpers.load_state_tests import fetch_state_test_files

# Run legacy general state tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/"
"GeneralStateTests/"
Expand All @@ -31,23 +32,61 @@ def test_general_state_tests(test_file: str) -> None:
pytest.xfail(f"{test_file} doesn't have post state")


# Test Invalid Block Headers
run_invalid_header_test = partial(
# Run legacy valid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/ValidBlocks/"
)

run_valid_block_test = partial(
run_frontier_blockchain_st_tests,
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks/bcInvalidHeaderTest",
test_dir,
)


@pytest.mark.parametrize(
"test_file_parent_hash",
"test_file_uncle_correctness",
[
"wrongParentHash.json",
"wrongParentHash2.json",
"bcUncleTest/oneUncle.json",
"bcUncleTest/oneUncleGeneration2.json",
"bcUncleTest/oneUncleGeneration3.json",
"bcUncleTest/oneUncleGeneration4.json",
"bcUncleTest/oneUncleGeneration5.json",
"bcUncleTest/oneUncleGeneration6.json",
"bcUncleTest/twoUncle.json",
"bcUncleTest/uncleHeaderAtBlock2.json",
"bcUncleSpecialTests/uncleBloomNot0.json",
"bcUncleSpecialTests/futureUncleTimestampDifficultyDrop.json",
],
)
def test_invalid_parent_hash(test_file_parent_hash: str) -> None:
with pytest.raises(EnsureError):
run_invalid_header_test(test_file_parent_hash)
def test_uncles_correctness(test_file_uncle_correctness: str) -> None:
run_valid_block_test(test_file_uncle_correctness)


# Run legacy invalid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks"
)

run_invalid_block_test = partial(
run_frontier_blockchain_st_tests,
test_dir,
)


@pytest.mark.parametrize(
"test_file", fetch_state_test_files(test_dir, (), FIXTURES_LOADER)
)
def test_invalid_block_tests(test_file: str) -> None:
try:
# Ideally correct.json should not have been in the InvalidBlocks folder
if test_file == "bcUncleHeaderValidity/correct.json":
run_invalid_block_test(test_file)
else:
with pytest.raises((EnsureError, AssertionError, ValueError)):
run_invalid_block_test(test_file)
except KeyError:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_file} doesn't have post state")


# Run Non-Legacy GeneralStateTests
Expand Down
56 changes: 47 additions & 9 deletions tests/homestead/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
run_homestead_blockchain_st_tests,
)

# Run legacy general state tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/"
"GeneralStateTests/"
Expand Down Expand Up @@ -107,23 +108,60 @@ def test_general_state_tests(test_file: str) -> None:
pytest.xfail(f"{test_file} doesn't have post state")


# Test Invalid Block Headers
run_invalid_header_test = partial(
# Run legacy valid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/ValidBlocks/"
)

run_valid_block_test = partial(
run_homestead_blockchain_st_tests,
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks/bcInvalidHeaderTest",
test_dir,
)


@pytest.mark.parametrize(
"test_file_parent_hash",
"test_file_uncle_correctness",
[
"wrongParentHash.json",
"wrongParentHash2.json",
"bcUncleTest/oneUncle.json",
"bcUncleTest/oneUncleGeneration2.json",
"bcUncleTest/oneUncleGeneration3.json",
"bcUncleTest/oneUncleGeneration4.json",
"bcUncleTest/oneUncleGeneration5.json",
"bcUncleTest/oneUncleGeneration6.json",
"bcUncleTest/twoUncle.json",
"bcUncleTest/uncleHeaderAtBlock2.json",
"bcUncleSpecialTests/uncleBloomNot0.json",
],
)
def test_invalid_parent_hash(test_file_parent_hash: str) -> None:
with pytest.raises(EnsureError):
run_invalid_header_test(test_file_parent_hash)
def test_uncles_correctness(test_file_uncle_correctness: str) -> None:
run_valid_block_test(test_file_uncle_correctness)


# Run legacy invalid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks"
)

run_invalid_block_test = partial(
run_homestead_blockchain_st_tests,
test_dir,
)


@pytest.mark.parametrize(
"test_file", fetch_state_test_files(test_dir, (), FIXTURES_LOADER)
)
def test_invalid_block_tests(test_file: str) -> None:
try:
# Ideally correct.json should not have been in the InvalidBlocks folder
if test_file == "bcUncleHeaderValidity/correct.json":
run_invalid_block_test(test_file)
else:
with pytest.raises((EnsureError, AssertionError, ValueError)):
run_invalid_block_test(test_file)
except KeyError:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_file} doesn't have post state")


# Run Non-Legacy GeneralStateTests
Expand Down
57 changes: 48 additions & 9 deletions tests/spurious_dragon/test_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
run_spurious_dragon_blockchain_st_tests,
)

# Run legacy general state tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/"
"GeneralStateTests/"
Expand All @@ -34,23 +35,61 @@ def test_general_state_tests(test_file: str) -> None:
pytest.xfail(f"{test_file} doesn't have post state")


# Test Invalid Block Headers
run_invalid_header_test = partial(
# Run legacy valid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/ValidBlocks/"
)

run_valid_block_test = partial(
run_spurious_dragon_blockchain_st_tests,
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks/bcInvalidHeaderTest",
test_dir,
)


@pytest.mark.parametrize(
"test_file_parent_hash",
"test_file_uncle_correctness",
[
"wrongParentHash.json",
"wrongParentHash2.json",
"bcUncleTest/oneUncle.json",
"bcUncleTest/oneUncleGeneration2.json",
"bcUncleTest/oneUncleGeneration3.json",
"bcUncleTest/oneUncleGeneration4.json",
"bcUncleTest/oneUncleGeneration5.json",
"bcUncleTest/oneUncleGeneration6.json",
"bcUncleTest/twoUncle.json",
"bcUncleTest/uncleHeaderAtBlock2.json",
"bcUncleSpecialTests/uncleBloomNot0.json",
"bcUncleSpecialTests/futureUncleTimestampDifficultyDrop.json",
],
)
def test_invalid_parent_hash(test_file_parent_hash: str) -> None:
with pytest.raises(EnsureError):
run_invalid_header_test(test_file_parent_hash)
def test_uncles_correctness(test_file_uncle_correctness: str) -> None:
run_valid_block_test(test_file_uncle_correctness)


# Run legacy invalid block tests
test_dir = (
"tests/fixtures/LegacyTests/Constantinople/BlockchainTests/InvalidBlocks"
)

run_invalid_block_test = partial(
run_spurious_dragon_blockchain_st_tests,
test_dir,
)


@pytest.mark.parametrize(
"test_file", fetch_state_test_files(test_dir, (), FIXTURES_LOADER)
)
def test_invalid_block_tests(test_file: str) -> None:
try:
# Ideally correct.json should not have been in the InvalidBlocks folder
if test_file == "bcUncleHeaderValidity/correct.json":
run_invalid_block_test(test_file)
else:
with pytest.raises((EnsureError, AssertionError, ValueError)):
run_invalid_block_test(test_file)
except KeyError:
# FIXME: Handle tests that don't have post state
pytest.xfail(f"{test_file} doesn't have post state")


# Run Non-Legacy GeneralStateTests
Expand Down
Loading

0 comments on commit fd10aa4

Please sign in to comment.