Skip to content

Commit 722bb63

Browse files
winsvegamarioevz
andcommitted
feat(tests): Scenarios double call (#1606)
* introduce scenario double call combinations * convert diffPlaces test * Update tests/frontier/scenarios/scenarios/double_call_combinations.py --------- Co-authored-by: Mario Vega <marioevz@gmail.com>
1 parent 314f18d commit 722bb63

File tree

8 files changed

+87
-671
lines changed

8 files changed

+87
-671
lines changed

converted-ethereum-tests.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
([#1606](https://github.com/ethereum/execution-spec-tests/pull/1606))
2+
BlockchainTests/GeneralStateTests/stSelfBalance/diffPlaces.json
3+
14
([#1535](https://github.com/ethereum/execution-spec-tests/pull/1535))
25
GeneralStateTests/stEIP1559/intrinsicCancun.json
36
BlockchainTests/ValidBlocks/bcEIP1559/intrinsic.json

tests/frontier/scenarios/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ class Scenario:
168168
Describe test scenario that will be run in test for each program.
169169
170170
Attributes:
171+
category (str): Scenario category name
171172
name (str): Scenario name for the test vector
172173
code (Address): Address that is an entry point for scenario code
173174
env (ScenarioEnvironment): Evm values for ScenarioExpectAddress map
174175
reverting (bool): If scenario reverts program execution, making result 0 (default: False)
175176
176177
"""
177178

179+
category: str
178180
name: str
179181
code: Address
180182
env: ScenarioEnvironment

tests/frontier/scenarios/scenarios/call_combinations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def _generate_one_call_scenario(self, first_call: Opcode) -> Scenario:
116116
)
117117

118118
return Scenario(
119+
category="call_combinations",
119120
name=f"scenario_{first_call}",
120121
code=root_contract,
121122
env=ScenarioEnvironment(
@@ -263,6 +264,7 @@ def _compute_callvalue() -> int:
263264
)
264265

265266
return Scenario(
267+
category="call_combinations",
266268
name=f"scenario_{first_call}_{second_call}",
267269
code=root_contract,
268270
env=ScenarioEnvironment(

tests/frontier/scenarios/scenarios/create_combinations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _compute_selfbalance() -> int:
7979
)
8080
scenarios_list.append(
8181
Scenario(
82+
category="create_constructor_combinations",
8283
name=f"scenario_{create}_constructor",
8384
code=scenario_contract,
8485
env=env,
@@ -162,6 +163,7 @@ def _compute_selfbalance() -> int:
162163
)
163164
scenarios_list.append(
164165
Scenario(
166+
category="create_call_combinations",
165167
name=f"scenario_{create}_then_{call}",
166168
code=root_contract,
167169
env=env,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Define Scenario that will run a given program and then revert."""
2+
3+
from typing import List
4+
5+
from ethereum_test_tools import Conditional
6+
from ethereum_test_tools.vm.opcode import Macro, Opcode
7+
from ethereum_test_tools.vm.opcode import Macros as Om
8+
from ethereum_test_tools.vm.opcode import Opcodes as Op
9+
10+
from ..common import Scenario, ScenarioEnvironment, ScenarioGeneratorInput
11+
12+
13+
def scenarios_double_call_combinations(scenario_input: ScenarioGeneratorInput) -> List[Scenario]:
14+
"""
15+
Generate Scenarios for double call combinations.
16+
First call the operation normally.
17+
Then do a subcall that will [OOG,REVERT,RETURN].
18+
Second call the operation normally.
19+
Compare the results of first call with the second operation call.
20+
"""
21+
scenarios_list: List[Scenario] = []
22+
keep_gas = 300000
23+
revert_types: List[Opcode | Macro] = [Op.STOP, Om.OOG, Op.RETURN]
24+
if Op.REVERT in scenario_input.fork.valid_opcodes():
25+
revert_types.append(Op.REVERT)
26+
for revert in revert_types:
27+
operation_contract = scenario_input.pre.deploy_contract(code=scenario_input.operation_code)
28+
subcall_contract = scenario_input.pre.deploy_contract(
29+
code=Op.MSTORE(0, 0x1122334455667788991011121314151617181920212223242526272829303132)
30+
+ revert(offset=0, size=32)
31+
)
32+
scenario_contract = scenario_input.pre.deploy_contract(
33+
code=Op.CALL(gas=Op.SUB(Op.GAS, keep_gas), address=operation_contract, ret_size=32)
34+
+ Op.MSTORE(100, Op.MLOAD(0))
35+
+ Op.MSTORE(0, 0)
36+
+ Op.CALL(gas=50_000, address=subcall_contract)
37+
+ Op.CALL(gas=Op.SUB(Op.GAS, keep_gas), address=operation_contract, ret_size=32)
38+
+ Op.MSTORE(200, Op.MLOAD(0))
39+
+ Conditional(
40+
condition=Op.EQ(Op.MLOAD(100), Op.MLOAD(200)),
41+
if_true=Op.RETURN(100, 32),
42+
if_false=Op.MSTORE(0, 0) + Op.RETURN(0, 32),
43+
)
44+
)
45+
env: ScenarioEnvironment = ScenarioEnvironment(
46+
code_address=operation_contract,
47+
code_caller=scenario_contract,
48+
selfbalance=0,
49+
call_value=0,
50+
call_dataload_0=0,
51+
call_datasize=0,
52+
)
53+
scenarios_list.append(
54+
Scenario(
55+
category="double_call_combinations",
56+
name=f"scenario_call_then_{revert}_in_subcall_then_call",
57+
code=scenario_contract,
58+
env=env,
59+
halts=False,
60+
)
61+
)
62+
63+
return scenarios_list

tests/frontier/scenarios/scenarios/revert_combinations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def scenarios_revert_combinations(scenario_input: ScenarioGeneratorInput) -> Lis
3434
)
3535
scenarios_list.append(
3636
Scenario(
37+
category="revert_combinations",
3738
name=f"scenario_revert_by_{revert}",
3839
code=scenario_contract,
3940
env=env,

tests/frontier/scenarios/test_scenarios.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
)
6868
from .scenarios.call_combinations import ScenariosCallCombinations
6969
from .scenarios.create_combinations import scenarios_create_combinations
70+
from .scenarios.double_call_combinations import scenarios_double_call_combinations
7071
from .scenarios.revert_combinations import scenarios_revert_combinations
7172

7273
REFERENCE_SPEC_GIT_PATH = "N/A"
@@ -96,6 +97,10 @@ def scenarios(fork: Fork, pre: Alloc, test_program: ScenarioTestProgram) -> List
9697
for combination in revert_combinations:
9798
scenarios_list.append(combination)
9899

100+
double_call_combinations = scenarios_double_call_combinations(scenario_input)
101+
for combination in double_call_combinations:
102+
scenarios_list.append(combination)
103+
99104
return scenarios_list
100105

101106

@@ -144,7 +149,12 @@ def scenarios(fork: Fork, pre: Alloc, test_program: ScenarioTestProgram) -> List
144149
# scenario_name="" select all scenarios
145150
# Example: [ScenarioDebug(program_id=ProgramSstoreSload().id, scenario_name="scenario_CALL_CALL")], # noqa: E501
146151
"debug",
147-
[ScenarioDebug(program_id="", scenario_name="")],
152+
[
153+
ScenarioDebug(
154+
program_id="",
155+
scenario_name="",
156+
)
157+
],
148158
ids=["debug"],
149159
)
150160
@pytest.mark.parametrize(
@@ -188,6 +198,9 @@ def test_scenarios(
188198
result_slot = post_storage.store_next(1, hint=f"runner result {scenario.name}")
189199

190200
tx_max_gas = 7_000_000 if test_program.id == ProgramInvalidOpcode().id else 1_000_000
201+
if scenario.category == "double_call_combinations":
202+
tx_max_gas *= 2
203+
191204
tx_gasprice: int = 10
192205
exec_env = ExecutionEnvironment(
193206
fork=fork,

0 commit comments

Comments
 (0)