From da5c0f96ef435d20e76a49a945bf4df0e07cfa6a Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Wed, 30 Jul 2025 12:16:21 +0200 Subject: [PATCH 01/14] refactor string patterns --- tests/berlin/test_state_transition.py | 51 +------- tests/byzantium/test_state_transition.py | 45 +------ tests/cancun/test_state_transition.py | 53 +------- tests/constantinople/test_state_transition.py | 45 +------ tests/frontier/test_state_transition.py | 34 +---- tests/helpers/exceptional_test_patterns.py | 80 ++++++++++++ tests/homestead/test_state_transition.py | 120 +----------------- tests/istanbul/test_state_transition.py | 53 +------- tests/london/test_state_transition.py | 53 +------- tests/osaka/test_state_transition.py | 60 +-------- tests/paris/test_state_transition.py | 53 +------- tests/prague/test_state_transition.py | 61 +-------- tests/shanghai/test_state_transition.py | 53 +------- .../spurious_dragon/test_state_transition.py | 38 +----- .../test_state_transition.py | 38 +----- 15 files changed, 164 insertions(+), 673 deletions(-) create mode 100644 tests/helpers/exceptional_test_patterns.py diff --git a/tests/berlin/test_state_transition.py b/tests/berlin/test_state_transition.py index b5d935463f..1db9e47757 100644 --- a/tests/berlin/test_state_transition.py +++ b/tests/berlin/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,57 +19,17 @@ NETWORK = "Berlin" PACKAGE = "berlin" -# Every test below takes more than 60s to run and -# hence they've been marked as slow -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Berlin", - "CALLBlake2f_d9g0v0_Berlin", - "CALLCODEBlake2f_d9g0v0", - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Berlin", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/byzantium/test_state_transition.py b/tests/byzantium/test_state_transition.py index dd15c234ab..b5145aa328 100644 --- a/tests/byzantium/test_state_transition.py +++ b/tests/byzantium/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,51 +19,17 @@ NETWORK = "Byzantium" PACKAGE = "byzantium" -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -LEGACY_IGNORE_LIST = ( - # ValidBlockTests - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTests - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Byzantium", -) - -# All tests that recursively create a large number of frames (50000) -LEGACY_BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - # ValidBlockTests - "randomStatetest94_", -) - -LEGACY_SLOW_TESTS = ( - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=LEGACY_SLOW_TESTS, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/cancun/test_state_transition.py b/tests/cancun/test_state_transition.py index 6c72238bb4..1ab08891da 100644 --- a/tests/cancun/test_state_transition.py +++ b/tests/cancun/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -16,59 +17,17 @@ NETWORK = "Cancun" PACKAGE = "cancun" -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Cancun", - "CALLBlake2f_d9g0v0_Cancun", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Cancun", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - "stBadOpcode/", - "stStaticCall/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/constantinople/test_state_transition.py b/tests/constantinople/test_state_transition.py index a6e8ae089e..29dd7aaa8f 100644 --- a/tests/constantinople/test_state_transition.py +++ b/tests/constantinople/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -19,51 +20,17 @@ PACKAGE = "constantinople" -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -LEGACY_IGNORE_LIST = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_ConstantinopleFix", -) - -# All tests that recursively create a large number of frames (50000) -LEGACY_BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - # ValidBlockTest - "randomStatetest94_", -) - -LEGACY_SLOW_TESTS = ( - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=LEGACY_SLOW_TESTS, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/frontier/test_state_transition.py b/tests/frontier/test_state_transition.py index 1f27ff15f9..13906998a5 100644 --- a/tests/frontier/test_state_transition.py +++ b/tests/frontier/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,40 +19,17 @@ NETWORK = "Frontier" PACKAGE = "frontier" -LEGACY_IGNORE_LIST = ( - # Valid block tests to be ignored - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest/", - "bcTotalDifficultyTest/", - "stTimeConsuming/", - # Invalid block tests to be ignored - "bcForgedTest", - "bcMultiChainTest", - # TODO: See https://github.com/ethereum/tests/issues/1218 - "GasLimitHigherThan2p63m1_Frontier", -) - -LEGACY_BIG_MEMORY_TESTS = ( - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", -) - -SLOW_LIST = ( - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=SLOW_LIST, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/helpers/exceptional_test_patterns.py b/tests/helpers/exceptional_test_patterns.py new file mode 100644 index 0000000000..a123c1cfcc --- /dev/null +++ b/tests/helpers/exceptional_test_patterns.py @@ -0,0 +1,80 @@ +from typing import Tuple + + +def get_exceptional_patterns( + network: str, package: str +) -> Tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]: + """ + Returns patterns for slow, ignored, and big-memory tests for a given network and package. + + Parameters + ---------- + network : str + The network name (e.g., "Frontier", "EIP150"). + package : str + The package name (e.g., "frontier", "tangerine_whistle"). + + Returns + ------- + slow_tests : + Patterns to match test files or test ids that should be marked as slow. + ignore_tests : + Patterns to match test files or test ids that should be ignored. + big_memory_tests : + Patterns to match test files or test ids that require large memory. + """ + slow_tests = ( + # GeneralStateTests + "stTimeConsuming/CALLBlake2f_MaxRounds.json", + "stTimeConsuming/static_Call50000_sha256.json", + "vmPerformance/loopExp.json", + "vmPerformance/loopMul.json", + f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{network}", + f"CALLBlake2f_d9g0v0_{network}", + "CALLCODEBlake2f_d9g0v0", + # GeneralStateTests + "stRandom/randomStatetest177.json", + "stCreateTest/CreateOOGafterMaxCodesize.json", + # ValidBlockTest + "bcExploitTest/DelegateCallSpam.json", + # InvalidBlockTest + "bcUncleHeaderValidity/nonceWrong.json", + "bcUncleHeaderValidity/wrongMixHash.json", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_non-degeneracy-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_bilinearity-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-inf_pair-\\]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-multi_inf_pair-\\]", + f"tests/{package}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_{network}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", + ) + + # These are tests that are considered to be incorrect, + # Please provide an explanation when adding entries + ignore_tests = ( + # ValidBlockTest + "bcForkStressTest/ForkStressTest.json", + "bcGasPricerTest/RPC_API_Test.json", + "bcMultiChainTest", + "bcTotalDifficultyTest", + # InvalidBlockTest + "bcForgedTest", + "bcMultiChainTest", + f"GasLimitHigherThan2p63m1_{network}", + ) + + # All tests that recursively create a large number of frames (50000) + big_memory_tests = ( + # GeneralStateTests + "50000_", + "/stQuadraticComplexityTest/", + "/stRandom2/", + "/stRandom/", + "/stSpecialTest/", + "stTimeConsuming/", + "stBadOpcode/", + "stStaticCall/", + ) + + return slow_tests, ignore_tests, big_memory_tests diff --git a/tests/homestead/test_state_transition.py b/tests/homestead/test_state_transition.py index 4fd6613646..ab17c4acf0 100644 --- a/tests/homestead/test_state_transition.py +++ b/tests/homestead/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,126 +19,17 @@ NETWORK = "Homestead" PACKAGE = "homestead" -# Every test below takes more than 60s to run and -# hence they've been marked as slow -LEGACY_SLOW_TESTS = ( - # GeneralStateTests - "stRandom/randomStatetest177_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_sha256_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_rip160_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_identity2_d0g0v0.json", - "stQuadraticComplexityTest/Callcode50000_d0g0v0.json", - "stQuadraticComplexityTest/Return50000_2_d0g0v0.json", - "stQuadraticComplexityTest/Call1MB1024Calldepth_d0g1v0.json", - "stQuadraticComplexityTest/Call50000bytesContract50_3_d0g0v0.json", - "stQuadraticComplexityTest/Create1000_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_identity_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_ecrec_d0g0v0.json", - "stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopy_d0g1v0.json", - "stQuadraticComplexityTest/Call50000bytesContract50_2_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_identity2_d0g1v0.json", - "stQuadraticComplexityTest/Call50000_rip160_d0g0v0.json", - "stQuadraticComplexityTest/Return50000_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_sha256_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_d0g0v0.json", - "stQuadraticComplexityTest/Call50000bytesContract50_1_d0g0v0.json", - "stQuadraticComplexityTest/Return50000_2_d0g1v0.json", - "stQuadraticComplexityTest/Callcode50000_d0g1v0.json", - "stQuadraticComplexityTest/Call50000bytesContract50_3_d0g1v0.json", - "stQuadraticComplexityTest/Call1MB1024Calldepth_d0g0v0.json", - "stQuadraticComplexityTest/Call50000bytesContract50_2_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_ecrec_d0g1v0.json", - "stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopy_d0g0v0.json", - "stQuadraticComplexityTest/Call50000_identity_d0g0v0.json", - "stStackTests/stackOverflowM1DUP_d10g0v0.json", - "stStackTests/stackOverflowM1DUP_d11g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecall_010_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcallcode_001_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecallcode_111_OOGMAfter_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_ABCB_RECURSIVE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecall_010_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcallcode_001_SuicideMiddle_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_110_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_110_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_OOGMBefore_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcallcode_ABCB_RECURSIVE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcall_100_SuicideMiddle_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcallcode_101_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecallcode_111_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcall_100_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcode_01_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_110_OOGMBefore_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcode_11_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcall_100_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecall_ABCB_RECURSIVE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcall_100_OOGMBefore_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcall_100_OOGMAfter_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_ABCB_RECURSIVE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecall_10_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcallcode_101_SuicideMiddle_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecall_10_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcode_11_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcallcode_ABCB_RECURSIVE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecallcode_111_SuicideMiddle_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecall_010_OOGMBefore_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecallcode_111_OOGMBefore_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcallcode_001_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcallcode_101_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_SuicideMiddle_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_OOGMAfter_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcallcode_101_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecallcode_011_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_110_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcode_01_SuicideEnd_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecall_110_OOGMAfter_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcodecall_010_OOGMAfter_d0g0v0.json", - "stCallDelegateCodesHomestead/callcallcode_01_OOGE_d0g0v0.json", - "stCallDelegateCodesHomestead/callcodecallcodecallcode_ABCB_RECURSIVE_d0g0v0.json", - "stSpecialTest/JUMPDEST_AttackwithJump_d0g0v0.json", - "stSpecialTest/JUMPDEST_Attack_d0g0v0.json", - # ValidBlockTests - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTests - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -LEGACY_IGNORE_LIST = ( - # ValidBlockTests - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest/", - "bcTotalDifficultyTest/", - # InvalidBlockTests - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Homestead", -) - -LEGACY_BIG_MEMORY_TESTS = ( - # GeneralStateTests - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - # ValidBlockTests - "randomStatetest94_", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=LEGACY_SLOW_TESTS, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/istanbul/test_state_transition.py b/tests/istanbul/test_state_transition.py index 50fada9659..e7006bf422 100644 --- a/tests/istanbul/test_state_transition.py +++ b/tests/istanbul/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,59 +19,17 @@ NETWORK = "Istanbul" PACKAGE = "istanbul" -# Every test below takes more than 60s to run and -# hence they've been marked as slow -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Istanbul", - "CALLBlake2f_d9g0v0_Istanbul", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Istanbul", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/london/test_state_transition.py b/tests/london/test_state_transition.py index 764ee942de..7bc0afffcb 100644 --- a/tests/london/test_state_transition.py +++ b/tests/london/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,59 +19,17 @@ NETWORK = "London" PACKAGE = "london" -# Every test below takes more than 60s to run and -# hence they've been marked as slow -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_London", - "CALLBlake2f_d9g0v0_London", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_London", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/osaka/test_state_transition.py b/tests/osaka/test_state_transition.py index 49a32ee2a9..f569e1582a 100644 --- a/tests/osaka/test_state_transition.py +++ b/tests/osaka/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import ETHEREUM_TESTS_PATH, OSAKA_TEST_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -16,67 +17,18 @@ NETWORK = "Osaka" PACKAGE = "osaka" -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Osaka", - "CALLBlake2f_d9g0v0_Osaka", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_non-degeneracy-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_bilinearity-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-inf_pair-\\]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Osaka-blockchain_test-multi_inf_pair-\\]", - "tests/osaka/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_Osaka-blockchain_test-full_history_plus_one_check_blockhash_first\\]", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Osaka", -) -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - "stBadOpcode/", - "stStaticCall/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/paris/test_state_transition.py b/tests/paris/test_state_transition.py index 5478389ca6..ed83b97c58 100644 --- a/tests/paris/test_state_transition.py +++ b/tests/paris/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,59 +19,17 @@ NETWORK = "Paris" PACKAGE = "paris" -# Every test below takes more than 60s to run and -# hence they've been marked as slow -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Paris", - "CALLBlake2f_d9g0v0_Paris", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Paris", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/prague/test_state_transition.py b/tests/prague/test_state_transition.py index dd2bd52b43..68b70bac0e 100644 --- a/tests/prague/test_state_transition.py +++ b/tests/prague/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -16,67 +17,17 @@ NETWORK = "Prague" PACKAGE = "prague" -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Prague", - "CALLBlake2f_d9g0v0_Prague", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_non-degeneracy-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_bilinearity-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-inf_pair-\\]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_Prague-blockchain_test-multi_inf_pair-\\]", - "tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_Prague-blockchain_test-full_history_plus_one_check_blockhash_first\\]", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Prague", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - "stBadOpcode/", - "stStaticCall/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/shanghai/test_state_transition.py b/tests/shanghai/test_state_transition.py index 700ad49756..d86f0f33c5 100644 --- a/tests/shanghai/test_state_transition.py +++ b/tests/shanghai/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -19,59 +20,17 @@ PACKAGE = "shanghai" -SLOW_TESTS = ( - # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", - "QuadraticComplexitySolidity_CallDataCopy_d0g1v0_Shanghai", - "CALLBlake2f_d9g0v0_Shanghai", - "CALLCODEBlake2f_d9g0v0", - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -# These are tests that are considered to be incorrect, -# Please provide an explanation when adding entries -IGNORE_TESTS = ( - # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTest - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_Shanghai", -) - -# All tests that recursively create a large number of frames (50000) -BIG_MEMORY_TESTS = ( - # GeneralStateTests - "50000_", - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", - "stBadOpcode/", - "stStaticCall/", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=IGNORE_TESTS, - slow_list=SLOW_TESTS, - big_memory_list=BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/spurious_dragon/test_state_transition.py b/tests/spurious_dragon/test_state_transition.py index dc2091b56a..7c169f929c 100644 --- a/tests/spurious_dragon/test_state_transition.py +++ b/tests/spurious_dragon/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,44 +19,17 @@ NETWORK = "EIP158" PACKAGE = "spurious_dragon" -LEGACY_SLOW_TESTS = ( - # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -LEGACY_BIG_MEMORY_TESTS = ( - # GeneralStateTests - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", -) - -LEGACY_IGNORE_LIST = ( - # ValidBlockTests - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_EIP158", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=LEGACY_SLOW_TESTS, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) diff --git a/tests/tangerine_whistle/test_state_transition.py b/tests/tangerine_whistle/test_state_transition.py index ba376d6aa7..8238a39354 100644 --- a/tests/tangerine_whistle/test_state_transition.py +++ b/tests/tangerine_whistle/test_state_transition.py @@ -4,6 +4,7 @@ import pytest from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH +from tests.helpers.exceptional_test_patterns import get_exceptional_patterns from tests.helpers.load_state_tests import ( Load, fetch_state_test_files, @@ -18,44 +19,17 @@ NETWORK = "EIP150" PACKAGE = "tangerine_whistle" -LEGACY_SLOW_TESTS = ( - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", - # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", - # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", -) - -LEGACY_BIG_MEMORY_TESTS = ( - # GeneralStateTests - "/stQuadraticComplexityTest/", - "/stRandom2/", - "/stRandom/", - "/stSpecialTest/", - "stTimeConsuming/", -) - -LEGACY_IGNORE_LIST = ( - # ValidBlockTests - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", - "bcMultiChainTest", - "bcTotalDifficultyTest", - # InvalidBlockTests - "bcForgedTest", - "bcMultiChainTest", - "GasLimitHigherThan2p63m1_EIP150", +slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( + NETWORK, PACKAGE ) # Define Tests fetch_tests = partial( fetch_state_test_files, network=NETWORK, - ignore_list=LEGACY_IGNORE_LIST, - slow_list=LEGACY_SLOW_TESTS, - big_memory_list=LEGACY_BIG_MEMORY_TESTS, + ignore_list=ignore_tests, + slow_list=slow_tests, + big_memory_list=big_memory_tests, ) FIXTURES_LOADER = Load(NETWORK, PACKAGE) From e9e38365ea021072089f4c3ad14332615d2dfdb7 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Wed, 30 Jul 2025 15:36:13 +0200 Subject: [PATCH 02/14] json blockchain tests under json_infra --- tests/berlin/test_state_transition.py | 57 ------- tests/byzantium/test_state_transition.py | 57 ------- tests/cancun/test_state_transition.py | 55 ------- tests/constantinople/test_state_transition.py | 58 ------- tests/evm_tools/__init__.py | 0 tests/evm_tools/test_b11r.py | 71 --------- tests/frontier/test_state_transition.py | 57 ------- tests/homestead/test_state_transition.py | 57 ------- tests/istanbul/test_state_transition.py | 57 ------- tests/json_infra/__init__.py | 143 ++++++++++++++++++ tests/{ => json_infra}/conftest.py | 15 +- .../helpers/exceptional_test_patterns.py | 2 +- .../helpers/load_blockchain_tests.py} | 50 +++--- tests/json_infra/test_blockchain_tests.py | 50 ++++++ tests/london/test_state_transition.py | 57 ------- tests/osaka/test_state_transition.py | 56 ------- tests/paris/test_state_transition.py | 57 ------- tests/prague/test_state_transition.py | 55 ------- tests/shanghai/test_state_transition.py | 58 ------- .../spurious_dragon/test_state_transition.py | 57 ------- .../test_state_transition.py | 57 ------- tox.ini | 10 +- 22 files changed, 241 insertions(+), 895 deletions(-) delete mode 100644 tests/berlin/test_state_transition.py delete mode 100644 tests/byzantium/test_state_transition.py delete mode 100644 tests/cancun/test_state_transition.py delete mode 100644 tests/constantinople/test_state_transition.py delete mode 100644 tests/evm_tools/__init__.py delete mode 100644 tests/evm_tools/test_b11r.py delete mode 100644 tests/frontier/test_state_transition.py delete mode 100644 tests/homestead/test_state_transition.py delete mode 100644 tests/istanbul/test_state_transition.py create mode 100644 tests/json_infra/__init__.py rename tests/{ => json_infra}/conftest.py (95%) rename tests/{ => json_infra}/helpers/exceptional_test_patterns.py (98%) rename tests/{helpers/load_state_tests.py => json_infra/helpers/load_blockchain_tests.py} (85%) create mode 100644 tests/json_infra/test_blockchain_tests.py delete mode 100644 tests/london/test_state_transition.py delete mode 100644 tests/osaka/test_state_transition.py delete mode 100644 tests/paris/test_state_transition.py delete mode 100644 tests/prague/test_state_transition.py delete mode 100644 tests/shanghai/test_state_transition.py delete mode 100644 tests/spurious_dragon/test_state_transition.py delete mode 100644 tests/tangerine_whistle/test_state_transition.py diff --git a/tests/berlin/test_state_transition.py b/tests/berlin/test_state_transition.py deleted file mode 100644 index 1db9e47757..0000000000 --- a/tests/berlin/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Berlin" -PACKAGE = "berlin" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/byzantium/test_state_transition.py b/tests/byzantium/test_state_transition.py deleted file mode 100644 index b5145aa328..0000000000 --- a/tests/byzantium/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Byzantium" -PACKAGE = "byzantium" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/cancun/test_state_transition.py b/tests/cancun/test_state_transition.py deleted file mode 100644 index 1ab08891da..0000000000 --- a/tests/cancun/test_state_transition.py +++ /dev/null @@ -1,55 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/BlockchainTests/" -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Cancun" -PACKAGE = "cancun" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/constantinople/test_state_transition.py b/tests/constantinople/test_state_transition.py deleted file mode 100644 index 29dd7aaa8f..0000000000 --- a/tests/constantinople/test_state_transition.py +++ /dev/null @@ -1,58 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "ConstantinopleFix" -PACKAGE = "constantinople" - - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/evm_tools/__init__.py b/tests/evm_tools/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/evm_tools/test_b11r.py b/tests/evm_tools/test_b11r.py deleted file mode 100644 index 6f13972a6a..0000000000 --- a/tests/evm_tools/test_b11r.py +++ /dev/null @@ -1,71 +0,0 @@ -import json -import os -import sys -from typing import Any, Dict, List - -import pytest - -from ethereum.utils.hexadecimal import hex_to_bytes -from ethereum_spec_tools.evm_tools import create_parser -from ethereum_spec_tools.evm_tools.b11r import B11R -from ethereum_spec_tools.evm_tools.utils import FatalException -from tests.helpers import TEST_FIXTURES - -B11R_TEST_PATH = TEST_FIXTURES["evm_tools_testdata"]["fixture_path"] - -IGNORE_TESTS: List[str] = [] - -parser = create_parser() - - -def find_test_fixtures() -> Any: - with open(os.path.join(B11R_TEST_PATH, "b11r_commands.json")) as f: - data = json.load(f) - - for key, value in data.items(): - final_args = [] - for arg in value["args"]: - final_args.append(arg.replace("__BASEDIR__", B11R_TEST_PATH)) - yield { - "name": key, - "args": final_args, - "expected": os.path.join(B11R_TEST_PATH, key), - "success": value["success"], - } - - -def idfn(test_case: Dict) -> str: - return test_case["name"] - - -def b11r_tool_test(test_case: Dict) -> None: - options = parser.parse_args(test_case["args"]) - - try: - b11r_tool = B11R(options, sys.stdout, sys.stdin) - b11r_tool.build_block() - except Exception as e: - raise FatalException(e) - - # json_result = b11r_tool.result.to_json() - with open(test_case["expected"], "r") as f: - data = json.load(f) - - assert hex_to_bytes(data["rlp"]) == b11r_tool.block_rlp - assert hex_to_bytes(data["hash"]) == b11r_tool.block_hash - - -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - find_test_fixtures(), - ids=idfn, -) -def test_b11r(test_case: Dict) -> None: - if test_case["name"] in IGNORE_TESTS: - pytest.xfail("Undefined behavior for specs") - elif test_case["success"]: - b11r_tool_test(test_case) - else: - with pytest.raises(FatalException): - b11r_tool_test(test_case) diff --git a/tests/frontier/test_state_transition.py b/tests/frontier/test_state_transition.py deleted file mode 100644 index 13906998a5..0000000000 --- a/tests/frontier/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Frontier" -PACKAGE = "frontier" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/homestead/test_state_transition.py b/tests/homestead/test_state_transition.py deleted file mode 100644 index ab17c4acf0..0000000000 --- a/tests/homestead/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Homestead" -PACKAGE = "homestead" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/istanbul/test_state_transition.py b/tests/istanbul/test_state_transition.py deleted file mode 100644 index e7006bf422..0000000000 --- a/tests/istanbul/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Istanbul" -PACKAGE = "istanbul" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/json_infra/__init__.py b/tests/json_infra/__init__.py new file mode 100644 index 0000000000..e6990c3c31 --- /dev/null +++ b/tests/json_infra/__init__.py @@ -0,0 +1,143 @@ +from typing import Dict, Optional, TypedDict + +from typing_extensions import NotRequired + + +class _FixtureSource(TypedDict): + url: str + fixture_path: str + commit_hash: NotRequired[str] + + +# Update the links and commit has in order to consume +# newer/other tests +TEST_FIXTURES: Dict[str, _FixtureSource] = { + "evm_tools_testdata": { + "url": "https://github.com/gurukamath/evm-tools-testdata.git", + "commit_hash": "792422d", + "fixture_path": "tests/json_infra/fixtures/evm_tools_testdata", + }, + "ethereum_tests": { + "url": "https://github.com/ethereum/tests.git", + "commit_hash": "3129f16519013b265fa309208f49406b2ef57b13", + "fixture_path": "tests/json_infra/fixtures/ethereum_tests", + }, + "latest_fork_tests": { + "url": "https://github.com/ethereum/execution-spec-tests/releases/download/v4.5.0/fixtures_stable.tar.gz", + "fixture_path": "tests/json_infra/fixtures/latest_fork_tests", + }, + "osaka_tests": { + "url": "https://github.com/ethereum/execution-spec-tests/releases/download/fusaka-devnet-3%40v1.0.0/fixtures_fusaka-devnet-3.tar.gz", + "fixture_path": "tests/json_infra/fixtures/osaka_tests", + }, +} + + +def _get_fixture_path(key: str) -> str: + return TEST_FIXTURES[key]["fixture_path"] + + +def _build_ethereum_test_paths( + base_path: str, legacy_fork: Optional[str] = None +) -> tuple: + if legacy_fork: + bc_path = f"{base_path}/LegacyTests/{legacy_fork}/BlockchainTests/" + state_path = ( + f"{base_path}/LegacyTests/{legacy_fork}/GeneralStateTests/" + ) + else: + bc_path = f"{base_path}/BlockchainTests/" + state_path = f"{base_path}/GeneralStateTests/" + return bc_path, state_path + + +def _build_eest_test_paths(base_path: str) -> tuple: + bc_path = f"{base_path}/fixtures/blockchain_tests/" + state_path = f"{base_path}/fixtures/state_tests/" + return bc_path, state_path + + +# Base paths +ETHEREUM_TESTS_BASE = _get_fixture_path("ethereum_tests") +EEST_TESTS_BASE = _get_fixture_path("latest_fork_tests") +OSAKA_TESTS_BASE = _get_fixture_path("osaka_tests") + +# Ethereum test paths +( + PRE_CONSTANTINOPLE_BC_ETHEREUM_TESTS, + PRE_CONSTANTINOPLE_STATE_ETHEREUM_TESTS, +) = _build_ethereum_test_paths(ETHEREUM_TESTS_BASE, "Constantinople") +( + PRE_CANCUN_BC_ETHEREUM_TESTS, + PRE_CANCUN_STATE_ETHEREUM_TESTS, +) = _build_ethereum_test_paths(ETHEREUM_TESTS_BASE, "Cancun") +BC_ETHEREUM_TESTS, STATE_ETHEREUM_TESTS = _build_ethereum_test_paths( + ETHEREUM_TESTS_BASE +) + +# EEST test paths +EEST_BC_TESTS, EEST_STATE_TESTS = _build_eest_test_paths(EEST_TESTS_BASE) +EEST_OSAKA_BC_TESTS, EEST_OSAKA_STATE_TESTS = _build_eest_test_paths( + OSAKA_TESTS_BASE +) + + +def _create_fork_config(package: str, bc_dirs: list, state_dirs: list) -> dict: + return { + "package": package, + "blockchain_test_dirs": bc_dirs, + "state_test_dirs": state_dirs, + } + + +PRE_CONSTANTINOPLE_DIRS = ( + [PRE_CONSTANTINOPLE_BC_ETHEREUM_TESTS, EEST_BC_TESTS], + [PRE_CONSTANTINOPLE_STATE_ETHEREUM_TESTS, EEST_STATE_TESTS], +) + +PRE_CANCUN_DIRS = ( + [PRE_CANCUN_BC_ETHEREUM_TESTS, EEST_BC_TESTS], + [PRE_CANCUN_STATE_ETHEREUM_TESTS, EEST_STATE_TESTS], +) + +CURRENT_DIRS = ( + [BC_ETHEREUM_TESTS, EEST_BC_TESTS], + [STATE_ETHEREUM_TESTS, EEST_STATE_TESTS], +) + +OSAKA_DIRS = ( + [BC_ETHEREUM_TESTS, EEST_OSAKA_BC_TESTS], + [STATE_ETHEREUM_TESTS, EEST_OSAKA_STATE_TESTS], +) + +FORKS = { + **{ + fork: _create_fork_config(package, *PRE_CONSTANTINOPLE_DIRS) + for fork, package in [ + ("Frontier", "frontier"), + ("Homestead", "homestead"), + ("EIP150", "tangerine_whistle"), + ("EIP158", "spurious_dragon"), + ("Byzantium", "byzantium"), + ("ConstantinopleFix", "constantinople"), + ] + }, + **{ + fork: _create_fork_config(package, *PRE_CANCUN_DIRS) + for fork, package in [ + ("Istanbul", "istanbul"), + ("Berlin", "berlin"), + ("London", "london"), + ("Paris", "paris"), + ("Shanghai", "shanghai"), + ] + }, + **{ + fork: _create_fork_config(package, *CURRENT_DIRS) + for fork, package in [ + ("Cancun", "cancun"), + ("Prague", "prague"), + ] + }, + "Osaka": _create_fork_config("osaka", *OSAKA_DIRS), +} diff --git a/tests/conftest.py b/tests/json_infra/conftest.py similarity index 95% rename from tests/conftest.py rename to tests/json_infra/conftest.py index 731fd54b9d..27b89678f5 100644 --- a/tests/conftest.py +++ b/tests/json_infra/conftest.py @@ -15,7 +15,10 @@ from requests_cache.backends.sqlite import SQLiteCache from typing_extensions import Self -from tests.helpers import TEST_FIXTURES +from . import TEST_FIXTURES + +# Global variable to store pytest config for access during test collection +pytest_config = None try: from xdist import get_xdist_worker_id # type: ignore[import-untyped] @@ -48,11 +51,21 @@ def pytest_addoption(parser: Parser) -> None: help="Create an evm trace", ) + parser.addoption( + "--fork", + dest="fork", + type=str, + help="Run tests for this fork only (e.g., --fork Osaka)", + ) + def pytest_configure(config: Config) -> None: """ Configure the ethereum module and log levels to output evm trace. """ + global pytest_config + pytest_config = config + if config.getoption("optimized"): import ethereum_optimized diff --git a/tests/helpers/exceptional_test_patterns.py b/tests/json_infra/helpers/exceptional_test_patterns.py similarity index 98% rename from tests/helpers/exceptional_test_patterns.py rename to tests/json_infra/helpers/exceptional_test_patterns.py index a123c1cfcc..9b7af2c1cf 100644 --- a/tests/helpers/exceptional_test_patterns.py +++ b/tests/json_infra/helpers/exceptional_test_patterns.py @@ -1,7 +1,7 @@ from typing import Tuple -def get_exceptional_patterns( +def get_exceptional_blockchain_test_patterns( network: str, package: str ) -> Tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]: """ diff --git a/tests/helpers/load_state_tests.py b/tests/json_infra/helpers/load_blockchain_tests.py similarity index 85% rename from tests/helpers/load_state_tests.py rename to tests/json_infra/helpers/load_blockchain_tests.py index 3e95e41bd4..d83ef0dcf8 100644 --- a/tests/helpers/load_state_tests.py +++ b/tests/json_infra/helpers/load_blockchain_tests.py @@ -3,7 +3,7 @@ import os.path import re from glob import glob -from typing import Any, Dict, Generator, Tuple +from typing import Any, Dict, Generator, cast from unittest.mock import call, patch import pytest @@ -17,6 +17,9 @@ from ethereum.utils.hexadecimal import hex_to_bytes from ethereum_spec_tools.evm_tools.loaders.fixture_loader import Load +from .. import FORKS +from .exceptional_test_patterns import get_exceptional_blockchain_test_patterns + class NoTestsFound(Exception): """ @@ -152,37 +155,39 @@ def load_json_fixture(test_file: str, network: str) -> Generator: yield { "test_file": test_file, "test_key": _key, + "network": network, } -def fetch_state_test_files( - test_dir: str, +def fetch_blockchain_tests( network: str, - only_in: Tuple[str, ...] = (), - slow_list: Tuple[str, ...] = (), - big_memory_list: Tuple[str, ...] = (), - ignore_list: Tuple[str, ...] = (), ) -> Generator[Dict | ParameterSet, None, None]: + # Filter FORKS based on fork_option parameter + package = cast(str, FORKS[network]["package"]) + test_dirs = cast(list[str], FORKS[network]["blockchain_test_dirs"]) + + ( + slow_list, + ignore_list, + big_memory_list, + ) = get_exceptional_blockchain_test_patterns(network, package) all_slow = [re.compile(x) for x in slow_list] all_big_memory = [re.compile(x) for x in big_memory_list] all_ignore = [re.compile(x) for x in ignore_list] - # Get all the files to iterate over - # Maybe from the custom file list or entire test_dir - files_to_iterate = [] - if len(only_in): - # Get file list from custom list, if one is specified - for test_path in only_in: - files_to_iterate.append(os.path.join(test_dir, test_path)) - else: - # If there isn't a custom list, iterate over the test_dir - all_jsons = glob(os.path.join(test_dir, "**/*.json"), recursive=True) + # Get all the files to iterate over from both eest_tests_path and ethereum_tests_path + all_jsons = [] + for test_dir in test_dirs: + all_jsons.extend( + glob(os.path.join(test_dir, "**/*.json"), recursive=True) + ) - for full_path in all_jsons: - if not any(x.search(full_path) for x in all_ignore): - # If a file or folder is marked for ignore, - # it can already be dropped at this stage - files_to_iterate.append(full_path) + files_to_iterate = [] + for full_path in all_jsons: + if not any(x.search(full_path) for x in all_ignore): + # If a file or folder is marked for ignore, + # it can already be dropped at this stage + files_to_iterate.append(full_path) # Start yielding individual test cases from the file list for _test_file in files_to_iterate: @@ -197,6 +202,7 @@ def fetch_state_test_files( + _test_case["test_key"] + ")" ) + _test_case["package"] = package if any(x.search(_identifier) for x in all_ignore): continue elif any(x.search(_identifier) for x in all_slow): diff --git a/tests/json_infra/test_blockchain_tests.py b/tests/json_infra/test_blockchain_tests.py new file mode 100644 index 0000000000..dad33eb5f6 --- /dev/null +++ b/tests/json_infra/test_blockchain_tests.py @@ -0,0 +1,50 @@ +from typing import Callable, Dict + +import pytest + +from . import FORKS +from .conftest import pytest_config +from .helpers.load_blockchain_tests import ( + Load, + fetch_blockchain_tests, + idfn, + run_blockchain_st_test, +) + + +def _generate_test_function(fork_name: str) -> Callable: + @pytest.mark.json_blockchain_tests + @pytest.mark.parametrize( + "blockchain_test_case", + fetch_blockchain_tests(fork_name), + ids=idfn, + ) + def test_func(blockchain_test_case: Dict) -> None: + load = Load( + blockchain_test_case["network"], blockchain_test_case["package"] + ) + run_blockchain_st_test(blockchain_test_case, load=load) + + test_func.__name__ = f"test_blockchain_tests_{fork_name.lower()}" + return test_func + + +# Get the fork option from pytest config if available + +# Determine which forks to generate tests for +if pytest_config and pytest_config.getoption("fork", None): + # If --fork option is specified, only generate test for that fork + fork_option = pytest_config.getoption("fork") + if fork_option in FORKS: + forks_to_test = [fork_option] + else: + # If specified fork is not valid, generate no tests + forks_to_test = [] +else: + # If no --fork option, generate tests for all forks + forks_to_test = list(FORKS.keys()) + +for fork_name in forks_to_test: + locals()[ + f"test_blockchain_tests_{fork_name.lower()}" + ] = _generate_test_function(fork_name) diff --git a/tests/london/test_state_transition.py b/tests/london/test_state_transition.py deleted file mode 100644 index 7bc0afffcb..0000000000 --- a/tests/london/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "London" -PACKAGE = "london" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/osaka/test_state_transition.py b/tests/osaka/test_state_transition.py deleted file mode 100644 index f569e1582a..0000000000 --- a/tests/osaka/test_state_transition.py +++ /dev/null @@ -1,56 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import ETHEREUM_TESTS_PATH, OSAKA_TEST_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/BlockchainTests/" -EEST_BLOCKCHAIN_TESTS_DIR = f"{OSAKA_TEST_PATH}/fixtures/blockchain_tests/" -NETWORK = "Osaka" -PACKAGE = "osaka" - - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/paris/test_state_transition.py b/tests/paris/test_state_transition.py deleted file mode 100644 index ed83b97c58..0000000000 --- a/tests/paris/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Paris" -PACKAGE = "paris" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/prague/test_state_transition.py b/tests/prague/test_state_transition.py deleted file mode 100644 index 68b70bac0e..0000000000 --- a/tests/prague/test_state_transition.py +++ /dev/null @@ -1,55 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/BlockchainTests/" -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Prague" -PACKAGE = "prague" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/shanghai/test_state_transition.py b/tests/shanghai/test_state_transition.py deleted file mode 100644 index d86f0f33c5..0000000000 --- a/tests/shanghai/test_state_transition.py +++ /dev/null @@ -1,58 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "Shanghai" -PACKAGE = "shanghai" - - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/spurious_dragon/test_state_transition.py b/tests/spurious_dragon/test_state_transition.py deleted file mode 100644 index 7c169f929c..0000000000 --- a/tests/spurious_dragon/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "EIP158" -PACKAGE = "spurious_dragon" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/tangerine_whistle/test_state_transition.py b/tests/tangerine_whistle/test_state_transition.py deleted file mode 100644 index 8238a39354..0000000000 --- a/tests/tangerine_whistle/test_state_transition.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.exceptional_test_patterns import get_exceptional_patterns -from tests.helpers.load_state_tests import ( - Load, - fetch_state_test_files, - idfn, - run_blockchain_st_test, -) - -ETHEREUM_BLOCKCHAIN_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/BlockchainTests/" -) -EEST_BLOCKCHAIN_TESTS_DIR = f"{EEST_TESTS_PATH}/blockchain_tests/" -NETWORK = "EIP150" -PACKAGE = "tangerine_whistle" - -slow_tests, ignore_tests, big_memory_tests = get_exceptional_patterns( - NETWORK, PACKAGE -) - -# Define Tests -fetch_tests = partial( - fetch_state_test_files, - network=NETWORK, - ignore_list=ignore_tests, - slow_list=slow_tests, - big_memory_list=big_memory_tests, -) - -FIXTURES_LOADER = Load(NETWORK, PACKAGE) - -run_tests = partial(run_blockchain_st_test, load=FIXTURES_LOADER) - - -# Run tests from ethereum/tests -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_BLOCKCHAIN_TESTS_DIR), - ids=idfn, -) -def test_eest_tests(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tox.ini b/tox.ini index 84349e6901..9aef35fc94 100644 --- a/tox.ini +++ b/tox.ini @@ -9,12 +9,12 @@ extras = test doc commands = - isort src tests --check --diff --skip-glob "tests/fixtures/*" - black src tests --check --diff --exclude "tests/fixtures/*" - flake8 src tests - mypy src tests --exclude "tests/fixtures/*" --namespace-packages + isort src tests --check --diff --skip-glob "tests/json_infra/fixtures/*" + black src tests --check --diff --exclude "tests/json_infra/fixtures/*" + flake8 src tests --exclude "tests/json_infra/fixtures/*" + mypy src tests --exclude "tests/json_infra/fixtures/*" --namespace-packages ethereum-spec-lint - vulture src tests vulture_whitelist.py --exclude "*/tests/fixtures/*" --ignore-names "pytest_*" + vulture src tests vulture_whitelist.py --exclude "*/tests/json_infra/fixtures/*" --ignore-names "pytest_*" [testenv:json_infra] extras = From e6bbba6b0932dedd22c48f4d5554901e8f50ad00 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Wed, 30 Jul 2025 16:40:08 +0200 Subject: [PATCH 03/14] move ethash tests to json_infra --- tests/byzantium/test_ethash.py | 109 -------------------- tests/constantinople/test_ethash.py | 109 -------------------- tests/frontier/test_ethash.py | 109 -------------------- tests/homestead/test_ethash.py | 109 -------------------- tests/istanbul/test_ethash.py | 109 -------------------- tests/{berlin => json_infra}/test_ethash.py | 51 ++++++--- tests/spurious_dragon/test_ethash.py | 109 -------------------- tests/tangerine_whistle/test_ethash.py | 109 -------------------- 8 files changed, 36 insertions(+), 778 deletions(-) delete mode 100644 tests/byzantium/test_ethash.py delete mode 100644 tests/constantinople/test_ethash.py delete mode 100644 tests/frontier/test_ethash.py delete mode 100644 tests/homestead/test_ethash.py delete mode 100644 tests/istanbul/test_ethash.py rename tests/{berlin => json_infra}/test_ethash.py (71%) delete mode 100644 tests/spurious_dragon/test_ethash.py delete mode 100644 tests/tangerine_whistle/test_ethash.py diff --git a/tests/byzantium/test_ethash.py b/tests/byzantium/test_ethash.py deleted file mode 100644 index 409ed6b986..0000000000 --- a/tests/byzantium/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.byzantium.blocks import Header -from ethereum.byzantium.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("Byzantium", "byzantium") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/constantinople/test_ethash.py b/tests/constantinople/test_ethash.py deleted file mode 100644 index f608de94f9..0000000000 --- a/tests/constantinople/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.constantinople.blocks import Header -from ethereum.constantinople.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("ConstantinopleFix", "constantinople") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/frontier/test_ethash.py b/tests/frontier/test_ethash.py deleted file mode 100644 index 64fc675866..0000000000 --- a/tests/frontier/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.frontier.blocks import Header -from ethereum.frontier.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("Frontier", "frontier") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/homestead/test_ethash.py b/tests/homestead/test_ethash.py deleted file mode 100644 index 0d651d7bb5..0000000000 --- a/tests/homestead/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.homestead.blocks import Header -from ethereum.homestead.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("Homestead", "homestead") - header: Header = cast(Header, load.json_to_header(block_json_data)) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/istanbul/test_ethash.py b/tests/istanbul/test_ethash.py deleted file mode 100644 index ea72cdc935..0000000000 --- a/tests/istanbul/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.istanbul.blocks import Header -from ethereum.istanbul.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("Istanbul", "istanbul") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/berlin/test_ethash.py b/tests/json_infra/test_ethash.py similarity index 71% rename from tests/berlin/test_ethash.py rename to tests/json_infra/test_ethash.py index 00f3cbfa57..bd17a161f1 100644 --- a/tests/berlin/test_ethash.py +++ b/tests/json_infra/test_ethash.py @@ -1,3 +1,4 @@ +import importlib import json import pkgutil from typing import Any, Dict, List, cast @@ -6,11 +7,6 @@ from ethereum_rlp import rlp from ethereum_types.numeric import Uint -from ethereum.berlin.blocks import Header -from ethereum.berlin.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) from ethereum.crypto.hash import keccak256 from ethereum.ethash import ( cache_size, @@ -25,14 +21,30 @@ hex_to_bytes32, ) from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load + +from ..json_infra.load_blockchain_tests import Load +from . import FORKS, TEST_FIXTURES ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +POW_FORKS = [ + "Frontier", + "Homestead", + "EIP150", + "EIP158", + "Byzantium", + "ConstantinopleFix", + "Istanbul", + "Berlin", +] + -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() +@pytest.mark.parametrize("network", POW_FORKS) +def test_ethtest_fixtures(network: str) -> None: + package = FORKS[network]["package"] + fork_module = importlib.import_module(f"ethereum.{package}.fork") + + ethereum_tests = load_pow_test_fixtures(network) for test in ethereum_tests: header = test["header"] assert header.nonce == test["nonce"] @@ -41,7 +53,7 @@ def test_ethtest_fixtures() -> None: assert cache_size(header.number) == test["cache_size"] assert dataset_size(header.number) == test["dataset_size"] - header_hash = generate_header_hash_for_pow(header) + header_hash = fork_module.generate_header_hash_for_pow(header) assert header_hash == test["header_hash"] cache = generate_cache(header.number) @@ -59,7 +71,10 @@ def test_ethtest_fixtures() -> None: assert result == test["result"] -def load_pow_test_fixtures() -> List[Dict[str, Any]]: +def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]: + package = FORKS[network]["package"] + Header = importlib.import_module(f"ethereum.{package}.blocks").Header + with open( f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" ) as pow_test_file_handler: @@ -82,6 +97,7 @@ def load_pow_test_fixtures() -> List[Dict[str, Any]]: @pytest.mark.slow +@pytest.mark.parametrize("network", POW_FORKS) @pytest.mark.parametrize( "block_file_name", [ @@ -90,15 +106,20 @@ def load_pow_test_fixtures() -> List[Dict[str, Any]]: "block_12964999.json", ], ) -def test_pow_validation_block_headers(block_file_name: str) -> None: +def test_pow_validation_block_headers( + network: str, block_file_name: str +) -> None: + package = cast(str, FORKS[network]["package"]) + fork_module = importlib.import_module(f"ethereum.{package}.fork") + block_str_data = cast( bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") ).decode() block_json_data = json.loads(block_str_data) - load = Load("Berlin", "berlin") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) + load = Load(network, package) + header = load.json_to_header(block_json_data) + fork_module.validate_proof_of_work(header) # TODO: Once there is a method to download blocks, test the proof-of-work diff --git a/tests/spurious_dragon/test_ethash.py b/tests/spurious_dragon/test_ethash.py deleted file mode 100644 index 7a50cf3fe9..0000000000 --- a/tests/spurious_dragon/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.spurious_dragon.blocks import Header -from ethereum.spurious_dragon.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("EIP158", "spurious_dragon") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork diff --git a/tests/tangerine_whistle/test_ethash.py b/tests/tangerine_whistle/test_ethash.py deleted file mode 100644 index fe82d033d8..0000000000 --- a/tests/tangerine_whistle/test_ethash.py +++ /dev/null @@ -1,109 +0,0 @@ -import json -import pkgutil -from typing import Any, Dict, List, cast - -import pytest -from ethereum_rlp import rlp -from ethereum_types.numeric import Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.ethash import ( - cache_size, - dataset_size, - generate_cache, - generate_seed, - hashimoto_light, -) -from ethereum.tangerine_whistle.blocks import Header -from ethereum.tangerine_whistle.fork import ( - generate_header_hash_for_pow, - validate_proof_of_work, -) -from ethereum.utils.hexadecimal import ( - hex_to_bytes, - hex_to_bytes8, - hex_to_bytes32, -) -from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from tests.helpers import TEST_FIXTURES -from tests.helpers.load_state_tests import Load - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def test_ethtest_fixtures() -> None: - ethereum_tests = load_pow_test_fixtures() - for test in ethereum_tests: - header = test["header"] - assert header.nonce == test["nonce"] - assert header.mix_digest == test["mix_digest"] - assert generate_seed(header.number) == test["seed"] - assert cache_size(header.number) == test["cache_size"] - assert dataset_size(header.number) == test["dataset_size"] - - header_hash = generate_header_hash_for_pow(header) - assert header_hash == test["header_hash"] - - cache = generate_cache(header.number) - cache_hash = keccak256( - b"".join( - le_uint32_sequence_to_bytes(cache_item) for cache_item in cache - ) - ) - assert cache_hash == test["cache_hash"] - - mix_digest, result = hashimoto_light( - header_hash, header.nonce, cache, dataset_size(header.number) - ) - assert mix_digest == test["mix_digest"] - assert result == test["result"] - - -def load_pow_test_fixtures() -> List[Dict[str, Any]]: - with open( - f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" - ) as pow_test_file_handler: - return [ - { - "nonce": hex_to_bytes8(raw_fixture["nonce"]), - "mix_digest": hex_to_bytes32(raw_fixture["mixHash"]), - "header": rlp.decode_to( - Header, hex_to_bytes(raw_fixture["header"]) - ), - "seed": hex_to_bytes32(raw_fixture["seed"]), - "result": hex_to_bytes32(raw_fixture["result"]), - "cache_size": Uint(raw_fixture["cache_size"]), - "dataset_size": Uint(raw_fixture["full_size"]), - "header_hash": hex_to_bytes32(raw_fixture["header_hash"]), - "cache_hash": hex_to_bytes32(raw_fixture["cache_hash"]), - } - for raw_fixture in json.load(pow_test_file_handler).values() - ] - - -@pytest.mark.slow -@pytest.mark.parametrize( - "block_file_name", - [ - "block_1.json", - "block_1234567.json", - "block_12964999.json", - ], -) -def test_pow_validation_block_headers(block_file_name: str) -> None: - block_str_data = cast( - bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") - ).decode() - block_json_data = json.loads(block_str_data) - - load = Load("EIP150", "tangerine_whistle") - header: Header = load.json_to_header(block_json_data) - validate_proof_of_work(header) - - -# TODO: Once there is a method to download blocks, test the proof-of-work -# validation for the following blocks in each hardfork (except London as the -# current PoW algo won't work from London): -# * Start of hardfork -# * two random blocks inside the hardfork -# * End of hardfork From 78ff049bfb2b641a630d79b562414ac84ff5b4a0 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Wed, 30 Jul 2025 20:16:12 +0200 Subject: [PATCH 04/14] move state tests to json_infra --- tests/berlin/test_evm_tools.py | 60 ----------------- tests/byzantium/test_evm_tools.py | 53 --------------- tests/cancun/test_evm_tools.py | 56 ---------------- tests/constantinople/test_evm_tools.py | 52 --------------- tests/frontier/test_evm_tools.py | 53 --------------- tests/homestead/test_evm_tools.py | 54 ---------------- tests/istanbul/test_evm_tools.py | 60 ----------------- tests/json_infra/helpers/__init__.py | 0 .../helpers/exceptional_test_patterns.py | 24 +++++++ .../helpers/load_state_tests.py} | 39 +++++++---- tests/json_infra/test_ethash.py | 2 +- tests/json_infra/test_state_tests.py | 43 +++++++++++++ tests/london/test_evm_tools.py | 60 ----------------- tests/osaka/test_evm_tools.py | 64 ------------------- tests/paris/test_evm_tools.py | 60 ----------------- tests/prague/test_evm_tools.py | 64 ------------------- tests/shanghai/test_evm_tools.py | 60 ----------------- tests/spurious_dragon/test_evm_tools.py | 53 --------------- tests/tangerine_whistle/test_evm_tools.py | 54 ---------------- 19 files changed, 93 insertions(+), 818 deletions(-) delete mode 100644 tests/berlin/test_evm_tools.py delete mode 100644 tests/byzantium/test_evm_tools.py delete mode 100644 tests/cancun/test_evm_tools.py delete mode 100644 tests/constantinople/test_evm_tools.py delete mode 100644 tests/frontier/test_evm_tools.py delete mode 100644 tests/homestead/test_evm_tools.py delete mode 100644 tests/istanbul/test_evm_tools.py create mode 100644 tests/json_infra/helpers/__init__.py rename tests/{helpers/load_evm_tools_tests.py => json_infra/helpers/load_state_tests.py} (75%) create mode 100644 tests/json_infra/test_state_tests.py delete mode 100644 tests/london/test_evm_tools.py delete mode 100644 tests/osaka/test_evm_tools.py delete mode 100644 tests/paris/test_evm_tools.py delete mode 100644 tests/prague/test_evm_tools.py delete mode 100644 tests/shanghai/test_evm_tools.py delete mode 100644 tests/spurious_dragon/test_evm_tools.py delete mode 100644 tests/tangerine_whistle/test_evm_tools.py diff --git a/tests/berlin/test_evm_tools.py b/tests/berlin/test_evm_tools.py deleted file mode 100644 index 8735219cde..0000000000 --- a/tests/berlin/test_evm_tools.py +++ /dev/null @@ -1,60 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Berlin" - -SLOW_TESTS = ( - "CALLBlake2f_MaxRounds", - "CALLCODEBlake2f", - "CALLBlake2f", - "loopExp", - "loopMul", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/byzantium/test_evm_tools.py b/tests/byzantium/test_evm_tools.py deleted file mode 100644 index cdf5ea6a22..0000000000 --- a/tests/byzantium/test_evm_tools.py +++ /dev/null @@ -1,53 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Byzantium" - -SLOW_TESTS = () - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/cancun/test_evm_tools.py b/tests/cancun/test_evm_tools.py deleted file mode 100644 index e0e71d253b..0000000000 --- a/tests/cancun/test_evm_tools.py +++ /dev/null @@ -1,56 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/GeneralStateTests/" -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Cancun" - -SLOW_TESTS = ( - "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/constantinople/test_evm_tools.py b/tests/constantinople/test_evm_tools.py deleted file mode 100644 index 0cafe1c7db..0000000000 --- a/tests/constantinople/test_evm_tools.py +++ /dev/null @@ -1,52 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "ConstantinopleFix" - -SLOW_TESTS = () -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/frontier/test_evm_tools.py b/tests/frontier/test_evm_tools.py deleted file mode 100644 index 7ef3de2ac3..0000000000 --- a/tests/frontier/test_evm_tools.py +++ /dev/null @@ -1,53 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Frontier" - -SLOW_TESTS = () - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/homestead/test_evm_tools.py b/tests/homestead/test_evm_tools.py deleted file mode 100644 index e8e2e24f52..0000000000 --- a/tests/homestead/test_evm_tools.py +++ /dev/null @@ -1,54 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Homestead" - - -SLOW_TESTS = () - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/istanbul/test_evm_tools.py b/tests/istanbul/test_evm_tools.py deleted file mode 100644 index 80c169a440..0000000000 --- a/tests/istanbul/test_evm_tools.py +++ /dev/null @@ -1,60 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Istanbul" - -SLOW_TESTS = ( - "CALLBlake2f_MaxRounds", - "CALLCODEBlake2f", - "CALLBlake2f", - "loopExp", - "loopMul", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/json_infra/helpers/__init__.py b/tests/json_infra/helpers/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/json_infra/helpers/exceptional_test_patterns.py b/tests/json_infra/helpers/exceptional_test_patterns.py index 9b7af2c1cf..43e3c4a7c4 100644 --- a/tests/json_infra/helpers/exceptional_test_patterns.py +++ b/tests/json_infra/helpers/exceptional_test_patterns.py @@ -78,3 +78,27 @@ def get_exceptional_blockchain_test_patterns( ) return slow_tests, ignore_tests, big_memory_tests + + +def get_exceptional_state_test_patterns( + network: str, package: str +) -> tuple[str, ...]: + slow_tests = ( + "CALLBlake2f_MaxRounds", + "CALLCODEBlake2f", + "CALLBlake2f", + "loopExp", + "loopMul", + "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_non-degeneracy-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_bilinearity-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-inf_pair-]", + f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-multi_inf_pair-]", + ) + + return slow_tests diff --git a/tests/helpers/load_evm_tools_tests.py b/tests/json_infra/helpers/load_state_tests.py similarity index 75% rename from tests/helpers/load_evm_tools_tests.py rename to tests/json_infra/helpers/load_state_tests.py index afbbd14f89..640c7a20cf 100644 --- a/tests/helpers/load_evm_tools_tests.py +++ b/tests/json_infra/helpers/load_state_tests.py @@ -3,7 +3,7 @@ import sys from glob import glob from io import StringIO -from typing import Dict, Generator, Optional, Tuple +from typing import Dict, Generator, cast import pytest @@ -13,31 +13,41 @@ from ethereum_spec_tools.evm_tools.statetest import read_test_cases from ethereum_spec_tools.evm_tools.t8n import T8N +from .. import FORKS +from .exceptional_test_patterns import get_exceptional_state_test_patterns + parser = create_parser() -def fetch_evm_tools_tests( - test_dir: str, - fork_name: str, - slow_tests: Optional[Tuple[str, ...]] = None, -) -> Generator: +def fetch_state_tests(network: str) -> Generator: """ Fetches all the general state tests from the given directory """ - if slow_tests is None: - slow_tests = tuple() + # Filter FORKS based on fork_option parameter + package = cast(str, FORKS[network]["package"]) + test_dirs = cast(list[str], FORKS[network]["state_test_dirs"]) + + slow_tests = get_exceptional_state_test_patterns(network, package) - pattern = os.path.join(test_dir, "**/*.json") - for test_file_path in glob(pattern, recursive=True): + # Get all the files to iterate over from both eest_tests_path and ethereum_tests_path + all_jsons = [] + for test_dir in test_dirs: + all_jsons.extend( + glob(os.path.join(test_dir, "**/*.json"), recursive=True) + ) + + for test_file_path in all_jsons: test_cases = read_test_cases(test_file_path) + for test_case in test_cases: - if test_case.fork_name != fork_name: + if test_case.fork_name != network: continue test_case_dict = { "test_file": test_case.path, "test_key": test_case.key, "index": test_case.index, + "network": network, } if test_case.key in slow_tests: @@ -58,13 +68,14 @@ def idfn(test_case: Dict) -> str: return f"{folder_name} - {test_key} - {index}" -def load_evm_tools_test(test_case: Dict[str, str], fork_name: str) -> None: +def run_state_test(test_case: Dict[str, str]) -> None: """ Runs a single general state test """ test_file = test_case["test_file"] test_key = test_case["test_key"] index = test_case["index"] + network = test_case["network"] with open(test_file) as f: tests = json.load(f) @@ -77,7 +88,7 @@ def load_evm_tools_test(test_case: Dict[str, str], fork_name: str) -> None: alloc = tests[test_key]["pre"] - post = tests[test_key]["post"][fork_name][index] + post = tests[test_key]["post"][network][index] post_hash = post["hash"] d = post["indexes"]["data"] g = post["indexes"]["gas"] @@ -119,7 +130,7 @@ def load_evm_tools_test(test_case: Dict[str, str], fork_name: str) -> None: "--input.txs", "stdin", "--state.fork", - f"{fork_name}", + f"{network}", "--state-test", ] t8n_options = parser.parse_args(t8n_args) diff --git a/tests/json_infra/test_ethash.py b/tests/json_infra/test_ethash.py index bd17a161f1..df2739897e 100644 --- a/tests/json_infra/test_ethash.py +++ b/tests/json_infra/test_ethash.py @@ -22,8 +22,8 @@ ) from ethereum.utils.numeric import le_uint32_sequence_to_bytes -from ..json_infra.load_blockchain_tests import Load from . import FORKS, TEST_FIXTURES +from .helpers.load_blockchain_tests import Load ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] diff --git a/tests/json_infra/test_state_tests.py b/tests/json_infra/test_state_tests.py new file mode 100644 index 0000000000..01d347b388 --- /dev/null +++ b/tests/json_infra/test_state_tests.py @@ -0,0 +1,43 @@ +from typing import Callable, Dict + +import pytest + +from . import FORKS +from .conftest import pytest_config +from .helpers.load_state_tests import fetch_state_tests, idfn, run_state_test + + +def _generate_test_function(fork_name: str) -> Callable: + @pytest.mark.evm_tools + @pytest.mark.json_state_tests + @pytest.mark.parametrize( + "state_test_case", + fetch_state_tests(fork_name), + ids=idfn, + ) + def test_func(state_test_case: Dict) -> None: + run_state_test(state_test_case) + + test_func.__name__ = f"test_state_tests_{fork_name.lower()}" + return test_func + + +# Get the fork option from pytest config if available + +# Determine which forks to generate tests for +if pytest_config and pytest_config.getoption("fork", None): + # If --fork option is specified, only generate test for that fork + fork_option = pytest_config.getoption("fork") + if fork_option in FORKS: + forks_to_test = [fork_option] + else: + # If specified fork is not valid, generate no tests + forks_to_test = [] +else: + # If no --fork option, generate tests for all forks + forks_to_test = list(FORKS.keys()) + +for fork_name in forks_to_test: + locals()[ + f"test_state_tests_{fork_name.lower()}" + ] = _generate_test_function(fork_name) diff --git a/tests/london/test_evm_tools.py b/tests/london/test_evm_tools.py deleted file mode 100644 index 0347da6cec..0000000000 --- a/tests/london/test_evm_tools.py +++ /dev/null @@ -1,60 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "London" - -SLOW_TESTS = ( - "CALLBlake2f_MaxRounds", - "CALLCODEBlake2f", - "CALLBlake2f", - "loopExp", - "loopMul", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/osaka/test_evm_tools.py b/tests/osaka/test_evm_tools.py deleted file mode 100644 index 2078846201..0000000000 --- a/tests/osaka/test_evm_tools.py +++ /dev/null @@ -1,64 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import ETHEREUM_TESTS_PATH, OSAKA_TEST_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/GeneralStateTests/" -EEST_STATE_TESTS_DIR = f"{OSAKA_TEST_PATH}/fixtures/state_tests/" -FORK_NAME = "Osaka" - - -SLOW_TESTS = ( - "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Osaka]-d0g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Osaka]-d[0-14]g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Osaka]-d[0-2]g0v0", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_non-degeneracy-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_bilinearity-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-inf_pair-]", - "tests/osaka/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Osaka-state_test-multi_inf_pair-]", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/paris/test_evm_tools.py b/tests/paris/test_evm_tools.py deleted file mode 100644 index 1598e44b4b..0000000000 --- a/tests/paris/test_evm_tools.py +++ /dev/null @@ -1,60 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Paris" - -SLOW_TESTS = ( - "CALLBlake2f_MaxRounds", - "CALLCODEBlake2f", - "CALLBlake2f", - "loopExp", - "loopMul", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/prague/test_evm_tools.py b/tests/prague/test_evm_tools.py deleted file mode 100644 index 376c11b77c..0000000000 --- a/tests/prague/test_evm_tools.py +++ /dev/null @@ -1,64 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = f"{ETHEREUM_TESTS_PATH}/GeneralStateTests/" -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Prague" - - -SLOW_TESTS = ( - "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_non-degeneracy-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_bilinearity-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-inf_pair-]", - "tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_Prague-state_test-multi_inf_pair-]", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/shanghai/test_evm_tools.py b/tests/shanghai/test_evm_tools.py deleted file mode 100644 index 4f7497ee7b..0000000000 --- a/tests/shanghai/test_evm_tools.py +++ /dev/null @@ -1,60 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Cancun/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "Shanghai" - -SLOW_TESTS = ( - "CALLBlake2f_MaxRounds", - "CALLCODEBlake2f", - "CALLBlake2f", - "loopExp", - "loopMul", -) - - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/spurious_dragon/test_evm_tools.py b/tests/spurious_dragon/test_evm_tools.py deleted file mode 100644 index 5394bd5c1c..0000000000 --- a/tests/spurious_dragon/test_evm_tools.py +++ /dev/null @@ -1,53 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "EIP158" - -SLOW_TESTS = () - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) diff --git a/tests/tangerine_whistle/test_evm_tools.py b/tests/tangerine_whistle/test_evm_tools.py deleted file mode 100644 index 94a6b8ab8a..0000000000 --- a/tests/tangerine_whistle/test_evm_tools.py +++ /dev/null @@ -1,54 +0,0 @@ -from functools import partial -from typing import Dict - -import pytest - -from tests.helpers import EEST_TESTS_PATH, ETHEREUM_TESTS_PATH -from tests.helpers.load_evm_tools_tests import ( - fetch_evm_tools_tests, - idfn, - load_evm_tools_test, -) - -ETHEREUM_STATE_TESTS_DIR = ( - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/GeneralStateTests/" -) -EEST_STATE_TESTS_DIR = f"{EEST_TESTS_PATH}/state_tests/" -FORK_NAME = "EIP150" - - -SLOW_TESTS = () - -# Define tests -fetch_tests = partial( - fetch_evm_tools_tests, - fork_name=FORK_NAME, - slow_tests=SLOW_TESTS, -) - -run_tests = partial( - load_evm_tools_test, - fork_name=FORK_NAME, -) - - -# Run tests from ethereum/tests -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(ETHEREUM_STATE_TESTS_DIR), - ids=idfn, -) -def test_ethereum_tests_evm_tools(test_case: Dict) -> None: - run_tests(test_case) - - -# Run EEST test fixtures -@pytest.mark.evm_tools -@pytest.mark.parametrize( - "test_case", - fetch_tests(EEST_STATE_TESTS_DIR), - ids=idfn, -) -def test_eest_evm_tools(test_case: Dict) -> None: - run_tests(test_case) From d3decdd2ac7f08df23c0336ab493c09657ff0f5c Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Thu, 31 Jul 2025 19:18:56 +0200 Subject: [PATCH 05/14] move trie tests to json_infra --- tests/berlin/test_trie.py | 89 --------------------- tests/byzantium/test_trie.py | 89 --------------------- tests/cancun/test_trie.py | 89 --------------------- tests/constantinople/test_trie.py | 89 --------------------- tests/frontier/test_trie.py | 89 --------------------- tests/homestead/test_trie.py | 89 --------------------- tests/istanbul/test_trie.py | 89 --------------------- tests/json_infra/test_trie.py | 114 +++++++++++++++++++++++++++ tests/london/test_trie.py | 89 --------------------- tests/osaka/test_trie.py | 89 --------------------- tests/paris/test_trie.py | 89 --------------------- tests/prague/test_trie.py | 89 --------------------- tests/shanghai/test_trie.py | 89 --------------------- tests/spurious_dragon/test_trie.py | 89 --------------------- tests/tangerine_whistle/test_trie.py | 89 --------------------- 15 files changed, 114 insertions(+), 1246 deletions(-) delete mode 100644 tests/berlin/test_trie.py delete mode 100644 tests/byzantium/test_trie.py delete mode 100644 tests/cancun/test_trie.py delete mode 100644 tests/constantinople/test_trie.py delete mode 100644 tests/frontier/test_trie.py delete mode 100644 tests/homestead/test_trie.py delete mode 100644 tests/istanbul/test_trie.py create mode 100644 tests/json_infra/test_trie.py delete mode 100644 tests/london/test_trie.py delete mode 100644 tests/osaka/test_trie.py delete mode 100644 tests/paris/test_trie.py delete mode 100644 tests/prague/test_trie.py delete mode 100644 tests/shanghai/test_trie.py delete mode 100644 tests/spurious_dragon/test_trie.py delete mode 100644 tests/tangerine_whistle/test_trie.py diff --git a/tests/berlin/test_trie.py b/tests/berlin/test_trie.py deleted file mode 100644 index b1ad2b90b1..0000000000 --- a/tests/berlin/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.berlin.fork_types import Bytes -from ethereum.berlin.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/byzantium/test_trie.py b/tests/byzantium/test_trie.py deleted file mode 100644 index 82a4739d56..0000000000 --- a/tests/byzantium/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.byzantium.fork_types import Bytes -from ethereum.byzantium.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/cancun/test_trie.py b/tests/cancun/test_trie.py deleted file mode 100644 index edc329c73c..0000000000 --- a/tests/cancun/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.cancun.fork_types import Bytes -from ethereum.cancun.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -FIXTURE_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{FIXTURE_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/constantinople/test_trie.py b/tests/constantinople/test_trie.py deleted file mode 100644 index b18b0e81ab..0000000000 --- a/tests/constantinople/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.constantinople.fork_types import Bytes -from ethereum.constantinople.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/frontier/test_trie.py b/tests/frontier/test_trie.py deleted file mode 100644 index 673e2ea1a7..0000000000 --- a/tests/frontier/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.frontier.fork_types import Bytes -from ethereum.frontier.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/homestead/test_trie.py b/tests/homestead/test_trie.py deleted file mode 100644 index e735892d2f..0000000000 --- a/tests/homestead/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.homestead.fork_types import Bytes -from ethereum.homestead.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/istanbul/test_trie.py b/tests/istanbul/test_trie.py deleted file mode 100644 index 713d2564d6..0000000000 --- a/tests/istanbul/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.istanbul.fork_types import Bytes -from ethereum.istanbul.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/json_infra/test_trie.py b/tests/json_infra/test_trie.py new file mode 100644 index 0000000000..4b262a4d7b --- /dev/null +++ b/tests/json_infra/test_trie.py @@ -0,0 +1,114 @@ +import importlib +import json +from typing import Any + +import pytest +from ethereum_types.bytes import Bytes + +from ethereum.utils.hexadecimal import ( + has_hex_prefix, + hex_to_bytes, + remove_hex_prefix, +) + +from . import FORKS, TEST_FIXTURES + +FIXTURE_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] + +forks = FORKS.keys() + + +def to_bytes(data: str) -> Bytes: + if data is None: + return b"" + if has_hex_prefix(data): + return hex_to_bytes(data) + + return data.encode() + + +@pytest.mark.parametrize("fork", forks) +def test_trie_secure_hex(fork: str) -> None: + tests = load_tests("hex_encoded_securetrie_test.json") + + package = FORKS[fork]["package"] + trie_module = importlib.import_module(f"ethereum.{package}.trie") + + for name, test in tests.items(): + st = trie_module.Trie(secured=True, default=b"") + for k, v in test.get("in").items(): + trie_module.trie_set(st, to_bytes(k), to_bytes(v)) + result = trie_module.root(st) + expected = remove_hex_prefix(test.get("root")) + assert result.hex() == expected, f"test {name} failed" + + +@pytest.mark.parametrize("fork", forks) +def test_trie_secure(fork: str) -> None: + tests = load_tests("trietest_secureTrie.json") + + package = FORKS[fork]["package"] + trie_module = importlib.import_module(f"ethereum.{package}.trie") + + for name, test in tests.items(): + st = trie_module.Trie(secured=True, default=b"") + for t in test.get("in"): + trie_module.trie_set(st, to_bytes(t[0]), to_bytes(t[1])) + result = trie_module.root(st) + expected = remove_hex_prefix(test.get("root")) + assert result.hex() == expected, f"test {name} failed" + + +@pytest.mark.parametrize("fork", forks) +def test_trie_secure_any_order(fork: str) -> None: + tests = load_tests("trieanyorder_secureTrie.json") + + package = FORKS[fork]["package"] + trie_module = importlib.import_module(f"ethereum.{package}.trie") + + for name, test in tests.items(): + st = trie_module.Trie(secured=True, default=b"") + for k, v in test.get("in").items(): + trie_module.trie_set(st, to_bytes(k), to_bytes(v)) + result = trie_module.root(st) + expected = remove_hex_prefix(test.get("root")) + assert result.hex() == expected, f"test {name} failed" + + +@pytest.mark.parametrize("fork", forks) +def test_trie(fork: str) -> None: + tests = load_tests("trietest.json") + + package = FORKS[fork]["package"] + trie_module = importlib.import_module(f"ethereum.{package}.trie") + + for name, test in tests.items(): + st = trie_module.Trie(secured=False, default=b"") + for t in test.get("in"): + trie_module.trie_set(st, to_bytes(t[0]), to_bytes(t[1])) + result = trie_module.root(st) + expected = remove_hex_prefix(test.get("root")) + assert result.hex() == expected, f"test {name} failed" + + +@pytest.mark.parametrize("fork", forks) +def test_trie_any_order(fork: str) -> None: + tests = load_tests("trieanyorder.json") + + package = FORKS[fork]["package"] + trie_module = importlib.import_module(f"ethereum.{package}.trie") + + for name, test in tests.items(): + st = trie_module.Trie(secured=False, default=b"") + for k, v in test.get("in").items(): + trie_module.trie_set(st, to_bytes(k), to_bytes(v)) + result = trie_module.root(st) + expected = remove_hex_prefix(test.get("root")) + assert result.hex() == expected, f"test {name} failed" + + +def load_tests(path: str) -> Any: + with open(f"{FIXTURE_PATH}/TrieTests/" + path) as f: + tests = json.load(f) + + return tests diff --git a/tests/london/test_trie.py b/tests/london/test_trie.py deleted file mode 100644 index dc4a33b291..0000000000 --- a/tests/london/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.london.fork_types import Bytes -from ethereum.london.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/osaka/test_trie.py b/tests/osaka/test_trie.py deleted file mode 100644 index 04c86a1e08..0000000000 --- a/tests/osaka/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.osaka.fork_types import Bytes -from ethereum.osaka.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -FIXTURE_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{FIXTURE_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/paris/test_trie.py b/tests/paris/test_trie.py deleted file mode 100644 index 27cb78ffeb..0000000000 --- a/tests/paris/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.paris.fork_types import Bytes -from ethereum.paris.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/prague/test_trie.py b/tests/prague/test_trie.py deleted file mode 100644 index 1938c238a2..0000000000 --- a/tests/prague/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.prague.fork_types import Bytes -from ethereum.prague.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -FIXTURE_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{FIXTURE_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/shanghai/test_trie.py b/tests/shanghai/test_trie.py deleted file mode 100644 index daf5b9e57b..0000000000 --- a/tests/shanghai/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.shanghai.fork_types import Bytes -from ethereum.shanghai.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -FIXTURE_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{FIXTURE_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/spurious_dragon/test_trie.py b/tests/spurious_dragon/test_trie.py deleted file mode 100644 index 910a39a81f..0000000000 --- a/tests/spurious_dragon/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.spurious_dragon.fork_types import Bytes -from ethereum.spurious_dragon.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests diff --git a/tests/tangerine_whistle/test_trie.py b/tests/tangerine_whistle/test_trie.py deleted file mode 100644 index cf376a627f..0000000000 --- a/tests/tangerine_whistle/test_trie.py +++ /dev/null @@ -1,89 +0,0 @@ -import json -from typing import Any - -from ethereum.tangerine_whistle.fork_types import Bytes -from ethereum.tangerine_whistle.trie import Trie, root, trie_set -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) -from tests.helpers import TEST_FIXTURES - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -def to_bytes(data: str) -> Bytes: - if data is None: - return b"" - if has_hex_prefix(data): - return hex_to_bytes(data) - - return data.encode() - - -def test_trie_secure_hex() -> None: - tests = load_tests("hex_encoded_securetrie_test.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure() -> None: - tests = load_tests("trietest_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_secure_any_order() -> None: - tests = load_tests("trieanyorder_secureTrie.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=True, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie() -> None: - tests = load_tests("trietest.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for t in test.get("in"): - trie_set(st, to_bytes(t[0]), to_bytes(t[1])) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def test_trie_any_order() -> None: - tests = load_tests("trieanyorder.json") - - for name, test in tests.items(): - st: Trie[Bytes, Bytes] = Trie(secured=False, default=b"") - for k, v in test.get("in").items(): - trie_set(st, to_bytes(k), to_bytes(v)) - result = root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" - - -def load_tests(path: str) -> Any: - with open(f"{ETHEREUM_TESTS_PATH}/TrieTests/" + path) as f: - tests = json.load(f) - - return tests From b612567d97abca8af533b98702a7b9dabd9525e0 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Fri, 1 Aug 2025 05:40:18 +0200 Subject: [PATCH 06/14] move transaction tests to json_infra --- tests/berlin/test_transaction.py | 57 ----------- tests/byzantium/test_transaction.py | 56 ----------- tests/constantinople/test_transaction.py | 59 ------------ tests/frontier/test_transaction.py | 54 ----------- tests/homestead/test_transaction.py | 56 ----------- tests/istanbul/test_transaction.py | 54 ----------- .../helpers/load_transaction_tests.py} | 13 ++- tests/json_infra/test_transaction.py | 96 +++++++++++++++++++ tests/london/test_transaction.py | 57 ----------- tests/spurious_dragon/test_transaction.py | 59 ------------ tests/tangerine_whistle/test_transaction.py | 59 ------------ 11 files changed, 107 insertions(+), 513 deletions(-) delete mode 100644 tests/berlin/test_transaction.py delete mode 100644 tests/byzantium/test_transaction.py delete mode 100644 tests/constantinople/test_transaction.py delete mode 100644 tests/frontier/test_transaction.py delete mode 100644 tests/homestead/test_transaction.py delete mode 100644 tests/istanbul/test_transaction.py rename tests/{helpers/fork_types_helpers.py => json_infra/helpers/load_transaction_tests.py} (63%) create mode 100644 tests/json_infra/test_transaction.py delete mode 100644 tests/london/test_transaction.py delete mode 100644 tests/spurious_dragon/test_transaction.py delete mode 100644 tests/tangerine_whistle/test_transaction.py diff --git a/tests/berlin/test_transaction.py b/tests/berlin/test_transaction.py deleted file mode 100644 index 8e2422201c..0000000000 --- a/tests/berlin/test_transaction.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.berlin.transactions import ( - LegacyTransaction, - validate_transaction, -) -from ethereum.exceptions import NonceOverflowError -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_berlin_transaction = partial(load_test_transaction, network="Berlin") - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_berlin_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(LegacyTransaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_berlin_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(LegacyTransaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/byzantium/test_transaction.py b/tests/byzantium/test_transaction.py deleted file mode 100644 index 357ad15d2c..0000000000 --- a/tests/byzantium/test_transaction.py +++ /dev/null @@ -1,56 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.byzantium.transactions import Transaction, validate_transaction -from ethereum.exceptions import NonceOverflowError -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_byzantium_transaction = partial( - load_test_transaction, network="Byzantium" -) - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_byzantium_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_byzantium_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/constantinople/test_transaction.py b/tests/constantinople/test_transaction.py deleted file mode 100644 index 4a302fb14b..0000000000 --- a/tests/constantinople/test_transaction.py +++ /dev/null @@ -1,59 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.constantinople.transactions import ( - Transaction, - validate_transaction, -) -from ethereum.exceptions import NonceOverflowError -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_constantinople_transaction = partial( - load_test_transaction, network="ConstantinopleFix" -) - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_constantinople_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_constantinople_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/frontier/test_transaction.py b/tests/frontier/test_transaction.py deleted file mode 100644 index 628b9c1787..0000000000 --- a/tests/frontier/test_transaction.py +++ /dev/null @@ -1,54 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.frontier.transactions import Transaction, validate_transaction -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_frontier_transaction = partial(load_test_transaction, network="Frontier") - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_frontier_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_frontier_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/homestead/test_transaction.py b/tests/homestead/test_transaction.py deleted file mode 100644 index 095f3a2331..0000000000 --- a/tests/homestead/test_transaction.py +++ /dev/null @@ -1,56 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.homestead.transactions import Transaction, validate_transaction -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_homestead_transaction = partial( - load_test_transaction, network="Homestead" -) - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_homestead_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_homestead_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/istanbul/test_transaction.py b/tests/istanbul/test_transaction.py deleted file mode 100644 index 9b9bc6ce80..0000000000 --- a/tests/istanbul/test_transaction.py +++ /dev/null @@ -1,54 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.istanbul.transactions import Transaction, validate_transaction -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_istanbul_transaction = partial(load_test_transaction, network="Istanbul") - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_istanbul_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_istanbul_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/helpers/fork_types_helpers.py b/tests/json_infra/helpers/load_transaction_tests.py similarity index 63% rename from tests/helpers/fork_types_helpers.py rename to tests/json_infra/helpers/load_transaction_tests.py index df60bf8b5b..72a4a74d42 100644 --- a/tests/helpers/fork_types_helpers.py +++ b/tests/json_infra/helpers/load_transaction_tests.py @@ -5,6 +5,13 @@ from ethereum.utils.hexadecimal import hex_to_bytes +class NoTestsFound(Exception): + """ + An exception thrown when the test for a particular fork isn't + available in the json fixture + """ + + def load_test_transaction( test_dir: str, test_file: str, network: str ) -> Dict[str, Any]: @@ -16,7 +23,9 @@ def load_test_transaction( json_data = json.load(fp)[f"{test_name}"] tx_rlp = hex_to_bytes(json_data["txbytes"]) - - test_result = json_data["result"][network] + try: + test_result = json_data["result"][network] + except KeyError: + raise NoTestsFound(f"No tests found for {network} in {test_file}") return {"tx_rlp": tx_rlp, "test_result": test_result} diff --git a/tests/json_infra/test_transaction.py b/tests/json_infra/test_transaction.py new file mode 100644 index 0000000000..8931b3ad14 --- /dev/null +++ b/tests/json_infra/test_transaction.py @@ -0,0 +1,96 @@ +from typing import Callable + +import pytest +from ethereum_rlp import rlp + +from ethereum.exceptions import NonceOverflowError +from ethereum.spurious_dragon.transactions import ( + Transaction, + validate_transaction, +) +from ethereum.utils.hexadecimal import hex_to_uint + +from . import FORKS, TEST_FIXTURES +from .conftest import pytest_config +from .helpers.load_transaction_tests import NoTestsFound, load_test_transaction + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] + +test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" + + +def _generate_high_nonce_tests_function(fork_name: str) -> Callable: + @pytest.mark.parametrize( + "test_file_high_nonce", + [ + "ttNonce/TransactionWithHighNonce64Minus1.json", + "ttNonce/TransactionWithHighNonce64.json", + "ttNonce/TransactionWithHighNonce64Plus1.json", + ], + ) + def test_func(test_file_high_nonce: str) -> None: + try: + test = load_test_transaction( + test_dir, test_file_high_nonce, fork_name + ) + except NoTestsFound: + pytest.skip( + f"No tests found for {fork_name} in {test_file_high_nonce}" + ) + + tx = rlp.decode_to(Transaction, test["tx_rlp"]) + + with pytest.raises(NonceOverflowError): + validate_transaction(tx) + + test_func.__name__ = f"test_high_nonce_tests_{fork_name.lower()}" + return test_func + + +def _generate_nonce_tests_function(fork_name: str) -> Callable: + @pytest.mark.parametrize( + "test_file_nonce", + [ + "ttNonce/TransactionWithHighNonce32.json", + "ttNonce/TransactionWithHighNonce64Minus2.json", + ], + ) + def test_func(test_file_nonce: str) -> None: + try: + test = load_test_transaction(test_dir, test_file_nonce, fork_name) + except NoTestsFound: + pytest.skip(f"No tests found for {fork_name} in {test_file_nonce}") + + tx = rlp.decode_to(Transaction, test["tx_rlp"]) + + result_intrinsic_gas_cost = hex_to_uint( + test["test_result"]["intrinsicGas"] + ) + + intrinsic_gas = validate_transaction(tx) + assert intrinsic_gas == result_intrinsic_gas_cost + + test_func.__name__ = f"test_nonce_tests_{fork_name.lower()}" + return test_func + + +# Determine which forks to generate tests for +if pytest_config and pytest_config.getoption("fork", None): + # If --fork option is specified, only generate test for that fork + fork_option = pytest_config.getoption("fork") + if fork_option in FORKS: + forks_to_test = [fork_option] + else: + # If specified fork is not valid, generate no tests + forks_to_test = [] +else: + # If no --fork option, generate tests for all forks + forks_to_test = list(FORKS.keys()) + +for fork_name in forks_to_test: + locals()[ + f"test_high_nonce_tests_{fork_name.lower()}" + ] = _generate_high_nonce_tests_function(fork_name) + locals()[ + f"test_nonce_tests_{fork_name.lower()}" + ] = _generate_nonce_tests_function(fork_name) diff --git a/tests/london/test_transaction.py b/tests/london/test_transaction.py deleted file mode 100644 index 5b47ee2b22..0000000000 --- a/tests/london/test_transaction.py +++ /dev/null @@ -1,57 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.london.transactions import ( - LegacyTransaction, - validate_transaction, -) -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_london_transaction = partial(load_test_transaction, network="London") - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_london_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(LegacyTransaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_london_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(LegacyTransaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/spurious_dragon/test_transaction.py b/tests/spurious_dragon/test_transaction.py deleted file mode 100644 index 07773db878..0000000000 --- a/tests/spurious_dragon/test_transaction.py +++ /dev/null @@ -1,59 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.spurious_dragon.transactions import ( - Transaction, - validate_transaction, -) -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_spurious_dragon_transaction = partial( - load_test_transaction, network="EIP158" -) - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_spurious_dragon_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_spurious_dragon_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost diff --git a/tests/tangerine_whistle/test_transaction.py b/tests/tangerine_whistle/test_transaction.py deleted file mode 100644 index 548dba328f..0000000000 --- a/tests/tangerine_whistle/test_transaction.py +++ /dev/null @@ -1,59 +0,0 @@ -from functools import partial - -import pytest -from ethereum_rlp import rlp - -from ethereum.exceptions import NonceOverflowError -from ethereum.tangerine_whistle.transactions import ( - Transaction, - validate_transaction, -) -from ethereum.utils.hexadecimal import hex_to_uint -from tests.helpers import TEST_FIXTURES - -from ..helpers.fork_types_helpers import load_test_transaction - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -test_dir = f"{ETHEREUM_TESTS_PATH}/TransactionTests" - -load_tangerine_whistle_transaction = partial( - load_test_transaction, network="EIP150" -) - - -@pytest.mark.parametrize( - "test_file_high_nonce", - [ - "ttNonce/TransactionWithHighNonce64Minus1.json", - "ttNonce/TransactionWithHighNonce64.json", - "ttNonce/TransactionWithHighNonce64Plus1.json", - ], -) -def test_high_nonce(test_file_high_nonce: str) -> None: - test = load_tangerine_whistle_transaction(test_dir, test_file_high_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - with pytest.raises(NonceOverflowError): - validate_transaction(tx) - - -@pytest.mark.parametrize( - "test_file_nonce", - [ - "ttNonce/TransactionWithHighNonce32.json", - "ttNonce/TransactionWithHighNonce64Minus2.json", - ], -) -def test_nonce(test_file_nonce: str) -> None: - test = load_tangerine_whistle_transaction(test_dir, test_file_nonce) - - tx = rlp.decode_to(Transaction, test["tx_rlp"]) - - result_intrinsic_gas_cost = hex_to_uint( - test["test_result"]["intrinsicGas"] - ) - - intrinsic_gas = validate_transaction(tx) - assert intrinsic_gas == result_intrinsic_gas_cost From 00c419c6b5a88a7ca21737cf6335378cb6fd79ae Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Fri, 1 Aug 2025 05:50:52 +0200 Subject: [PATCH 07/14] remove difficulty tests --- tests/byzantium/test_difficulty.py | 20 ------- tests/constantinople/test_difficulty.py | 20 ------- tests/frontier/test_difficulty.py | 19 ------ tests/helpers/load_difficulty_tests.py | 68 ---------------------- tests/homestead/test_difficulty.py | 19 ------ tests/spurious_dragon/test_difficulty.py | 19 ------ tests/tangerine_whistle/test_difficulty.py | 19 ------ 7 files changed, 184 deletions(-) delete mode 100644 tests/byzantium/test_difficulty.py delete mode 100644 tests/constantinople/test_difficulty.py delete mode 100644 tests/frontier/test_difficulty.py delete mode 100644 tests/helpers/load_difficulty_tests.py delete mode 100644 tests/homestead/test_difficulty.py delete mode 100644 tests/spurious_dragon/test_difficulty.py delete mode 100644 tests/tangerine_whistle/test_difficulty.py diff --git a/tests/byzantium/test_difficulty.py b/tests/byzantium/test_difficulty.py deleted file mode 100644 index 9829dcd6d8..0000000000 --- a/tests/byzantium/test_difficulty.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("Byzantium", "byzantium") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - inputs["parent_has_ommers"], - ) diff --git a/tests/constantinople/test_difficulty.py b/tests/constantinople/test_difficulty.py deleted file mode 100644 index 200b8ea173..0000000000 --- a/tests/constantinople/test_difficulty.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("Constantinople", "constantinople") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - inputs["parent_has_ommers"], - ) diff --git a/tests/frontier/test_difficulty.py b/tests/frontier/test_difficulty.py deleted file mode 100644 index 0e85c53d54..0000000000 --- a/tests/frontier/test_difficulty.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("Frontier", "frontier") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - ) diff --git a/tests/helpers/load_difficulty_tests.py b/tests/helpers/load_difficulty_tests.py deleted file mode 100644 index b918786ea5..0000000000 --- a/tests/helpers/load_difficulty_tests.py +++ /dev/null @@ -1,68 +0,0 @@ -import json -import os -from importlib import import_module -from typing import Any, Dict, List - -from ethereum.utils.hexadecimal import hex_to_u256, hex_to_uint - - -class DifficultyTestLoader: - """ - All the methods and imports required to run the difficulty tests. - """ - - def __init__(self, network: str, fork_name: str): - self.network = network - self.fork_name = fork_name - self.test_dir = f"tests/fixtures/DifficultyTests/df{fork_name}" - try: - self.test_files = [file for file in os.listdir(self.test_dir)] - except OSError: - self.test_files = [] - - self.fork = self._module("fork") - self.calculate_block_difficulty = self.fork.calculate_block_difficulty - - def _module(self, name: str) -> Any: - return import_module(f"ethereum.{self.fork_name}.{name}") - - def load_test(self, test_file: str) -> List[Dict]: - """ - Read tests from a file. - """ - test_name = os.path.splitext(test_file)[0] - path = os.path.join(self.test_dir, test_file) - - with open(path, "r") as fp: - json_data = json.load(fp)[test_name][self.network] - - test_list = [] - for test_name in json_data: - has_ommers = json_data[test_name]["parentUncles"] - - parent_has_ommers = False if has_ommers == "0x00" else True - - test = { - "name": test_name, - "inputs": { - "block_number": hex_to_uint( - json_data[test_name]["currentBlockNumber"] - ), - "block_timestamp": hex_to_u256( - json_data[test_name]["currentTimestamp"] - ), - "parent_timestamp": hex_to_u256( - json_data[test_name]["parentTimestamp"] - ), - "parent_difficulty": hex_to_uint( - json_data[test_name]["parentDifficulty"] - ), - "parent_has_ommers": parent_has_ommers, - }, - "expected": hex_to_uint( - json_data[test_name]["currentDifficulty"] - ), - } - test_list.append(test) - - return test_list diff --git a/tests/homestead/test_difficulty.py b/tests/homestead/test_difficulty.py deleted file mode 100644 index 8803491fa9..0000000000 --- a/tests/homestead/test_difficulty.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("Homestead", "homestead") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - ) diff --git a/tests/spurious_dragon/test_difficulty.py b/tests/spurious_dragon/test_difficulty.py deleted file mode 100644 index 67e75ecdfc..0000000000 --- a/tests/spurious_dragon/test_difficulty.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("EIP158", "spurious_dragon") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - ) diff --git a/tests/tangerine_whistle/test_difficulty.py b/tests/tangerine_whistle/test_difficulty.py deleted file mode 100644 index 794b10cba0..0000000000 --- a/tests/tangerine_whistle/test_difficulty.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest - -from ..helpers.load_difficulty_tests import DifficultyTestLoader - -test_loader = DifficultyTestLoader("EIP150", "tangerine_whistle") - - -@pytest.mark.parametrize("test_file", test_loader.test_files) -def test_difficulty(test_file: str) -> None: - test_list = test_loader.load_test(test_file) - - for test in test_list: - inputs = test["inputs"] - assert test["expected"] == test_loader.calculate_block_difficulty( - inputs["block_number"], - inputs["block_timestamp"], - inputs["parent_timestamp"], - inputs["parent_difficulty"], - ) From 44d65e4b511d93f27a169484e42855e5724ad3db Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Fri, 1 Aug 2025 11:27:37 +0200 Subject: [PATCH 08/14] move vm tests to json_infra --- tests/byzantium/vm/__init__.py | 0 .../vm/test_arithmetic_operations.py | 242 ------------------ .../vm/test_bitwise_logic_operations.py | 174 ------------- tests/byzantium/vm/test_block_operations.py | 32 --- .../vm/test_environmental_operations.py | 107 -------- tests/byzantium/vm/test_keccak.py | 49 ---- tests/byzantium/vm/test_logging_operations.py | 104 -------- tests/byzantium/vm/test_memory_operations.py | 75 ------ tests/byzantium/vm/test_stack_operations.py | 74 ------ tests/byzantium/vm/test_storage_operations.py | 28 -- tests/byzantium/vm/test_system_operations.py | 47 ---- tests/byzantium/vm/vm_test_helpers.py | 3 - tests/constantinople/vm/__init__.py | 0 .../vm/test_arithmetic_operations.py | 242 ------------------ .../vm/test_bitwise_logic_operations.py | 174 ------------- .../vm/test_block_operations.py | 32 --- .../vm/test_control_flow_operations.py | 183 ------------- .../vm/test_environmental_operations.py | 107 -------- .../vm/test_logging_operations.py | 104 -------- .../vm/test_memory_operations.py | 75 ------ .../vm/test_stack_operations.py | 74 ------ .../vm/test_storage_operations.py | 28 -- .../vm/test_system_operations.py | 47 ---- tests/constantinople/vm/vm_test_helpers.py | 3 - tests/frontier/vm/__init__.py | 0 .../frontier/vm/test_arithmetic_operations.py | 238 ----------------- .../vm/test_bitwise_logic_operations.py | 174 ------------- tests/frontier/vm/test_block_operations.py | 32 --- .../vm/test_control_flow_operations.py | 183 ------------- .../vm/test_environmental_operations.py | 107 -------- tests/frontier/vm/test_keccak.py | 49 ---- tests/frontier/vm/test_memory_operations.py | 75 ------ tests/frontier/vm/test_stack_operations.py | 74 ------ tests/frontier/vm/test_storage_operations.py | 28 -- tests/frontier/vm/test_system_operations.py | 47 ---- tests/frontier/vm/vm_test_helpers.py | 3 - tests/helpers/__init__.py | 39 --- tests/homestead/vm/__init__.py | 0 .../vm/test_arithmetic_operations.py | 238 ----------------- tests/homestead/vm/test_block_operations.py | 32 --- .../vm/test_control_flow_operations.py | 183 ------------- .../vm/test_environmental_operations.py | 107 -------- tests/homestead/vm/test_keccak.py | 49 ---- tests/homestead/vm/test_logging_operations.py | 104 -------- tests/homestead/vm/test_memory_operations.py | 75 ------ tests/homestead/vm/test_stack_operations.py | 74 ------ tests/homestead/vm/test_storage_operations.py | 28 -- tests/homestead/vm/test_system_operations.py | 47 ---- tests/homestead/vm/vm_test_helpers.py | 3 - .../{ => json_infra}/helpers/load_vm_tests.py | 0 tests/json_infra/vm/__init__.py | 27 ++ .../vm/test_arithmetic_operations.py | 136 +++++++--- .../vm/test_bitwise_logic_operations.py | 69 ++--- tests/json_infra/vm/test_block_operations.py | 37 +++ .../vm/test_control_flow_operations.py | 57 +++-- .../vm/test_environmental_operations.py | 113 ++++++++ .../vm/test_keccak.py | 29 +-- .../vm/test_logging_operations.py | 39 +-- tests/json_infra/vm/test_memory_operations.py | 76 ++++++ tests/json_infra/vm/test_stack_operations.py | 81 ++++++ .../json_infra/vm/test_storage_operations.py | 29 +++ tests/json_infra/vm/test_system_operations.py | 50 ++++ tests/spurious_dragon/vm/__init__.py | 0 .../vm/test_bitwise_logic_operations.py | 174 ------------- .../vm/test_block_operations.py | 32 --- .../vm/test_control_flow_operations.py | 183 ------------- .../vm/test_environmental_operations.py | 107 -------- tests/spurious_dragon/vm/test_keccak.py | 49 ---- .../vm/test_logging_operations.py | 104 -------- .../vm/test_memory_operations.py | 75 ------ .../vm/test_stack_operations.py | 74 ------ .../vm/test_storage_operations.py | 28 -- .../vm/test_system_operations.py | 47 ---- tests/spurious_dragon/vm/vm_test_helpers.py | 3 - tests/tangerine_whistle/vm/__init__.py | 0 .../vm/test_arithmetic_operations.py | 238 ----------------- .../vm/test_bitwise_logic_operations.py | 174 ------------- .../vm/test_block_operations.py | 32 --- .../vm/test_control_flow_operations.py | 183 ------------- .../vm/test_environmental_operations.py | 107 -------- tests/tangerine_whistle/vm/test_keccak.py | 49 ---- .../vm/test_logging_operations.py | 104 -------- .../vm/test_memory_operations.py | 75 ------ .../vm/test_stack_operations.py | 74 ------ .../vm/test_storage_operations.py | 28 -- .../vm/test_system_operations.py | 47 ---- tests/tangerine_whistle/vm/vm_test_helpers.py | 3 - tests/test_rlp.py | 3 +- 88 files changed, 616 insertions(+), 6113 deletions(-) delete mode 100644 tests/byzantium/vm/__init__.py delete mode 100644 tests/byzantium/vm/test_arithmetic_operations.py delete mode 100644 tests/byzantium/vm/test_bitwise_logic_operations.py delete mode 100644 tests/byzantium/vm/test_block_operations.py delete mode 100644 tests/byzantium/vm/test_environmental_operations.py delete mode 100644 tests/byzantium/vm/test_keccak.py delete mode 100644 tests/byzantium/vm/test_logging_operations.py delete mode 100644 tests/byzantium/vm/test_memory_operations.py delete mode 100644 tests/byzantium/vm/test_stack_operations.py delete mode 100644 tests/byzantium/vm/test_storage_operations.py delete mode 100644 tests/byzantium/vm/test_system_operations.py delete mode 100644 tests/byzantium/vm/vm_test_helpers.py delete mode 100644 tests/constantinople/vm/__init__.py delete mode 100644 tests/constantinople/vm/test_arithmetic_operations.py delete mode 100644 tests/constantinople/vm/test_bitwise_logic_operations.py delete mode 100644 tests/constantinople/vm/test_block_operations.py delete mode 100644 tests/constantinople/vm/test_control_flow_operations.py delete mode 100644 tests/constantinople/vm/test_environmental_operations.py delete mode 100644 tests/constantinople/vm/test_logging_operations.py delete mode 100644 tests/constantinople/vm/test_memory_operations.py delete mode 100644 tests/constantinople/vm/test_stack_operations.py delete mode 100644 tests/constantinople/vm/test_storage_operations.py delete mode 100644 tests/constantinople/vm/test_system_operations.py delete mode 100644 tests/constantinople/vm/vm_test_helpers.py delete mode 100644 tests/frontier/vm/__init__.py delete mode 100644 tests/frontier/vm/test_arithmetic_operations.py delete mode 100644 tests/frontier/vm/test_bitwise_logic_operations.py delete mode 100644 tests/frontier/vm/test_block_operations.py delete mode 100644 tests/frontier/vm/test_control_flow_operations.py delete mode 100644 tests/frontier/vm/test_environmental_operations.py delete mode 100644 tests/frontier/vm/test_keccak.py delete mode 100644 tests/frontier/vm/test_memory_operations.py delete mode 100644 tests/frontier/vm/test_stack_operations.py delete mode 100644 tests/frontier/vm/test_storage_operations.py delete mode 100644 tests/frontier/vm/test_system_operations.py delete mode 100644 tests/frontier/vm/vm_test_helpers.py delete mode 100644 tests/helpers/__init__.py delete mode 100644 tests/homestead/vm/__init__.py delete mode 100644 tests/homestead/vm/test_arithmetic_operations.py delete mode 100644 tests/homestead/vm/test_block_operations.py delete mode 100644 tests/homestead/vm/test_control_flow_operations.py delete mode 100644 tests/homestead/vm/test_environmental_operations.py delete mode 100644 tests/homestead/vm/test_keccak.py delete mode 100644 tests/homestead/vm/test_logging_operations.py delete mode 100644 tests/homestead/vm/test_memory_operations.py delete mode 100644 tests/homestead/vm/test_stack_operations.py delete mode 100644 tests/homestead/vm/test_storage_operations.py delete mode 100644 tests/homestead/vm/test_system_operations.py delete mode 100644 tests/homestead/vm/vm_test_helpers.py rename tests/{ => json_infra}/helpers/load_vm_tests.py (100%) create mode 100644 tests/json_infra/vm/__init__.py rename tests/{spurious_dragon => json_infra}/vm/test_arithmetic_operations.py (54%) rename tests/{homestead => json_infra}/vm/test_bitwise_logic_operations.py (50%) create mode 100644 tests/json_infra/vm/test_block_operations.py rename tests/{byzantium => json_infra}/vm/test_control_flow_operations.py (79%) create mode 100644 tests/json_infra/vm/test_environmental_operations.py rename tests/{constantinople => json_infra}/vm/test_keccak.py (57%) rename tests/{frontier => json_infra}/vm/test_logging_operations.py (68%) create mode 100644 tests/json_infra/vm/test_memory_operations.py create mode 100644 tests/json_infra/vm/test_stack_operations.py create mode 100644 tests/json_infra/vm/test_storage_operations.py create mode 100644 tests/json_infra/vm/test_system_operations.py delete mode 100644 tests/spurious_dragon/vm/__init__.py delete mode 100644 tests/spurious_dragon/vm/test_bitwise_logic_operations.py delete mode 100644 tests/spurious_dragon/vm/test_block_operations.py delete mode 100644 tests/spurious_dragon/vm/test_control_flow_operations.py delete mode 100644 tests/spurious_dragon/vm/test_environmental_operations.py delete mode 100644 tests/spurious_dragon/vm/test_keccak.py delete mode 100644 tests/spurious_dragon/vm/test_logging_operations.py delete mode 100644 tests/spurious_dragon/vm/test_memory_operations.py delete mode 100644 tests/spurious_dragon/vm/test_stack_operations.py delete mode 100644 tests/spurious_dragon/vm/test_storage_operations.py delete mode 100644 tests/spurious_dragon/vm/test_system_operations.py delete mode 100644 tests/spurious_dragon/vm/vm_test_helpers.py delete mode 100644 tests/tangerine_whistle/vm/__init__.py delete mode 100644 tests/tangerine_whistle/vm/test_arithmetic_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_bitwise_logic_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_block_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_control_flow_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_environmental_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_keccak.py delete mode 100644 tests/tangerine_whistle/vm/test_logging_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_memory_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_stack_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_storage_operations.py delete mode 100644 tests/tangerine_whistle/vm/test_system_operations.py delete mode 100644 tests/tangerine_whistle/vm/vm_test_helpers.py diff --git a/tests/byzantium/vm/__init__.py b/tests/byzantium/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/byzantium/vm/test_arithmetic_operations.py b/tests/byzantium/vm/test_arithmetic_operations.py deleted file mode 100644 index e9f91b35eb..0000000000 --- a/tests/byzantium/vm/test_arithmetic_operations.py +++ /dev/null @@ -1,242 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "add0.json", - "add1.json", - "add2.json", - "add3.json", - "add4.json", - ], -) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sub0.json", - "sub1.json", - "sub2.json", - "sub3.json", - "sub4.json", - ], -) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mul0.json", - "mul1.json", - "mul2.json", - "mul3.json", - "mul4.json", - "mul5.json", - "mul6.json", - "mul7.json", - ], -) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "div1.json", - "divBoostBug.json", - "divByNonZero0.json", - "divByNonZero1.json", - "divByNonZero2.json", - "divByNonZero3.json", - "divByZero.json", - "divByZero_2.json", - ], -) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sdiv0.json", - "sdiv1.json", - "sdiv2.json", - "sdiv3.json", - "sdiv4.json", - "sdiv5.json", - "sdiv6.json", - "sdiv7.json", - "sdiv8.json", - "sdiv9.json", - "sdivByZero0.json", - "sdivByZero1.json", - "sdivByZero2.json", - "sdiv_i256min.json", - "sdiv_i256min2.json", - "sdiv_i256min3.json", - "sdiv_dejavu.json", - ], -) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mod0.json", - "mod1.json", - "mod2.json", - "mod3.json", - "mod4.json", - "modByZero.json", - ], -) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "smod0.json", - "smod1.json", - "smod2.json", - "smod3.json", - "smod4.json", - "smod5.json", - "smod6.json", - "smod7.json", - "smod8_byZero.json", - "smod_i256min1.json", - "smod_i256min2.json", - ], -) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "addmod0.json", - "addmod1.json", - "addmod1_overflow2.json", - "addmod1_overflow3.json", - "addmod1_overflow4.json", - "addmod1_overflowDiff.json", - "addmod2.json", - "addmod2_0.json", - "addmod2_1.json", - "addmod3.json", - "addmod3_0.json", - ], -) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mulmod0.json", - "mulmod1.json", - "mulmod1_overflow.json", - "mulmod1_overflow2.json", - "mulmod1_overflow3.json", - "mulmod1_overflow4.json", - "mulmod2.json", - "mulmod2_0.json", - "mulmod2_1.json", - "mulmod3.json", - "mulmod3_0.json", - "mulmod4.json", - ], -) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "exp0.json", - "exp1.json", - "exp2.json", - "exp3.json", - "exp4.json", - "exp5.json", - "exp6.json", - "exp7.json", - "exp8.json", - "expXY.json", - "expXY_success.json", - ], -) -def test_exp(test_file: str) -> None: - run_arithmetic_vm_test(test_file, check_gas_left=False) - - -@pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test( - f"expPowerOf2_{exponent}.json", check_gas_left=False - ) - - -def test_exp_power_256() -> None: - for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json", check_gas_left=False) - - for i in range(34): - run_arithmetic_vm_test( - f"expPowerOf256Of256_{i}.json", check_gas_left=False - ) - - -@pytest.mark.parametrize( - "test_file", - [ - "signextend_0_BigByte.json", - "signextend_00.json", - "signextend_AlmostBiggestByte.json", - "signextend_BigByte_0.json", - "signextend_BigByteBigByte.json", - "signextend_BigBytePlus1_2.json", - "signextend_bigBytePlus1.json", - "signextend_BitIsNotSet.json", - "signextend_BitIsNotSetInHigherByte.json", - "signextend_bitIsSet.json", - "signextend_BitIsSetInHigherByte.json", - "signextend_Overflow_dj42.json", - "signextendInvalidByteNumber.json", - ], -) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") diff --git a/tests/byzantium/vm/test_bitwise_logic_operations.py b/tests/byzantium/vm/test_bitwise_logic_operations.py deleted file mode 100644 index bc98c473c1..0000000000 --- a/tests/byzantium/vm/test_bitwise_logic_operations.py +++ /dev/null @@ -1,174 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "lt0.json", - "lt1.json", - "lt2.json", - "lt3.json", - ], -) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "gt0.json", - "gt1.json", - "gt2.json", - "gt3.json", - ], -) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "slt0.json", - "slt1.json", - "slt2.json", - "slt3.json", - "slt4.json", - ], -) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sgt0.json", - "sgt1.json", - "sgt2.json", - "sgt3.json", - "sgt4.json", - ], -) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "eq0.json", - "eq1.json", - "eq2.json", - ], -) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "iszero0.json", - "iszero1.json", - "iszeo2.json", - ], -) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "and0.json", - "and1.json", - "and2.json", - "and3.json", - "and4.json", - "and5.json", - ], -) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "or0.json", - "or1.json", - "or2.json", - "or3.json", - "or4.json", - "or5.json", - ], -) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "xor0.json", - "xor1.json", - "xor2.json", - "xor3.json", - "xor4.json", - "xor5.json", - ], -) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "not0.json", - "not1.json", - "not2.json", - "not3.json", - "not4.json", - "not5.json", - ], -) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "byte0.json", - "byte1.json", - "byte2.json", - "byte3.json", - "byte4.json", - "byte5.json", - "byte6.json", - "byte7.json", - "byte8.json", - "byte9.json", - "byte10.json", - "byte11.json", - "byteBN.json", - ], -) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) diff --git a/tests/byzantium/vm/test_block_operations.py b/tests/byzantium/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/byzantium/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/byzantium/vm/test_environmental_operations.py b/tests/byzantium/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/byzantium/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/byzantium/vm/test_keccak.py b/tests/byzantium/vm/test_keccak.py deleted file mode 100644 index 4c44bb02b7..0000000000 --- a/tests/byzantium/vm/test_keccak.py +++ /dev/null @@ -1,49 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sha3_0.json", - "sha3_1.json", - "sha3_2.json", - "sha3_bigOffset2.json", - "sha3_memSizeNoQuadraticCost31.json", - "sha3_memSizeQuadraticCost32.json", - "sha3_memSizeQuadraticCost32_zeroSize.json", - "sha3_memSizeQuadraticCost33.json", - "sha3_memSizeQuadraticCost63.json", - "sha3_memSizeQuadraticCost64.json", - "sha3_memSizeQuadraticCost64_2.json", - "sha3_memSizeQuadraticCost65.json", - "sha3_3.json", - "sha3_4.json", - "sha3_5.json", - "sha3_6.json", - "sha3_bigOffset.json", - "sha3_bigSize.json", - ], -) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) - - -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") diff --git a/tests/byzantium/vm/test_logging_operations.py b/tests/byzantium/vm/test_logging_operations.py deleted file mode 100644 index e7c2222098..0000000000 --- a/tests/byzantium/vm/test_logging_operations.py +++ /dev/null @@ -1,104 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "log0_emptyMem.json", - "log0_logMemsizeZero.json", - "log0_nonEmptyMem.json", - "log0_nonEmptyMem_logMemSize1.json", - "log0_nonEmptyMem_logMemSize1_logMemStart31.json", - "log0_logMemsizeTooHigh.json", - "log0_logMemStartTooHigh.json", - ], -) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log1_Caller.json", - "log1_emptyMem.json", - "log1_logMemsizeZero.json", - "log1_MaxTopic.json", - "log1_nonEmptyMem.json", - "log1_nonEmptyMem_logMemSize1.json", - "log1_nonEmptyMem_logMemSize1_logMemStart31.json", - "log1_logMemsizeTooHigh.json", - "log1_logMemStartTooHigh.json", - ], -) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log2_Caller.json", - "log2_emptyMem.json", - "log2_logMemsizeZero.json", - "log2_MaxTopic.json", - "log2_nonEmptyMem.json", - "log2_nonEmptyMem_logMemSize1.json", - "log2_nonEmptyMem_logMemSize1_logMemStart31.json", - "log2_logMemsizeTooHigh.json", - "log2_logMemStartTooHigh.json", - ], -) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log3_Caller.json", - "log3_emptyMem.json", - "log3_logMemsizeZero.json", - "log3_MaxTopic.json", - "log3_nonEmptyMem.json", - "log3_nonEmptyMem_logMemSize1.json", - "log3_nonEmptyMem_logMemSize1_logMemStart31.json", - "log3_PC.json", - "log3_logMemsizeTooHigh.json", - "log3_logMemStartTooHigh.json", - ], -) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log4_Caller.json", - "log4_emptyMem.json", - "log4_logMemsizeZero.json", - "log4_MaxTopic.json", - "log4_nonEmptyMem.json", - "log4_nonEmptyMem_logMemSize1.json", - "log4_nonEmptyMem_logMemSize1_logMemStart31.json", - "log4_PC.json", - "log4_logMemsizeTooHigh.json", - "log4_logMemStartTooHigh.json", - ], -) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) diff --git a/tests/byzantium/vm/test_memory_operations.py b/tests/byzantium/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/byzantium/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/byzantium/vm/test_stack_operations.py b/tests/byzantium/vm/test_stack_operations.py deleted file mode 100644 index 8845fa29ab..0000000000 --- a/tests/byzantium/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [(f"push{i}.json", True) for i in range(1, 34)] - + [ - ("push32Undefined2.json", True), - ("push32AndSuicide.json", False), - ], -) -def test_push_successfully(test_file: str, check_gas_left: bool) -> None: - run_push_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/byzantium/vm/test_storage_operations.py b/tests/byzantium/vm/test_storage_operations.py deleted file mode 100644 index 3a83f3f8f2..0000000000 --- a/tests/byzantium/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("sstore_load_0.json", False), - ("sstore_load_1.json", False), - ("sstore_load_2.json", False), - ("sstore_underflow.json", True), - ("kv1.json", True), - ], -) -def test_sstore_and_sload(test_file: str, check_gas_left: bool) -> None: - run_storage_vm_test(test_file, check_gas_left=check_gas_left) diff --git a/tests/byzantium/vm/test_system_operations.py b/tests/byzantium/vm/test_system_operations.py deleted file mode 100644 index e314fec6c4..0000000000 --- a/tests/byzantium/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("suicide0.json", False), - ("suicideNotExistingAccount.json", False), - ("suicideSendEtherToMe.json", False), - ], -) -def test_seldestruct(test_file: str, check_gas_left: bool) -> None: - run_system_vm_test(test_file, check_gas_left=check_gas_left) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json", check_gas_left=False) - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/byzantium/vm/vm_test_helpers.py b/tests/byzantium/vm/vm_test_helpers.py deleted file mode 100644 index e6ce5e12e8..0000000000 --- a/tests/byzantium/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("Byzantium", "byzantium").run_test diff --git a/tests/constantinople/vm/__init__.py b/tests/constantinople/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/constantinople/vm/test_arithmetic_operations.py b/tests/constantinople/vm/test_arithmetic_operations.py deleted file mode 100644 index e9f91b35eb..0000000000 --- a/tests/constantinople/vm/test_arithmetic_operations.py +++ /dev/null @@ -1,242 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "add0.json", - "add1.json", - "add2.json", - "add3.json", - "add4.json", - ], -) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sub0.json", - "sub1.json", - "sub2.json", - "sub3.json", - "sub4.json", - ], -) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mul0.json", - "mul1.json", - "mul2.json", - "mul3.json", - "mul4.json", - "mul5.json", - "mul6.json", - "mul7.json", - ], -) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "div1.json", - "divBoostBug.json", - "divByNonZero0.json", - "divByNonZero1.json", - "divByNonZero2.json", - "divByNonZero3.json", - "divByZero.json", - "divByZero_2.json", - ], -) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sdiv0.json", - "sdiv1.json", - "sdiv2.json", - "sdiv3.json", - "sdiv4.json", - "sdiv5.json", - "sdiv6.json", - "sdiv7.json", - "sdiv8.json", - "sdiv9.json", - "sdivByZero0.json", - "sdivByZero1.json", - "sdivByZero2.json", - "sdiv_i256min.json", - "sdiv_i256min2.json", - "sdiv_i256min3.json", - "sdiv_dejavu.json", - ], -) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mod0.json", - "mod1.json", - "mod2.json", - "mod3.json", - "mod4.json", - "modByZero.json", - ], -) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "smod0.json", - "smod1.json", - "smod2.json", - "smod3.json", - "smod4.json", - "smod5.json", - "smod6.json", - "smod7.json", - "smod8_byZero.json", - "smod_i256min1.json", - "smod_i256min2.json", - ], -) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "addmod0.json", - "addmod1.json", - "addmod1_overflow2.json", - "addmod1_overflow3.json", - "addmod1_overflow4.json", - "addmod1_overflowDiff.json", - "addmod2.json", - "addmod2_0.json", - "addmod2_1.json", - "addmod3.json", - "addmod3_0.json", - ], -) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mulmod0.json", - "mulmod1.json", - "mulmod1_overflow.json", - "mulmod1_overflow2.json", - "mulmod1_overflow3.json", - "mulmod1_overflow4.json", - "mulmod2.json", - "mulmod2_0.json", - "mulmod2_1.json", - "mulmod3.json", - "mulmod3_0.json", - "mulmod4.json", - ], -) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "exp0.json", - "exp1.json", - "exp2.json", - "exp3.json", - "exp4.json", - "exp5.json", - "exp6.json", - "exp7.json", - "exp8.json", - "expXY.json", - "expXY_success.json", - ], -) -def test_exp(test_file: str) -> None: - run_arithmetic_vm_test(test_file, check_gas_left=False) - - -@pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test( - f"expPowerOf2_{exponent}.json", check_gas_left=False - ) - - -def test_exp_power_256() -> None: - for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json", check_gas_left=False) - - for i in range(34): - run_arithmetic_vm_test( - f"expPowerOf256Of256_{i}.json", check_gas_left=False - ) - - -@pytest.mark.parametrize( - "test_file", - [ - "signextend_0_BigByte.json", - "signextend_00.json", - "signextend_AlmostBiggestByte.json", - "signextend_BigByte_0.json", - "signextend_BigByteBigByte.json", - "signextend_BigBytePlus1_2.json", - "signextend_bigBytePlus1.json", - "signextend_BitIsNotSet.json", - "signextend_BitIsNotSetInHigherByte.json", - "signextend_bitIsSet.json", - "signextend_BitIsSetInHigherByte.json", - "signextend_Overflow_dj42.json", - "signextendInvalidByteNumber.json", - ], -) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") diff --git a/tests/constantinople/vm/test_bitwise_logic_operations.py b/tests/constantinople/vm/test_bitwise_logic_operations.py deleted file mode 100644 index bc98c473c1..0000000000 --- a/tests/constantinople/vm/test_bitwise_logic_operations.py +++ /dev/null @@ -1,174 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "lt0.json", - "lt1.json", - "lt2.json", - "lt3.json", - ], -) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "gt0.json", - "gt1.json", - "gt2.json", - "gt3.json", - ], -) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "slt0.json", - "slt1.json", - "slt2.json", - "slt3.json", - "slt4.json", - ], -) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sgt0.json", - "sgt1.json", - "sgt2.json", - "sgt3.json", - "sgt4.json", - ], -) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "eq0.json", - "eq1.json", - "eq2.json", - ], -) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "iszero0.json", - "iszero1.json", - "iszeo2.json", - ], -) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "and0.json", - "and1.json", - "and2.json", - "and3.json", - "and4.json", - "and5.json", - ], -) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "or0.json", - "or1.json", - "or2.json", - "or3.json", - "or4.json", - "or5.json", - ], -) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "xor0.json", - "xor1.json", - "xor2.json", - "xor3.json", - "xor4.json", - "xor5.json", - ], -) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "not0.json", - "not1.json", - "not2.json", - "not3.json", - "not4.json", - "not5.json", - ], -) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "byte0.json", - "byte1.json", - "byte2.json", - "byte3.json", - "byte4.json", - "byte5.json", - "byte6.json", - "byte7.json", - "byte8.json", - "byte9.json", - "byte10.json", - "byte11.json", - "byteBN.json", - ], -) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) diff --git a/tests/constantinople/vm/test_block_operations.py b/tests/constantinople/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/constantinople/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/constantinople/vm/test_control_flow_operations.py b/tests/constantinople/vm/test_control_flow_operations.py deleted file mode 100644 index 1f8d2e27ea..0000000000 --- a/tests/constantinople/vm/test_control_flow_operations.py +++ /dev/null @@ -1,183 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jump0_jumpdest0.json", True), - ("jump0_jumpdest2.json", True), - ("jumpAfterStop.json", True), - ("jumpdestBigList.json", True), - ("jumpTo1InstructionafterJump.json", True), - ("jumpDynamicJumpSameDest.json", True), - ("indirect_jump1.json", True), - ("indirect_jump2.json", True), - ("indirect_jump3.json", True), - ("DynamicJump_value1.json", True), - ("DynamicJump_value2.json", True), - ("DynamicJump_value3.json", True), - ("stackjump1.json", True), - ("indirect_jump4.json", True), - ("JDfromStorageDynamicJump0_jumpdest0.json", False), - ("JDfromStorageDynamicJump0_jumpdest2.json", False), - ("DynamicJump0_jumpdest0.json", True), - ("DynamicJump0_jumpdest2.json", True), - ("DynamicJumpAfterStop.json", True), - ("DynamicJumpJD_DependsOnJumps1.json", True), - ("DynamicJumpPathologicalTest0.json", True), - ("DynamicJumpStartWithJumpDest.json", True), - ("BlockNumberDynamicJump0_jumpdest0.json", True), - ("BlockNumberDynamicJump0_jumpdest2.json", True), - ("bad_indirect_jump1.json", True), - ("bad_indirect_jump2.json", True), - ("jump0_AfterJumpdest.json", True), - ("jump0_AfterJumpdest3.json", True), - ("jump0_outOfBoundary.json", True), - ("jump0_withoutJumpdest.json", True), - ("jump1.json", True), - ("jumpHigh.json", True), - ("jumpInsidePushWithJumpDest.json", True), - ("jumpInsidePushWithoutJumpDest.json", True), - ("jumpTo1InstructionafterJump_jumpdestFirstInstruction.json", True), - ("jumpTo1InstructionafterJump_noJumpDest.json", True), - ("jumpToUint64maxPlus1.json", True), - ("jumpToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest3.json", True), - ("JDfromStorageDynamicJump0_withoutJumpdest.json", True), - ("JDfromStorageDynamicJump1.json", True), - ("JDfromStorageDynamicJumpInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpInsidePushWithoutJumpDest.json", True), - ("DyanmicJump0_outOfBoundary.json", True), - ("DynamicJump0_AfterJumpdest.json", True), - ("DynamicJump0_AfterJumpdest3.json", True), - ("DynamicJump0_withoutJumpdest.json", True), - ("DynamicJump1.json", True), - ("DynamicJumpInsidePushWithJumpDest.json", True), - ("DynamicJumpInsidePushWithoutJumpDest.json", True), - ("DynamicJumpJD_DependsOnJumps0.json", True), - ("DynamicJumpPathologicalTest1.json", True), - ("DynamicJumpPathologicalTest2.json", True), - ("DynamicJumpPathologicalTest3.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest3.json", True), - ("BlockNumberDynamicJump0_withoutJumpdest.json", True), - ("BlockNumberDynamicJump1.json", True), - ("BlockNumberDynamicJumpInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpInsidePushWithoutJumpDest.json", True), - ("jump0_foreverOutOfGas.json", True), - ("JDfromStorageDynamicJump0_foreverOutOfGas.json", True), - ("DynamicJump0_foreverOutOfGas.json", True), - ("BlockNumberDynamicJump0_foreverOutOfGas.json", True), - ("jumpOntoJump.json", True), - ("DynamicJump_valueUnderflow.json", True), - ("stack_loop.json", True), - ], -) -def test_jump(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jumpi1.json", True), - ("jumpiAfterStop.json", True), - ("jumpi_at_the_end.json", True), - ("JDfromStorageDynamicJumpi1.json", False), - ("JDfromStorageDynamicJumpiAfterStop.json", False), - ("DynamicJumpi1.json", True), - ("DynamicJumpiAfterStop.json", True), - ("BlockNumberDynamicJumpi1.json", True), - ("BlockNumberDynamicJumpiAfterStop.json", True), - ("jumpi0.json", True), - ("jumpi1_jumpdest.json", True), - ("jumpifInsidePushWithJumpDest.json", True), - ("jumpifInsidePushWithoutJumpDest.json", True), - ("jumpiOutsideBoundary.json", True), - ("jumpiToUint64maxPlus1.json", True), - ("jumpiToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJumpi0.json", True), - ("JDfromStorageDynamicJumpi1_jumpdest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("JDfromStorageDynamicJumpiOutsideBoundary.json", True), - ("DynamicJumpi0.json", True), - ("DynamicJumpi1_jumpdest.json", True), - ("DynamicJumpifInsidePushWithJumpDest.json", True), - ("DynamicJumpifInsidePushWithoutJumpDest.json", True), - ("DynamicJumpiOutsideBoundary.json", True), - ("BlockNumberDynamicJumpi0.json", True), - ("BlockNumberDynamicJumpi1_jumpdest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("BlockNumberDynamicJumpiOutsideBoundary.json", True), - ], -) -def test_jumpi(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "pc0.json", - "pc1.json", - ], -) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - ["gas0.json", "gas1.json", "gasOverFlow.json"], -) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "for_loop1.json", - "for_loop2.json", - "loop_stacklimit_1020.json", - "loop_stacklimit_1021.json", - ], -) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "byte1.json", - "calldatacopyMemExp.json", - "codecopyMemExp.json", - "deadCode_1.json", - "dupAt51becameMload.json", - "swapAt52becameMstore.json", - "log1MemExp.json", - ], -) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) diff --git a/tests/constantinople/vm/test_environmental_operations.py b/tests/constantinople/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/constantinople/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/constantinople/vm/test_logging_operations.py b/tests/constantinople/vm/test_logging_operations.py deleted file mode 100644 index e7c2222098..0000000000 --- a/tests/constantinople/vm/test_logging_operations.py +++ /dev/null @@ -1,104 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "log0_emptyMem.json", - "log0_logMemsizeZero.json", - "log0_nonEmptyMem.json", - "log0_nonEmptyMem_logMemSize1.json", - "log0_nonEmptyMem_logMemSize1_logMemStart31.json", - "log0_logMemsizeTooHigh.json", - "log0_logMemStartTooHigh.json", - ], -) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log1_Caller.json", - "log1_emptyMem.json", - "log1_logMemsizeZero.json", - "log1_MaxTopic.json", - "log1_nonEmptyMem.json", - "log1_nonEmptyMem_logMemSize1.json", - "log1_nonEmptyMem_logMemSize1_logMemStart31.json", - "log1_logMemsizeTooHigh.json", - "log1_logMemStartTooHigh.json", - ], -) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log2_Caller.json", - "log2_emptyMem.json", - "log2_logMemsizeZero.json", - "log2_MaxTopic.json", - "log2_nonEmptyMem.json", - "log2_nonEmptyMem_logMemSize1.json", - "log2_nonEmptyMem_logMemSize1_logMemStart31.json", - "log2_logMemsizeTooHigh.json", - "log2_logMemStartTooHigh.json", - ], -) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log3_Caller.json", - "log3_emptyMem.json", - "log3_logMemsizeZero.json", - "log3_MaxTopic.json", - "log3_nonEmptyMem.json", - "log3_nonEmptyMem_logMemSize1.json", - "log3_nonEmptyMem_logMemSize1_logMemStart31.json", - "log3_PC.json", - "log3_logMemsizeTooHigh.json", - "log3_logMemStartTooHigh.json", - ], -) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log4_Caller.json", - "log4_emptyMem.json", - "log4_logMemsizeZero.json", - "log4_MaxTopic.json", - "log4_nonEmptyMem.json", - "log4_nonEmptyMem_logMemSize1.json", - "log4_nonEmptyMem_logMemSize1_logMemStart31.json", - "log4_PC.json", - "log4_logMemsizeTooHigh.json", - "log4_logMemStartTooHigh.json", - ], -) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) diff --git a/tests/constantinople/vm/test_memory_operations.py b/tests/constantinople/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/constantinople/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/constantinople/vm/test_stack_operations.py b/tests/constantinople/vm/test_stack_operations.py deleted file mode 100644 index 8845fa29ab..0000000000 --- a/tests/constantinople/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [(f"push{i}.json", True) for i in range(1, 34)] - + [ - ("push32Undefined2.json", True), - ("push32AndSuicide.json", False), - ], -) -def test_push_successfully(test_file: str, check_gas_left: bool) -> None: - run_push_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/constantinople/vm/test_storage_operations.py b/tests/constantinople/vm/test_storage_operations.py deleted file mode 100644 index 3a83f3f8f2..0000000000 --- a/tests/constantinople/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("sstore_load_0.json", False), - ("sstore_load_1.json", False), - ("sstore_load_2.json", False), - ("sstore_underflow.json", True), - ("kv1.json", True), - ], -) -def test_sstore_and_sload(test_file: str, check_gas_left: bool) -> None: - run_storage_vm_test(test_file, check_gas_left=check_gas_left) diff --git a/tests/constantinople/vm/test_system_operations.py b/tests/constantinople/vm/test_system_operations.py deleted file mode 100644 index e314fec6c4..0000000000 --- a/tests/constantinople/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("suicide0.json", False), - ("suicideNotExistingAccount.json", False), - ("suicideSendEtherToMe.json", False), - ], -) -def test_seldestruct(test_file: str, check_gas_left: bool) -> None: - run_system_vm_test(test_file, check_gas_left=check_gas_left) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json", check_gas_left=False) - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/constantinople/vm/vm_test_helpers.py b/tests/constantinople/vm/vm_test_helpers.py deleted file mode 100644 index 2988b0e435..0000000000 --- a/tests/constantinople/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("ConstantinopleFix", "constantinople").run_test diff --git a/tests/frontier/vm/__init__.py b/tests/frontier/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/frontier/vm/test_arithmetic_operations.py b/tests/frontier/vm/test_arithmetic_operations.py deleted file mode 100644 index 6f6ffe54b7..0000000000 --- a/tests/frontier/vm/test_arithmetic_operations.py +++ /dev/null @@ -1,238 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "add0.json", - "add1.json", - "add2.json", - "add3.json", - "add4.json", - ], -) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sub0.json", - "sub1.json", - "sub2.json", - "sub3.json", - "sub4.json", - ], -) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mul0.json", - "mul1.json", - "mul2.json", - "mul3.json", - "mul4.json", - "mul5.json", - "mul6.json", - "mul7.json", - ], -) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "div1.json", - "divBoostBug.json", - "divByNonZero0.json", - "divByNonZero1.json", - "divByNonZero2.json", - "divByNonZero3.json", - "divByZero.json", - "divByZero_2.json", - ], -) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sdiv0.json", - "sdiv1.json", - "sdiv2.json", - "sdiv3.json", - "sdiv4.json", - "sdiv5.json", - "sdiv6.json", - "sdiv7.json", - "sdiv8.json", - "sdiv9.json", - "sdivByZero0.json", - "sdivByZero1.json", - "sdivByZero2.json", - "sdiv_i256min.json", - "sdiv_i256min2.json", - "sdiv_i256min3.json", - "sdiv_dejavu.json", - ], -) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mod0.json", - "mod1.json", - "mod2.json", - "mod3.json", - "mod4.json", - "modByZero.json", - ], -) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "smod0.json", - "smod1.json", - "smod2.json", - "smod3.json", - "smod4.json", - "smod5.json", - "smod6.json", - "smod7.json", - "smod8_byZero.json", - "smod_i256min1.json", - "smod_i256min2.json", - ], -) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "addmod0.json", - "addmod1.json", - "addmod1_overflow2.json", - "addmod1_overflow3.json", - "addmod1_overflow4.json", - "addmod1_overflowDiff.json", - "addmod2.json", - "addmod2_0.json", - "addmod2_1.json", - "addmod3.json", - "addmod3_0.json", - ], -) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mulmod0.json", - "mulmod1.json", - "mulmod1_overflow.json", - "mulmod1_overflow2.json", - "mulmod1_overflow3.json", - "mulmod1_overflow4.json", - "mulmod2.json", - "mulmod2_0.json", - "mulmod2_1.json", - "mulmod3.json", - "mulmod3_0.json", - "mulmod4.json", - ], -) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "exp0.json", - "exp1.json", - "exp2.json", - "exp3.json", - "exp4.json", - "exp5.json", - "exp6.json", - "exp7.json", - "exp8.json", - "expXY.json", - "expXY_success.json", - ], -) -def test_exp(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test(f"expPowerOf2_{exponent}.json") - - -def test_exp_power_256() -> None: - for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json") - - for i in range(34): - run_arithmetic_vm_test(f"expPowerOf256Of256_{i}.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "signextend_0_BigByte.json", - "signextend_00.json", - "signextend_AlmostBiggestByte.json", - "signextend_BigByte_0.json", - "signextend_BigByteBigByte.json", - "signextend_BigBytePlus1_2.json", - "signextend_bigBytePlus1.json", - "signextend_BitIsNotSet.json", - "signextend_BitIsNotSetInHigherByte.json", - "signextend_bitIsSet.json", - "signextend_BitIsSetInHigherByte.json", - "signextend_Overflow_dj42.json", - "signextendInvalidByteNumber.json", - ], -) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") diff --git a/tests/frontier/vm/test_bitwise_logic_operations.py b/tests/frontier/vm/test_bitwise_logic_operations.py deleted file mode 100644 index bc98c473c1..0000000000 --- a/tests/frontier/vm/test_bitwise_logic_operations.py +++ /dev/null @@ -1,174 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "lt0.json", - "lt1.json", - "lt2.json", - "lt3.json", - ], -) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "gt0.json", - "gt1.json", - "gt2.json", - "gt3.json", - ], -) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "slt0.json", - "slt1.json", - "slt2.json", - "slt3.json", - "slt4.json", - ], -) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sgt0.json", - "sgt1.json", - "sgt2.json", - "sgt3.json", - "sgt4.json", - ], -) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "eq0.json", - "eq1.json", - "eq2.json", - ], -) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "iszero0.json", - "iszero1.json", - "iszeo2.json", - ], -) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "and0.json", - "and1.json", - "and2.json", - "and3.json", - "and4.json", - "and5.json", - ], -) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "or0.json", - "or1.json", - "or2.json", - "or3.json", - "or4.json", - "or5.json", - ], -) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "xor0.json", - "xor1.json", - "xor2.json", - "xor3.json", - "xor4.json", - "xor5.json", - ], -) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "not0.json", - "not1.json", - "not2.json", - "not3.json", - "not4.json", - "not5.json", - ], -) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "byte0.json", - "byte1.json", - "byte2.json", - "byte3.json", - "byte4.json", - "byte5.json", - "byte6.json", - "byte7.json", - "byte8.json", - "byte9.json", - "byte10.json", - "byte11.json", - "byteBN.json", - ], -) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) diff --git a/tests/frontier/vm/test_block_operations.py b/tests/frontier/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/frontier/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/frontier/vm/test_control_flow_operations.py b/tests/frontier/vm/test_control_flow_operations.py deleted file mode 100644 index 9a56b21f99..0000000000 --- a/tests/frontier/vm/test_control_flow_operations.py +++ /dev/null @@ -1,183 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "jump0_jumpdest0.json", - "jump0_jumpdest2.json", - "jumpAfterStop.json", - "jumpdestBigList.json", - "jumpTo1InstructionafterJump.json", - "jumpDynamicJumpSameDest.json", - "indirect_jump1.json", - "indirect_jump2.json", - "indirect_jump3.json", - "DynamicJump_value1.json", - "DynamicJump_value2.json", - "DynamicJump_value3.json", - "stackjump1.json", - "indirect_jump4.json", - "JDfromStorageDynamicJump0_jumpdest0.json", - "JDfromStorageDynamicJump0_jumpdest2.json", - "DynamicJump0_jumpdest0.json", - "DynamicJump0_jumpdest2.json", - "DynamicJumpAfterStop.json", - "DynamicJumpJD_DependsOnJumps1.json", - "DynamicJumpPathologicalTest0.json", - "DynamicJumpStartWithJumpDest.json", - "BlockNumberDynamicJump0_jumpdest0.json", - "BlockNumberDynamicJump0_jumpdest2.json", - "bad_indirect_jump1.json", - "bad_indirect_jump2.json", - "jump0_AfterJumpdest.json", - "jump0_AfterJumpdest3.json", - "jump0_outOfBoundary.json", - "jump0_withoutJumpdest.json", - "jump1.json", - "jumpHigh.json", - "jumpInsidePushWithJumpDest.json", - "jumpInsidePushWithoutJumpDest.json", - "jumpTo1InstructionafterJump_jumpdestFirstInstruction.json", - "jumpTo1InstructionafterJump_noJumpDest.json", - "jumpToUint64maxPlus1.json", - "jumpToUintmaxPlus1.json", - "JDfromStorageDynamicJump0_AfterJumpdest.json", - "JDfromStorageDynamicJump0_AfterJumpdest3.json", - "JDfromStorageDynamicJump0_withoutJumpdest.json", - "JDfromStorageDynamicJump1.json", - "JDfromStorageDynamicJumpInsidePushWithJumpDest.json", - "JDfromStorageDynamicJumpInsidePushWithoutJumpDest.json", - "DyanmicJump0_outOfBoundary.json", - "DynamicJump0_AfterJumpdest.json", - "DynamicJump0_AfterJumpdest3.json", - "DynamicJump0_withoutJumpdest.json", - "DynamicJump1.json", - "DynamicJumpInsidePushWithJumpDest.json", - "DynamicJumpInsidePushWithoutJumpDest.json", - "DynamicJumpJD_DependsOnJumps0.json", - "DynamicJumpPathologicalTest1.json", - "DynamicJumpPathologicalTest2.json", - "DynamicJumpPathologicalTest3.json", - "BlockNumberDynamicJump0_AfterJumpdest.json", - "BlockNumberDynamicJump0_AfterJumpdest3.json", - "BlockNumberDynamicJump0_withoutJumpdest.json", - "BlockNumberDynamicJump1.json", - "BlockNumberDynamicJumpInsidePushWithJumpDest.json", - "BlockNumberDynamicJumpInsidePushWithoutJumpDest.json", - "jump0_foreverOutOfGas.json", - "JDfromStorageDynamicJump0_foreverOutOfGas.json", - "DynamicJump0_foreverOutOfGas.json", - "BlockNumberDynamicJump0_foreverOutOfGas.json", - "jumpOntoJump.json", - "DynamicJump_valueUnderflow.json", - "stack_loop.json", - ], -) -def test_jump(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "jumpi1.json", - "jumpiAfterStop.json", - "jumpi_at_the_end.json", - "JDfromStorageDynamicJumpi1.json", - "JDfromStorageDynamicJumpiAfterStop.json", - "DynamicJumpi1.json", - "DynamicJumpiAfterStop.json", - "BlockNumberDynamicJumpi1.json", - "BlockNumberDynamicJumpiAfterStop.json", - "jumpi0.json", - "jumpi1_jumpdest.json", - "jumpifInsidePushWithJumpDest.json", - "jumpifInsidePushWithoutJumpDest.json", - "jumpiOutsideBoundary.json", - "jumpiToUint64maxPlus1.json", - "jumpiToUintmaxPlus1.json", - "JDfromStorageDynamicJumpi0.json", - "JDfromStorageDynamicJumpi1_jumpdest.json", - "JDfromStorageDynamicJumpifInsidePushWithJumpDest.json", - "JDfromStorageDynamicJumpifInsidePushWithoutJumpDest.json", - "JDfromStorageDynamicJumpiOutsideBoundary.json", - "DynamicJumpi0.json", - "DynamicJumpi1_jumpdest.json", - "DynamicJumpifInsidePushWithJumpDest.json", - "DynamicJumpifInsidePushWithoutJumpDest.json", - "DynamicJumpiOutsideBoundary.json", - "BlockNumberDynamicJumpi0.json", - "BlockNumberDynamicJumpi1_jumpdest.json", - "BlockNumberDynamicJumpifInsidePushWithJumpDest.json", - "BlockNumberDynamicJumpifInsidePushWithoutJumpDest.json", - "BlockNumberDynamicJumpiOutsideBoundary.json", - ], -) -def test_jumpi(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "pc0.json", - "pc1.json", - ], -) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - ["gas0.json", "gas1.json", "gasOverFlow.json"], -) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "for_loop1.json", - "for_loop2.json", - "loop_stacklimit_1020.json", - "loop_stacklimit_1021.json", - ], -) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "byte1.json", - "calldatacopyMemExp.json", - "codecopyMemExp.json", - "deadCode_1.json", - "dupAt51becameMload.json", - "swapAt52becameMstore.json", - "log1MemExp.json", - ], -) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) diff --git a/tests/frontier/vm/test_environmental_operations.py b/tests/frontier/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/frontier/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/frontier/vm/test_keccak.py b/tests/frontier/vm/test_keccak.py deleted file mode 100644 index 4c44bb02b7..0000000000 --- a/tests/frontier/vm/test_keccak.py +++ /dev/null @@ -1,49 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sha3_0.json", - "sha3_1.json", - "sha3_2.json", - "sha3_bigOffset2.json", - "sha3_memSizeNoQuadraticCost31.json", - "sha3_memSizeQuadraticCost32.json", - "sha3_memSizeQuadraticCost32_zeroSize.json", - "sha3_memSizeQuadraticCost33.json", - "sha3_memSizeQuadraticCost63.json", - "sha3_memSizeQuadraticCost64.json", - "sha3_memSizeQuadraticCost64_2.json", - "sha3_memSizeQuadraticCost65.json", - "sha3_3.json", - "sha3_4.json", - "sha3_5.json", - "sha3_6.json", - "sha3_bigOffset.json", - "sha3_bigSize.json", - ], -) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) - - -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") diff --git a/tests/frontier/vm/test_memory_operations.py b/tests/frontier/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/frontier/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/frontier/vm/test_stack_operations.py b/tests/frontier/vm/test_stack_operations.py deleted file mode 100644 index 718d7b8c86..0000000000 --- a/tests/frontier/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file", - [f"push{i}.json" for i in range(1, 34)] - + [ - "push32Undefined2.json", - "push32AndSuicide.json", - ], -) -def test_push_successfully(test_file: str) -> None: - run_push_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/frontier/vm/test_storage_operations.py b/tests/frontier/vm/test_storage_operations.py deleted file mode 100644 index fbe4f78146..0000000000 --- a/tests/frontier/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sstore_load_0.json", - "sstore_load_1.json", - "sstore_load_2.json", - "sstore_underflow.json", - "kv1.json", - ], -) -def test_sstore_and_sload(test_file: str) -> None: - run_storage_vm_test(test_file) diff --git a/tests/frontier/vm/test_system_operations.py b/tests/frontier/vm/test_system_operations.py deleted file mode 100644 index f21981e7bb..0000000000 --- a/tests/frontier/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "suicide0.json", - "suicideNotExistingAccount.json", - "suicideSendEtherToMe.json", - ], -) -def test_seldestruct(test_file: str) -> None: - run_system_vm_test(test_file) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/frontier/vm/vm_test_helpers.py b/tests/frontier/vm/vm_test_helpers.py deleted file mode 100644 index 6399aa5de9..0000000000 --- a/tests/frontier/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("Frontier", "frontier").run_test diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py deleted file mode 100644 index 881791e935..0000000000 --- a/tests/helpers/__init__.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import Dict, TypedDict - -from typing_extensions import NotRequired - - -class _FixtureSource(TypedDict): - url: str - fixture_path: str - commit_hash: NotRequired[str] - - -# Update the links and commit has in order to consume -# newer/other tests -TEST_FIXTURES: Dict[str, _FixtureSource] = { - "evm_tools_testdata": { - "url": "https://github.com/gurukamath/evm-tools-testdata.git", - "commit_hash": "792422d", - "fixture_path": "tests/fixtures/evm_tools_testdata", - }, - "ethereum_tests": { - "url": "https://github.com/ethereum/tests.git", - "commit_hash": "3129f16519013b265fa309208f49406b2ef57b13", - "fixture_path": "tests/fixtures/ethereum_tests", - }, - "latest_fork_tests": { - "url": "https://github.com/ethereum/execution-spec-tests/releases/download/v4.5.0/fixtures_stable.tar.gz", - "fixture_path": "tests/fixtures/latest_fork_tests", - }, - "osaka_tests": { - "url": "https://github.com/ethereum/execution-spec-tests/releases/download/fusaka-devnet-3%40v1.0.0/fixtures_fusaka-devnet-3.tar.gz", - "fixture_path": "tests/fixtures/osaka_tests", - }, -} - - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] -EEST_TESTS_PATH = TEST_FIXTURES["latest_fork_tests"]["fixture_path"] - -OSAKA_TEST_PATH = TEST_FIXTURES["osaka_tests"]["fixture_path"] diff --git a/tests/homestead/vm/__init__.py b/tests/homestead/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/homestead/vm/test_arithmetic_operations.py b/tests/homestead/vm/test_arithmetic_operations.py deleted file mode 100644 index 6f6ffe54b7..0000000000 --- a/tests/homestead/vm/test_arithmetic_operations.py +++ /dev/null @@ -1,238 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "add0.json", - "add1.json", - "add2.json", - "add3.json", - "add4.json", - ], -) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sub0.json", - "sub1.json", - "sub2.json", - "sub3.json", - "sub4.json", - ], -) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mul0.json", - "mul1.json", - "mul2.json", - "mul3.json", - "mul4.json", - "mul5.json", - "mul6.json", - "mul7.json", - ], -) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "div1.json", - "divBoostBug.json", - "divByNonZero0.json", - "divByNonZero1.json", - "divByNonZero2.json", - "divByNonZero3.json", - "divByZero.json", - "divByZero_2.json", - ], -) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sdiv0.json", - "sdiv1.json", - "sdiv2.json", - "sdiv3.json", - "sdiv4.json", - "sdiv5.json", - "sdiv6.json", - "sdiv7.json", - "sdiv8.json", - "sdiv9.json", - "sdivByZero0.json", - "sdivByZero1.json", - "sdivByZero2.json", - "sdiv_i256min.json", - "sdiv_i256min2.json", - "sdiv_i256min3.json", - "sdiv_dejavu.json", - ], -) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mod0.json", - "mod1.json", - "mod2.json", - "mod3.json", - "mod4.json", - "modByZero.json", - ], -) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "smod0.json", - "smod1.json", - "smod2.json", - "smod3.json", - "smod4.json", - "smod5.json", - "smod6.json", - "smod7.json", - "smod8_byZero.json", - "smod_i256min1.json", - "smod_i256min2.json", - ], -) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "addmod0.json", - "addmod1.json", - "addmod1_overflow2.json", - "addmod1_overflow3.json", - "addmod1_overflow4.json", - "addmod1_overflowDiff.json", - "addmod2.json", - "addmod2_0.json", - "addmod2_1.json", - "addmod3.json", - "addmod3_0.json", - ], -) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mulmod0.json", - "mulmod1.json", - "mulmod1_overflow.json", - "mulmod1_overflow2.json", - "mulmod1_overflow3.json", - "mulmod1_overflow4.json", - "mulmod2.json", - "mulmod2_0.json", - "mulmod2_1.json", - "mulmod3.json", - "mulmod3_0.json", - "mulmod4.json", - ], -) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "exp0.json", - "exp1.json", - "exp2.json", - "exp3.json", - "exp4.json", - "exp5.json", - "exp6.json", - "exp7.json", - "exp8.json", - "expXY.json", - "expXY_success.json", - ], -) -def test_exp(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test(f"expPowerOf2_{exponent}.json") - - -def test_exp_power_256() -> None: - for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json") - - for i in range(34): - run_arithmetic_vm_test(f"expPowerOf256Of256_{i}.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "signextend_0_BigByte.json", - "signextend_00.json", - "signextend_AlmostBiggestByte.json", - "signextend_BigByte_0.json", - "signextend_BigByteBigByte.json", - "signextend_BigBytePlus1_2.json", - "signextend_bigBytePlus1.json", - "signextend_BitIsNotSet.json", - "signextend_BitIsNotSetInHigherByte.json", - "signextend_bitIsSet.json", - "signextend_BitIsSetInHigherByte.json", - "signextend_Overflow_dj42.json", - "signextendInvalidByteNumber.json", - ], -) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") diff --git a/tests/homestead/vm/test_block_operations.py b/tests/homestead/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/homestead/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/homestead/vm/test_control_flow_operations.py b/tests/homestead/vm/test_control_flow_operations.py deleted file mode 100644 index 9a56b21f99..0000000000 --- a/tests/homestead/vm/test_control_flow_operations.py +++ /dev/null @@ -1,183 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "jump0_jumpdest0.json", - "jump0_jumpdest2.json", - "jumpAfterStop.json", - "jumpdestBigList.json", - "jumpTo1InstructionafterJump.json", - "jumpDynamicJumpSameDest.json", - "indirect_jump1.json", - "indirect_jump2.json", - "indirect_jump3.json", - "DynamicJump_value1.json", - "DynamicJump_value2.json", - "DynamicJump_value3.json", - "stackjump1.json", - "indirect_jump4.json", - "JDfromStorageDynamicJump0_jumpdest0.json", - "JDfromStorageDynamicJump0_jumpdest2.json", - "DynamicJump0_jumpdest0.json", - "DynamicJump0_jumpdest2.json", - "DynamicJumpAfterStop.json", - "DynamicJumpJD_DependsOnJumps1.json", - "DynamicJumpPathologicalTest0.json", - "DynamicJumpStartWithJumpDest.json", - "BlockNumberDynamicJump0_jumpdest0.json", - "BlockNumberDynamicJump0_jumpdest2.json", - "bad_indirect_jump1.json", - "bad_indirect_jump2.json", - "jump0_AfterJumpdest.json", - "jump0_AfterJumpdest3.json", - "jump0_outOfBoundary.json", - "jump0_withoutJumpdest.json", - "jump1.json", - "jumpHigh.json", - "jumpInsidePushWithJumpDest.json", - "jumpInsidePushWithoutJumpDest.json", - "jumpTo1InstructionafterJump_jumpdestFirstInstruction.json", - "jumpTo1InstructionafterJump_noJumpDest.json", - "jumpToUint64maxPlus1.json", - "jumpToUintmaxPlus1.json", - "JDfromStorageDynamicJump0_AfterJumpdest.json", - "JDfromStorageDynamicJump0_AfterJumpdest3.json", - "JDfromStorageDynamicJump0_withoutJumpdest.json", - "JDfromStorageDynamicJump1.json", - "JDfromStorageDynamicJumpInsidePushWithJumpDest.json", - "JDfromStorageDynamicJumpInsidePushWithoutJumpDest.json", - "DyanmicJump0_outOfBoundary.json", - "DynamicJump0_AfterJumpdest.json", - "DynamicJump0_AfterJumpdest3.json", - "DynamicJump0_withoutJumpdest.json", - "DynamicJump1.json", - "DynamicJumpInsidePushWithJumpDest.json", - "DynamicJumpInsidePushWithoutJumpDest.json", - "DynamicJumpJD_DependsOnJumps0.json", - "DynamicJumpPathologicalTest1.json", - "DynamicJumpPathologicalTest2.json", - "DynamicJumpPathologicalTest3.json", - "BlockNumberDynamicJump0_AfterJumpdest.json", - "BlockNumberDynamicJump0_AfterJumpdest3.json", - "BlockNumberDynamicJump0_withoutJumpdest.json", - "BlockNumberDynamicJump1.json", - "BlockNumberDynamicJumpInsidePushWithJumpDest.json", - "BlockNumberDynamicJumpInsidePushWithoutJumpDest.json", - "jump0_foreverOutOfGas.json", - "JDfromStorageDynamicJump0_foreverOutOfGas.json", - "DynamicJump0_foreverOutOfGas.json", - "BlockNumberDynamicJump0_foreverOutOfGas.json", - "jumpOntoJump.json", - "DynamicJump_valueUnderflow.json", - "stack_loop.json", - ], -) -def test_jump(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "jumpi1.json", - "jumpiAfterStop.json", - "jumpi_at_the_end.json", - "JDfromStorageDynamicJumpi1.json", - "JDfromStorageDynamicJumpiAfterStop.json", - "DynamicJumpi1.json", - "DynamicJumpiAfterStop.json", - "BlockNumberDynamicJumpi1.json", - "BlockNumberDynamicJumpiAfterStop.json", - "jumpi0.json", - "jumpi1_jumpdest.json", - "jumpifInsidePushWithJumpDest.json", - "jumpifInsidePushWithoutJumpDest.json", - "jumpiOutsideBoundary.json", - "jumpiToUint64maxPlus1.json", - "jumpiToUintmaxPlus1.json", - "JDfromStorageDynamicJumpi0.json", - "JDfromStorageDynamicJumpi1_jumpdest.json", - "JDfromStorageDynamicJumpifInsidePushWithJumpDest.json", - "JDfromStorageDynamicJumpifInsidePushWithoutJumpDest.json", - "JDfromStorageDynamicJumpiOutsideBoundary.json", - "DynamicJumpi0.json", - "DynamicJumpi1_jumpdest.json", - "DynamicJumpifInsidePushWithJumpDest.json", - "DynamicJumpifInsidePushWithoutJumpDest.json", - "DynamicJumpiOutsideBoundary.json", - "BlockNumberDynamicJumpi0.json", - "BlockNumberDynamicJumpi1_jumpdest.json", - "BlockNumberDynamicJumpifInsidePushWithJumpDest.json", - "BlockNumberDynamicJumpifInsidePushWithoutJumpDest.json", - "BlockNumberDynamicJumpiOutsideBoundary.json", - ], -) -def test_jumpi(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "pc0.json", - "pc1.json", - ], -) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - ["gas0.json", "gas1.json", "gasOverFlow.json"], -) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "for_loop1.json", - "for_loop2.json", - "loop_stacklimit_1020.json", - "loop_stacklimit_1021.json", - ], -) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "byte1.json", - "calldatacopyMemExp.json", - "codecopyMemExp.json", - "deadCode_1.json", - "dupAt51becameMload.json", - "swapAt52becameMstore.json", - "log1MemExp.json", - ], -) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) diff --git a/tests/homestead/vm/test_environmental_operations.py b/tests/homestead/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/homestead/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/homestead/vm/test_keccak.py b/tests/homestead/vm/test_keccak.py deleted file mode 100644 index 4c44bb02b7..0000000000 --- a/tests/homestead/vm/test_keccak.py +++ /dev/null @@ -1,49 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sha3_0.json", - "sha3_1.json", - "sha3_2.json", - "sha3_bigOffset2.json", - "sha3_memSizeNoQuadraticCost31.json", - "sha3_memSizeQuadraticCost32.json", - "sha3_memSizeQuadraticCost32_zeroSize.json", - "sha3_memSizeQuadraticCost33.json", - "sha3_memSizeQuadraticCost63.json", - "sha3_memSizeQuadraticCost64.json", - "sha3_memSizeQuadraticCost64_2.json", - "sha3_memSizeQuadraticCost65.json", - "sha3_3.json", - "sha3_4.json", - "sha3_5.json", - "sha3_6.json", - "sha3_bigOffset.json", - "sha3_bigSize.json", - ], -) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) - - -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") diff --git a/tests/homestead/vm/test_logging_operations.py b/tests/homestead/vm/test_logging_operations.py deleted file mode 100644 index e7c2222098..0000000000 --- a/tests/homestead/vm/test_logging_operations.py +++ /dev/null @@ -1,104 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "log0_emptyMem.json", - "log0_logMemsizeZero.json", - "log0_nonEmptyMem.json", - "log0_nonEmptyMem_logMemSize1.json", - "log0_nonEmptyMem_logMemSize1_logMemStart31.json", - "log0_logMemsizeTooHigh.json", - "log0_logMemStartTooHigh.json", - ], -) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log1_Caller.json", - "log1_emptyMem.json", - "log1_logMemsizeZero.json", - "log1_MaxTopic.json", - "log1_nonEmptyMem.json", - "log1_nonEmptyMem_logMemSize1.json", - "log1_nonEmptyMem_logMemSize1_logMemStart31.json", - "log1_logMemsizeTooHigh.json", - "log1_logMemStartTooHigh.json", - ], -) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log2_Caller.json", - "log2_emptyMem.json", - "log2_logMemsizeZero.json", - "log2_MaxTopic.json", - "log2_nonEmptyMem.json", - "log2_nonEmptyMem_logMemSize1.json", - "log2_nonEmptyMem_logMemSize1_logMemStart31.json", - "log2_logMemsizeTooHigh.json", - "log2_logMemStartTooHigh.json", - ], -) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log3_Caller.json", - "log3_emptyMem.json", - "log3_logMemsizeZero.json", - "log3_MaxTopic.json", - "log3_nonEmptyMem.json", - "log3_nonEmptyMem_logMemSize1.json", - "log3_nonEmptyMem_logMemSize1_logMemStart31.json", - "log3_PC.json", - "log3_logMemsizeTooHigh.json", - "log3_logMemStartTooHigh.json", - ], -) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log4_Caller.json", - "log4_emptyMem.json", - "log4_logMemsizeZero.json", - "log4_MaxTopic.json", - "log4_nonEmptyMem.json", - "log4_nonEmptyMem_logMemSize1.json", - "log4_nonEmptyMem_logMemSize1_logMemStart31.json", - "log4_PC.json", - "log4_logMemsizeTooHigh.json", - "log4_logMemStartTooHigh.json", - ], -) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) diff --git a/tests/homestead/vm/test_memory_operations.py b/tests/homestead/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/homestead/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/homestead/vm/test_stack_operations.py b/tests/homestead/vm/test_stack_operations.py deleted file mode 100644 index 718d7b8c86..0000000000 --- a/tests/homestead/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file", - [f"push{i}.json" for i in range(1, 34)] - + [ - "push32Undefined2.json", - "push32AndSuicide.json", - ], -) -def test_push_successfully(test_file: str) -> None: - run_push_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/homestead/vm/test_storage_operations.py b/tests/homestead/vm/test_storage_operations.py deleted file mode 100644 index fbe4f78146..0000000000 --- a/tests/homestead/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sstore_load_0.json", - "sstore_load_1.json", - "sstore_load_2.json", - "sstore_underflow.json", - "kv1.json", - ], -) -def test_sstore_and_sload(test_file: str) -> None: - run_storage_vm_test(test_file) diff --git a/tests/homestead/vm/test_system_operations.py b/tests/homestead/vm/test_system_operations.py deleted file mode 100644 index f21981e7bb..0000000000 --- a/tests/homestead/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "suicide0.json", - "suicideNotExistingAccount.json", - "suicideSendEtherToMe.json", - ], -) -def test_seldestruct(test_file: str) -> None: - run_system_vm_test(test_file) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/homestead/vm/vm_test_helpers.py b/tests/homestead/vm/vm_test_helpers.py deleted file mode 100644 index d5e5fbfadd..0000000000 --- a/tests/homestead/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("Homestead", "homestead").run_test diff --git a/tests/helpers/load_vm_tests.py b/tests/json_infra/helpers/load_vm_tests.py similarity index 100% rename from tests/helpers/load_vm_tests.py rename to tests/json_infra/helpers/load_vm_tests.py diff --git a/tests/json_infra/vm/__init__.py b/tests/json_infra/vm/__init__.py new file mode 100644 index 0000000000..db1202e8cb --- /dev/null +++ b/tests/json_infra/vm/__init__.py @@ -0,0 +1,27 @@ +from ..conftest import pytest_config + +FORKS = [ + ("ConstantinopleFix", "constantinople"), + ("Byzantium", "byzantium"), + ("EIP158", "spurious_dragon"), + ("EIP150", "tangerine_whistle"), + ("Homestead", "homestead"), + ("Frontier", "frontier"), +] + + +# Determine which forks to generate tests for +if pytest_config and pytest_config.getoption("fork", None): + # If --fork option is specified, only generate test for that fork + fork_option = pytest_config.getoption("fork") + has_vm_tests = False + for fork in FORKS: + if fork[0] == fork_option: + has_vm_tests = True + forks_to_test = [fork] + break + if not has_vm_tests: + forks_to_test = [] +else: + # If no --fork option, generate tests for all forks + forks_to_test = FORKS diff --git a/tests/spurious_dragon/vm/test_arithmetic_operations.py b/tests/json_infra/vm/test_arithmetic_operations.py similarity index 54% rename from tests/spurious_dragon/vm/test_arithmetic_operations.py rename to tests/json_infra/vm/test_arithmetic_operations.py index e9f91b35eb..008135d067 100644 --- a/tests/spurious_dragon/vm/test_arithmetic_operations.py +++ b/tests/json_infra/vm/test_arithmetic_operations.py @@ -1,20 +1,16 @@ -from functools import partial +from typing import Tuple import pytest -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest" -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -25,10 +21,14 @@ "add4.json", ], ) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_add(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -39,10 +39,14 @@ def test_add(test_file: str) -> None: "sub4.json", ], ) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_sub(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -56,10 +60,14 @@ def test_sub(test_file: str) -> None: "mul7.json", ], ) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_mul(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -73,10 +81,14 @@ def test_mul(test_file: str) -> None: "divByZero_2.json", ], ) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_div(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -99,10 +111,14 @@ def test_div(test_file: str) -> None: "sdiv_dejavu.json", ], ) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_sdiv(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -114,10 +130,14 @@ def test_sdiv(test_file: str) -> None: "modByZero.json", ], ) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_mod(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -134,10 +154,14 @@ def test_mod(test_file: str) -> None: "smod_i256min2.json", ], ) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_smod(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -154,10 +178,14 @@ def test_smod(test_file: str) -> None: "addmod3_0.json", ], ) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_addmod(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -175,10 +203,14 @@ def test_addmod(test_file: str) -> None: "mulmod4.json", ], ) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_mulmod(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -195,27 +227,42 @@ def test_mulmod(test_file: str) -> None: "expXY_success.json", ], ) -def test_exp(test_file: str) -> None: - run_arithmetic_vm_test(test_file, check_gas_left=False) +def test_exp(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + check_gas_left=False, + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test( - f"expPowerOf2_{exponent}.json", check_gas_left=False +def test_exp_power_2(fork: Tuple[str, str], exponent: int) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + f"expPowerOf2_{exponent}.json", + check_gas_left=False, ) -def test_exp_power_256() -> None: +@pytest.mark.parametrize("fork", forks_to_test) +def test_exp_power_256(fork: Tuple[str, str]) -> None: for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json", check_gas_left=False) + VmTestLoader(*fork).run_test( + TEST_DIR, + f"expPowerOf256_{i}.json", + check_gas_left=False, + ) for i in range(34): - run_arithmetic_vm_test( - f"expPowerOf256Of256_{i}.json", check_gas_left=False + VmTestLoader(*fork).run_test( + TEST_DIR, + f"expPowerOf256Of256_{i}.json", + check_gas_left=False, ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -234,9 +281,16 @@ def test_exp_power_256() -> None: "signextendInvalidByteNumber.json", ], ) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) +def test_signextend(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + test_file, + ) -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") +@pytest.mark.parametrize("fork", forks_to_test) +def test_stop(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, + "stop.json", + ) diff --git a/tests/homestead/vm/test_bitwise_logic_operations.py b/tests/json_infra/vm/test_bitwise_logic_operations.py similarity index 50% rename from tests/homestead/vm/test_bitwise_logic_operations.py rename to tests/json_infra/vm/test_bitwise_logic_operations.py index bc98c473c1..a9df08c00e 100644 --- a/tests/homestead/vm/test_bitwise_logic_operations.py +++ b/tests/json_infra/vm/test_bitwise_logic_operations.py @@ -1,19 +1,16 @@ -from functools import partial +from typing import Tuple import pytest -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation" +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -23,10 +20,11 @@ "lt3.json", ], ) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_lt(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -36,10 +34,11 @@ def test_lt(test_file: str) -> None: "gt3.json", ], ) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_gt(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -50,10 +49,11 @@ def test_gt(test_file: str) -> None: "slt4.json", ], ) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_slt(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -64,10 +64,11 @@ def test_slt(test_file: str) -> None: "sgt4.json", ], ) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_sgt(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -76,10 +77,11 @@ def test_sgt(test_file: str) -> None: "eq2.json", ], ) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_eq(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -88,10 +90,11 @@ def test_eq(test_file: str) -> None: "iszeo2.json", ], ) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_iszero(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -103,10 +106,11 @@ def test_iszero(test_file: str) -> None: "and5.json", ], ) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_and(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -118,10 +122,11 @@ def test_and(test_file: str) -> None: "or5.json", ], ) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_or(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -133,10 +138,11 @@ def test_or(test_file: str) -> None: "xor5.json", ], ) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_xor(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -148,10 +154,11 @@ def test_xor(test_file: str) -> None: "not5.json", ], ) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_not(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -170,5 +177,5 @@ def test_not(test_file: str) -> None: "byteBN.json", ], ) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) +def test_byte(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) diff --git a/tests/json_infra/vm/test_block_operations.py b/tests/json_infra/vm/test_block_operations.py new file mode 100644 index 0000000000..9716e7816e --- /dev/null +++ b/tests/json_infra/vm/test_block_operations.py @@ -0,0 +1,37 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = ( + f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest" +) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_coinbase(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "coinbase.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_timestamp(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "timestamp.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_number(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "number.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_difficulty(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "difficulty.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_gas_limit(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "gaslimit.json") diff --git a/tests/byzantium/vm/test_control_flow_operations.py b/tests/json_infra/vm/test_control_flow_operations.py similarity index 79% rename from tests/byzantium/vm/test_control_flow_operations.py rename to tests/json_infra/vm/test_control_flow_operations.py index 1f8d2e27ea..963999815b 100644 --- a/tests/byzantium/vm/test_control_flow_operations.py +++ b/tests/json_infra/vm/test_control_flow_operations.py @@ -1,19 +1,16 @@ -from functools import partial +from typing import Tuple import pytest -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file, check_gas_left", [ @@ -87,10 +84,15 @@ ("stack_loop.json", True), ], ) -def test_jump(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) +def test_jump( + fork: Tuple[str, str], test_file: str, check_gas_left: bool +) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, test_file, check_gas_left=check_gas_left + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file, check_gas_left", [ @@ -127,10 +129,15 @@ def test_jump(test_file: str, check_gas_left: bool) -> None: ("BlockNumberDynamicJumpiOutsideBoundary.json", True), ], ) -def test_jumpi(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) +def test_jumpi( + fork: Tuple[str, str], test_file: str, check_gas_left: bool +) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, test_file, check_gas_left=check_gas_left + ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -138,18 +145,20 @@ def test_jumpi(test_file: str, check_gas_left: bool) -> None: "pc1.json", ], ) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) +def test_pc(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", ["gas0.json", "gas1.json", "gasOverFlow.json"], ) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) +def test_gas(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -159,14 +168,16 @@ def test_gas(test_file: str) -> None: "loop_stacklimit_1021.json", ], ) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) +def test_loop(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") +@pytest.mark.parametrize("fork", forks_to_test) +def test_when(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "when.json") +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -179,5 +190,5 @@ def test_when() -> None: "log1MemExp.json", ], ) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) +def test_miscellaneous(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) diff --git a/tests/json_infra/vm/test_environmental_operations.py b/tests/json_infra/vm/test_environmental_operations.py new file mode 100644 index 0000000000..6361391fca --- /dev/null +++ b/tests/json_infra/vm/test_environmental_operations.py @@ -0,0 +1,113 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo" + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "address0.json", + "address1.json", + ], +) +def test_address(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_origin(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "origin.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_caller(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "caller.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_callvalue(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "callvalue.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "calldataload0.json", + "calldataload1.json", + "calldataload2.json", + "calldataload_BigOffset.json", + "calldataloadSizeTooHigh.json", + "calldataloadSizeTooHighPartial.json", + ], +) +def test_calldataload(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "calldatasize0.json", + "calldatasize1.json", + "calldatasize2.json", + ], +) +def test_calldatasize(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "calldatacopy0.json", + "calldatacopy1.json", + "calldatacopy2.json", + "calldatacopyZeroMemExpansion.json", + "calldatacopy_DataIndexTooHigh.json", + "calldatacopy_DataIndexTooHigh2.json", + "calldatacopy_sec.json", + "calldatacopyUnderFlow.json", + "calldatacopy0_return.json", + "calldatacopy1_return.json", + "calldatacopy2_return.json", + "calldatacopyZeroMemExpansion_return.json", + "calldatacopy_DataIndexTooHigh_return.json", + "calldatacopy_DataIndexTooHigh2_return.json", + ], +) +def test_calldatacopy(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_codesize(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "codesize.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "codecopy0.json", + "codecopyZeroMemExpansion.json", + "codecopy_DataIndexTooHigh.json", + ], +) +def test_codecopy(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_gasprice(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, "gasprice.json") diff --git a/tests/constantinople/vm/test_keccak.py b/tests/json_infra/vm/test_keccak.py similarity index 57% rename from tests/constantinople/vm/test_keccak.py rename to tests/json_infra/vm/test_keccak.py index 4c44bb02b7..771b1e0496 100644 --- a/tests/constantinople/vm/test_keccak.py +++ b/tests/json_infra/vm/test_keccak.py @@ -1,23 +1,19 @@ -from functools import partial +from typing import Tuple import pytest -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", +TEST_DIR = ( + f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test" ) +SPECIAL_TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -41,9 +37,10 @@ "sha3_bigSize.json", ], ) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) +def test_sha3_succeeds(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") +@pytest.mark.parametrize("fork", forks_to_test) +def test_sha3_fails_out_of_gas_memory_expansion(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(SPECIAL_TEST_DIR, "sha3MemExp.json") diff --git a/tests/frontier/vm/test_logging_operations.py b/tests/json_infra/vm/test_logging_operations.py similarity index 68% rename from tests/frontier/vm/test_logging_operations.py rename to tests/json_infra/vm/test_logging_operations.py index e7c2222098..3dda2e3cd1 100644 --- a/tests/frontier/vm/test_logging_operations.py +++ b/tests/json_infra/vm/test_logging_operations.py @@ -1,19 +1,18 @@ -from functools import partial +from typing import Tuple import pytest -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", +TEST_DIR = ( + f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest" ) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -26,10 +25,11 @@ "log0_logMemStartTooHigh.json", ], ) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) +def test_log0(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -44,10 +44,11 @@ def test_log0(test_file: str) -> None: "log1_logMemStartTooHigh.json", ], ) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) +def test_log1(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -62,10 +63,11 @@ def test_log1(test_file: str) -> None: "log2_logMemStartTooHigh.json", ], ) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) +def test_log2(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -81,10 +83,11 @@ def test_log2(test_file: str) -> None: "log3_logMemStartTooHigh.json", ], ) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) +def test_log3(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) +@pytest.mark.parametrize("fork", forks_to_test) @pytest.mark.parametrize( "test_file", [ @@ -100,5 +103,5 @@ def test_log3(test_file: str) -> None: "log4_logMemStartTooHigh.json", ], ) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) +def test_log4(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) diff --git a/tests/json_infra/vm/test_memory_operations.py b/tests/json_infra/vm/test_memory_operations.py new file mode 100644 index 0000000000..f3031c3154 --- /dev/null +++ b/tests/json_infra/vm/test_memory_operations.py @@ -0,0 +1,76 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "mstore0.json", + "mstore1.json", + "mstoreMemExp.json", + ], +) +def test_mstore(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "mstore8_0.json", + "mstore8_1.json", + "mstore8WordToBigError.json", + "mstore8MemExp.json", + ], +) +def test_mstore8(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "mloadError0.json", + "mloadError1.json", + "mstore_mload0.json", + "mloadOutOfGasError2.json", + ], +) +def test_mload(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "mstore_mload0.json", + ], +) +def test_mstore_mload(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "msize0.json", + "msize1.json", + "msize2.json", + "msize3.json", + ], +) +def test_msize(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) diff --git a/tests/json_infra/vm/test_stack_operations.py b/tests/json_infra/vm/test_stack_operations.py new file mode 100644 index 0000000000..3c7a4d002e --- /dev/null +++ b/tests/json_infra/vm/test_stack_operations.py @@ -0,0 +1,81 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +PUSH_TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest" +POP_TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" + +DUP_TEST_DIR = SWAP_TEST_DIR = PUSH_TEST_DIR + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file, check_gas_left", + [(f"push{i}.json", True) for i in range(1, 34)] + + [ + ("push32Undefined2.json", True), + ("push32AndSuicide.json", False), + ], +) +def test_push_successfully( + fork: Tuple[str, str], test_file: str, check_gas_left: bool +) -> None: + VmTestLoader(*fork).run_test( + PUSH_TEST_DIR, test_file, check_gas_left=check_gas_left + ) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "push1_missingStack.json", + "push32Undefined.json", + "push32Undefined3.json", + "push32FillUpInputWithZerosAtTheEnd.json", + ], +) +def test_push_failed(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(PUSH_TEST_DIR, test_file) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_dup(fork: Tuple[str, str]) -> None: + for i in range(1, 17): + VmTestLoader(*fork).run_test(DUP_TEST_DIR, f"dup{i}.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_dup_error(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(DUP_TEST_DIR, "dup2error.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_swap(fork: Tuple[str, str]) -> None: + for i in range(1, 17): + VmTestLoader(*fork).run_test(SWAP_TEST_DIR, f"swap{i}.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_swap_jump(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(SWAP_TEST_DIR, "swapjump1.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_swap_error(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(SWAP_TEST_DIR, "swap2error.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_pop(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(POP_TEST_DIR, "pop0.json") + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_pop_fails_when_stack_underflowed(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test(POP_TEST_DIR, "pop1.json") diff --git a/tests/json_infra/vm/test_storage_operations.py b/tests/json_infra/vm/test_storage_operations.py new file mode 100644 index 0000000000..d2fc18f297 --- /dev/null +++ b/tests/json_infra/vm/test_storage_operations.py @@ -0,0 +1,29 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file, check_gas_left", + [ + ("sstore_load_0.json", False), + ("sstore_load_1.json", False), + ("sstore_load_2.json", False), + ("sstore_underflow.json", True), + ("kv1.json", True), + ], +) +def test_sstore_and_sload( + fork: Tuple[str, str], test_file: str, check_gas_left: bool +) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, test_file, check_gas_left=check_gas_left + ) diff --git a/tests/json_infra/vm/test_system_operations.py b/tests/json_infra/vm/test_system_operations.py new file mode 100644 index 0000000000..2e0168c8c2 --- /dev/null +++ b/tests/json_infra/vm/test_system_operations.py @@ -0,0 +1,50 @@ +from typing import Tuple + +import pytest + +from .. import TEST_FIXTURES +from ..helpers.load_vm_tests import VmTestLoader +from . import forks_to_test + +ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] +TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations" +VM_TEST_DIR = ( + f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests" +) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file, check_gas_left", + [ + ("suicide0.json", False), + ("suicideNotExistingAccount.json", False), + ("suicideSendEtherToMe.json", False), + ], +) +def test_seldestruct( + fork: Tuple[str, str], test_file: str, check_gas_left: bool +) -> None: + VmTestLoader(*fork).run_test( + TEST_DIR, test_file, check_gas_left=check_gas_left + ) + + +@pytest.mark.parametrize("fork", forks_to_test) +def test_seldestruct_vm_test(fork: Tuple[str, str]) -> None: + VmTestLoader(*fork).run_test( + VM_TEST_DIR, "suicide.json", check_gas_left=False + ) + + +@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.parametrize( + "test_file", + [ + "return0.json", + "return1.json", + "return2.json", + ], +) +def test_return(fork: Tuple[str, str], test_file: str) -> None: + VmTestLoader(*fork).run_test(TEST_DIR, test_file) diff --git a/tests/spurious_dragon/vm/__init__.py b/tests/spurious_dragon/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/spurious_dragon/vm/test_bitwise_logic_operations.py b/tests/spurious_dragon/vm/test_bitwise_logic_operations.py deleted file mode 100644 index bc98c473c1..0000000000 --- a/tests/spurious_dragon/vm/test_bitwise_logic_operations.py +++ /dev/null @@ -1,174 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "lt0.json", - "lt1.json", - "lt2.json", - "lt3.json", - ], -) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "gt0.json", - "gt1.json", - "gt2.json", - "gt3.json", - ], -) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "slt0.json", - "slt1.json", - "slt2.json", - "slt3.json", - "slt4.json", - ], -) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sgt0.json", - "sgt1.json", - "sgt2.json", - "sgt3.json", - "sgt4.json", - ], -) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "eq0.json", - "eq1.json", - "eq2.json", - ], -) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "iszero0.json", - "iszero1.json", - "iszeo2.json", - ], -) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "and0.json", - "and1.json", - "and2.json", - "and3.json", - "and4.json", - "and5.json", - ], -) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "or0.json", - "or1.json", - "or2.json", - "or3.json", - "or4.json", - "or5.json", - ], -) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "xor0.json", - "xor1.json", - "xor2.json", - "xor3.json", - "xor4.json", - "xor5.json", - ], -) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "not0.json", - "not1.json", - "not2.json", - "not3.json", - "not4.json", - "not5.json", - ], -) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "byte0.json", - "byte1.json", - "byte2.json", - "byte3.json", - "byte4.json", - "byte5.json", - "byte6.json", - "byte7.json", - "byte8.json", - "byte9.json", - "byte10.json", - "byte11.json", - "byteBN.json", - ], -) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) diff --git a/tests/spurious_dragon/vm/test_block_operations.py b/tests/spurious_dragon/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/spurious_dragon/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/spurious_dragon/vm/test_control_flow_operations.py b/tests/spurious_dragon/vm/test_control_flow_operations.py deleted file mode 100644 index 1f8d2e27ea..0000000000 --- a/tests/spurious_dragon/vm/test_control_flow_operations.py +++ /dev/null @@ -1,183 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jump0_jumpdest0.json", True), - ("jump0_jumpdest2.json", True), - ("jumpAfterStop.json", True), - ("jumpdestBigList.json", True), - ("jumpTo1InstructionafterJump.json", True), - ("jumpDynamicJumpSameDest.json", True), - ("indirect_jump1.json", True), - ("indirect_jump2.json", True), - ("indirect_jump3.json", True), - ("DynamicJump_value1.json", True), - ("DynamicJump_value2.json", True), - ("DynamicJump_value3.json", True), - ("stackjump1.json", True), - ("indirect_jump4.json", True), - ("JDfromStorageDynamicJump0_jumpdest0.json", False), - ("JDfromStorageDynamicJump0_jumpdest2.json", False), - ("DynamicJump0_jumpdest0.json", True), - ("DynamicJump0_jumpdest2.json", True), - ("DynamicJumpAfterStop.json", True), - ("DynamicJumpJD_DependsOnJumps1.json", True), - ("DynamicJumpPathologicalTest0.json", True), - ("DynamicJumpStartWithJumpDest.json", True), - ("BlockNumberDynamicJump0_jumpdest0.json", True), - ("BlockNumberDynamicJump0_jumpdest2.json", True), - ("bad_indirect_jump1.json", True), - ("bad_indirect_jump2.json", True), - ("jump0_AfterJumpdest.json", True), - ("jump0_AfterJumpdest3.json", True), - ("jump0_outOfBoundary.json", True), - ("jump0_withoutJumpdest.json", True), - ("jump1.json", True), - ("jumpHigh.json", True), - ("jumpInsidePushWithJumpDest.json", True), - ("jumpInsidePushWithoutJumpDest.json", True), - ("jumpTo1InstructionafterJump_jumpdestFirstInstruction.json", True), - ("jumpTo1InstructionafterJump_noJumpDest.json", True), - ("jumpToUint64maxPlus1.json", True), - ("jumpToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest3.json", True), - ("JDfromStorageDynamicJump0_withoutJumpdest.json", True), - ("JDfromStorageDynamicJump1.json", True), - ("JDfromStorageDynamicJumpInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpInsidePushWithoutJumpDest.json", True), - ("DyanmicJump0_outOfBoundary.json", True), - ("DynamicJump0_AfterJumpdest.json", True), - ("DynamicJump0_AfterJumpdest3.json", True), - ("DynamicJump0_withoutJumpdest.json", True), - ("DynamicJump1.json", True), - ("DynamicJumpInsidePushWithJumpDest.json", True), - ("DynamicJumpInsidePushWithoutJumpDest.json", True), - ("DynamicJumpJD_DependsOnJumps0.json", True), - ("DynamicJumpPathologicalTest1.json", True), - ("DynamicJumpPathologicalTest2.json", True), - ("DynamicJumpPathologicalTest3.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest3.json", True), - ("BlockNumberDynamicJump0_withoutJumpdest.json", True), - ("BlockNumberDynamicJump1.json", True), - ("BlockNumberDynamicJumpInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpInsidePushWithoutJumpDest.json", True), - ("jump0_foreverOutOfGas.json", True), - ("JDfromStorageDynamicJump0_foreverOutOfGas.json", True), - ("DynamicJump0_foreverOutOfGas.json", True), - ("BlockNumberDynamicJump0_foreverOutOfGas.json", True), - ("jumpOntoJump.json", True), - ("DynamicJump_valueUnderflow.json", True), - ("stack_loop.json", True), - ], -) -def test_jump(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jumpi1.json", True), - ("jumpiAfterStop.json", True), - ("jumpi_at_the_end.json", True), - ("JDfromStorageDynamicJumpi1.json", False), - ("JDfromStorageDynamicJumpiAfterStop.json", False), - ("DynamicJumpi1.json", True), - ("DynamicJumpiAfterStop.json", True), - ("BlockNumberDynamicJumpi1.json", True), - ("BlockNumberDynamicJumpiAfterStop.json", True), - ("jumpi0.json", True), - ("jumpi1_jumpdest.json", True), - ("jumpifInsidePushWithJumpDest.json", True), - ("jumpifInsidePushWithoutJumpDest.json", True), - ("jumpiOutsideBoundary.json", True), - ("jumpiToUint64maxPlus1.json", True), - ("jumpiToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJumpi0.json", True), - ("JDfromStorageDynamicJumpi1_jumpdest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("JDfromStorageDynamicJumpiOutsideBoundary.json", True), - ("DynamicJumpi0.json", True), - ("DynamicJumpi1_jumpdest.json", True), - ("DynamicJumpifInsidePushWithJumpDest.json", True), - ("DynamicJumpifInsidePushWithoutJumpDest.json", True), - ("DynamicJumpiOutsideBoundary.json", True), - ("BlockNumberDynamicJumpi0.json", True), - ("BlockNumberDynamicJumpi1_jumpdest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("BlockNumberDynamicJumpiOutsideBoundary.json", True), - ], -) -def test_jumpi(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "pc0.json", - "pc1.json", - ], -) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - ["gas0.json", "gas1.json", "gasOverFlow.json"], -) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "for_loop1.json", - "for_loop2.json", - "loop_stacklimit_1020.json", - "loop_stacklimit_1021.json", - ], -) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "byte1.json", - "calldatacopyMemExp.json", - "codecopyMemExp.json", - "deadCode_1.json", - "dupAt51becameMload.json", - "swapAt52becameMstore.json", - "log1MemExp.json", - ], -) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) diff --git a/tests/spurious_dragon/vm/test_environmental_operations.py b/tests/spurious_dragon/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/spurious_dragon/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/spurious_dragon/vm/test_keccak.py b/tests/spurious_dragon/vm/test_keccak.py deleted file mode 100644 index 4c44bb02b7..0000000000 --- a/tests/spurious_dragon/vm/test_keccak.py +++ /dev/null @@ -1,49 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sha3_0.json", - "sha3_1.json", - "sha3_2.json", - "sha3_bigOffset2.json", - "sha3_memSizeNoQuadraticCost31.json", - "sha3_memSizeQuadraticCost32.json", - "sha3_memSizeQuadraticCost32_zeroSize.json", - "sha3_memSizeQuadraticCost33.json", - "sha3_memSizeQuadraticCost63.json", - "sha3_memSizeQuadraticCost64.json", - "sha3_memSizeQuadraticCost64_2.json", - "sha3_memSizeQuadraticCost65.json", - "sha3_3.json", - "sha3_4.json", - "sha3_5.json", - "sha3_6.json", - "sha3_bigOffset.json", - "sha3_bigSize.json", - ], -) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) - - -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") diff --git a/tests/spurious_dragon/vm/test_logging_operations.py b/tests/spurious_dragon/vm/test_logging_operations.py deleted file mode 100644 index e7c2222098..0000000000 --- a/tests/spurious_dragon/vm/test_logging_operations.py +++ /dev/null @@ -1,104 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "log0_emptyMem.json", - "log0_logMemsizeZero.json", - "log0_nonEmptyMem.json", - "log0_nonEmptyMem_logMemSize1.json", - "log0_nonEmptyMem_logMemSize1_logMemStart31.json", - "log0_logMemsizeTooHigh.json", - "log0_logMemStartTooHigh.json", - ], -) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log1_Caller.json", - "log1_emptyMem.json", - "log1_logMemsizeZero.json", - "log1_MaxTopic.json", - "log1_nonEmptyMem.json", - "log1_nonEmptyMem_logMemSize1.json", - "log1_nonEmptyMem_logMemSize1_logMemStart31.json", - "log1_logMemsizeTooHigh.json", - "log1_logMemStartTooHigh.json", - ], -) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log2_Caller.json", - "log2_emptyMem.json", - "log2_logMemsizeZero.json", - "log2_MaxTopic.json", - "log2_nonEmptyMem.json", - "log2_nonEmptyMem_logMemSize1.json", - "log2_nonEmptyMem_logMemSize1_logMemStart31.json", - "log2_logMemsizeTooHigh.json", - "log2_logMemStartTooHigh.json", - ], -) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log3_Caller.json", - "log3_emptyMem.json", - "log3_logMemsizeZero.json", - "log3_MaxTopic.json", - "log3_nonEmptyMem.json", - "log3_nonEmptyMem_logMemSize1.json", - "log3_nonEmptyMem_logMemSize1_logMemStart31.json", - "log3_PC.json", - "log3_logMemsizeTooHigh.json", - "log3_logMemStartTooHigh.json", - ], -) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log4_Caller.json", - "log4_emptyMem.json", - "log4_logMemsizeZero.json", - "log4_MaxTopic.json", - "log4_nonEmptyMem.json", - "log4_nonEmptyMem_logMemSize1.json", - "log4_nonEmptyMem_logMemSize1_logMemStart31.json", - "log4_PC.json", - "log4_logMemsizeTooHigh.json", - "log4_logMemStartTooHigh.json", - ], -) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) diff --git a/tests/spurious_dragon/vm/test_memory_operations.py b/tests/spurious_dragon/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/spurious_dragon/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/spurious_dragon/vm/test_stack_operations.py b/tests/spurious_dragon/vm/test_stack_operations.py deleted file mode 100644 index 8845fa29ab..0000000000 --- a/tests/spurious_dragon/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [(f"push{i}.json", True) for i in range(1, 34)] - + [ - ("push32Undefined2.json", True), - ("push32AndSuicide.json", False), - ], -) -def test_push_successfully(test_file: str, check_gas_left: bool) -> None: - run_push_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/spurious_dragon/vm/test_storage_operations.py b/tests/spurious_dragon/vm/test_storage_operations.py deleted file mode 100644 index 3a83f3f8f2..0000000000 --- a/tests/spurious_dragon/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("sstore_load_0.json", False), - ("sstore_load_1.json", False), - ("sstore_load_2.json", False), - ("sstore_underflow.json", True), - ("kv1.json", True), - ], -) -def test_sstore_and_sload(test_file: str, check_gas_left: bool) -> None: - run_storage_vm_test(test_file, check_gas_left=check_gas_left) diff --git a/tests/spurious_dragon/vm/test_system_operations.py b/tests/spurious_dragon/vm/test_system_operations.py deleted file mode 100644 index e314fec6c4..0000000000 --- a/tests/spurious_dragon/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("suicide0.json", False), - ("suicideNotExistingAccount.json", False), - ("suicideSendEtherToMe.json", False), - ], -) -def test_seldestruct(test_file: str, check_gas_left: bool) -> None: - run_system_vm_test(test_file, check_gas_left=check_gas_left) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json", check_gas_left=False) - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/spurious_dragon/vm/vm_test_helpers.py b/tests/spurious_dragon/vm/vm_test_helpers.py deleted file mode 100644 index 419b27de2c..0000000000 --- a/tests/spurious_dragon/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("EIP158", "spurious_dragon").run_test diff --git a/tests/tangerine_whistle/vm/__init__.py b/tests/tangerine_whistle/vm/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/tangerine_whistle/vm/test_arithmetic_operations.py b/tests/tangerine_whistle/vm/test_arithmetic_operations.py deleted file mode 100644 index 9ab21688a7..0000000000 --- a/tests/tangerine_whistle/vm/test_arithmetic_operations.py +++ /dev/null @@ -1,238 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - - -run_arithmetic_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "add0.json", - "add1.json", - "add2.json", - "add3.json", - "add4.json", - ], -) -def test_add(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sub0.json", - "sub1.json", - "sub2.json", - "sub3.json", - "sub4.json", - ], -) -def test_sub(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mul0.json", - "mul1.json", - "mul2.json", - "mul3.json", - "mul4.json", - "mul5.json", - "mul6.json", - "mul7.json", - ], -) -def test_mul(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "div1.json", - "divBoostBug.json", - "divByNonZero0.json", - "divByNonZero1.json", - "divByNonZero2.json", - "divByNonZero3.json", - "divByZero.json", - "divByZero_2.json", - ], -) -def test_div(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sdiv0.json", - "sdiv1.json", - "sdiv2.json", - "sdiv3.json", - "sdiv4.json", - "sdiv5.json", - "sdiv6.json", - "sdiv7.json", - "sdiv8.json", - "sdiv9.json", - "sdivByZero0.json", - "sdivByZero1.json", - "sdivByZero2.json", - "sdiv_i256min.json", - "sdiv_i256min2.json", - "sdiv_i256min3.json", - "sdiv_dejavu.json", - ], -) -def test_sdiv(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mod0.json", - "mod1.json", - "mod2.json", - "mod3.json", - "mod4.json", - "modByZero.json", - ], -) -def test_mod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "smod0.json", - "smod1.json", - "smod2.json", - "smod3.json", - "smod4.json", - "smod5.json", - "smod6.json", - "smod7.json", - "smod8_byZero.json", - "smod_i256min1.json", - "smod_i256min2.json", - ], -) -def test_smod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "addmod0.json", - "addmod1.json", - "addmod1_overflow2.json", - "addmod1_overflow3.json", - "addmod1_overflow4.json", - "addmod1_overflowDiff.json", - "addmod2.json", - "addmod2_0.json", - "addmod2_1.json", - "addmod3.json", - "addmod3_0.json", - ], -) -def test_addmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mulmod0.json", - "mulmod1.json", - "mulmod1_overflow.json", - "mulmod1_overflow2.json", - "mulmod1_overflow3.json", - "mulmod1_overflow4.json", - "mulmod2.json", - "mulmod2_0.json", - "mulmod2_1.json", - "mulmod3.json", - "mulmod3_0.json", - "mulmod4.json", - ], -) -def test_mulmod(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("exp0.json", True), - ("exp1.json", True), - ("exp2.json", True), - ("exp3.json", True), - ("exp4.json", True), - ("exp5.json", True), - ("exp6.json", True), - ("exp7.json", True), - ("exp8.json", True), - ("expXY.json", False), - ("expXY_success.json", False), - ], -) -def test_exp(test_file: str, check_gas_left: bool) -> None: - run_arithmetic_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) -def test_exp_power_2(exponent: int) -> None: - run_arithmetic_vm_test(f"expPowerOf2_{exponent}.json") - - -def test_exp_power_256() -> None: - for i in range(1, 34): - run_arithmetic_vm_test(f"expPowerOf256_{i}.json") - - for i in range(34): - run_arithmetic_vm_test(f"expPowerOf256Of256_{i}.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "signextend_0_BigByte.json", - "signextend_00.json", - "signextend_AlmostBiggestByte.json", - "signextend_BigByte_0.json", - "signextend_BigByteBigByte.json", - "signextend_BigBytePlus1_2.json", - "signextend_bigBytePlus1.json", - "signextend_BitIsNotSet.json", - "signextend_BitIsNotSetInHigherByte.json", - "signextend_bitIsSet.json", - "signextend_BitIsSetInHigherByte.json", - "signextend_Overflow_dj42.json", - "signextendInvalidByteNumber.json", - ], -) -def test_signextend(test_file: str) -> None: - run_arithmetic_vm_test(test_file) - - -def test_stop() -> None: - run_arithmetic_vm_test("stop.json") diff --git a/tests/tangerine_whistle/vm/test_bitwise_logic_operations.py b/tests/tangerine_whistle/vm/test_bitwise_logic_operations.py deleted file mode 100644 index bc98c473c1..0000000000 --- a/tests/tangerine_whistle/vm/test_bitwise_logic_operations.py +++ /dev/null @@ -1,174 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_bitwise_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "lt0.json", - "lt1.json", - "lt2.json", - "lt3.json", - ], -) -def test_lt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "gt0.json", - "gt1.json", - "gt2.json", - "gt3.json", - ], -) -def test_gt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "slt0.json", - "slt1.json", - "slt2.json", - "slt3.json", - "slt4.json", - ], -) -def test_slt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "sgt0.json", - "sgt1.json", - "sgt2.json", - "sgt3.json", - "sgt4.json", - ], -) -def test_sgt(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "eq0.json", - "eq1.json", - "eq2.json", - ], -) -def test_eq(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "iszero0.json", - "iszero1.json", - "iszeo2.json", - ], -) -def test_iszero(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "and0.json", - "and1.json", - "and2.json", - "and3.json", - "and4.json", - "and5.json", - ], -) -def test_and(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "or0.json", - "or1.json", - "or2.json", - "or3.json", - "or4.json", - "or5.json", - ], -) -def test_or(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "xor0.json", - "xor1.json", - "xor2.json", - "xor3.json", - "xor4.json", - "xor5.json", - ], -) -def test_xor(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "not0.json", - "not1.json", - "not2.json", - "not3.json", - "not4.json", - "not5.json", - ], -) -def test_not(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "byte0.json", - "byte1.json", - "byte2.json", - "byte3.json", - "byte4.json", - "byte5.json", - "byte6.json", - "byte7.json", - "byte8.json", - "byte9.json", - "byte10.json", - "byte11.json", - "byteBN.json", - ], -) -def test_byte(test_file: str) -> None: - run_bitwise_ops_vm_test(test_file) diff --git a/tests/tangerine_whistle/vm/test_block_operations.py b/tests/tangerine_whistle/vm/test_block_operations.py deleted file mode 100644 index ebf1ce5d8e..0000000000 --- a/tests/tangerine_whistle/vm/test_block_operations.py +++ /dev/null @@ -1,32 +0,0 @@ -from functools import partial - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_block_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -) - - -def test_coinbase() -> None: - run_block_ops_vm_test("coinbase.json") - - -def test_timestamp() -> None: - run_block_ops_vm_test("timestamp.json") - - -def test_number() -> None: - run_block_ops_vm_test("number.json") - - -def test_difficulty() -> None: - run_block_ops_vm_test("difficulty.json") - - -def test_gas_limit() -> None: - run_block_ops_vm_test("gaslimit.json") diff --git a/tests/tangerine_whistle/vm/test_control_flow_operations.py b/tests/tangerine_whistle/vm/test_control_flow_operations.py deleted file mode 100644 index 1f8d2e27ea..0000000000 --- a/tests/tangerine_whistle/vm/test_control_flow_operations.py +++ /dev/null @@ -1,183 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from .vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_control_flow_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jump0_jumpdest0.json", True), - ("jump0_jumpdest2.json", True), - ("jumpAfterStop.json", True), - ("jumpdestBigList.json", True), - ("jumpTo1InstructionafterJump.json", True), - ("jumpDynamicJumpSameDest.json", True), - ("indirect_jump1.json", True), - ("indirect_jump2.json", True), - ("indirect_jump3.json", True), - ("DynamicJump_value1.json", True), - ("DynamicJump_value2.json", True), - ("DynamicJump_value3.json", True), - ("stackjump1.json", True), - ("indirect_jump4.json", True), - ("JDfromStorageDynamicJump0_jumpdest0.json", False), - ("JDfromStorageDynamicJump0_jumpdest2.json", False), - ("DynamicJump0_jumpdest0.json", True), - ("DynamicJump0_jumpdest2.json", True), - ("DynamicJumpAfterStop.json", True), - ("DynamicJumpJD_DependsOnJumps1.json", True), - ("DynamicJumpPathologicalTest0.json", True), - ("DynamicJumpStartWithJumpDest.json", True), - ("BlockNumberDynamicJump0_jumpdest0.json", True), - ("BlockNumberDynamicJump0_jumpdest2.json", True), - ("bad_indirect_jump1.json", True), - ("bad_indirect_jump2.json", True), - ("jump0_AfterJumpdest.json", True), - ("jump0_AfterJumpdest3.json", True), - ("jump0_outOfBoundary.json", True), - ("jump0_withoutJumpdest.json", True), - ("jump1.json", True), - ("jumpHigh.json", True), - ("jumpInsidePushWithJumpDest.json", True), - ("jumpInsidePushWithoutJumpDest.json", True), - ("jumpTo1InstructionafterJump_jumpdestFirstInstruction.json", True), - ("jumpTo1InstructionafterJump_noJumpDest.json", True), - ("jumpToUint64maxPlus1.json", True), - ("jumpToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest.json", True), - ("JDfromStorageDynamicJump0_AfterJumpdest3.json", True), - ("JDfromStorageDynamicJump0_withoutJumpdest.json", True), - ("JDfromStorageDynamicJump1.json", True), - ("JDfromStorageDynamicJumpInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpInsidePushWithoutJumpDest.json", True), - ("DyanmicJump0_outOfBoundary.json", True), - ("DynamicJump0_AfterJumpdest.json", True), - ("DynamicJump0_AfterJumpdest3.json", True), - ("DynamicJump0_withoutJumpdest.json", True), - ("DynamicJump1.json", True), - ("DynamicJumpInsidePushWithJumpDest.json", True), - ("DynamicJumpInsidePushWithoutJumpDest.json", True), - ("DynamicJumpJD_DependsOnJumps0.json", True), - ("DynamicJumpPathologicalTest1.json", True), - ("DynamicJumpPathologicalTest2.json", True), - ("DynamicJumpPathologicalTest3.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest.json", True), - ("BlockNumberDynamicJump0_AfterJumpdest3.json", True), - ("BlockNumberDynamicJump0_withoutJumpdest.json", True), - ("BlockNumberDynamicJump1.json", True), - ("BlockNumberDynamicJumpInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpInsidePushWithoutJumpDest.json", True), - ("jump0_foreverOutOfGas.json", True), - ("JDfromStorageDynamicJump0_foreverOutOfGas.json", True), - ("DynamicJump0_foreverOutOfGas.json", True), - ("BlockNumberDynamicJump0_foreverOutOfGas.json", True), - ("jumpOntoJump.json", True), - ("DynamicJump_valueUnderflow.json", True), - ("stack_loop.json", True), - ], -) -def test_jump(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("jumpi1.json", True), - ("jumpiAfterStop.json", True), - ("jumpi_at_the_end.json", True), - ("JDfromStorageDynamicJumpi1.json", False), - ("JDfromStorageDynamicJumpiAfterStop.json", False), - ("DynamicJumpi1.json", True), - ("DynamicJumpiAfterStop.json", True), - ("BlockNumberDynamicJumpi1.json", True), - ("BlockNumberDynamicJumpiAfterStop.json", True), - ("jumpi0.json", True), - ("jumpi1_jumpdest.json", True), - ("jumpifInsidePushWithJumpDest.json", True), - ("jumpifInsidePushWithoutJumpDest.json", True), - ("jumpiOutsideBoundary.json", True), - ("jumpiToUint64maxPlus1.json", True), - ("jumpiToUintmaxPlus1.json", True), - ("JDfromStorageDynamicJumpi0.json", True), - ("JDfromStorageDynamicJumpi1_jumpdest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithJumpDest.json", True), - ("JDfromStorageDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("JDfromStorageDynamicJumpiOutsideBoundary.json", True), - ("DynamicJumpi0.json", True), - ("DynamicJumpi1_jumpdest.json", True), - ("DynamicJumpifInsidePushWithJumpDest.json", True), - ("DynamicJumpifInsidePushWithoutJumpDest.json", True), - ("DynamicJumpiOutsideBoundary.json", True), - ("BlockNumberDynamicJumpi0.json", True), - ("BlockNumberDynamicJumpi1_jumpdest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithJumpDest.json", True), - ("BlockNumberDynamicJumpifInsidePushWithoutJumpDest.json", True), - ("BlockNumberDynamicJumpiOutsideBoundary.json", True), - ], -) -def test_jumpi(test_file: str, check_gas_left: bool) -> None: - run_control_flow_ops_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "pc0.json", - "pc1.json", - ], -) -def test_pc(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - ["gas0.json", "gas1.json", "gasOverFlow.json"], -) -def test_gas(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "for_loop1.json", - "for_loop2.json", - "loop_stacklimit_1020.json", - "loop_stacklimit_1021.json", - ], -) -def test_loop(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) - - -def test_when() -> None: - run_control_flow_ops_vm_test("when.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "byte1.json", - "calldatacopyMemExp.json", - "codecopyMemExp.json", - "deadCode_1.json", - "dupAt51becameMload.json", - "swapAt52becameMstore.json", - "log1MemExp.json", - ], -) -def test_miscellaneous(test_file: str) -> None: - run_control_flow_ops_vm_test(test_file) diff --git a/tests/tangerine_whistle/vm/test_environmental_operations.py b/tests/tangerine_whistle/vm/test_environmental_operations.py deleted file mode 100644 index eb5b24f63e..0000000000 --- a/tests/tangerine_whistle/vm/test_environmental_operations.py +++ /dev/null @@ -1,107 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_environmental_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "address0.json", - "address1.json", - ], -) -def test_address(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_origin() -> None: - run_environmental_vm_test("origin.json") - - -def test_caller() -> None: - run_environmental_vm_test("caller.json") - - -def test_callvalue() -> None: - run_environmental_vm_test("callvalue.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "calldataload0.json", - "calldataload1.json", - "calldataload2.json", - "calldataload_BigOffset.json", - "calldataloadSizeTooHigh.json", - "calldataloadSizeTooHighPartial.json", - ], -) -def test_calldataload(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatasize0.json", - "calldatasize1.json", - "calldatasize2.json", - ], -) -def test_calldatasize(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "calldatacopy0.json", - "calldatacopy1.json", - "calldatacopy2.json", - "calldatacopyZeroMemExpansion.json", - "calldatacopy_DataIndexTooHigh.json", - "calldatacopy_DataIndexTooHigh2.json", - "calldatacopy_sec.json", - "calldatacopyUnderFlow.json", - "calldatacopy0_return.json", - "calldatacopy1_return.json", - "calldatacopy2_return.json", - "calldatacopyZeroMemExpansion_return.json", - "calldatacopy_DataIndexTooHigh_return.json", - "calldatacopy_DataIndexTooHigh2_return.json", - ], -) -def test_calldatacopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_codesize() -> None: - run_environmental_vm_test("codesize.json") - - -@pytest.mark.parametrize( - "test_file", - [ - "codecopy0.json", - "codecopyZeroMemExpansion.json", - "codecopy_DataIndexTooHigh.json", - ], -) -def test_codecopy(test_file: str) -> None: - run_environmental_vm_test(test_file) - - -def test_gasprice() -> None: - run_environmental_vm_test("gasprice.json") diff --git a/tests/tangerine_whistle/vm/test_keccak.py b/tests/tangerine_whistle/vm/test_keccak.py deleted file mode 100644 index 4c44bb02b7..0000000000 --- a/tests/tangerine_whistle/vm/test_keccak.py +++ /dev/null @@ -1,49 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSha3Test", -) -run_special_sha3_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "sha3_0.json", - "sha3_1.json", - "sha3_2.json", - "sha3_bigOffset2.json", - "sha3_memSizeNoQuadraticCost31.json", - "sha3_memSizeQuadraticCost32.json", - "sha3_memSizeQuadraticCost32_zeroSize.json", - "sha3_memSizeQuadraticCost33.json", - "sha3_memSizeQuadraticCost63.json", - "sha3_memSizeQuadraticCost64.json", - "sha3_memSizeQuadraticCost64_2.json", - "sha3_memSizeQuadraticCost65.json", - "sha3_3.json", - "sha3_4.json", - "sha3_5.json", - "sha3_6.json", - "sha3_bigOffset.json", - "sha3_bigSize.json", - ], -) -def test_sha3_succeeds(test_file: str) -> None: - run_sha3_vm_test(test_file) - - -def test_sha3_fails_out_of_gas_memory_expansion() -> None: - run_special_sha3_vm_test("sha3MemExp.json") diff --git a/tests/tangerine_whistle/vm/test_logging_operations.py b/tests/tangerine_whistle/vm/test_logging_operations.py deleted file mode 100644 index e7c2222098..0000000000 --- a/tests/tangerine_whistle/vm/test_logging_operations.py +++ /dev/null @@ -1,104 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_logging_ops_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmLogTest", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "log0_emptyMem.json", - "log0_logMemsizeZero.json", - "log0_nonEmptyMem.json", - "log0_nonEmptyMem_logMemSize1.json", - "log0_nonEmptyMem_logMemSize1_logMemStart31.json", - "log0_logMemsizeTooHigh.json", - "log0_logMemStartTooHigh.json", - ], -) -def test_log0(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log1_Caller.json", - "log1_emptyMem.json", - "log1_logMemsizeZero.json", - "log1_MaxTopic.json", - "log1_nonEmptyMem.json", - "log1_nonEmptyMem_logMemSize1.json", - "log1_nonEmptyMem_logMemSize1_logMemStart31.json", - "log1_logMemsizeTooHigh.json", - "log1_logMemStartTooHigh.json", - ], -) -def test_log1(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log2_Caller.json", - "log2_emptyMem.json", - "log2_logMemsizeZero.json", - "log2_MaxTopic.json", - "log2_nonEmptyMem.json", - "log2_nonEmptyMem_logMemSize1.json", - "log2_nonEmptyMem_logMemSize1_logMemStart31.json", - "log2_logMemsizeTooHigh.json", - "log2_logMemStartTooHigh.json", - ], -) -def test_log2(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log3_Caller.json", - "log3_emptyMem.json", - "log3_logMemsizeZero.json", - "log3_MaxTopic.json", - "log3_nonEmptyMem.json", - "log3_nonEmptyMem_logMemSize1.json", - "log3_nonEmptyMem_logMemSize1_logMemStart31.json", - "log3_PC.json", - "log3_logMemsizeTooHigh.json", - "log3_logMemStartTooHigh.json", - ], -) -def test_log3(test_file: str) -> None: - run_logging_ops_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "log4_Caller.json", - "log4_emptyMem.json", - "log4_logMemsizeZero.json", - "log4_MaxTopic.json", - "log4_nonEmptyMem.json", - "log4_nonEmptyMem_logMemSize1.json", - "log4_nonEmptyMem_logMemSize1_logMemStart31.json", - "log4_PC.json", - "log4_logMemsizeTooHigh.json", - "log4_logMemStartTooHigh.json", - ], -) -def test_log4(test_file: str) -> None: - run_logging_ops_vm_test(test_file) diff --git a/tests/tangerine_whistle/vm/test_memory_operations.py b/tests/tangerine_whistle/vm/test_memory_operations.py deleted file mode 100644 index 91cb04783c..0000000000 --- a/tests/tangerine_whistle/vm/test_memory_operations.py +++ /dev/null @@ -1,75 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_memory_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations/", -) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore0.json", - "mstore1.json", - "mstoreMemExp.json", - ], -) -def test_mstore(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore8_0.json", - "mstore8_1.json", - "mstore8WordToBigError.json", - "mstore8MemExp.json", - ], -) -def test_mstore8(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mloadError0.json", - "mloadError1.json", - "mstore_mload0.json", - "mloadOutOfGasError2.json", - ], -) -def test_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "mstore_mload0.json", - ], -) -def test_mstore_mload(test_file: str) -> None: - run_memory_vm_test(test_file) - - -@pytest.mark.parametrize( - "test_file", - [ - "msize0.json", - "msize1.json", - "msize2.json", - "msize3.json", - ], -) -def test_msize(test_file: str) -> None: - run_memory_vm_test(test_file) diff --git a/tests/tangerine_whistle/vm/test_stack_operations.py b/tests/tangerine_whistle/vm/test_stack_operations.py deleted file mode 100644 index 8845fa29ab..0000000000 --- a/tests/tangerine_whistle/vm/test_stack_operations.py +++ /dev/null @@ -1,74 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_push_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -) -run_pop_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) -run_dup_vm_test = run_swap_vm_test = run_push_vm_test - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [(f"push{i}.json", True) for i in range(1, 34)] - + [ - ("push32Undefined2.json", True), - ("push32AndSuicide.json", False), - ], -) -def test_push_successfully(test_file: str, check_gas_left: bool) -> None: - run_push_vm_test(test_file, check_gas_left=check_gas_left) - - -@pytest.mark.parametrize( - "test_file", - [ - "push1_missingStack.json", - "push32Undefined.json", - "push32Undefined3.json", - "push32FillUpInputWithZerosAtTheEnd.json", - ], -) -def test_push_failed(test_file: str) -> None: - run_push_vm_test(test_file) - - -def test_dup() -> None: - for i in range(1, 17): - run_dup_vm_test(f"dup{i}.json") - - -def test_dup_error() -> None: - run_dup_vm_test("dup2error.json") - - -def test_swap() -> None: - for i in range(1, 17): - run_swap_vm_test(f"swap{i}.json") - - -def test_swap_jump() -> None: - run_swap_vm_test("swapjump1.json") - - -def test_swap_error() -> None: - run_swap_vm_test("swap2error.json") - - -def test_pop() -> None: - run_pop_vm_test("pop0.json") - - -def test_pop_fails_when_stack_underflowed() -> None: - run_pop_vm_test("pop1.json") diff --git a/tests/tangerine_whistle/vm/test_storage_operations.py b/tests/tangerine_whistle/vm/test_storage_operations.py deleted file mode 100644 index 3a83f3f8f2..0000000000 --- a/tests/tangerine_whistle/vm/test_storage_operations.py +++ /dev/null @@ -1,28 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_storage_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("sstore_load_0.json", False), - ("sstore_load_1.json", False), - ("sstore_load_2.json", False), - ("sstore_underflow.json", True), - ("kv1.json", True), - ], -) -def test_sstore_and_sload(test_file: str, check_gas_left: bool) -> None: - run_storage_vm_test(test_file, check_gas_left=check_gas_left) diff --git a/tests/tangerine_whistle/vm/test_system_operations.py b/tests/tangerine_whistle/vm/test_system_operations.py deleted file mode 100644 index e314fec6c4..0000000000 --- a/tests/tangerine_whistle/vm/test_system_operations.py +++ /dev/null @@ -1,47 +0,0 @@ -from functools import partial - -import pytest - -from tests.helpers import TEST_FIXTURES - -from ..vm.vm_test_helpers import run_test - -ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] - -run_system_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations", -) - -run_vm_test = partial( - run_test, - f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmTests", -) - - -@pytest.mark.parametrize( - "test_file, check_gas_left", - [ - ("suicide0.json", False), - ("suicideNotExistingAccount.json", False), - ("suicideSendEtherToMe.json", False), - ], -) -def test_seldestruct(test_file: str, check_gas_left: bool) -> None: - run_system_vm_test(test_file, check_gas_left=check_gas_left) - - -def test_seldestruct_vm_test() -> None: - run_vm_test("suicide.json", check_gas_left=False) - - -@pytest.mark.parametrize( - "test_file", - [ - "return0.json", - "return1.json", - "return2.json", - ], -) -def test_return(test_file: str) -> None: - run_system_vm_test(test_file) diff --git a/tests/tangerine_whistle/vm/vm_test_helpers.py b/tests/tangerine_whistle/vm/vm_test_helpers.py deleted file mode 100644 index 43bf23a6c8..0000000000 --- a/tests/tangerine_whistle/vm/vm_test_helpers.py +++ /dev/null @@ -1,3 +0,0 @@ -from ...helpers.load_vm_tests import VmTestLoader - -run_test = VmTestLoader("EIP150", "tangerine_whistle").run_test diff --git a/tests/test_rlp.py b/tests/test_rlp.py index de7d8ccaa9..906adcca99 100644 --- a/tests/test_rlp.py +++ b/tests/test_rlp.py @@ -7,7 +7,8 @@ from ethereum.frontier.fork_types import Bytes, Uint from ethereum.utils.hexadecimal import hex_to_bytes -from tests.helpers import TEST_FIXTURES + +from .json_infra import TEST_FIXTURES ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] From d97ddd0bbc3a63c2a7ff2f616e49e7fafc2d1f26 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Fri, 1 Aug 2025 16:44:24 +0200 Subject: [PATCH 09/14] remove rlp tests --- tests/berlin/__init__.py | 0 tests/berlin/test_rlp.py | 138 ---------------------- tests/byzantium/__init__.py | 0 tests/byzantium/test_rlp.py | 109 ------------------ tests/cancun/__init__.py | 0 tests/cancun/test_rlp.py | 171 --------------------------- tests/constantinople/__init__.py | 0 tests/constantinople/test_rlp.py | 109 ------------------ tests/frontier/__init__.py | 0 tests/frontier/test_rlp.py | 109 ------------------ tests/homestead/__init__.py | 0 tests/homestead/test_rlp.py | 109 ------------------ tests/istanbul/__init__.py | 0 tests/istanbul/test_rlp.py | 109 ------------------ tests/london/__init__.py | 0 tests/london/test_rlp.py | 163 -------------------------- tests/osaka/__init__.py | 0 tests/osaka/test_rlp.py | 173 ---------------------------- tests/paris/__init__.py | 0 tests/paris/test_rlp.py | 163 -------------------------- tests/prague/__init__.py | 0 tests/prague/test_rlp.py | 173 ---------------------------- tests/shanghai/__init__.py | 0 tests/shanghai/test_rlp.py | 168 --------------------------- tests/spurious_dragon/__init__.py | 0 tests/spurious_dragon/test_rlp.py | 109 ------------------ tests/tangerine_whistle/__init__.py | 0 tests/tangerine_whistle/test_rlp.py | 109 ------------------ 28 files changed, 1912 deletions(-) delete mode 100644 tests/berlin/__init__.py delete mode 100644 tests/berlin/test_rlp.py delete mode 100644 tests/byzantium/__init__.py delete mode 100644 tests/byzantium/test_rlp.py delete mode 100644 tests/cancun/__init__.py delete mode 100644 tests/cancun/test_rlp.py delete mode 100644 tests/constantinople/__init__.py delete mode 100644 tests/constantinople/test_rlp.py delete mode 100644 tests/frontier/__init__.py delete mode 100644 tests/frontier/test_rlp.py delete mode 100644 tests/homestead/__init__.py delete mode 100644 tests/homestead/test_rlp.py delete mode 100644 tests/istanbul/__init__.py delete mode 100644 tests/istanbul/test_rlp.py delete mode 100644 tests/london/__init__.py delete mode 100644 tests/london/test_rlp.py delete mode 100644 tests/osaka/__init__.py delete mode 100644 tests/osaka/test_rlp.py delete mode 100644 tests/paris/__init__.py delete mode 100644 tests/paris/test_rlp.py delete mode 100644 tests/prague/__init__.py delete mode 100644 tests/prague/test_rlp.py delete mode 100644 tests/shanghai/__init__.py delete mode 100644 tests/shanghai/test_rlp.py delete mode 100644 tests/spurious_dragon/__init__.py delete mode 100644 tests/spurious_dragon/test_rlp.py delete mode 100644 tests/tangerine_whistle/__init__.py delete mode 100644 tests/tangerine_whistle/test_rlp.py diff --git a/tests/berlin/__init__.py b/tests/berlin/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/berlin/test_rlp.py b/tests/berlin/test_rlp.py deleted file mode 100644 index 59e92f320e..0000000000 --- a/tests/berlin/test_rlp.py +++ /dev/null @@ -1,138 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.berlin.blocks import Block, Header, Log, Receipt -from ethereum.berlin.transactions import ( - Access, - AccessListTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.berlin.utils.hexadecimal import hex_to_address -from ethereum.crypto.hash import keccak256 -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - ), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - header, - block, - log1, - log2, - receipt, - ], -) -def test_berlin_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize("tx", [legacy_transaction, access_list_transaction]) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/byzantium/__init__.py b/tests/byzantium/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/byzantium/test_rlp.py b/tests/byzantium/test_rlp.py deleted file mode 100644 index 83a15b2e30..0000000000 --- a/tests/byzantium/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.byzantium.blocks import Block, Header, Log, Receipt -from ethereum.byzantium.transactions import Transaction -from ethereum.byzantium.utils.hexadecimal import hex_to_address -from ethereum.crypto.hash import keccak256 -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_byzantium_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/cancun/__init__.py b/tests/cancun/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/cancun/test_rlp.py b/tests/cancun/test_rlp.py deleted file mode 100644 index d0752de8ef..0000000000 --- a/tests/cancun/test_rlp.py +++ /dev/null @@ -1,171 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8, Bytes32 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.cancun.blocks import Block, Header, Log, Receipt, Withdrawal -from ethereum.cancun.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.cancun.utils.hexadecimal import hex_to_address -from ethereum.crypto.hash import keccak256 -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -withdrawal = Withdrawal(U64(0), U64(1), address1, U256(2)) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - prev_randao=Bytes32(b"1234567890abcdef1234567890abcdef"), - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), - withdrawals_root=hash6, - parent_beacon_block_root=Bytes32(b"1234567890abcdef1234567890abcdef"), - blob_gas_used=U64(7), - excess_blob_gas=U64(8), -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(), - withdrawals=(withdrawal,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - withdrawal, - ], -) -def test_cancun_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/constantinople/__init__.py b/tests/constantinople/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/constantinople/test_rlp.py b/tests/constantinople/test_rlp.py deleted file mode 100644 index f8e4312082..0000000000 --- a/tests/constantinople/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.constantinople.blocks import Block, Header, Log, Receipt -from ethereum.constantinople.transactions import Transaction -from ethereum.constantinople.utils.hexadecimal import hex_to_address -from ethereum.crypto.hash import keccak256 -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_constantinople_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/frontier/__init__.py b/tests/frontier/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/frontier/test_rlp.py b/tests/frontier/test_rlp.py deleted file mode 100644 index f7289e5c46..0000000000 --- a/tests/frontier/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.frontier.blocks import Block, Header, Log, Receipt -from ethereum.frontier.transactions import Transaction -from ethereum.frontier.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - post_state=hash1, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_frontier_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/homestead/__init__.py b/tests/homestead/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/homestead/test_rlp.py b/tests/homestead/test_rlp.py deleted file mode 100644 index f73fb1c9cd..0000000000 --- a/tests/homestead/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.homestead.blocks import Block, Header, Log, Receipt -from ethereum.homestead.transactions import Transaction -from ethereum.homestead.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - post_state=hash1, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_homestead_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/istanbul/__init__.py b/tests/istanbul/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/istanbul/test_rlp.py b/tests/istanbul/test_rlp.py deleted file mode 100644 index 07d13d423a..0000000000 --- a/tests/istanbul/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.istanbul.blocks import Block, Header, Log, Receipt -from ethereum.istanbul.transactions import Transaction -from ethereum.istanbul.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_istanbul_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/london/__init__.py b/tests/london/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/london/test_rlp.py b/tests/london/test_rlp.py deleted file mode 100644 index db85edb3ed..0000000000 --- a/tests/london/test_rlp.py +++ /dev/null @@ -1,163 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.london.blocks import Block, Header, Log, Receipt -from ethereum.london.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.london.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - ], -) -def test_london_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/osaka/__init__.py b/tests/osaka/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/osaka/test_rlp.py b/tests/osaka/test_rlp.py deleted file mode 100644 index b33aaf404e..0000000000 --- a/tests/osaka/test_rlp.py +++ /dev/null @@ -1,173 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8, Bytes32 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.osaka.blocks import Block, Header, Log, Receipt, Withdrawal -from ethereum.osaka.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.osaka.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") -hash7 = keccak256(b"quuxbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -withdrawal = Withdrawal(U64(0), U64(1), address1, U256(2)) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - prev_randao=Bytes32(b"1234567890abcdef1234567890abcdef"), - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), - withdrawals_root=hash6, - parent_beacon_block_root=Bytes32(b"1234567890abcdef1234567890abcdef"), - blob_gas_used=U64(7), - excess_blob_gas=U64(8), - requests_hash=hash7, -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(), - withdrawals=(withdrawal,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - withdrawal, - ], -) -def test_cancun_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/paris/__init__.py b/tests/paris/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/paris/test_rlp.py b/tests/paris/test_rlp.py deleted file mode 100644 index 65903f641e..0000000000 --- a/tests/paris/test_rlp.py +++ /dev/null @@ -1,163 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8, Bytes32 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.paris.blocks import Block, Header, Log, Receipt -from ethereum.paris.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.paris.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - prev_randao=Bytes32(b"1234567890abcdef1234567890abcdef"), - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - ], -) -def test_paris_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/prague/__init__.py b/tests/prague/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/prague/test_rlp.py b/tests/prague/test_rlp.py deleted file mode 100644 index b59726f7a0..0000000000 --- a/tests/prague/test_rlp.py +++ /dev/null @@ -1,173 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8, Bytes32 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.prague.blocks import Block, Header, Log, Receipt, Withdrawal -from ethereum.prague.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.prague.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") -hash7 = keccak256(b"quuxbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -withdrawal = Withdrawal(U64(0), U64(1), address1, U256(2)) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - prev_randao=Bytes32(b"1234567890abcdef1234567890abcdef"), - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), - withdrawals_root=hash6, - parent_beacon_block_root=Bytes32(b"1234567890abcdef1234567890abcdef"), - blob_gas_used=U64(7), - excess_blob_gas=U64(8), - requests_hash=hash7, -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(), - withdrawals=(withdrawal,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - withdrawal, - ], -) -def test_cancun_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/shanghai/__init__.py b/tests/shanghai/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/shanghai/test_rlp.py b/tests/shanghai/test_rlp.py deleted file mode 100644 index ea63460814..0000000000 --- a/tests/shanghai/test_rlp.py +++ /dev/null @@ -1,168 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8, Bytes32 -from ethereum_types.numeric import U64, U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.shanghai.blocks import Block, Header, Log, Receipt, Withdrawal -from ethereum.shanghai.transactions import ( - Access, - AccessListTransaction, - FeeMarketTransaction, - LegacyTransaction, - Transaction, - decode_transaction, - encode_transaction, -) -from ethereum.shanghai.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -legacy_transaction = LegacyTransaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -access_list_transaction = AccessListTransaction( - U64(1), - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -transaction_1559 = FeeMarketTransaction( - U64(1), - U256(1), - Uint(7), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"bar"), - ( - Access(account=address1, slots=(hash1, hash2)), - Access(account=address2, slots=()), - ), - U256(27), - U256(5), - U256(6), -) - -withdrawal = Withdrawal(U64(0), U64(1), address1, U256(2)) - - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - prev_randao=Bytes32(b"1234567890abcdef1234567890abcdef"), - nonce=Bytes8(b"12345678"), - base_fee_per_gas=Uint(6), - withdrawals_root=hash6, -) - -block = Block( - header=header, - transactions=( - encode_transaction(legacy_transaction), - encode_transaction(access_list_transaction), - encode_transaction(transaction_1559), - ), - ommers=(), - withdrawals=(withdrawal,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - succeeded=True, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [ - legacy_transaction, - access_list_transaction, - transaction_1559, - header, - block, - log1, - log2, - receipt, - withdrawal, - ], -) -def test_shanghai_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object - - -@pytest.mark.parametrize( - "tx", [legacy_transaction, access_list_transaction, transaction_1559] -) -def test_transaction_encoding(tx: Transaction) -> None: - encoded = encode_transaction(tx) - assert decode_transaction(encoded) == tx diff --git a/tests/spurious_dragon/__init__.py b/tests/spurious_dragon/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/spurious_dragon/test_rlp.py b/tests/spurious_dragon/test_rlp.py deleted file mode 100644 index 8e660b0fe8..0000000000 --- a/tests/spurious_dragon/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.spurious_dragon.blocks import Block, Header, Log, Receipt -from ethereum.spurious_dragon.transactions import Transaction -from ethereum.spurious_dragon.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - post_state=hash1, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_spurious_dragon_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object diff --git a/tests/tangerine_whistle/__init__.py b/tests/tangerine_whistle/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/tangerine_whistle/test_rlp.py b/tests/tangerine_whistle/test_rlp.py deleted file mode 100644 index 697269caca..0000000000 --- a/tests/tangerine_whistle/test_rlp.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest -from ethereum_rlp import rlp -from ethereum_types.bytes import Bytes, Bytes0, Bytes8 -from ethereum_types.numeric import U256, Uint - -from ethereum.crypto.hash import keccak256 -from ethereum.tangerine_whistle.blocks import Block, Header, Log, Receipt -from ethereum.tangerine_whistle.transactions import Transaction -from ethereum.tangerine_whistle.utils.hexadecimal import hex_to_address -from ethereum.utils.hexadecimal import hex_to_bytes256 - -hash1 = keccak256(b"foo") -hash2 = keccak256(b"bar") -hash3 = keccak256(b"baz") -hash4 = keccak256(b"foobar") -hash5 = keccak256(b"quux") -hash6 = keccak256(b"foobarbaz") - -address1 = hex_to_address("0x00000000219ab540356cbb839cbe05303d7705fa") -address2 = hex_to_address("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") - -bloom = hex_to_bytes256( - "0x886480c00200620d84180d0470000c503081160044d05015808" - "0037401107060120040105281100100104500414203040a208003" - "4814200610da1208a638d16e440c024880800301e1004c2b02285" - "0602000084c3249a0c084569c90c2002001586241041e8004035a" - "4400a0100938001e041180083180b0340661372060401428c0200" - "87410402b9484028100049481900c08034864314688d001548c30" - "00828e542284180280006402a28a0264da00ac223004006209609" - "83206603200084040122a4739080501251542082020a4087c0002" - "81c08800898d0900024047380000127038098e090801080000429" - "0c84201661040200201c0004b8490ad588804" -) - -transaction1 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -transaction2 = Transaction( - U256(1), - Uint(2), - Uint(3), - Bytes0(), - U256(4), - Bytes(b"foo"), - U256(27), - U256(5), - U256(6), -) - -header = Header( - parent_hash=hash1, - ommers_hash=hash2, - coinbase=address1, - state_root=hash3, - transactions_root=hash4, - receipt_root=hash5, - bloom=bloom, - difficulty=Uint(1), - number=Uint(2), - gas_limit=Uint(3), - gas_used=Uint(4), - timestamp=U256(5), - extra_data=Bytes(b"foobar"), - mix_digest=hash6, - nonce=Bytes8(b"12345678"), -) - -block = Block( - header=header, - transactions=(transaction1, transaction2), - ommers=(header,), -) - -log1 = Log( - address=address1, - topics=(hash1, hash2), - data=Bytes(b"foobar"), -) - -log2 = Log( - address=address1, - topics=(hash1,), - data=Bytes(b"quux"), -) - -receipt = Receipt( - post_state=hash1, - cumulative_gas_used=Uint(1), - bloom=bloom, - logs=(log1, log2), -) - - -@pytest.mark.parametrize( - "rlp_object", - [transaction1, transaction2, header, block, log1, log2, receipt], -) -def test_tangerine_whistle_rlp(rlp_object: rlp.Extended) -> None: - encoded = rlp.encode(rlp_object) - assert rlp.decode_to(type(rlp_object), encoded) == rlp_object From 245265034951c4a16cab43715e87548ed7063c7b Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Fri, 1 Aug 2025 16:46:10 +0200 Subject: [PATCH 10/14] move other tests to json_infra --- tests/{ => json_infra}/test_ethash_general.py | 0 tests/{ => json_infra}/test_genesis.py | 0 tests/{ => json_infra}/test_optimized_state.py | 0 tests/{ => json_infra}/test_rlp.py | 2 +- tests/{ => json_infra}/test_tools.py | 0 tests/{ => json_infra}/test_trace.py | 0 tox.ini | 9 ++++----- vulture_whitelist.py | 4 ++++ 8 files changed, 9 insertions(+), 6 deletions(-) rename tests/{ => json_infra}/test_ethash_general.py (100%) rename tests/{ => json_infra}/test_genesis.py (100%) rename tests/{ => json_infra}/test_optimized_state.py (100%) rename tests/{ => json_infra}/test_rlp.py (98%) rename tests/{ => json_infra}/test_tools.py (100%) rename tests/{ => json_infra}/test_trace.py (100%) diff --git a/tests/test_ethash_general.py b/tests/json_infra/test_ethash_general.py similarity index 100% rename from tests/test_ethash_general.py rename to tests/json_infra/test_ethash_general.py diff --git a/tests/test_genesis.py b/tests/json_infra/test_genesis.py similarity index 100% rename from tests/test_genesis.py rename to tests/json_infra/test_genesis.py diff --git a/tests/test_optimized_state.py b/tests/json_infra/test_optimized_state.py similarity index 100% rename from tests/test_optimized_state.py rename to tests/json_infra/test_optimized_state.py diff --git a/tests/test_rlp.py b/tests/json_infra/test_rlp.py similarity index 98% rename from tests/test_rlp.py rename to tests/json_infra/test_rlp.py index 906adcca99..1dfb6f7be7 100644 --- a/tests/test_rlp.py +++ b/tests/json_infra/test_rlp.py @@ -8,7 +8,7 @@ from ethereum.frontier.fork_types import Bytes, Uint from ethereum.utils.hexadecimal import hex_to_bytes -from .json_infra import TEST_FIXTURES +from . import TEST_FIXTURES ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] diff --git a/tests/test_tools.py b/tests/json_infra/test_tools.py similarity index 100% rename from tests/test_tools.py rename to tests/json_infra/test_tools.py diff --git a/tests/test_trace.py b/tests/json_infra/test_trace.py similarity index 100% rename from tests/test_trace.py rename to tests/json_infra/test_trace.py diff --git a/tox.ini b/tox.ini index 9aef35fc94..bbb018aa24 100644 --- a/tox.ini +++ b/tox.ini @@ -29,9 +29,9 @@ commands = --cov-report "xml:{toxworkdir}/coverage.xml" \ --no-cov-on-fail \ --cov-branch \ - --ignore-glob='tests/fixtures/*' \ + --ignore-glob='tests/json_infra/fixtures/*' \ --basetemp="{temp_dir}/pytest" \ - tests + tests/json_infra [testenv:py3] extras = @@ -87,11 +87,10 @@ commands = pytest \ -m "not slow and not evm_tools" \ -n auto --maxprocesses 5 \ - --ignore-glob='tests/fixtures/*' \ - --ignore-glob='tests/test_t8n.py' \ + --ignore-glob='tests/json_infra/fixtures/*' \ --basetemp="{temp_dir}/pytest" \ --optimized \ - tests + tests/json_infra [testenv:doc] basepython = python3 diff --git a/vulture_whitelist.py b/vulture_whitelist.py index 70146cef1b..0367458374 100644 --- a/vulture_whitelist.py +++ b/vulture_whitelist.py @@ -1,6 +1,7 @@ from ethereum.cancun.blocks import Withdrawal from ethereum.ethash import * from ethereum.fork_criteria import Unscheduled +from ethereum.utils.hexadecimal import hex_to_bytes256 from ethereum_optimized.state_db import State from ethereum_spec_tools.docc import * from ethereum_spec_tools.evm_tools.daemon import _EvmToolHandler @@ -20,6 +21,9 @@ from ethereum_spec_tools.lint.lints.import_hygiene import ImportHygiene from ethereum.trace import EvmTracer +# src/ethereum/utils/hexadecimal.py +hex_to_bytes256 + # src/ethereum/cancun/blocks.py Withdrawal.validator_index From 7881f927c8258ba12c799960096e440cb1db0bbf Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Mon, 11 Aug 2025 18:17:29 +0530 Subject: [PATCH 11/14] post-review: use pytest mark --- pyproject.toml | 3 ++ tests/json_infra/conftest.py | 39 +++++++++++++--- tests/json_infra/test_blockchain_tests.py | 19 +------- tests/json_infra/test_state_tests.py | 19 +------- tests/json_infra/test_transaction.py | 17 +------ tests/json_infra/vm/__init__.py | 19 -------- .../vm/test_arithmetic_operations.py | 44 ++++++++++++------- .../vm/test_bitwise_logic_operations.py | 35 ++++++++++----- tests/json_infra/vm/test_block_operations.py | 17 ++++--- .../vm/test_control_flow_operations.py | 23 ++++++---- .../vm/test_environmental_operations.py | 32 +++++++++----- tests/json_infra/vm/test_keccak.py | 8 ++-- .../json_infra/vm/test_logging_operations.py | 17 ++++--- tests/json_infra/vm/test_memory_operations.py | 17 ++++--- tests/json_infra/vm/test_stack_operations.py | 29 +++++++----- .../json_infra/vm/test_storage_operations.py | 5 ++- tests/json_infra/vm/test_system_operations.py | 11 +++-- 17 files changed, 197 insertions(+), 157 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 20b5dda3c5..a188a57c84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -224,6 +224,9 @@ markers = [ "slow: marks tests as slow (deselect with '-m \"not slow\"')", "bigmem: marks tests as big memory (deselect with '-m \"not bigmem\"')", "evm_tools: marks tests as evm_tools (deselect with '-m \"not evm_tools\"')", + "json_blockchain_tests: marks tests as json_blockchain_tests (deselect with '-m \"not json_blockchain_tests\"')", + "json_state_tests: marks tests as json_state_tests (deselect with '-m \"not json_state_tests\"')", + "vm_test: marks tests as vm_test (deselect with '-m \"not vm_test\"')", ] [tool.coverage.run] diff --git a/tests/json_infra/conftest.py b/tests/json_infra/conftest.py index 27b89678f5..b770ed67c1 100644 --- a/tests/json_infra/conftest.py +++ b/tests/json_infra/conftest.py @@ -8,6 +8,7 @@ import requests_cache from _pytest.config import Config from _pytest.config.argparsing import Parser +from _pytest.nodes import Item from filelock import FileLock from git.exc import GitCommandError, InvalidGitRepositoryError from pytest import Session, StashKey @@ -17,9 +18,6 @@ from . import TEST_FIXTURES -# Global variable to store pytest config for access during test collection -pytest_config = None - try: from xdist import get_xdist_worker_id # type: ignore[import-untyped] except ImportError: @@ -63,9 +61,6 @@ def pytest_configure(config: Config) -> None: """ Configure the ethereum module and log levels to output evm trace. """ - global pytest_config - pytest_config = config - if config.getoption("optimized"): import ethereum_optimized @@ -81,6 +76,38 @@ def pytest_configure(config: Config) -> None: ethereum.trace.set_evm_trace(Eip3155Tracer()) +def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None: + desired_fork = config.getoption("fork", None) + if not desired_fork: + return + + selected = [] + deselected = [] + + for item in items: + forks_of_test = [m.args[0] for m in item.iter_markers(name="fork")] + if forks_of_test and desired_fork not in forks_of_test: + deselected.append(item) + # Check if the test has a vm test marker + elif any(item.iter_markers(name="vm_test")): + callspec = getattr(item, "callspec", None) + if not callspec or "fork" not in getattr(callspec, "params", {}): + # no fork param on this test. We keep the test + selected.append(item) + continue + fork_param = callspec.params["fork"] + if fork_param[0] == desired_fork: + selected.append(item) + else: + deselected.append(item) + else: + selected.append(item) + + if deselected: + config.hook.pytest_deselected(items=deselected) + items[:] = selected # keep only what matches + + class _FixturesDownloader: cache: Final[SQLiteCache] session: Final[CachedSession] diff --git a/tests/json_infra/test_blockchain_tests.py b/tests/json_infra/test_blockchain_tests.py index dad33eb5f6..661666af64 100644 --- a/tests/json_infra/test_blockchain_tests.py +++ b/tests/json_infra/test_blockchain_tests.py @@ -3,7 +3,6 @@ import pytest from . import FORKS -from .conftest import pytest_config from .helpers.load_blockchain_tests import ( Load, fetch_blockchain_tests, @@ -13,6 +12,7 @@ def _generate_test_function(fork_name: str) -> Callable: + @pytest.mark.fork(fork_name) @pytest.mark.json_blockchain_tests @pytest.mark.parametrize( "blockchain_test_case", @@ -29,22 +29,7 @@ def test_func(blockchain_test_case: Dict) -> None: return test_func -# Get the fork option from pytest config if available - -# Determine which forks to generate tests for -if pytest_config and pytest_config.getoption("fork", None): - # If --fork option is specified, only generate test for that fork - fork_option = pytest_config.getoption("fork") - if fork_option in FORKS: - forks_to_test = [fork_option] - else: - # If specified fork is not valid, generate no tests - forks_to_test = [] -else: - # If no --fork option, generate tests for all forks - forks_to_test = list(FORKS.keys()) - -for fork_name in forks_to_test: +for fork_name in FORKS.keys(): locals()[ f"test_blockchain_tests_{fork_name.lower()}" ] = _generate_test_function(fork_name) diff --git a/tests/json_infra/test_state_tests.py b/tests/json_infra/test_state_tests.py index 01d347b388..736030ad6a 100644 --- a/tests/json_infra/test_state_tests.py +++ b/tests/json_infra/test_state_tests.py @@ -3,11 +3,11 @@ import pytest from . import FORKS -from .conftest import pytest_config from .helpers.load_state_tests import fetch_state_tests, idfn, run_state_test def _generate_test_function(fork_name: str) -> Callable: + @pytest.mark.fork(fork_name) @pytest.mark.evm_tools @pytest.mark.json_state_tests @pytest.mark.parametrize( @@ -22,22 +22,7 @@ def test_func(state_test_case: Dict) -> None: return test_func -# Get the fork option from pytest config if available - -# Determine which forks to generate tests for -if pytest_config and pytest_config.getoption("fork", None): - # If --fork option is specified, only generate test for that fork - fork_option = pytest_config.getoption("fork") - if fork_option in FORKS: - forks_to_test = [fork_option] - else: - # If specified fork is not valid, generate no tests - forks_to_test = [] -else: - # If no --fork option, generate tests for all forks - forks_to_test = list(FORKS.keys()) - -for fork_name in forks_to_test: +for fork_name in FORKS.keys(): locals()[ f"test_state_tests_{fork_name.lower()}" ] = _generate_test_function(fork_name) diff --git a/tests/json_infra/test_transaction.py b/tests/json_infra/test_transaction.py index 8931b3ad14..edcc8a1634 100644 --- a/tests/json_infra/test_transaction.py +++ b/tests/json_infra/test_transaction.py @@ -11,7 +11,6 @@ from ethereum.utils.hexadecimal import hex_to_uint from . import FORKS, TEST_FIXTURES -from .conftest import pytest_config from .helpers.load_transaction_tests import NoTestsFound, load_test_transaction ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] @@ -20,6 +19,7 @@ def _generate_high_nonce_tests_function(fork_name: str) -> Callable: + @pytest.mark.fork(fork_name) @pytest.mark.parametrize( "test_file_high_nonce", [ @@ -74,20 +74,7 @@ def test_func(test_file_nonce: str) -> None: return test_func -# Determine which forks to generate tests for -if pytest_config and pytest_config.getoption("fork", None): - # If --fork option is specified, only generate test for that fork - fork_option = pytest_config.getoption("fork") - if fork_option in FORKS: - forks_to_test = [fork_option] - else: - # If specified fork is not valid, generate no tests - forks_to_test = [] -else: - # If no --fork option, generate tests for all forks - forks_to_test = list(FORKS.keys()) - -for fork_name in forks_to_test: +for fork_name in FORKS.keys(): locals()[ f"test_high_nonce_tests_{fork_name.lower()}" ] = _generate_high_nonce_tests_function(fork_name) diff --git a/tests/json_infra/vm/__init__.py b/tests/json_infra/vm/__init__.py index db1202e8cb..8b858fcfcc 100644 --- a/tests/json_infra/vm/__init__.py +++ b/tests/json_infra/vm/__init__.py @@ -1,5 +1,3 @@ -from ..conftest import pytest_config - FORKS = [ ("ConstantinopleFix", "constantinople"), ("Byzantium", "byzantium"), @@ -8,20 +6,3 @@ ("Homestead", "homestead"), ("Frontier", "frontier"), ] - - -# Determine which forks to generate tests for -if pytest_config and pytest_config.getoption("fork", None): - # If --fork option is specified, only generate test for that fork - fork_option = pytest_config.getoption("fork") - has_vm_tests = False - for fork in FORKS: - if fork[0] == fork_option: - has_vm_tests = True - forks_to_test = [fork] - break - if not has_vm_tests: - forks_to_test = [] -else: - # If no --fork option, generate tests for all forks - forks_to_test = FORKS diff --git a/tests/json_infra/vm/test_arithmetic_operations.py b/tests/json_infra/vm/test_arithmetic_operations.py index 008135d067..5c662fff89 100644 --- a/tests/json_infra/vm/test_arithmetic_operations.py +++ b/tests/json_infra/vm/test_arithmetic_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmArithmeticTest" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -28,7 +29,8 @@ def test_add(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -46,7 +48,8 @@ def test_sub(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -67,7 +70,8 @@ def test_mul(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -88,7 +92,8 @@ def test_div(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -118,7 +123,8 @@ def test_sdiv(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -137,7 +143,8 @@ def test_mod(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -161,7 +168,8 @@ def test_smod(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -185,7 +193,8 @@ def test_addmod(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -210,7 +219,8 @@ def test_mulmod(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -235,7 +245,8 @@ def test_exp(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize("exponent", ([2, 4, 8, 16, 32, 64, 128, 256])) def test_exp_power_2(fork: Tuple[str, str], exponent: int) -> None: VmTestLoader(*fork).run_test( @@ -245,7 +256,8 @@ def test_exp_power_2(fork: Tuple[str, str], exponent: int) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_exp_power_256(fork: Tuple[str, str]) -> None: for i in range(1, 34): VmTestLoader(*fork).run_test( @@ -262,7 +274,8 @@ def test_exp_power_256(fork: Tuple[str, str]) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -288,7 +301,8 @@ def test_signextend(fork: Tuple[str, str], test_file: str) -> None: ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_stop(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test( TEST_DIR, diff --git a/tests/json_infra/vm/test_bitwise_logic_operations.py b/tests/json_infra/vm/test_bitwise_logic_operations.py index a9df08c00e..a4aee4b63a 100644 --- a/tests/json_infra/vm/test_bitwise_logic_operations.py +++ b/tests/json_infra/vm/test_bitwise_logic_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -24,7 +25,8 @@ def test_lt(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -38,7 +40,8 @@ def test_gt(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -53,7 +56,8 @@ def test_slt(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -68,7 +72,8 @@ def test_sgt(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -81,7 +86,8 @@ def test_eq(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -94,7 +100,8 @@ def test_iszero(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -110,7 +117,8 @@ def test_and(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -126,7 +134,8 @@ def test_or(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -142,7 +151,8 @@ def test_xor(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -158,7 +168,8 @@ def test_not(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ diff --git a/tests/json_infra/vm/test_block_operations.py b/tests/json_infra/vm/test_block_operations.py index 9716e7816e..205097693b 100644 --- a/tests/json_infra/vm/test_block_operations.py +++ b/tests/json_infra/vm/test_block_operations.py @@ -4,7 +4,7 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = ( @@ -12,26 +12,31 @@ ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_coinbase(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "coinbase.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_timestamp(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "timestamp.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_number(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "number.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_difficulty(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "difficulty.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_gas_limit(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "gaslimit.json") diff --git a/tests/json_infra/vm/test_control_flow_operations.py b/tests/json_infra/vm/test_control_flow_operations.py index 963999815b..aafd0706fc 100644 --- a/tests/json_infra/vm/test_control_flow_operations.py +++ b/tests/json_infra/vm/test_control_flow_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file, check_gas_left", [ @@ -92,7 +93,8 @@ def test_jump( ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file, check_gas_left", [ @@ -137,7 +139,8 @@ def test_jumpi( ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -149,7 +152,8 @@ def test_pc(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", ["gas0.json", "gas1.json", "gasOverFlow.json"], @@ -158,7 +162,8 @@ def test_gas(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -172,12 +177,14 @@ def test_loop(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_when(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "when.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ diff --git a/tests/json_infra/vm/test_environmental_operations.py b/tests/json_infra/vm/test_environmental_operations.py index 6361391fca..96b694c63c 100644 --- a/tests/json_infra/vm/test_environmental_operations.py +++ b/tests/json_infra/vm/test_environmental_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -22,22 +23,26 @@ def test_address(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_origin(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "origin.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_caller(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "caller.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_callvalue(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "callvalue.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -53,7 +58,8 @@ def test_calldataload(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -66,7 +72,8 @@ def test_calldatasize(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -90,12 +97,14 @@ def test_calldatacopy(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_codesize(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "codesize.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -108,6 +117,7 @@ def test_codecopy(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_gasprice(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(TEST_DIR, "gasprice.json") diff --git a/tests/json_infra/vm/test_keccak.py b/tests/json_infra/vm/test_keccak.py index 771b1e0496..5ef7656ecf 100644 --- a/tests/json_infra/vm/test_keccak.py +++ b/tests/json_infra/vm/test_keccak.py @@ -4,7 +4,7 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = ( @@ -13,7 +13,8 @@ SPECIAL_TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -41,6 +42,7 @@ def test_sha3_succeeds(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_sha3_fails_out_of_gas_memory_expansion(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(SPECIAL_TEST_DIR, "sha3MemExp.json") diff --git a/tests/json_infra/vm/test_logging_operations.py b/tests/json_infra/vm/test_logging_operations.py index 3dda2e3cd1..dae579b0dc 100644 --- a/tests/json_infra/vm/test_logging_operations.py +++ b/tests/json_infra/vm/test_logging_operations.py @@ -4,7 +4,7 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = ( @@ -12,7 +12,8 @@ ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -29,7 +30,8 @@ def test_log0(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -48,7 +50,8 @@ def test_log1(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -67,7 +70,8 @@ def test_log2(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -87,7 +91,8 @@ def test_log3(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ diff --git a/tests/json_infra/vm/test_memory_operations.py b/tests/json_infra/vm/test_memory_operations.py index f3031c3154..317a95b9fd 100644 --- a/tests/json_infra/vm/test_memory_operations.py +++ b/tests/json_infra/vm/test_memory_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -23,7 +24,8 @@ def test_mstore(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -37,7 +39,8 @@ def test_mstore8(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -51,7 +54,8 @@ def test_mload(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -62,7 +66,8 @@ def test_mstore_mload(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ diff --git a/tests/json_infra/vm/test_stack_operations.py b/tests/json_infra/vm/test_stack_operations.py index 3c7a4d002e..285e8e3820 100644 --- a/tests/json_infra/vm/test_stack_operations.py +++ b/tests/json_infra/vm/test_stack_operations.py @@ -4,7 +4,7 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] PUSH_TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmPushDupSwapTest" @@ -13,7 +13,8 @@ DUP_TEST_DIR = SWAP_TEST_DIR = PUSH_TEST_DIR -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file, check_gas_left", [(f"push{i}.json", True) for i in range(1, 34)] @@ -30,7 +31,8 @@ def test_push_successfully( ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ @@ -44,38 +46,45 @@ def test_push_failed(fork: Tuple[str, str], test_file: str) -> None: VmTestLoader(*fork).run_test(PUSH_TEST_DIR, test_file) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_dup(fork: Tuple[str, str]) -> None: for i in range(1, 17): VmTestLoader(*fork).run_test(DUP_TEST_DIR, f"dup{i}.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_dup_error(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(DUP_TEST_DIR, "dup2error.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_swap(fork: Tuple[str, str]) -> None: for i in range(1, 17): VmTestLoader(*fork).run_test(SWAP_TEST_DIR, f"swap{i}.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_swap_jump(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(SWAP_TEST_DIR, "swapjump1.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_swap_error(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(SWAP_TEST_DIR, "swap2error.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_pop(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(POP_TEST_DIR, "pop0.json") -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_pop_fails_when_stack_underflowed(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test(POP_TEST_DIR, "pop1.json") diff --git a/tests/json_infra/vm/test_storage_operations.py b/tests/json_infra/vm/test_storage_operations.py index d2fc18f297..4457684525 100644 --- a/tests/json_infra/vm/test_storage_operations.py +++ b/tests/json_infra/vm/test_storage_operations.py @@ -4,13 +4,14 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmIOandFlowOperations" -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file, check_gas_left", [ diff --git a/tests/json_infra/vm/test_system_operations.py b/tests/json_infra/vm/test_system_operations.py index 2e0168c8c2..2cf56ca4f0 100644 --- a/tests/json_infra/vm/test_system_operations.py +++ b/tests/json_infra/vm/test_system_operations.py @@ -4,7 +4,7 @@ from .. import TEST_FIXTURES from ..helpers.load_vm_tests import VmTestLoader -from . import forks_to_test +from . import FORKS ETHEREUM_TESTS_PATH = TEST_FIXTURES["ethereum_tests"]["fixture_path"] TEST_DIR = f"{ETHEREUM_TESTS_PATH}/LegacyTests/Constantinople/VMTests/vmSystemOperations" @@ -13,7 +13,8 @@ ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file, check_gas_left", [ @@ -30,14 +31,16 @@ def test_seldestruct( ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) def test_seldestruct_vm_test(fork: Tuple[str, str]) -> None: VmTestLoader(*fork).run_test( VM_TEST_DIR, "suicide.json", check_gas_left=False ) -@pytest.mark.parametrize("fork", forks_to_test) +@pytest.mark.vm_test +@pytest.mark.parametrize("fork", FORKS) @pytest.mark.parametrize( "test_file", [ From f4da6415de9dc2c3c2d48a678e9317730fa0c9ae Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Tue, 12 Aug 2025 13:36:59 +0530 Subject: [PATCH 12/14] post review: rename to json_fork and eels_fork --- tests/json_infra/__init__.py | 18 ++++--- .../helpers/exceptional_test_patterns.py | 50 +++++++++---------- .../helpers/load_blockchain_tests.py | 18 +++---- tests/json_infra/helpers/load_state_tests.py | 18 +++---- tests/json_infra/test_blockchain_tests.py | 3 +- 5 files changed, 55 insertions(+), 52 deletions(-) diff --git a/tests/json_infra/__init__.py b/tests/json_infra/__init__.py index e6990c3c31..f69a0783e5 100644 --- a/tests/json_infra/__init__.py +++ b/tests/json_infra/__init__.py @@ -82,9 +82,11 @@ def _build_eest_test_paths(base_path: str) -> tuple: ) -def _create_fork_config(package: str, bc_dirs: list, state_dirs: list) -> dict: +def _create_fork_config( + eels_fork: str, bc_dirs: list, state_dirs: list +) -> dict: return { - "package": package, + "eels_fork": eels_fork, "blockchain_test_dirs": bc_dirs, "state_test_dirs": state_dirs, } @@ -112,8 +114,8 @@ def _create_fork_config(package: str, bc_dirs: list, state_dirs: list) -> dict: FORKS = { **{ - fork: _create_fork_config(package, *PRE_CONSTANTINOPLE_DIRS) - for fork, package in [ + json_fork: _create_fork_config(eels_fork, *PRE_CONSTANTINOPLE_DIRS) + for json_fork, eels_fork in [ ("Frontier", "frontier"), ("Homestead", "homestead"), ("EIP150", "tangerine_whistle"), @@ -123,8 +125,8 @@ def _create_fork_config(package: str, bc_dirs: list, state_dirs: list) -> dict: ] }, **{ - fork: _create_fork_config(package, *PRE_CANCUN_DIRS) - for fork, package in [ + json_fork: _create_fork_config(eels_fork, *PRE_CANCUN_DIRS) + for json_fork, eels_fork in [ ("Istanbul", "istanbul"), ("Berlin", "berlin"), ("London", "london"), @@ -133,8 +135,8 @@ def _create_fork_config(package: str, bc_dirs: list, state_dirs: list) -> dict: ] }, **{ - fork: _create_fork_config(package, *CURRENT_DIRS) - for fork, package in [ + json_fork: _create_fork_config(eels_fork, *CURRENT_DIRS) + for json_fork, eels_fork in [ ("Cancun", "cancun"), ("Prague", "prague"), ] diff --git a/tests/json_infra/helpers/exceptional_test_patterns.py b/tests/json_infra/helpers/exceptional_test_patterns.py index 43e3c4a7c4..9f2971bbdf 100644 --- a/tests/json_infra/helpers/exceptional_test_patterns.py +++ b/tests/json_infra/helpers/exceptional_test_patterns.py @@ -2,17 +2,17 @@ def get_exceptional_blockchain_test_patterns( - network: str, package: str + json_fork: str, eels_fork: str ) -> Tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]: """ - Returns patterns for slow, ignored, and big-memory tests for a given network and package. + Returns patterns for slow, ignored, and big-memory tests for a given json_fork and eels_fork. Parameters ---------- - network : str - The network name (e.g., "Frontier", "EIP150"). - package : str - The package name (e.g., "frontier", "tangerine_whistle"). + json_fork : str + The json_fork name (e.g., "Frontier", "EIP150"). + eels_fork : str + The eels_fork name (e.g., "frontier", "tangerine_whistle"). Returns ------- @@ -29,8 +29,8 @@ def get_exceptional_blockchain_test_patterns( "stTimeConsuming/static_Call50000_sha256.json", "vmPerformance/loopExp.json", "vmPerformance/loopMul.json", - f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{network}", - f"CALLBlake2f_d9g0v0_{network}", + f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{json_fork}", + f"CALLBlake2f_d9g0v0_{json_fork}", "CALLCODEBlake2f_d9g0v0", # GeneralStateTests "stRandom/randomStatetest177.json", @@ -40,14 +40,14 @@ def get_exceptional_blockchain_test_patterns( # InvalidBlockTest "bcUncleHeaderValidity/nonceWrong.json", "bcUncleHeaderValidity/wrongMixHash.json", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_non-degeneracy-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_bilinearity-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-inf_pair-\\]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{network}-blockchain_test-multi_inf_pair-\\]", - f"tests/{package}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_{network}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_non-degeneracy-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_bilinearity-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-inf_pair-\\]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-multi_inf_pair-\\]", + f"tests/{eels_fork}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_{json_fork}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", ) # These are tests that are considered to be incorrect, @@ -61,7 +61,7 @@ def get_exceptional_blockchain_test_patterns( # InvalidBlockTest "bcForgedTest", "bcMultiChainTest", - f"GasLimitHigherThan2p63m1_{network}", + f"GasLimitHigherThan2p63m1_{json_fork}", ) # All tests that recursively create a large number of frames (50000) @@ -81,7 +81,7 @@ def get_exceptional_blockchain_test_patterns( def get_exceptional_state_test_patterns( - network: str, package: str + json_fork: str, eels_fork: str ) -> tuple[str, ...]: slow_tests = ( "CALLBlake2f_MaxRounds", @@ -92,13 +92,13 @@ def get_exceptional_state_test_patterns( "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0", "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0", "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_non-degeneracy-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_bilinearity-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-inf_pair-]", - f"tests/{package}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{network}-state_test-multi_inf_pair-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_non-degeneracy-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_bilinearity-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-inf_pair-]", + f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-multi_inf_pair-]", ) return slow_tests diff --git a/tests/json_infra/helpers/load_blockchain_tests.py b/tests/json_infra/helpers/load_blockchain_tests.py index d83ef0dcf8..1406312b63 100644 --- a/tests/json_infra/helpers/load_blockchain_tests.py +++ b/tests/json_infra/helpers/load_blockchain_tests.py @@ -131,7 +131,7 @@ def add_block_to_chain( # Functions that fetch individual test cases -def load_json_fixture(test_file: str, network: str) -> Generator: +def load_json_fixture(test_file: str, json_fork: str) -> Generator: # Extract the pure basename of the file without the path to the file. # Ex: Extract "world.json" from "path/to/file/world.json" # Extract the filename without the extension. Ex: Extract "world" from @@ -145,7 +145,7 @@ def load_json_fixture(test_file: str, network: str) -> Generator: if "network" not in test: continue - if test["network"] == network: + if test["network"] == json_fork: found_keys.append(key) if not any(found_keys): @@ -155,22 +155,22 @@ def load_json_fixture(test_file: str, network: str) -> Generator: yield { "test_file": test_file, "test_key": _key, - "network": network, + "json_fork": json_fork, } def fetch_blockchain_tests( - network: str, + json_fork: str, ) -> Generator[Dict | ParameterSet, None, None]: # Filter FORKS based on fork_option parameter - package = cast(str, FORKS[network]["package"]) - test_dirs = cast(list[str], FORKS[network]["blockchain_test_dirs"]) + eels_fork = cast(str, FORKS[json_fork]["eels_fork"]) + test_dirs = cast(list[str], FORKS[json_fork]["blockchain_test_dirs"]) ( slow_list, ignore_list, big_memory_list, - ) = get_exceptional_blockchain_test_patterns(network, package) + ) = get_exceptional_blockchain_test_patterns(json_fork, eels_fork) all_slow = [re.compile(x) for x in slow_list] all_big_memory = [re.compile(x) for x in big_memory_list] all_ignore = [re.compile(x) for x in ignore_list] @@ -192,7 +192,7 @@ def fetch_blockchain_tests( # Start yielding individual test cases from the file list for _test_file in files_to_iterate: try: - for _test_case in load_json_fixture(_test_file, network): + for _test_case in load_json_fixture(_test_file, json_fork): # _identifier could identify files, folders through test_file # individual cases through test_key _identifier = ( @@ -202,7 +202,7 @@ def fetch_blockchain_tests( + _test_case["test_key"] + ")" ) - _test_case["package"] = package + _test_case["eels_fork"] = eels_fork if any(x.search(_identifier) for x in all_ignore): continue elif any(x.search(_identifier) for x in all_slow): diff --git a/tests/json_infra/helpers/load_state_tests.py b/tests/json_infra/helpers/load_state_tests.py index 640c7a20cf..fdd14af423 100644 --- a/tests/json_infra/helpers/load_state_tests.py +++ b/tests/json_infra/helpers/load_state_tests.py @@ -19,15 +19,15 @@ parser = create_parser() -def fetch_state_tests(network: str) -> Generator: +def fetch_state_tests(json_fork: str) -> Generator: """ Fetches all the general state tests from the given directory """ # Filter FORKS based on fork_option parameter - package = cast(str, FORKS[network]["package"]) - test_dirs = cast(list[str], FORKS[network]["state_test_dirs"]) + eels_fork = cast(str, FORKS[json_fork]["eels_fork"]) + test_dirs = cast(list[str], FORKS[json_fork]["state_test_dirs"]) - slow_tests = get_exceptional_state_test_patterns(network, package) + slow_tests = get_exceptional_state_test_patterns(json_fork, eels_fork) # Get all the files to iterate over from both eest_tests_path and ethereum_tests_path all_jsons = [] @@ -40,14 +40,14 @@ def fetch_state_tests(network: str) -> Generator: test_cases = read_test_cases(test_file_path) for test_case in test_cases: - if test_case.fork_name != network: + if test_case.fork_name != json_fork: continue test_case_dict = { "test_file": test_case.path, "test_key": test_case.key, "index": test_case.index, - "network": network, + "json_fork": json_fork, } if test_case.key in slow_tests: @@ -75,7 +75,7 @@ def run_state_test(test_case: Dict[str, str]) -> None: test_file = test_case["test_file"] test_key = test_case["test_key"] index = test_case["index"] - network = test_case["network"] + json_fork = test_case["json_fork"] with open(test_file) as f: tests = json.load(f) @@ -88,7 +88,7 @@ def run_state_test(test_case: Dict[str, str]) -> None: alloc = tests[test_key]["pre"] - post = tests[test_key]["post"][network][index] + post = tests[test_key]["post"][json_fork][index] post_hash = post["hash"] d = post["indexes"]["data"] g = post["indexes"]["gas"] @@ -130,7 +130,7 @@ def run_state_test(test_case: Dict[str, str]) -> None: "--input.txs", "stdin", "--state.fork", - f"{network}", + f"{json_fork}", "--state-test", ] t8n_options = parser.parse_args(t8n_args) diff --git a/tests/json_infra/test_blockchain_tests.py b/tests/json_infra/test_blockchain_tests.py index 661666af64..9d660a7030 100644 --- a/tests/json_infra/test_blockchain_tests.py +++ b/tests/json_infra/test_blockchain_tests.py @@ -21,7 +21,8 @@ def _generate_test_function(fork_name: str) -> Callable: ) def test_func(blockchain_test_case: Dict) -> None: load = Load( - blockchain_test_case["network"], blockchain_test_case["package"] + blockchain_test_case["json_fork"], + blockchain_test_case["eels_fork"], ) run_blockchain_st_test(blockchain_test_case, load=load) From 3dad5f719f2c62ec3917fb666235791dd1976fc7 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Tue, 12 Aug 2025 13:50:10 +0530 Subject: [PATCH 13/14] post review: other fixes --- tests/json_infra/__init__.py | 16 +++- .../helpers/exceptional_test_patterns.py | 93 ++++++++++++------- .../helpers/load_blockchain_tests.py | 30 +++--- tests/json_infra/helpers/load_state_tests.py | 12 +-- tests/json_infra/test_ethash.py | 26 +++--- tests/json_infra/test_trie.py | 50 +++++----- 6 files changed, 126 insertions(+), 101 deletions(-) diff --git a/tests/json_infra/__init__.py b/tests/json_infra/__init__.py index f69a0783e5..c7355e9d56 100644 --- a/tests/json_infra/__init__.py +++ b/tests/json_infra/__init__.py @@ -9,7 +9,7 @@ class _FixtureSource(TypedDict): commit_hash: NotRequired[str] -# Update the links and commit has in order to consume +# Update the links and commit hash in order to consume # newer/other tests TEST_FIXTURES: Dict[str, _FixtureSource] = { "evm_tools_testdata": { @@ -82,9 +82,19 @@ def _build_eest_test_paths(base_path: str) -> tuple: ) +ForkConfig = TypedDict( + "ForkConfig", + { + "eels_fork": str, + "blockchain_test_dirs": list[str], + "state_test_dirs": list[str], + }, +) + + def _create_fork_config( eels_fork: str, bc_dirs: list, state_dirs: list -) -> dict: +) -> ForkConfig: return { "eels_fork": eels_fork, "blockchain_test_dirs": bc_dirs, @@ -112,7 +122,7 @@ def _create_fork_config( [STATE_ETHEREUM_TESTS, EEST_OSAKA_STATE_TESTS], ) -FORKS = { +FORKS: Dict[str, ForkConfig] = { **{ json_fork: _create_fork_config(eels_fork, *PRE_CONSTANTINOPLE_DIRS) for json_fork, eels_fork in [ diff --git a/tests/json_infra/helpers/exceptional_test_patterns.py b/tests/json_infra/helpers/exceptional_test_patterns.py index 9f2971bbdf..7efd0d66f3 100644 --- a/tests/json_infra/helpers/exceptional_test_patterns.py +++ b/tests/json_infra/helpers/exceptional_test_patterns.py @@ -1,9 +1,23 @@ -from typing import Tuple +import re +from dataclasses import dataclass +from typing import Pattern, Tuple -def get_exceptional_blockchain_test_patterns( +@dataclass +class TestPatterns: + """ + Identify test patterns which are slow, are to be ignored + or are to be marked as consuming large memory at runtime. + """ + + slow: Tuple[Pattern[str], ...] + expected_fail: Tuple[Pattern[str], ...] + big_memory: Tuple[Pattern[str], ...] + + +def exceptional_blockchain_test_patterns( json_fork: str, eels_fork: str -) -> Tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]: +) -> TestPatterns: """ Returns patterns for slow, ignored, and big-memory tests for a given json_fork and eels_fork. @@ -16,21 +30,20 @@ def get_exceptional_blockchain_test_patterns( Returns ------- - slow_tests : - Patterns to match test files or test ids that should be marked as slow. - ignore_tests : - Patterns to match test files or test ids that should be ignored. - big_memory_tests : - Patterns to match test files or test ids that require large memory. + TestPatterns : + Patterns that are relevant to the current fork. """ + jf = re.escape(json_fork) + ef = re.escape(eels_fork) + slow_tests = ( # GeneralStateTests "stTimeConsuming/CALLBlake2f_MaxRounds.json", "stTimeConsuming/static_Call50000_sha256.json", "vmPerformance/loopExp.json", "vmPerformance/loopMul.json", - f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{json_fork}", - f"CALLBlake2f_d9g0v0_{json_fork}", + f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{jf}", + f"CALLBlake2f_d9g0v0_{jf}", "CALLCODEBlake2f_d9g0v0", # GeneralStateTests "stRandom/randomStatetest177.json", @@ -40,19 +53,19 @@ def get_exceptional_blockchain_test_patterns( # InvalidBlockTest "bcUncleHeaderValidity/nonceWrong.json", "bcUncleHeaderValidity/wrongMixHash.json", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_non-degeneracy-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_bilinearity-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(G1,-G2\\)=e\\(-G1,G2\\)-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(abG1,G2\\)-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-bls_pairing_e\\(aG1,bG2\\)=e\\(G1,abG2\\)-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-inf_pair-\\]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py\\:\\:test_valid\\[fork_{json_fork}-blockchain_test-multi_inf_pair-\\]", - f"tests/{eels_fork}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py\\:\\:test_block_hashes_history\\[fork_{json_fork}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_non-degeneracy-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_bilinearity-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-inf_pair-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-multi_inf_pair-\\]", + f"tests/{ef}/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_block_hashes_history\\[fork_{jf}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", ) # These are tests that are considered to be incorrect, # Please provide an explanation when adding entries - ignore_tests = ( + expected_fail = ( # ValidBlockTest "bcForkStressTest/ForkStressTest.json", "bcGasPricerTest/RPC_API_Test.json", @@ -61,7 +74,7 @@ def get_exceptional_blockchain_test_patterns( # InvalidBlockTest "bcForgedTest", "bcMultiChainTest", - f"GasLimitHigherThan2p63m1_{json_fork}", + f"GasLimitHigherThan2p63m1_{jf}", ) # All tests that recursively create a large number of frames (50000) @@ -77,28 +90,38 @@ def get_exceptional_blockchain_test_patterns( "stStaticCall/", ) - return slow_tests, ignore_tests, big_memory_tests + return TestPatterns( + slow=tuple(re.compile(p) for p in slow_tests), + expected_fail=tuple(re.compile(p) for p in expected_fail), + big_memory=tuple(re.compile(p) for p in big_memory_tests), + ) -def get_exceptional_state_test_patterns( +def exceptional_state_test_patterns( json_fork: str, eels_fork: str -) -> tuple[str, ...]: +) -> TestPatterns: + jf = re.escape(json_fork) + ef = re.escape(eels_fork) slow_tests = ( "CALLBlake2f_MaxRounds", "CALLCODEBlake2f", "CALLBlake2f", "loopExp", "loopMul", - "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_[Cancun-Prague]-d0g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_[Cancun-Prague]-d[0-14]g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_[Cancun-Prague]-d[0-2]g0v0", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_non-degeneracy-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_bilinearity-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-inf_pair-]", - f"tests/{eels_fork}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid[fork_{json_fork}-state_test-multi_inf_pair-]", + "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_\\[Cancun-Prague\\]-d0g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_\\[Cancun-Prague\\]-d[0-14]g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_\\[Cancun-Prague\\]-d[0-2]g0v0", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_non-degeneracy-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_bilinearity-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-inf_pair-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-multi_inf_pair-\\]", ) - return slow_tests + return TestPatterns( + slow=tuple(re.compile(p) for p in slow_tests), + expected_fail=tuple(), + big_memory=tuple(), + ) diff --git a/tests/json_infra/helpers/load_blockchain_tests.py b/tests/json_infra/helpers/load_blockchain_tests.py index 1406312b63..001575ee41 100644 --- a/tests/json_infra/helpers/load_blockchain_tests.py +++ b/tests/json_infra/helpers/load_blockchain_tests.py @@ -1,9 +1,8 @@ import importlib import json import os.path -import re from glob import glob -from typing import Any, Dict, Generator, cast +from typing import Any, Dict, Generator from unittest.mock import call, patch import pytest @@ -18,7 +17,7 @@ from ethereum_spec_tools.evm_tools.loaders.fixture_loader import Load from .. import FORKS -from .exceptional_test_patterns import get_exceptional_blockchain_test_patterns +from .exceptional_test_patterns import exceptional_blockchain_test_patterns class NoTestsFound(Exception): @@ -163,17 +162,10 @@ def fetch_blockchain_tests( json_fork: str, ) -> Generator[Dict | ParameterSet, None, None]: # Filter FORKS based on fork_option parameter - eels_fork = cast(str, FORKS[json_fork]["eels_fork"]) - test_dirs = cast(list[str], FORKS[json_fork]["blockchain_test_dirs"]) + eels_fork = FORKS[json_fork]["eels_fork"] + test_dirs = FORKS[json_fork]["blockchain_test_dirs"] - ( - slow_list, - ignore_list, - big_memory_list, - ) = get_exceptional_blockchain_test_patterns(json_fork, eels_fork) - all_slow = [re.compile(x) for x in slow_list] - all_big_memory = [re.compile(x) for x in big_memory_list] - all_ignore = [re.compile(x) for x in ignore_list] + test_patterns = exceptional_blockchain_test_patterns(json_fork, eels_fork) # Get all the files to iterate over from both eest_tests_path and ethereum_tests_path all_jsons = [] @@ -184,7 +176,7 @@ def fetch_blockchain_tests( files_to_iterate = [] for full_path in all_jsons: - if not any(x.search(full_path) for x in all_ignore): + if not any(x.search(full_path) for x in test_patterns.expected_fail): # If a file or folder is marked for ignore, # it can already be dropped at this stage files_to_iterate.append(full_path) @@ -203,11 +195,15 @@ def fetch_blockchain_tests( + ")" ) _test_case["eels_fork"] = eels_fork - if any(x.search(_identifier) for x in all_ignore): + if any( + x.search(_identifier) for x in test_patterns.expected_fail + ): continue - elif any(x.search(_identifier) for x in all_slow): + elif any(x.search(_identifier) for x in test_patterns.slow): yield pytest.param(_test_case, marks=pytest.mark.slow) - elif any(x.search(_identifier) for x in all_big_memory): + elif any( + x.search(_identifier) for x in test_patterns.big_memory + ): yield pytest.param(_test_case, marks=pytest.mark.bigmem) else: yield _test_case diff --git a/tests/json_infra/helpers/load_state_tests.py b/tests/json_infra/helpers/load_state_tests.py index fdd14af423..0ca5d0450a 100644 --- a/tests/json_infra/helpers/load_state_tests.py +++ b/tests/json_infra/helpers/load_state_tests.py @@ -3,7 +3,7 @@ import sys from glob import glob from io import StringIO -from typing import Dict, Generator, cast +from typing import Dict, Generator import pytest @@ -14,7 +14,7 @@ from ethereum_spec_tools.evm_tools.t8n import T8N from .. import FORKS -from .exceptional_test_patterns import get_exceptional_state_test_patterns +from .exceptional_test_patterns import exceptional_state_test_patterns parser = create_parser() @@ -24,10 +24,10 @@ def fetch_state_tests(json_fork: str) -> Generator: Fetches all the general state tests from the given directory """ # Filter FORKS based on fork_option parameter - eels_fork = cast(str, FORKS[json_fork]["eels_fork"]) - test_dirs = cast(list[str], FORKS[json_fork]["state_test_dirs"]) + eels_fork = FORKS[json_fork]["eels_fork"] + test_dirs = FORKS[json_fork]["state_test_dirs"] - slow_tests = get_exceptional_state_test_patterns(json_fork, eels_fork) + test_patterns = exceptional_state_test_patterns(json_fork, eels_fork) # Get all the files to iterate over from both eest_tests_path and ethereum_tests_path all_jsons = [] @@ -50,7 +50,7 @@ def fetch_state_tests(json_fork: str) -> Generator: "json_fork": json_fork, } - if test_case.key in slow_tests: + if any(x.search(test_case.key) for x in test_patterns.slow): yield pytest.param(test_case_dict, marks=pytest.mark.slow) else: yield test_case_dict diff --git a/tests/json_infra/test_ethash.py b/tests/json_infra/test_ethash.py index df2739897e..d7b5ba02bb 100644 --- a/tests/json_infra/test_ethash.py +++ b/tests/json_infra/test_ethash.py @@ -39,12 +39,12 @@ ] -@pytest.mark.parametrize("network", POW_FORKS) -def test_ethtest_fixtures(network: str) -> None: - package = FORKS[network]["package"] - fork_module = importlib.import_module(f"ethereum.{package}.fork") +@pytest.mark.parametrize("json_fork", POW_FORKS) +def test_ethtest_fixtures(json_fork: str) -> None: + eels_fork = FORKS[json_fork]["eels_fork"] + fork_module = importlib.import_module(f"ethereum.{eels_fork}.fork") - ethereum_tests = load_pow_test_fixtures(network) + ethereum_tests = load_pow_test_fixtures(json_fork) for test in ethereum_tests: header = test["header"] assert header.nonce == test["nonce"] @@ -71,9 +71,9 @@ def test_ethtest_fixtures(network: str) -> None: assert result == test["result"] -def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]: - package = FORKS[network]["package"] - Header = importlib.import_module(f"ethereum.{package}.blocks").Header +def load_pow_test_fixtures(json_fork: str) -> List[Dict[str, Any]]: + eels_fork = FORKS[json_fork]["eels_fork"] + Header = importlib.import_module(f"ethereum.{eels_fork}.blocks").Header with open( f"{ETHEREUM_TESTS_PATH}/PoWTests/ethash_tests.json" @@ -97,7 +97,7 @@ def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]: @pytest.mark.slow -@pytest.mark.parametrize("network", POW_FORKS) +@pytest.mark.parametrize("json_fork", POW_FORKS) @pytest.mark.parametrize( "block_file_name", [ @@ -107,17 +107,17 @@ def load_pow_test_fixtures(network: str) -> List[Dict[str, Any]]: ], ) def test_pow_validation_block_headers( - network: str, block_file_name: str + json_fork: str, block_file_name: str ) -> None: - package = cast(str, FORKS[network]["package"]) - fork_module = importlib.import_module(f"ethereum.{package}.fork") + eels_fork = FORKS[json_fork]["eels_fork"] + fork_module = importlib.import_module(f"ethereum.{eels_fork}.fork") block_str_data = cast( bytes, pkgutil.get_data("ethereum", f"assets/blocks/{block_file_name}") ).decode() block_json_data = json.loads(block_str_data) - load = Load(network, package) + load = Load(json_fork, eels_fork) header = load.json_to_header(block_json_data) fork_module.validate_proof_of_work(header) diff --git a/tests/json_infra/test_trie.py b/tests/json_infra/test_trie.py index 4b262a4d7b..5929c2ed8a 100644 --- a/tests/json_infra/test_trie.py +++ b/tests/json_infra/test_trie.py @@ -1,15 +1,11 @@ import importlib import json -from typing import Any +from typing import Any, Optional import pytest from ethereum_types.bytes import Bytes -from ethereum.utils.hexadecimal import ( - has_hex_prefix, - hex_to_bytes, - remove_hex_prefix, -) +from ethereum.utils.hexadecimal import has_hex_prefix, hex_to_bytes from . import FORKS, TEST_FIXTURES @@ -18,7 +14,7 @@ forks = FORKS.keys() -def to_bytes(data: str) -> Bytes: +def to_bytes(data: Optional[str]) -> Bytes: if data is None: return b"" if has_hex_prefix(data): @@ -31,80 +27,80 @@ def to_bytes(data: str) -> Bytes: def test_trie_secure_hex(fork: str) -> None: tests = load_tests("hex_encoded_securetrie_test.json") - package = FORKS[fork]["package"] - trie_module = importlib.import_module(f"ethereum.{package}.trie") + eels_fork = FORKS[fork]["eels_fork"] + trie_module = importlib.import_module(f"ethereum.{eels_fork}.trie") for name, test in tests.items(): st = trie_module.Trie(secured=True, default=b"") for k, v in test.get("in").items(): trie_module.trie_set(st, to_bytes(k), to_bytes(v)) result = trie_module.root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" + expected = hex_to_bytes(test.get("root")) + assert result == expected, f"test {name} failed" @pytest.mark.parametrize("fork", forks) def test_trie_secure(fork: str) -> None: tests = load_tests("trietest_secureTrie.json") - package = FORKS[fork]["package"] - trie_module = importlib.import_module(f"ethereum.{package}.trie") + eels_fork = FORKS[fork]["eels_fork"] + trie_module = importlib.import_module(f"ethereum.{eels_fork}.trie") for name, test in tests.items(): st = trie_module.Trie(secured=True, default=b"") for t in test.get("in"): trie_module.trie_set(st, to_bytes(t[0]), to_bytes(t[1])) result = trie_module.root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" + expected = hex_to_bytes(test.get("root")) + assert result == expected, f"test {name} failed" @pytest.mark.parametrize("fork", forks) def test_trie_secure_any_order(fork: str) -> None: tests = load_tests("trieanyorder_secureTrie.json") - package = FORKS[fork]["package"] - trie_module = importlib.import_module(f"ethereum.{package}.trie") + eels_fork = FORKS[fork]["eels_fork"] + trie_module = importlib.import_module(f"ethereum.{eels_fork}.trie") for name, test in tests.items(): st = trie_module.Trie(secured=True, default=b"") for k, v in test.get("in").items(): trie_module.trie_set(st, to_bytes(k), to_bytes(v)) result = trie_module.root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" + expected = hex_to_bytes(test.get("root")) + assert result == expected, f"test {name} failed" @pytest.mark.parametrize("fork", forks) def test_trie(fork: str) -> None: tests = load_tests("trietest.json") - package = FORKS[fork]["package"] - trie_module = importlib.import_module(f"ethereum.{package}.trie") + eels_fork = FORKS[fork]["eels_fork"] + trie_module = importlib.import_module(f"ethereum.{eels_fork}.trie") for name, test in tests.items(): st = trie_module.Trie(secured=False, default=b"") for t in test.get("in"): trie_module.trie_set(st, to_bytes(t[0]), to_bytes(t[1])) result = trie_module.root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" + expected = hex_to_bytes(test.get("root")) + assert result == expected, f"test {name} failed" @pytest.mark.parametrize("fork", forks) def test_trie_any_order(fork: str) -> None: tests = load_tests("trieanyorder.json") - package = FORKS[fork]["package"] - trie_module = importlib.import_module(f"ethereum.{package}.trie") + eels_fork = FORKS[fork]["eels_fork"] + trie_module = importlib.import_module(f"ethereum.{eels_fork}.trie") for name, test in tests.items(): st = trie_module.Trie(secured=False, default=b"") for k, v in test.get("in").items(): trie_module.trie_set(st, to_bytes(k), to_bytes(v)) result = trie_module.root(st) - expected = remove_hex_prefix(test.get("root")) - assert result.hex() == expected, f"test {name} failed" + expected = hex_to_bytes(test.get("root")) + assert result == expected, f"test {name} failed" def load_tests(path: str) -> Any: From 90de63ba2c6832b22bfb3254916367ebcc508b88 Mon Sep 17 00:00:00 2001 From: Guruprasad Kamath Date: Thu, 14 Aug 2025 13:31:19 +0530 Subject: [PATCH 14/14] update regexes patterns --- .../helpers/exceptional_test_patterns.py | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/json_infra/helpers/exceptional_test_patterns.py b/tests/json_infra/helpers/exceptional_test_patterns.py index 7efd0d66f3..9bac234691 100644 --- a/tests/json_infra/helpers/exceptional_test_patterns.py +++ b/tests/json_infra/helpers/exceptional_test_patterns.py @@ -38,37 +38,37 @@ def exceptional_blockchain_test_patterns( slow_tests = ( # GeneralStateTests - "stTimeConsuming/CALLBlake2f_MaxRounds.json", - "stTimeConsuming/static_Call50000_sha256.json", - "vmPerformance/loopExp.json", - "vmPerformance/loopMul.json", + "stTimeConsuming/CALLBlake2f_MaxRounds\\.json", + "stTimeConsuming/static_Call50000_sha256\\.json", + "vmPerformance/loopExp\\.json", + "vmPerformance/loopMul\\.json", f"QuadraticComplexitySolidity_CallDataCopy_d0g1v0_{jf}", f"CALLBlake2f_d9g0v0_{jf}", "CALLCODEBlake2f_d9g0v0", # GeneralStateTests - "stRandom/randomStatetest177.json", - "stCreateTest/CreateOOGafterMaxCodesize.json", + "stRandom/randomStatetest177\\.json", + "stCreateTest/CreateOOGafterMaxCodesize\\.json", # ValidBlockTest - "bcExploitTest/DelegateCallSpam.json", + "bcExploitTest/DelegateCallSpam\\.json", # InvalidBlockTest - "bcUncleHeaderValidity/nonceWrong.json", - "bcUncleHeaderValidity/wrongMixHash.json", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_non-degeneracy-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_bilinearity-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-inf_pair-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-blockchain_test-multi_inf_pair-\\]", - f"tests/{ef}/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_block_hashes_history\\[fork_{jf}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", + "bcUncleHeaderValidity/nonceWrong\\.json", + "bcUncleHeaderValidity/wrongMixHash\\.json", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_non-degeneracy-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_bilinearity-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-inf_pair-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-blockchain_test-multi_inf_pair-\\]", + f"tests/{ef}/eip2935_historical_block_hashes_from_state/test_block_hashes\\.py::test_block_hashes_history\\[fork_{jf}-blockchain_test-full_history_plus_one_check_blockhash_first\\]", ) # These are tests that are considered to be incorrect, # Please provide an explanation when adding entries expected_fail = ( # ValidBlockTest - "bcForkStressTest/ForkStressTest.json", - "bcGasPricerTest/RPC_API_Test.json", + "bcForkStressTest/ForkStressTest\\.json", + "bcGasPricerTest/RPC_API_Test\\.json", "bcMultiChainTest", "bcTotalDifficultyTest", # InvalidBlockTest @@ -108,16 +108,16 @@ def exceptional_state_test_patterns( "CALLBlake2f", "loopExp", "loopMul", - "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds.json::CALLBlake2f_MaxRounds-fork_\\[Cancun-Prague\\]-d0g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopExp.json::loopExp-fork_\\[Cancun-Prague\\]-d[0-14]g0v0", - "GeneralStateTests/VMTests/vmPerformance/loopMul.json::loopMul-fork_\\[Cancun-Prague\\]-d[0-2]g0v0", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_non-degeneracy-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_bilinearity-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-inf_pair-\\]", - f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid\\[fork_{jf}-state_test-multi_inf_pair-\\]", + "GeneralStateTests/stTimeConsuming/CALLBlake2f_MaxRounds\\.json::CALLBlake2f_MaxRounds-fork_\\[Cancun-Prague\\]-d0g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopExp\\.json::loopExp-fork_\\[Cancun-Prague\\]-d[0-14]g0v0", + "GeneralStateTests/VMTests/vmPerformance/loopMul\\.json::loopMul-fork_\\[Cancun-Prague\\]-d[0-2]g0v0", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-bls_pairing_non-degeneracy-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-bls_pairing_bilinearity-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(G1,-G2)=e(-G1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(abG1,G2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-bls_pairing_e(aG1,bG2)=e(G1,abG2)-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-inf_pair-\\]", + f"tests/{ef}/eip2537_bls_12_381_precompiles/test_bls12_pairing\\.py::test_valid\\[fork_{jf}-state_test-multi_inf_pair-\\]", ) return TestPatterns(