pull/1378/head
Simone 2 years ago
parent 1c869df9e9
commit 2ee6d0a4c8
  1. BIN
      tests/ast-parsing/compile/using-for-3-0.8.0.sol-0.8.15-compact.zip
  2. BIN
      tests/ast-parsing/compile/using-for-4-0.8.0.sol-0.8.15-compact.zip
  3. 8
      tests/ast-parsing/expected/using-for-3-0.8.0.sol-0.8.15-compact.json
  4. 8
      tests/ast-parsing/expected/using-for-4-0.8.0.sol-0.8.15-compact.json
  5. 27
      tests/ast-parsing/using-for-3-0.8.0.sol
  6. 25
      tests/ast-parsing/using-for-4-0.8.0.sol
  7. 2
      tests/test_ast_parsing.py
  8. 21
      tests/test_features.py

@ -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"
}
}

@ -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"
}
}

@ -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));
}
}

@ -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
}
}

@ -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"]),

@ -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

Loading…
Cancel
Save