Skip to content

Commit

Permalink
fix: issue where could not set returndata in root kwargs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Nov 15, 2022
1 parent 714918c commit da997e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion evm_trace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _create_node_from_call(
# TODO: Handle "execution halted" vs. gas limit reached
break

elif frame.op in ("RETURN", "REVERT"):
elif frame.op in ("RETURN", "REVERT") and not node.returndata:
node.returndata = _extract_memory(
offset=frame.stack[-1], size=frame.stack[-2], memory=frame.memory
)
Expand Down
39 changes: 36 additions & 3 deletions tests/test_trace_frame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from hexbytes import HexBytes
from pydantic import ValidationError

from evm_trace.base import TraceFrame
from evm_trace import CallType
from evm_trace.base import TraceFrame, get_calltree_from_geth_trace


def test_trace_frame_validation_passes(trace_frame_data):
Expand All @@ -10,8 +12,19 @@ def test_trace_frame_validation_passes(trace_frame_data):


def test_trace_no_memory():
raw_frame = {"pc": 0, "op": "PUSH1", "gas": 4732305, "gasCost": 3, "depth": 1, "stack": []}
assert TraceFrame(**raw_frame)
pc = 0
op = "REVERT"
gas = 4732305
gas_cost = 3
depth = 1
stack = []
trace_frame = TraceFrame(pc=pc, op=op, gas=gas, gasCost=gas_cost, depth=depth, stack=stack)
assert trace_frame.pc == pc
assert trace_frame.op == op
assert trace_frame.gas == gas
assert trace_frame.gas_cost == gas_cost
assert trace_frame.depth == depth
assert trace_frame.stack == []


@pytest.mark.parametrize(
Expand All @@ -26,3 +39,23 @@ def test_trace_frame_validation_fails(test_data, trace_frame_data):
data = {**trace_frame_data, **test_data}
with pytest.raises(ValidationError):
TraceFrame(**data)


def test_get_calltree_from_geth_trace(trace_frame_data):
trace_frame_data["op"] = "RETURN"
returndata = HexBytes("0x0000000000000000000000004d4d2c55eae97a04acafb66011df29463b665732")
root_node_kwargs = {
"gas_cost": 123,
"gas_limit": 1234,
"address": "0x56764a0000000000000000000000000000000031",
"calldata": HexBytes("0x21325"),
"value": 34,
"call_type": CallType.CALL,
"failed": False,
"returndata": returndata,
}
frames = (TraceFrame(**d) for d in (trace_frame_data,))
actual = get_calltree_from_geth_trace(frames, **root_node_kwargs)

# Tests against a bug where we could not set the return data.
assert actual.returndata == returndata

0 comments on commit da997e0

Please sign in to comment.