Skip to content

Commit 3432a3e

Browse files
authored
Merge pull request #2668 from crytic/dev_update_entry_points_printer
Dev update entry points printer
2 parents e4e828b + d82ef12 commit 3432a3e

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

slither/printers/summary/entry_points.py

+17-21
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Module printing all the state-changing entry point functions of the contracts
33
"""
44

5+
from pathlib import Path
56
from slither.printers.abstract_printer import AbstractPrinter
67
from slither.core.declarations.function_contract import FunctionContract
78
from slither.utils.colors import Colors
89
from slither.utils.output import Output
910
from slither.utils.myprettytable import MyPrettyTable
11+
from slither.utils.tests_pattern import is_test_file
1012

1113

1214
class PrinterEntryPoints(AbstractPrinter):
@@ -27,15 +29,13 @@ def output(self, _filename) -> Output:
2729
for contract in sorted(
2830
(
2931
c
30-
for c in self.contracts
31-
if not c.is_interface
32+
for c in self.slither.contracts_derived
33+
if not c.is_test
34+
and not c.is_from_dependency()
35+
and not is_test_file(Path(c.source_mapping.filename.absolute))
36+
and not c.is_interface
3237
and not c.is_library
3338
and not c.is_abstract
34-
and "lib/" not in c.source_mapping.filename.absolute
35-
and "node_modules/" not in c.source_mapping.filename.absolute
36-
and not any(
37-
mock in c.source_mapping.filename.absolute.lower() for mock in ["mock", "mocks"]
38-
)
3939
),
4040
key=lambda x: x.name,
4141
):
@@ -48,8 +48,6 @@ def output(self, _filename) -> Output:
4848
and not f.is_constructor
4949
and not f.view
5050
and not f.pure
51-
and not f.contract_declarer.is_interface
52-
and not f.contract_declarer.is_library
5351
and not f.is_shadowed
5452
)
5553
]
@@ -65,29 +63,27 @@ def output(self, _filename) -> Output:
6563

6664
for f in sorted(
6765
entry_points,
68-
key=lambda x: (x.visibility != "external", x.visibility != "public", x.full_name),
66+
key=lambda x, contract=contract: (
67+
x.contract_declarer != contract,
68+
x.contract_declarer.name if x.contract_declarer != contract else "",
69+
x.source_mapping.start,
70+
),
6971
):
70-
modifier_list = [m.name for m in f.modifiers]
71-
if f.payable:
72-
modifier_list.append("payable")
73-
modifiers = ", ".join(modifier_list) if modifier_list else ""
74-
inherited = f"{f.contract_declarer.name}" if f.contract_declarer != contract else ""
75-
7672
name_parts = f.full_name.split("(", 1)
77-
function_name = (
78-
f"{Colors.BOLD}{Colors.RED}{name_parts[0]}{Colors.END}" f"({name_parts[1]}"
73+
inherited = f.contract_declarer.name if f.contract_declarer != contract else ""
74+
modifiers = ", ".join(
75+
[m.name for m in f.modifiers] + (["payable"] if f.payable else [])
7976
)
8077

8178
table.add_row(
8279
[
83-
function_name,
80+
f"{Colors.BOLD}{Colors.RED}{name_parts[0]}{Colors.END}({name_parts[1]}",
8481
f"{Colors.GREEN}{modifiers}{Colors.END}" if modifiers else "",
8582
f"{Colors.MAGENTA}{inherited}{Colors.END}" if inherited else "",
8683
]
8784
)
8885

89-
contract_info.append(str(table))
90-
all_contracts.append("\n".join(contract_info))
86+
all_contracts.append("\n".join(contract_info + [str(table)]))
9187

9288
info = "\n".join(all_contracts) if all_contracts else ""
9389
self.info(info)

0 commit comments

Comments
 (0)