mirror of https://github.com/crytic/slither
commit
46061c5d27
@ -1,8 +1,8 @@ |
||||
Test.indirect() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#19-21) sends eth to arbitrary user |
||||
Test.direct() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#16-18) sends eth to arbitrary user |
||||
Dangerous calls: |
||||
- destination.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#20) |
||||
- msg.sender.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#17) |
||||
|
||||
Test.direct() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#11-13) sends eth to arbitrary user |
||||
Test.indirect() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#24-26) sends eth to arbitrary user |
||||
Dangerous calls: |
||||
- msg.sender.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#12) |
||||
- destination.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.6.11/arbitrary_send_eth.sol#25) |
||||
|
||||
|
@ -1,8 +1,8 @@ |
||||
Test.direct() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#11-13) sends eth to arbitrary user |
||||
Test.direct() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#16-18) sends eth to arbitrary user |
||||
Dangerous calls: |
||||
- msg.sender.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#12) |
||||
- msg.sender.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#17) |
||||
|
||||
Test.indirect() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#19-21) sends eth to arbitrary user |
||||
Test.indirect() (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#24-26) sends eth to arbitrary user |
||||
Dangerous calls: |
||||
- destination.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#20) |
||||
- destination.send(address(this).balance) (tests/e2e/detectors/test_data/arbitrary-send-eth/0.7.6/arbitrary_send_eth.sol#25) |
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,20 +0,0 @@ |
||||
import sys |
||||
import tempfile |
||||
import pytest |
||||
|
||||
from slither.__main__ import main_impl |
||||
|
||||
|
||||
def test_cli_exit_on_invalid_compilation_file(caplog): |
||||
|
||||
with tempfile.NamedTemporaryFile("w") as f: |
||||
f.write("pragma solidity ^0.10000.0;") |
||||
|
||||
sys.argv = ["slither", f.name] |
||||
with pytest.raises(SystemExit) as pytest_wrapped_e: |
||||
main_impl([], []) |
||||
|
||||
assert pytest_wrapped_e.type == SystemExit |
||||
assert pytest_wrapped_e.value.code == 2 |
||||
|
||||
assert caplog.record_tuples[0] == ("Slither", 40, "Unable to compile all targets.") |
@ -0,0 +1,4 @@ |
||||
INFO:Slither: |
||||
Contract_no_bug_reinitializer (tests/tools/check_upgradeability/contract_initialization.sol#23-29) needs to be initialized by Contract_no_bug_reinitializer.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#25-27). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither:1 findings, 12 detectors run |
@ -0,0 +1,15 @@ |
||||
INFO:Slither: |
||||
Contract_reinitializer_V2 (tests/tools/check_upgradeability/contract_initialization.sol#63-77) needs to be initialized by Contract_reinitializer_V2.initialize(uint256) (tests/tools/check_upgradeability/contract_initialization.sol#66-68). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither: |
||||
Extra variables in Counter_reinitializer_V3_V4 (tests/tools/check_upgradeability/contract_initialization.sol#79-104): Counter_reinitializer_V3_V4.y (tests/tools/check_upgradeability/contract_initialization.sol#81) |
||||
Extra variables in Counter_reinitializer_V3_V4 (tests/tools/check_upgradeability/contract_initialization.sol#79-104): Counter_reinitializer_V3_V4.z (tests/tools/check_upgradeability/contract_initialization.sol#82) |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#extra-variables-in-the-v2 |
||||
INFO:Slither: |
||||
Counter_reinitializer_V3_V4.initializeV3(uint256) (tests/tools/check_upgradeability/contract_initialization.sol#92-94) multiple new reinitializers which should be combined into one per upgrade. |
||||
Counter_reinitializer_V3_V4.initializeV4(uint256) (tests/tools/check_upgradeability/contract_initialization.sol#96-98) multiple new reinitializers which should be combined into one per upgrade. |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#multiple-new-reinitializers |
||||
INFO:Slither: |
||||
Counter_reinitializer_V3_V4 (tests/tools/check_upgradeability/contract_initialization.sol#79-104) needs to be initialized by Counter_reinitializer_V3_V4.initialize(uint256) (tests/tools/check_upgradeability/contract_initialization.sol#84-86). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither:6 findings, 22 detectors run |
@ -1,4 +1,4 @@ |
||||
INFO:Slither: |
||||
Contract_no_bug (tests/check-upgradeability/contract_initialization.sol#11-17) needs to be initialized by Contract_no_bug.initialize() (tests/check-upgradeability/contract_initialization.sol#13-15). |
||||
Contract_no_bug (tests/tools/check_upgradeability/contract_initialization.sol#15-21) needs to be initialized by Contract_no_bug.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#17-19). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither:1 findings, 12 detectors run |
||||
|
@ -1,7 +1,7 @@ |
||||
INFO:Slither: |
||||
Contract_lack_to_call_modifier (tests/check-upgradeability/contract_initialization.sol#19-24) needs to be initialized by Contract_lack_to_call_modifier.initialize() (tests/check-upgradeability/contract_initialization.sol#21-23). |
||||
Contract_lack_to_call_modifier (tests/tools/check_upgradeability/contract_initialization.sol#31-36) needs to be initialized by Contract_lack_to_call_modifier.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#33-35). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither: |
||||
Contract_lack_to_call_modifier.initialize() (tests/check-upgradeability/contract_initialization.sol#21-23) does not call the initializer modifier. |
||||
Contract_lack_to_call_modifier.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#33-35) does not call the initializer or reinitializer modifier. |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializer-is-not-called |
||||
INFO:Slither:2 findings, 12 detectors run |
||||
|
@ -1,7 +1,7 @@ |
||||
INFO:Slither: |
||||
Contract_not_called_super_init (tests/check-upgradeability/contract_initialization.sol#26-32) needs to be initialized by Contract_not_called_super_init.initialize() (tests/check-upgradeability/contract_initialization.sol#28-30). |
||||
Contract_not_called_super_init (tests/tools/check_upgradeability/contract_initialization.sol#38-44) needs to be initialized by Contract_not_called_super_init.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#40-42). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither: |
||||
Missing call to Contract_no_bug.initialize() (tests/check-upgradeability/contract_initialization.sol#13-15) in Contract_not_called_super_init.initialize() (tests/check-upgradeability/contract_initialization.sol#28-30). |
||||
Missing call to Contract_no_bug.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#17-19) in Contract_not_called_super_init.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#40-42). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-functions-are-not-called |
||||
INFO:Slither:2 findings, 12 detectors run |
||||
|
@ -1,4 +1,4 @@ |
||||
INFO:Slither: |
||||
Contract_no_bug_inherits (tests/check-upgradeability/contract_initialization.sol#34-40) needs to be initialized by Contract_no_bug_inherits.initialize() (tests/check-upgradeability/contract_initialization.sol#36-38). |
||||
Contract_no_bug_inherits (tests/tools/check_upgradeability/contract_initialization.sol#46-52) needs to be initialized by Contract_no_bug_inherits.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#48-50). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither:1 findings, 12 detectors run |
||||
|
@ -1,7 +1,7 @@ |
||||
INFO:Slither: |
||||
Contract_double_call (tests/check-upgradeability/contract_initialization.sol#42-49) needs to be initialized by Contract_double_call.initialize() (tests/check-upgradeability/contract_initialization.sol#44-47). |
||||
Contract_double_call (tests/tools/check_upgradeability/contract_initialization.sol#54-61) needs to be initialized by Contract_double_call.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#56-59). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-function |
||||
INFO:Slither: |
||||
Contract_no_bug.initialize() (tests/check-upgradeability/contract_initialization.sol#13-15) is called multiple times in Contract_double_call.initialize() (tests/check-upgradeability/contract_initialization.sol#44-47). |
||||
Contract_no_bug.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#17-19) is called multiple times in Contract_double_call.initialize() (tests/tools/check_upgradeability/contract_initialization.sol#56-59). |
||||
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initialize-functions-are-called-multiple-times |
||||
INFO:Slither:2 findings, 12 detectors run |
||||
|
@ -0,0 +1,7 @@ |
||||
# Counter |
||||
|
||||
Init using : |
||||
|
||||
```shell |
||||
forge install --no-commit --no-git . |
||||
``` |
@ -0,0 +1,7 @@ |
||||
[profile.default] |
||||
src = 'src' |
||||
out = 'out' |
||||
libs = ['lib'] |
||||
solc = "0.8.15" |
||||
|
||||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config |
@ -0,0 +1,12 @@ |
||||
// SPDX-License-Identifier: UNLICENSED |
||||
pragma solidity ^0.8.13; |
||||
|
||||
import {Script, console} from "forge-std/Script.sol"; |
||||
|
||||
contract CounterScript is Script { |
||||
function setUp() public {} |
||||
|
||||
function run() public { |
||||
vm.broadcast(); |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
// SPDX-License-Identifier: UNLICENSED |
||||
pragma solidity ^0.8.15; |
||||
|
||||
contract Counter { |
||||
uint256 public number; |
||||
|
||||
function setNumber(uint256 newNumber) public { |
||||
number = newNumber; |
||||
} |
||||
|
||||
function increment() public { |
||||
number++; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
// SPDX-License-Identifier: UNLICENSED |
||||
pragma solidity ^0.8.15; |
||||
|
||||
import {Test, console} from "forge-std/Test.sol"; |
||||
import {Counter} from "../src/Counter.sol"; |
||||
|
||||
contract CounterTest is Test { |
||||
Counter public counter; |
||||
|
||||
function setUp() public { |
||||
counter = new Counter(); |
||||
counter.setNumber(0); |
||||
} |
||||
|
||||
function test_Increment() public { |
||||
counter.increment(); |
||||
assertEq(counter.number(), 1); |
||||
} |
||||
|
||||
function testFuzz_SetNumber(uint256 x) public { |
||||
counter.setNumber(x); |
||||
assertEq(counter.number(), x); |
||||
} |
||||
} |
@ -0,0 +1,133 @@ |
||||
import argparse |
||||
from contextlib import contextmanager |
||||
import os |
||||
from pathlib import Path |
||||
import shutil |
||||
import subprocess |
||||
import tempfile |
||||
from unittest import mock |
||||
|
||||
import pytest |
||||
from slither import Slither |
||||
from slither.tools.mutator.__main__ import _get_mutators, main |
||||
from slither.tools.mutator.utils.testing_generated_mutant import run_test_cmd |
||||
from slither.tools.mutator.utils.file_handling import get_sol_file_list, backup_source_file |
||||
|
||||
|
||||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" |
||||
|
||||
foundry_available = shutil.which("forge") is not None |
||||
project_ready = Path(TEST_DATA_DIR, "test_source_unit/lib/forge-std").exists() |
||||
|
||||
|
||||
@contextmanager |
||||
def change_directory(new_dir): |
||||
original_dir = os.getcwd() |
||||
os.chdir(new_dir) |
||||
try: |
||||
yield |
||||
finally: |
||||
os.chdir(original_dir) |
||||
|
||||
|
||||
def test_get_mutators(): |
||||
|
||||
mutators = _get_mutators(None) |
||||
assert mutators |
||||
|
||||
mutators = _get_mutators(["ASOR"]) |
||||
assert len(mutators) == 1 |
||||
assert mutators[0].NAME == "ASOR" |
||||
|
||||
mutators = _get_mutators(["ASOR", "NotExisiting"]) |
||||
assert len(mutators) == 1 |
||||
|
||||
|
||||
@mock.patch( |
||||
"argparse.ArgumentParser.parse_args", |
||||
return_value=argparse.Namespace( |
||||
test_cmd="forge test", |
||||
test_dir=None, |
||||
ignore_dirs="lib,mutation_campaign", |
||||
output_dir=None, |
||||
timeout=None, |
||||
solc_remaps="forge-std=./lib/forge-std", |
||||
verbose=None, |
||||
very_verbose=None, |
||||
mutators_to_run=None, |
||||
comprehensive=None, |
||||
codebase=(TEST_DATA_DIR / "test_source_unit" / "src" / "Counter.sol").as_posix(), |
||||
contract_names="Counter", |
||||
), |
||||
) |
||||
@pytest.mark.skip(reason="Slow test") |
||||
def test_mutator(mock_args, solc_binary_path): # pylint: disable=unused-argument |
||||
|
||||
with change_directory(TEST_DATA_DIR / "test_source_unit"): |
||||
main() |
||||
|
||||
|
||||
def test_backup_source_file(solc_binary_path): |
||||
solc_path = solc_binary_path("0.8.15") |
||||
|
||||
file_path = (TEST_DATA_DIR / "test_source_unit" / "src" / "Counter.sol").as_posix() |
||||
sl = Slither(file_path, solc=solc_path) |
||||
|
||||
with tempfile.TemporaryDirectory() as directory: |
||||
files_dict = backup_source_file(sl.source_code, Path(directory)) |
||||
|
||||
assert len(files_dict) == 1 |
||||
assert Path(files_dict[file_path]).exists() |
||||
|
||||
|
||||
@pytest.mark.skipif( |
||||
not foundry_available or not project_ready, reason="requires Foundry and project setup" |
||||
) |
||||
def test_get_sol_file_list(): |
||||
|
||||
project_directory = TEST_DATA_DIR / "test_source_unit" |
||||
|
||||
files = get_sol_file_list(project_directory, None) |
||||
|
||||
assert len(files) == 46 |
||||
|
||||
files = get_sol_file_list(project_directory, ["lib"]) |
||||
assert len(files) == 3 |
||||
|
||||
files = get_sol_file_list(project_directory, ["lib", "script"]) |
||||
assert len(files) == 2 |
||||
|
||||
files = get_sol_file_list(project_directory / "src" / "Counter.sol", None) |
||||
assert len(files) == 1 |
||||
|
||||
(project_directory / "test.sol").mkdir() |
||||
files = get_sol_file_list(project_directory, None) |
||||
assert all("test.sol" not in file for file in files) |
||||
(project_directory / "test.sol").rmdir() |
||||
|
||||
|
||||
@pytest.mark.skipif( |
||||
not foundry_available or not project_ready, reason="requires Foundry and project setup" |
||||
) |
||||
def test_run_test(caplog): |
||||
with change_directory(TEST_DATA_DIR / "test_source_unit"): |
||||
result = run_test_cmd("forge test", timeout=None, target_file=None, verbose=True) |
||||
assert result |
||||
assert not caplog.records |
||||
|
||||
# Failed command |
||||
result = run_test_cmd("forge non-test", timeout=None, target_file=None, verbose=True) |
||||
assert not result |
||||
assert caplog.records |
||||
|
||||
|
||||
def test_run_tests_timeout(caplog, monkeypatch): |
||||
def mock_run(*args, **kwargs): |
||||
raise subprocess.TimeoutExpired(cmd=args[0], timeout=kwargs.get("timeout")) |
||||
|
||||
monkeypatch.setattr(subprocess, "run", mock_run) |
||||
|
||||
with change_directory(TEST_DATA_DIR / "test_source_unit"): |
||||
result = run_test_cmd("forge test", timeout=1) |
||||
assert not result |
||||
assert "Tests took too long" in caplog.messages[0] |
Loading…
Reference in new issue