Skip to content

Commit b28f2ef

Browse files
committed
cover all opcodes in different scenarios
1 parent 10860cc commit b28f2ef

File tree

11 files changed

+1432
-0
lines changed

11 files changed

+1432
-0
lines changed

converted-ethereum-tests.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,119 @@
1+
GeneralStateTests/stBadOpcode/opc0CDiffPlaces.json
2+
GeneralStateTests/stBadOpcode/opc0DDiffPlaces.json
3+
GeneralStateTests/stBadOpcode/opc0EDiffPlaces.json
4+
GeneralStateTests/stBadOpcode/opc0FDiffPlaces.json
5+
GeneralStateTests/stBadOpcode/opc1EDiffPlaces.json
6+
GeneralStateTests/stBadOpcode/opc1FDiffPlaces.json
7+
GeneralStateTests/stBadOpcode/opc2ADiffPlaces.json
8+
GeneralStateTests/stBadOpcode/opc2BDiffPlaces.json
9+
GeneralStateTests/stBadOpcode/opc2CDiffPlaces.json
10+
GeneralStateTests/stBadOpcode/opc2DDiffPlaces.json
11+
GeneralStateTests/stBadOpcode/opc2EDiffPlaces.json
12+
GeneralStateTests/stBadOpcode/opc2FDiffPlaces.json
13+
GeneralStateTests/stBadOpcode/opc4ADiffPlaces.json
14+
GeneralStateTests/stBadOpcode/opc4BDiffPlaces.json
15+
GeneralStateTests/stBadOpcode/opc4CDiffPlaces.json
16+
GeneralStateTests/stBadOpcode/opc4DDiffPlaces.json
17+
GeneralStateTests/stBadOpcode/opc4EDiffPlaces.json
18+
GeneralStateTests/stBadOpcode/opc4FDiffPlaces.json
19+
GeneralStateTests/stBadOpcode/opc5CDiffPlaces.json
20+
GeneralStateTests/stBadOpcode/opc5DDiffPlaces.json
21+
GeneralStateTests/stBadOpcode/opc5EDiffPlaces.json
22+
GeneralStateTests/stBadOpcode/opc5FDiffPlaces.json
23+
GeneralStateTests/stBadOpcode/opc21DiffPlaces.json
24+
GeneralStateTests/stBadOpcode/opc22DiffPlaces.json
25+
GeneralStateTests/stBadOpcode/opc23DiffPlaces.json
26+
GeneralStateTests/stBadOpcode/opc24DiffPlaces.json
27+
GeneralStateTests/stBadOpcode/opc25DiffPlaces.json
28+
GeneralStateTests/stBadOpcode/opc26DiffPlaces.json
29+
GeneralStateTests/stBadOpcode/opc27DiffPlaces.json
30+
GeneralStateTests/stBadOpcode/opc28DiffPlaces.json
31+
GeneralStateTests/stBadOpcode/opc29DiffPlaces.json
32+
GeneralStateTests/stBadOpcode/opc49DiffPlaces.json
33+
GeneralStateTests/stBadOpcode/opcA5DiffPlaces.json
34+
GeneralStateTests/stBadOpcode/opcA6DiffPlaces.json
35+
GeneralStateTests/stBadOpcode/opcA7DiffPlaces.json
36+
GeneralStateTests/stBadOpcode/opcA8DiffPlaces.json
37+
GeneralStateTests/stBadOpcode/opcA9DiffPlaces.json
38+
GeneralStateTests/stBadOpcode/opcAADiffPlaces.json
39+
GeneralStateTests/stBadOpcode/opcABDiffPlaces.json
40+
GeneralStateTests/stBadOpcode/opcACDiffPlaces.json
41+
GeneralStateTests/stBadOpcode/opcADDiffPlaces.json
42+
GeneralStateTests/stBadOpcode/opcAEDiffPlaces.json
43+
GeneralStateTests/stBadOpcode/opcAFDiffPlaces.json
44+
GeneralStateTests/stBadOpcode/opcB0DiffPlaces.json
45+
GeneralStateTests/stBadOpcode/opcB1DiffPlaces.json
46+
GeneralStateTests/stBadOpcode/opcB2DiffPlaces.json
47+
GeneralStateTests/stBadOpcode/opcB3DiffPlaces.json
48+
GeneralStateTests/stBadOpcode/opcB4DiffPlaces.json
49+
GeneralStateTests/stBadOpcode/opcB5DiffPlaces.json
50+
GeneralStateTests/stBadOpcode/opcB6DiffPlaces.json
51+
GeneralStateTests/stBadOpcode/opcB7DiffPlaces.json
52+
GeneralStateTests/stBadOpcode/opcB8DiffPlaces.json
53+
GeneralStateTests/stBadOpcode/opcB9DiffPlaces.json
54+
GeneralStateTests/stBadOpcode/opcBADiffPlaces.json
55+
GeneralStateTests/stBadOpcode/opcBBDiffPlaces.json
56+
GeneralStateTests/stBadOpcode/opcBCDiffPlaces.json
57+
GeneralStateTests/stBadOpcode/opcBDDiffPlaces.json
58+
GeneralStateTests/stBadOpcode/opcBEDiffPlaces.json
59+
GeneralStateTests/stBadOpcode/opcBFDiffPlaces.json
60+
GeneralStateTests/stBadOpcode/opcC0DiffPlaces.json
61+
GeneralStateTests/stBadOpcode/opcC1DiffPlaces.json
62+
GeneralStateTests/stBadOpcode/opcC2DiffPlaces.json
63+
GeneralStateTests/stBadOpcode/opcC3DiffPlaces.json
64+
GeneralStateTests/stBadOpcode/opcC4DiffPlaces.json
65+
GeneralStateTests/stBadOpcode/opcC5DiffPlaces.json
66+
GeneralStateTests/stBadOpcode/opcC6DiffPlaces.json
67+
GeneralStateTests/stBadOpcode/opcC7DiffPlaces.json
68+
GeneralStateTests/stBadOpcode/opcC8DiffPlaces.json
69+
GeneralStateTests/stBadOpcode/opcC9DiffPlaces.json
70+
GeneralStateTests/stBadOpcode/opcCADiffPlaces.json
71+
GeneralStateTests/stBadOpcode/opcCBDiffPlaces.json
72+
GeneralStateTests/stBadOpcode/opcCCDiffPlaces.json
73+
GeneralStateTests/stBadOpcode/opcCDDiffPlaces.json
74+
GeneralStateTests/stBadOpcode/opcCEDiffPlaces.json
75+
GeneralStateTests/stBadOpcode/opcCFDiffPlaces.json
76+
GeneralStateTests/stBadOpcode/opcD0DiffPlaces.json
77+
GeneralStateTests/stBadOpcode/opcD1DiffPlaces.json
78+
GeneralStateTests/stBadOpcode/opcD2DiffPlaces.json
79+
GeneralStateTests/stBadOpcode/opcD3DiffPlaces.json
80+
GeneralStateTests/stBadOpcode/opcD4DiffPlaces.json
81+
GeneralStateTests/stBadOpcode/opcD5DiffPlaces.json
82+
GeneralStateTests/stBadOpcode/opcD6DiffPlaces.json
83+
GeneralStateTests/stBadOpcode/opcD7DiffPlaces.json
84+
GeneralStateTests/stBadOpcode/opcD8DiffPlaces.json
85+
GeneralStateTests/stBadOpcode/opcD9DiffPlaces.json
86+
GeneralStateTests/stBadOpcode/opcDADiffPlaces.json
87+
GeneralStateTests/stBadOpcode/opcDBDiffPlaces.json
88+
GeneralStateTests/stBadOpcode/opcDCDiffPlaces.json
89+
GeneralStateTests/stBadOpcode/opcDDDiffPlaces.json
90+
GeneralStateTests/stBadOpcode/opcDEDiffPlaces.json
91+
GeneralStateTests/stBadOpcode/opcDFDiffPlaces.json
92+
GeneralStateTests/stBadOpcode/opcE0DiffPlaces.json
93+
GeneralStateTests/stBadOpcode/opcE1DiffPlaces.json
94+
GeneralStateTests/stBadOpcode/opcE2DiffPlaces.json
95+
GeneralStateTests/stBadOpcode/opcE3DiffPlaces.json
96+
GeneralStateTests/stBadOpcode/opcE4DiffPlaces.json
97+
GeneralStateTests/stBadOpcode/opcE5DiffPlaces.json
98+
GeneralStateTests/stBadOpcode/opcE6DiffPlaces.json
99+
GeneralStateTests/stBadOpcode/opcE7DiffPlaces.json
100+
GeneralStateTests/stBadOpcode/opcE8DiffPlaces.json
101+
GeneralStateTests/stBadOpcode/opcE9DiffPlaces.json
102+
GeneralStateTests/stBadOpcode/opcEADiffPlaces.json
103+
GeneralStateTests/stBadOpcode/opcEBDiffPlaces.json
104+
GeneralStateTests/stBadOpcode/opcECDiffPlaces.json
105+
GeneralStateTests/stBadOpcode/opcEDDiffPlaces.json
106+
GeneralStateTests/stBadOpcode/opcEEDiffPlaces.json
107+
GeneralStateTests/stBadOpcode/opcEFDiffPlaces.json
108+
GeneralStateTests/stBadOpcode/opcF6DiffPlaces.json
109+
GeneralStateTests/stBadOpcode/opcF7DiffPlaces.json
110+
GeneralStateTests/stBadOpcode/opcF8DiffPlaces.json
111+
GeneralStateTests/stBadOpcode/opcF9DiffPlaces.json
112+
GeneralStateTests/stBadOpcode/opcFBDiffPlaces.json
113+
GeneralStateTests/stBadOpcode/opcFCDiffPlaces.json
114+
GeneralStateTests/stBadOpcode/opcFEDiffPlaces.json
115+
116+
1117
([#748](https://github.com/ethereum/execution-spec-tests/pull/748))
2118
GeneralStateTests/stBadOpcode/badOpcodes.json
3119
GeneralStateTests/stBugs/evmBytecode.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Scenarios common import
3+
"""

tests/frontier/scenarios/common.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
Define Scenario class for test_scenarios test
3+
"""
4+
5+
from dataclasses import dataclass
6+
from enum import Enum
7+
8+
from ethereum_test_forks import Fork, Frontier
9+
from ethereum_test_tools import Address, Alloc, Bytecode
10+
11+
12+
class ScenarioExpectOpcode(Enum):
13+
"""Opcodes that are replaced to real values computed by the scenario"""
14+
15+
TX_ORIGIN = 1
16+
CODE_ADDRESS = 2
17+
CODE_CALLER = 3
18+
SELFBALANCE = 4
19+
BALANCE = 5
20+
CALL_VALUE = 6
21+
CALL_DATALOAD_0 = 7
22+
CALL_DATASIZE = 8
23+
GASPRICE = 9
24+
25+
26+
@dataclass
27+
class ProgramResult:
28+
"""
29+
Describe expected result of a program
30+
31+
Attributes:
32+
result (int | ScenarioExpectOpcode): The result of the program
33+
from_fork (Fork): The result is only valid from this fork (default: Frontier)
34+
"""
35+
36+
result: int | ScenarioExpectOpcode
37+
38+
"""The result is only valid from this fork"""
39+
from_fork: Fork = Frontier
40+
41+
42+
@dataclass
43+
class ScenarioEnvironment:
44+
"""
45+
Scenario evm environment
46+
Each scenario must define an environment on which program is executed
47+
This is so post state verification could check results of evm opcodes
48+
"""
49+
50+
code_address: Address # Op.ADDRESS, address scope for program
51+
code_caller: Address # Op.CALLER, caller of the program
52+
selfbalance: int # Op.SELFBALANCE, balance of the environment of the program
53+
ext_balance: int # Op.BALANCE(external) of fixed address deployed in state
54+
call_value: int # Op.CALLVALUE of call that is done to the program
55+
call_dataload_0: int # Op.CALLDATALOAD(0) expected result
56+
call_datasize: int # Op.CALLDATASIZE expected result
57+
58+
59+
@dataclass
60+
class ExecutionEnvironment:
61+
"""
62+
Scenario execution environment which is determined by test
63+
"""
64+
65+
fork: Fork
66+
gasprice: int
67+
origin: Address
68+
69+
70+
@dataclass
71+
class ScenarioGeneratorInput:
72+
"""
73+
Parameters for the scenario generator function
74+
75+
Attributes:
76+
fork (Fork): Fork for which we ask to generate scenarios
77+
pre (Alloc): Access to the state to be able to deploy contracts into pre
78+
operation (Bytecode): Evm bytecode program that will be tested
79+
external_address (Address): Static external address for ext opcodes
80+
"""
81+
82+
fork: Fork
83+
pre: Alloc
84+
operation_code: Bytecode
85+
external_address: Address
86+
external_balance: int
87+
88+
89+
@dataclass
90+
class Scenario:
91+
"""
92+
Describe test scenario that will be run in test for each program
93+
94+
Attributes:
95+
name (str): Scenario name for the test vector
96+
code (Address): Address that is an entry point for scenario code
97+
env (ScenarioEnvironment): Evm values for ScenarioExpectAddress map
98+
reverting (bool): If scenario reverts program execution, making result 0 (default: False)
99+
"""
100+
101+
name: str
102+
code: Address
103+
env: ScenarioEnvironment
104+
reverting: bool = False
105+
106+
107+
def translate_result(
108+
res: ProgramResult, env: ScenarioEnvironment, exec_env: ExecutionEnvironment
109+
) -> int:
110+
"""
111+
Translate expected program result code into concrete value,
112+
given the scenario evm environment and test execution environment
113+
"""
114+
if exec_env.fork < res.from_fork:
115+
return 0
116+
if isinstance(res.result, ScenarioExpectOpcode):
117+
if res.result == ScenarioExpectOpcode.TX_ORIGIN:
118+
return int(exec_env.origin.hex(), 16)
119+
if res.result == ScenarioExpectOpcode.CODE_ADDRESS:
120+
return int(env.code_address.hex(), 16)
121+
if res.result == ScenarioExpectOpcode.CODE_CALLER:
122+
return int(env.code_caller.hex(), 16)
123+
if res.result == ScenarioExpectOpcode.SELFBALANCE:
124+
return int(env.selfbalance)
125+
if res.result == ScenarioExpectOpcode.BALANCE:
126+
return int(env.ext_balance)
127+
if res.result == ScenarioExpectOpcode.CALL_VALUE:
128+
return int(env.call_value)
129+
if res.result == ScenarioExpectOpcode.CALL_DATALOAD_0:
130+
return env.call_dataload_0
131+
if res.result == ScenarioExpectOpcode.CALL_DATASIZE:
132+
return env.call_datasize
133+
if res.result == ScenarioExpectOpcode.GASPRICE:
134+
return exec_env.gasprice
135+
136+
return res.result
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Scenarios common import
3+
"""

0 commit comments

Comments
 (0)