-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: address issue #2107 add contract id in inheritance graph printer
- Loading branch information
Showing
8 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
contract A { | ||
function a_main() public pure {} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import "./A.sol"; | ||
|
||
contract B is A { | ||
function b_main() public pure { | ||
a_main(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "./A.sol"; | ||
|
||
contract B is A { | ||
function b2_main() public pure { | ||
a_main(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "./A.sol"; | ||
|
||
contract C is A { | ||
function c_main() public pure { | ||
a_main(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
from collections import Counter | ||
from pathlib import Path | ||
|
||
from crytic_compile import CryticCompile | ||
from crytic_compile.platform.solc_standard_json import SolcStandardJson | ||
|
||
from slither import Slither | ||
from slither.printers.inheritance.inheritance_graph import PrinterInheritanceGraph | ||
|
||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
|
||
|
||
def test_inheritance_printer(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.0") | ||
standard_json = SolcStandardJson() | ||
standard_json.add_source_file( | ||
Path(TEST_DATA_DIR, "test_contract_names", "A.sol").as_posix() | ||
) | ||
standard_json.add_source_file( | ||
Path(TEST_DATA_DIR, "test_contract_names", "B.sol").as_posix() | ||
) | ||
standard_json.add_source_file( | ||
Path(TEST_DATA_DIR, "test_contract_names", "B2.sol").as_posix() | ||
) | ||
standard_json.add_source_file( | ||
Path(TEST_DATA_DIR, "test_contract_names", "C.sol").as_posix() | ||
) | ||
compilation = CryticCompile(standard_json, solc=solc_path) | ||
slither = Slither(compilation) | ||
printer = PrinterInheritanceGraph(slither=slither, logger=None) | ||
|
||
content = "" | ||
for contract in slither.contracts: | ||
content += printer._summary(contract) | ||
|
||
pattern = re.compile(r"(?:c\d+_)?(\w+ -> )(?:c\d+_)(\w+)") | ||
matches = re.findall(pattern, content) | ||
relations = ["".join(m) for m in matches] | ||
|
||
counter = Counter(relations) | ||
|
||
assert counter["B -> A"] == 2 | ||
assert counter["C -> A"] == 1 |