mirror of https://github.com/crytic/slither
Improve message error for when Crytic throws a KeyError. (#2418)
* Improve message error for when Crytic throws a KeyError. * Remove unneeded logger usage and fix typopull/2473/head
parent
b9a3ea6189
commit
4d09e59915
@ -0,0 +1,3 @@ |
||||
# Foundry |
||||
|
||||
To init this test case, run `forge install --no-commit --no-git foundry-rs/forge-std` |
@ -0,0 +1,6 @@ |
||||
[profile.default] |
||||
src = "src" |
||||
out = "out" |
||||
libs = ["lib"] |
||||
|
||||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
@ -0,0 +1,16 @@ |
||||
// SPDX-License-Identifier: UNLICENSED |
||||
pragma solidity ^0.8.13; |
||||
|
||||
contract Counter { |
||||
uint256 public number; |
||||
|
||||
function setNumber(uint256 newNumber) public { |
||||
number = newNumber; |
||||
} |
||||
|
||||
//START |
||||
function increment() public { |
||||
number++; |
||||
} |
||||
//END |
||||
} |
@ -0,0 +1,40 @@ |
||||
from pathlib import Path |
||||
import shutil |
||||
import re |
||||
|
||||
import pytest |
||||
|
||||
from slither import Slither |
||||
from slither.exceptions import SlitherException |
||||
|
||||
|
||||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" |
||||
|
||||
foundry_available = shutil.which("forge") is not None |
||||
project_ready = Path(TEST_DATA_DIR, "test_change/lib/forge-std").exists() |
||||
|
||||
|
||||
@pytest.mark.skipif( |
||||
not foundry_available or not project_ready, reason="requires Foundry and project setup" |
||||
) |
||||
def test_diagnostic(): |
||||
|
||||
test_file_directory = TEST_DATA_DIR / "test_change" |
||||
|
||||
sl = Slither(test_file_directory.as_posix()) |
||||
assert len(sl.compilation_units) == 1 |
||||
|
||||
counter_file = test_file_directory / "src" / "Counter.sol" |
||||
shutil.copy(counter_file, counter_file.with_suffix(".bak")) |
||||
|
||||
with counter_file.open("r") as file: |
||||
content = file.read() |
||||
|
||||
with counter_file.open("w") as file: |
||||
file.write(re.sub(r"//START.*?//END\n?", "", content, flags=re.DOTALL)) |
||||
|
||||
with pytest.raises(SlitherException): |
||||
Slither(test_file_directory.as_posix(), ignore_compile=True) |
||||
|
||||
# Restore the original counter so the test is idempotent |
||||
Path(counter_file.with_suffix(".bak")).rename(counter_file) |
Loading…
Reference in new issue