Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/testing/src/execution_testing/specs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def make_state_test_fixture(
env=env,
enable_post_processing=enable_post_processing,
)
gas_optimization = current_gas_limit
gas_optimization = minimum_gas_limit
else:
raise Exception("Impossible to compare.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
TestAddress,
TestPrivateKey,
)
from execution_testing.client_clis import TransitionTool
from execution_testing.client_clis import (
ExecutionSpecsTransitionTool,
TransitionTool,
)
from execution_testing.exceptions import TransactionException
from execution_testing.fixtures import (
BlockchainFixture,
Expand All @@ -30,6 +33,7 @@
TransactionReceipt,
)

from ..base import OpMode
from ..blockchain import BlockchainEngineFixture, BlockchainTest
from ..helpers import (
ExecutionExceptionMismatchError,
Expand Down Expand Up @@ -96,6 +100,47 @@ def state_test( # noqa: D103
)


def test_gas_optimization_records_converged_minimum(
state_test: StateTest,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Record the converged gas limit after the binary search finishes."""
minimum_equivalent_gas_limit = 7
state_test.operation_mode = OpMode.OPTIMIZE_GAS

def fake_verify_modified_gas_limit(
self: StateTest,
*,
current_gas_limit: int,
**_: Any,
) -> bool:
del self
return current_gas_limit >= minimum_equivalent_gas_limit

monkeypatch.setattr(
StateTest,
"verify_modified_gas_limit",
fake_verify_modified_gas_limit,
)

t8n = ExecutionSpecsTransitionTool(trace=True)
t8n.reset_traces()
evaluate = t8n.evaluate

def evaluate_with_traces(**kwargs: Any) -> Any:
output = evaluate(**kwargs)
traces = t8n.get_traces()
if output.result.traces is None and traces:
output.result.traces = traces[-1]
return output

monkeypatch.setattr(t8n, "evaluate", evaluate_with_traces)

fill_result = state_test.generate(t8n=t8n, fixture_format=StateFixture)

assert fill_result.gas_optimization == minimum_equivalent_gas_limit


# Storage value mismatch tests
@pytest.mark.parametrize(
"pre,post,expected_exception",
Expand Down
Loading