File tree 2 files changed +16
-5
lines changed
slither/analyses/data_dependency
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -293,7 +293,7 @@ def get_all_dependencies_ssa(
293
293
return context .context [KEY_SSA ]
294
294
295
295
296
- def get_must_depends_on (variable : SUPPORTED_TYPES ) -> SUPPORTED_TYPES | None :
296
+ def get_must_depends_on (variable : SUPPORTED_TYPES ) -> List :
297
297
"""
298
298
Return must dependency of a variable if exist otherwise return None.
299
299
@@ -305,7 +305,8 @@ def get_must_depends_on(variable: SUPPORTED_TYPES) -> SUPPORTED_TYPES | None:
305
305
return []
306
306
return [list (must_dependencies )[0 ]]
307
307
308
- def compute_must_dependencies (v :SUPPORTED_TYPES ) -> Set [Variable ]:
308
+
309
+ def compute_must_dependencies (v : SUPPORTED_TYPES ) -> Set [Variable ]:
309
310
if isinstance (v , (SolidityVariableComposed , Constant )) or (
310
311
v .function .visibility in ["public" , "external" ] and v in v .function .parameters
311
312
):
@@ -359,6 +360,7 @@ def compute_must_dependencies(v:SUPPORTED_TYPES) -> Set[Variable]:
359
360
must_dependencies = must_dependencies .union (result )
360
361
return must_dependencies
361
362
363
+
362
364
# endregion
363
365
###################################################################################
364
366
###################################################################################
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
from slither import Slither
3
- from slither .analyses .data_dependency .data_dependency import (
4
- get_must_depends_on
3
+ from slither .analyses .data_dependency .data_dependency import get_must_depends_on
4
+ from slither .core .variables .variable import Variable
5
+ from slither .core .declarations import (
6
+ SolidityVariable ,
7
+ )
8
+ from typing import Union
9
+ from slither .slithir .variables import (
10
+ Constant ,
5
11
)
6
12
7
13
TEST_DATA_DIR = Path (__file__ ).resolve ().parent / "test_data"
14
+ SUPPORTED_TYPES = Union [Variable , SolidityVariable , Constant ]
15
+
8
16
9
17
def test_must_depend_on_returns (solc_binary_path ):
10
18
solc_path = solc_binary_path ("0.8.19" )
11
19
file = Path (TEST_DATA_DIR , "must_depend_on.sol" ).as_posix ()
12
20
slither_obj = Slither (file , solc = solc_path )
13
21
result = get_must_depends_on (slither_obj .contracts [1 ].functions [2 ].parameters [0 ])
14
- assert isinstance (result , list ) and len (result ) <= 1
22
+ assert isinstance (result , list )
23
+ assert len (result ) == 0 or (len (result ) == 1 and result [0 ] in SUPPORTED_TYPES )
You can’t perform that action at this time.
0 commit comments