Skip to content

Commit 377a3aa

Browse files
authored
fix(test-client-clis): detect EELS-style OutOfGasError in GasExhaustionTraceComparator (ethereum#2879)
1 parent 2de6b9f commit 377a3aa

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

packages/testing/src/execution_testing/client_clis/tests/test_trace_comparators.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,3 +1420,72 @@ def test_multi_transaction_via_compare_traces(
14201420
result = comparator.compare_traces(baseline, current)
14211421
assert result.equivalent is False
14221422
assert all(d.transaction_index == 1 for d in result.differences)
1423+
1424+
@pytest.mark.parametrize(
1425+
"error",
1426+
["out of gas", "Out Of Gas", "OutOfGasError"],
1427+
)
1428+
def test_oog_detected_for_each_convention(
1429+
self,
1430+
comparator: GasExhaustionTraceComparator,
1431+
error: str,
1432+
) -> None:
1433+
"""OOG detection covers both geth-style and EELS-style errors."""
1434+
baseline = _make_transaction_traces(
1435+
[_make_trace_line(), _make_trace_line(error=error)]
1436+
)
1437+
current = _make_transaction_traces(
1438+
[_make_trace_line(), _make_trace_line()]
1439+
)
1440+
result = comparator.compare_transaction_traces(baseline, current, 0)
1441+
assert result.equivalent is False
1442+
assert len(result.differences) == 1
1443+
assert result.differences[0].trace_line_index == 1
1444+
1445+
def test_mixed_geth_and_eels_oog_is_equivalent(
1446+
self, comparator: GasExhaustionTraceComparator
1447+
) -> None:
1448+
"""
1449+
Baseline (geth-style "out of gas") and current (EELS-style
1450+
"OutOfGasError") describe the same OOG event and are equivalent.
1451+
"""
1452+
baseline = _make_transaction_traces(
1453+
[_make_trace_line(), _make_trace_line(error="out of gas")]
1454+
)
1455+
current = _make_transaction_traces(
1456+
[_make_trace_line(), _make_trace_line(error="OutOfGasError")]
1457+
)
1458+
result = comparator.compare_transaction_traces(baseline, current, 0)
1459+
assert result.equivalent is True
1460+
1461+
def test_all_eels_oog_at_same_line_is_equivalent(
1462+
self, comparator: GasExhaustionTraceComparator
1463+
) -> None:
1464+
"""Two EELS-style traces with OOG at the same line are equivalent."""
1465+
oog_line = _make_trace_line(error="OutOfGasError")
1466+
baseline = _make_transaction_traces([_make_trace_line(), oog_line])
1467+
current = _make_transaction_traces([_make_trace_line(), oog_line])
1468+
result = comparator.compare_transaction_traces(baseline, current, 0)
1469+
assert result.equivalent is True
1470+
1471+
def test_all_eels_oog_at_different_lines(
1472+
self, comparator: GasExhaustionTraceComparator
1473+
) -> None:
1474+
"""Two EELS-style traces with OOG at different lines differ."""
1475+
baseline = _make_transaction_traces(
1476+
[
1477+
_make_trace_line(),
1478+
_make_trace_line(error="OutOfGasError"),
1479+
_make_trace_line(),
1480+
]
1481+
)
1482+
current = _make_transaction_traces(
1483+
[
1484+
_make_trace_line(),
1485+
_make_trace_line(),
1486+
_make_trace_line(error="OutOfGasError"),
1487+
]
1488+
)
1489+
result = comparator.compare_transaction_traces(baseline, current, 0)
1490+
assert result.equivalent is False
1491+
assert len(result.differences) == 2

packages/testing/src/execution_testing/client_clis/trace_comparators.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ def _is_out_of_gas_error(error: str | None) -> bool:
216216
"""Return True if the error string indicates an out-of-gas condition."""
217217
if error is None:
218218
return False
219-
return "out of gas" in error.lower()
219+
s = error.lower()
220+
# Two trace conventions coexist: geth-style natural-language messages
221+
# ("out of gas", "contract creation code storage out of gas") and the
222+
# EELS EIP-3155 emitter, which writes the Python exception class name
223+
# ("OutOfGasError"). The class name has no spaces, so the substring
224+
# match alone misses it — match it explicitly.
225+
return "out of gas" in s or s == "outofgaserror"
220226

221227

222228
def _find_gas_exhaustion_points(

0 commit comments

Comments
 (0)