-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2320 from crytic/fix/inheritance-renaming
fix: support renaming in base inheritance and base constructor calls
- Loading branch information
Showing
5 changed files
with
73 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {B as Base} from "./b.sol"; | ||
contract A is Base(address(0)) { | ||
constructor (address x) {} | ||
} |
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 @@ | ||
import {C as C2} from "./c.sol"; | ||
contract B is C2 { | ||
constructor (address x) C2(x) {} | ||
} |
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,3 @@ | ||
contract C { | ||
constructor (address) {} | ||
} |
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,36 @@ | ||
from pathlib import Path | ||
|
||
from crytic_compile import CryticCompile | ||
from crytic_compile.platform.solc_standard_json import SolcStandardJson | ||
from slither import Slither | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "inheritance_with_renaming" | ||
|
||
# https://github.com/crytic/slither/issues/2304 | ||
def test_inheritance_with_renaming(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.15") | ||
standard_json = SolcStandardJson() | ||
for source_file in Path(TEST_DATA_DIR).rglob("*.sol"): | ||
print(source_file) | ||
standard_json.add_source_file(Path(source_file).as_posix()) | ||
compilation = CryticCompile(standard_json, solc=solc_path) | ||
slither = Slither(compilation) | ||
|
||
a = slither.get_contract_from_name("A")[0] | ||
b = slither.get_contract_from_name("B")[0] | ||
c = slither.get_contract_from_name("C")[0] | ||
|
||
assert len(a.immediate_inheritance) == 1 | ||
assert a.immediate_inheritance[0] == b | ||
assert len(a.inheritance) == 2 | ||
assert a.inheritance[0] == b | ||
assert a.inheritance[1] == c | ||
assert len(a.explicit_base_constructor_calls) == 1 | ||
a_base_constructor_call = a.explicit_base_constructor_calls[0] | ||
assert a_base_constructor_call == b.constructor | ||
|
||
assert len(b.inheritance) == 1 | ||
assert b.inheritance[0] == c | ||
assert len(b.immediate_inheritance) == 1 | ||
assert b.immediate_inheritance[0] == c | ||
assert len(b.explicit_base_constructor_calls) == 0 |