Skip to content

Commit 44b6a13

Browse files
authored
fix: general improvements [APE-647] (#34)
1 parent c27e848 commit 44b6a13

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pip install .[lint]
2828
2929
- name: Run Black
30-
run: black --check .
30+
run: black --check . --diff
3131

3232
- name: Run isort
3333
run: isort --check-only .

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: isort
1111

1212
- repo: https://github.com/psf/black
13-
rev: 22.10.0
13+
rev: 23.1.0
1414
hooks:
1515
- id: black
1616
name: black

evm_trace/enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
class CallType(Enum):
55
INTERNAL = "INTERNAL" # Non-opcode internal call
66
CREATE = "CREATE"
7+
CREATE2 = "CREATE2"
78
CALL = "CALL"
89
DELEGATECALL = "DELEGATECALL"
910
STATICCALL = "STATICCALL"
1011
CALLCODE = "CALLCODE"
1112
SELFDESTRUCT = "SELFDESTRUCT"
13+
14+
15+
CALL_OPCODES = (CallType.CALL, CallType.CALLCODE, CallType.DELEGATECALL, CallType.STATICCALL)

evm_trace/gas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def merge_reports(*reports: GasReport) -> GasReport:
3030
If given a single report, it only returns it.
3131
"""
3232
reports_ls = list(reports)
33-
if len(reports_ls) == 1:
33+
num_reports = len(reports_ls)
34+
if num_reports == 0:
35+
return {}
36+
37+
elif num_reports == 1:
3438
return reports_ls[0]
3539

3640
merged_report: GasReport = copy.deepcopy(reports_ls.pop(0))

evm_trace/geth.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import Field, validator
77

88
from evm_trace.base import CallTreeNode
9-
from evm_trace.enums import CallType
9+
from evm_trace.enums import CALL_OPCODES, CallType
1010

1111

1212
class TraceFrame(BaseModel):
@@ -142,19 +142,18 @@ def _create_node_from_call(
142142

143143
node = CallTreeNode(**node_kwargs)
144144
for frame in trace:
145-
if frame.op in ("CALL", "DELEGATECALL", "STATICCALL"):
146-
145+
if frame.op in [x.value for x in CALL_OPCODES]:
147146
# NOTE: Because of the different meanings in structLog style gas values,
148147
# gas is not set for nodes created this way.
149148
child_node_kwargs = {"address": frame.stack[-2][-20:], "depth": frame.depth}
150149

151-
if frame.op == "CALL":
150+
if frame.op == CallType.CALL.value:
152151
child_node_kwargs["call_type"] = CallType.CALL
153152
child_node_kwargs["value"] = int(frame.stack[-3].hex(), 16)
154153
child_node_kwargs["calldata"] = _extract_memory(
155154
offset=frame.stack[-4], size=frame.stack[-5], memory=frame.memory
156155
)
157-
elif frame.op == "DELEGATECALL":
156+
elif frame.op == CallType.DELEGATECALL.value:
158157
child_node_kwargs["call_type"] = CallType.DELEGATECALL
159158
child_node_kwargs["calldata"] = _extract_memory(
160159
offset=frame.stack[-3], size=frame.stack[-4], memory=frame.memory
@@ -172,7 +171,7 @@ def _create_node_from_call(
172171

173172
# TODO: Handle internal nodes using JUMP and JUMPI
174173

175-
elif frame.op == "SELFDESTRUCT":
174+
elif frame.op == CallType.SELFDESTRUCT.value:
176175
# TODO: Handle the internal value transfer
177176
node.selfdestruct = True
178177
break

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"eth-hash[pysha3]", # For eth-utils address checksumming
1111
],
1212
"lint": [
13-
"black>=22.10.0", # auto-formatter and linter
13+
"black>=23.1.0", # auto-formatter and linter
1414
"mypy>=0.991", # Static type analyzer
1515
"types-setuptools", # Needed due to mypy typeshed
1616
"flake8>=5.0.4", # Style linter

tests/test_gas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ def test_merge_single_report():
5151
actual = merge_reports(reports[0])
5252
expected = reports[0]
5353
assert actual == expected
54+
55+
56+
def test_merge_no_reports():
57+
assert merge_reports() == {}

0 commit comments

Comments
 (0)