2
2
Module printing all the state-changing entry point functions of the contracts
3
3
"""
4
4
5
+ from pathlib import Path
5
6
from slither .printers .abstract_printer import AbstractPrinter
6
7
from slither .core .declarations .function_contract import FunctionContract
7
8
from slither .utils .colors import Colors
8
9
from slither .utils .output import Output
9
10
from slither .utils .myprettytable import MyPrettyTable
11
+ from slither .utils .tests_pattern import is_test_file
10
12
11
13
12
14
class PrinterEntryPoints (AbstractPrinter ):
@@ -27,15 +29,13 @@ def output(self, _filename) -> Output:
27
29
for contract in sorted (
28
30
(
29
31
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
32
37
and not c .is_library
33
38
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
- )
39
39
),
40
40
key = lambda x : x .name ,
41
41
):
@@ -48,8 +48,6 @@ def output(self, _filename) -> Output:
48
48
and not f .is_constructor
49
49
and not f .view
50
50
and not f .pure
51
- and not f .contract_declarer .is_interface
52
- and not f .contract_declarer .is_library
53
51
and not f .is_shadowed
54
52
)
55
53
]
@@ -65,29 +63,27 @@ def output(self, _filename) -> Output:
65
63
66
64
for f in sorted (
67
65
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
+ ),
69
71
):
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
-
76
72
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 [])
79
76
)
80
77
81
78
table .add_row (
82
79
[
83
- function_name ,
80
+ f" { Colors . BOLD } { Colors . RED } { name_parts [ 0 ] } { Colors . END } ( { name_parts [ 1 ] } " ,
84
81
f"{ Colors .GREEN } { modifiers } { Colors .END } " if modifiers else "" ,
85
82
f"{ Colors .MAGENTA } { inherited } { Colors .END } " if inherited else "" ,
86
83
]
87
84
)
88
85
89
- contract_info .append (str (table ))
90
- all_contracts .append ("\n " .join (contract_info ))
86
+ all_contracts .append ("\n " .join (contract_info + [str (table )]))
91
87
92
88
info = "\n " .join (all_contracts ) if all_contracts else ""
93
89
self .info (info )
0 commit comments