-
Notifications
You must be signed in to change notification settings - Fork 996
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 #2459 from crytic/fix/identifier-resolve-with-rena…
…ming fix: use contract declarer's scope for name resolution
- Loading branch information
Showing
7 changed files
with
106 additions
and
2 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
41 changes: 41 additions & 0 deletions
41
tests/unit/core/test_data/scope_with_renaming/core/MainContract.sol
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,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
import { | ||
ParentContract | ||
} from "./ParentContract.sol"; | ||
|
||
import { | ||
MainErrors as Errors | ||
} from "./../errors/MainErrors.sol"; | ||
|
||
|
||
contract MainContract is ParentContract { | ||
|
||
|
||
function functionWithMainError1(uint256 a, uint256 b) external pure returns (uint256) { | ||
if (a == b) { | ||
revert Errors.MainError1(); | ||
} | ||
// Add some arithmetic operations here | ||
return a + b; | ||
} | ||
|
||
function functionWithMainError2(uint256 a, uint256 b) external pure returns (uint256) { | ||
if (a < b) { | ||
revert Errors.MainError2(); | ||
} | ||
// Add some arithmetic operations here | ||
return a - b; | ||
} | ||
|
||
function functionWithMainError3(uint256 a, uint256 b) external pure returns (uint256) { | ||
if (b == 0) { | ||
revert Errors.MainError3(); | ||
} | ||
// Add some arithmetic operations here | ||
return a * b; | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
tests/unit/core/test_data/scope_with_renaming/core/ParentContract.sol
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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
|
||
import { | ||
AccessControlErrors as Errors | ||
} from "../errors/ParentContractErrors.sol"; | ||
|
||
|
||
contract ParentContract { | ||
|
||
|
||
function functionWithAccessControlErrors1(uint256 a, uint256 b) external pure returns (uint256) { | ||
if (a == b) { | ||
revert Errors.AccessControlErrors1(); | ||
} | ||
// Add some arithmetic operations here | ||
return a + b; | ||
} | ||
|
||
function functionWithAccessControlErrors2(uint256 a, uint256 b) external pure returns (uint256) { | ||
if (a < b) { | ||
revert Errors.AccessControlErrors2(); | ||
} | ||
// Add some arithmetic operations here | ||
return a - b; | ||
} | ||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
tests/unit/core/test_data/scope_with_renaming/errors/MainErrors.sol
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,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
// TODO: remove unused errors | ||
library MainErrors { | ||
error MainError1(); | ||
error MainError2(); | ||
error MainError3(); | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/unit/core/test_data/scope_with_renaming/errors/ParentContractErrors.sol
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
library AccessControlErrors { | ||
error AccessControlErrors1(); | ||
error AccessControlErrors2(); | ||
} |
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,17 @@ | ||
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" | ||
SCOPE_RENAMING_TEST_DATA_DIR = Path(TEST_DATA_DIR, "scope_with_renaming") | ||
|
||
# https://github.com/crytic/slither/issues/2454 | ||
def test_find_variable_scope_with_renaming(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.24") | ||
standard_json = SolcStandardJson() | ||
for source_file in SCOPE_RENAMING_TEST_DATA_DIR.rglob("**/*.sol"): | ||
standard_json.add_source_file(Path(source_file).as_posix()) | ||
compilation = CryticCompile(standard_json, solc=solc_path) | ||
Slither(compilation, disallow_partial=True) |
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