diff --git a/tests/ast-parsing/compile/using-for-3-0.8.0.sol-0.8.15-compact.zip b/tests/ast-parsing/compile/using-for-3-0.8.0.sol-0.8.15-compact.zip new file mode 100644 index 000000000..e51c777db Binary files /dev/null and b/tests/ast-parsing/compile/using-for-3-0.8.0.sol-0.8.15-compact.zip differ diff --git a/tests/ast-parsing/compile/using-for-4-0.8.0.sol-0.8.15-compact.zip b/tests/ast-parsing/compile/using-for-4-0.8.0.sol-0.8.15-compact.zip new file mode 100644 index 000000000..12452d862 Binary files /dev/null and b/tests/ast-parsing/compile/using-for-4-0.8.0.sol-0.8.15-compact.zip differ diff --git a/tests/ast-parsing/expected/using-for-3-0.8.0.sol-0.8.15-compact.json b/tests/ast-parsing/expected/using-for-3-0.8.0.sol-0.8.15-compact.json new file mode 100644 index 000000000..a3b8987d4 --- /dev/null +++ b/tests/ast-parsing/expected/using-for-3-0.8.0.sol-0.8.15-compact.json @@ -0,0 +1,8 @@ +{ + "Lib": { + "a(Data,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n" + }, + "C": { + "libCall(uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + } +} \ No newline at end of file diff --git a/tests/ast-parsing/expected/using-for-4-0.8.0.sol-0.8.15-compact.json b/tests/ast-parsing/expected/using-for-4-0.8.0.sol-0.8.15-compact.json new file mode 100644 index 000000000..6ff9c9780 --- /dev/null +++ b/tests/ast-parsing/expected/using-for-4-0.8.0.sol-0.8.15-compact.json @@ -0,0 +1,8 @@ +{ + "Lib": { + "f(St,uint256)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n" + }, + "C": { + "libCall(uint16)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n" + } +} \ No newline at end of file diff --git a/tests/ast-parsing/using-for-3-0.8.0.sol b/tests/ast-parsing/using-for-3-0.8.0.sol new file mode 100644 index 000000000..1da4f3dc6 --- /dev/null +++ b/tests/ast-parsing/using-for-3-0.8.0.sol @@ -0,0 +1,27 @@ +using {a} for Data; + +struct Data { mapping(uint => bool) flags; } + +function a(Data storage self, uint value, uint value2) returns(bool){ + return false; +} + +library Lib { + function a(Data storage self, uint value) public + view + returns (bool) + { + return true; + } + +} + +contract C { + using Lib for Data; + Data knownValues; + + function libCall(uint value) public { + require(knownValues.a(value)); + } + +} \ No newline at end of file diff --git a/tests/ast-parsing/using-for-4-0.8.0.sol b/tests/ast-parsing/using-for-4-0.8.0.sol new file mode 100644 index 000000000..d50e107a4 --- /dev/null +++ b/tests/ast-parsing/using-for-4-0.8.0.sol @@ -0,0 +1,25 @@ +using {f} for St; +struct St { uint field; } + + +function f(St storage self, uint8 v) view returns(uint){ + return 0; +} + + +library Lib { + function f(St storage self, uint256 v) public view returns (uint) { + return 1; + } + +} + +contract C { + using Lib for St; + St st; + + function libCall(uint16 v) public view returns(uint){ + return st.f(v); // return 1 + } + +} \ No newline at end of file diff --git a/tests/test_ast_parsing.py b/tests/test_ast_parsing.py index 9d5662b91..92fd93a17 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -426,6 +426,8 @@ ALL_TESTS = [ Test("ternary-with-max.sol", ["0.8.15"]), Test("using-for-1-0.8.0.sol", ["0.8.15"]), Test("using-for-2-0.8.0.sol", ["0.8.15"]), + Test("using-for-3-0.8.0.sol", ["0.8.15"]), + Test("using-for-4-0.8.0.sol", ["0.8.15"]), Test("using-for-functions-list-1-0.8.0.sol", ["0.8.15"]), Test("using-for-functions-list-2-0.8.0.sol", ["0.8.15"]), Test("using-for-functions-list-3-0.8.0.sol", ["0.8.15"]), diff --git a/tests/test_features.py b/tests/test_features.py index c06ee96ce..1bf7ba4ff 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -7,6 +7,7 @@ from solc_select import solc_select from slither import Slither from slither.detectors import all_detectors from slither.detectors.abstract_detector import AbstractDetector +from slither.slithir.operations import LibraryCall def _run_all_detectors(slither: Slither): @@ -50,3 +51,23 @@ def test_funcion_id_rec_structure(): for compilation_unit in slither.compilation_units: for function in compilation_unit.functions: assert function.solidity_signature + + +def test_using_for_top_level_same_name() -> None: + slither = Slither("./tests/ast-parsing/using-for-3-0.8.0.sol") + contract_c = slither.get_contract_from_name("C")[0] + libCall = contract_c.get_function_from_full_name("libCall(uint256)") + for ir in libCall.all_slithir_operations(): + if isinstance(ir, LibraryCall) and ir.destination == "Lib" and ir.function_name == "a": + return + assert False + + +def test_using_for_top_level_implicit_conversion() -> None: + slither = Slither("./tests/ast-parsing/using-for-4-0.8.0.sol") + contract_c = slither.get_contract_from_name("C")[0] + libCall = contract_c.get_function_from_full_name("libCall(uint16)") + for ir in libCall.all_slithir_operations(): + if isinstance(ir, LibraryCall) and ir.destination == "Lib" and ir.function_name == "f": + return + assert False