Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct instances of typo throughout repo: initiliaze -> initialize #1239

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

kylebakerio
Copy link
Contributor

@kylebakerio kylebakerio commented Jun 15, 2022

WIP, though, and would like advising--when replacing all instances, 4 related tests fail.

Advice on how to get those tests passing to get this corrected welcome.

~/code/forks/slither$ pytest ./tests/test_detectors.py
========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.9.5, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/kyle/code/forks/slither
plugins: mock-3.7.0, cov-3.0.0
collected 291 items                                                                                                                                                                                      

tests/test_detectors.py .......................................................................................................................................................................... [ 58%]
......................F..F..F..F.........................................................................................                                                                          [100%]

================================================================================================ FAILURES ================================================================================================
_________________________________________ test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.4.25/Buggy.sol] _________________________________________

test_item = <tests.test_detectors.Test object at 0x7fba0cb16280>

    @pytest.mark.parametrize("test_item", ALL_TESTS, ids=id_test)
    def test_detector(test_item: Test):
        test_dir_path = pathlib.Path(
            pathlib.Path().absolute(),
            "tests",
            "detectors",
            test_item.detector.ARGUMENT,
            test_item.solc_ver,
        )
        test_file_path = str(pathlib.Path(test_dir_path, test_item.test_file))
        expected_result_path = str(pathlib.Path(test_dir_path, test_item.expected_result).absolute())
    
        set_solc(test_item)
        sl = Slither(test_file_path)
        sl.register_detector(test_item.detector)
        results = sl.run_detectors()
    
        with open(expected_result_path, encoding="utf8") as f:
            expected_result = json.load(f)
    
        results_as_string = json.dumps(results)
    
        for additional_file in test_item.additional_files:
            additional_path = str(pathlib.Path(test_dir_path, additional_file).absolute())
            additional_path = additional_path.replace("\\", "\\\\")
            results_as_string = results_as_string.replace(additional_path, GENERIC_PATH)
        test_file_path = test_file_path.replace("\\", "\\\\")
        results_as_string = results_as_string.replace(test_file_path, GENERIC_PATH)
        results = json.loads(results_as_string)
    
        diff = DeepDiff(results, expected_result, ignore_order=True, verbose_level=2)
        if diff:
            pprint(diff)
            diff_as_dict = diff.to_dict()
    
            if "iterable_item_added" in diff_as_dict:
                print("#### Findings added")
                for finding_added in diff_as_dict["iterable_item_added"].values():
                    print(finding_added["description"])
            if "iterable_item_removed" in diff_as_dict:
                print("#### Findings removed")
                for finding_added in diff_as_dict["iterable_item_removed"].values():
                    print(finding_added["description"])
>           assert False
E           assert False

tests/test_detectors.py:1391: AssertionError
------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------
{'values_changed': {"root[0][0]['id']": {'new_value': 'aceca400ce0b482809a70df612af22e24d154c5c89c24d630ec0ee5a366d09fe',
                                         'old_value': 'd85b90230632a30f7ffb5140a791d4a9ae8b0be045c5b27175f3c477e189c08c'}}}
_________________________________________ test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.5.16/Buggy.sol] _________________________________________

test_item = <tests.test_detectors.Test object at 0x7fba0cb163a0>

    @pytest.mark.parametrize("test_item", ALL_TESTS, ids=id_test)
    def test_detector(test_item: Test):
        test_dir_path = pathlib.Path(
            pathlib.Path().absolute(),
            "tests",
            "detectors",
            test_item.detector.ARGUMENT,
            test_item.solc_ver,
        )
        test_file_path = str(pathlib.Path(test_dir_path, test_item.test_file))
        expected_result_path = str(pathlib.Path(test_dir_path, test_item.expected_result).absolute())
    
        set_solc(test_item)
        sl = Slither(test_file_path)
        sl.register_detector(test_item.detector)
        results = sl.run_detectors()
    
        with open(expected_result_path, encoding="utf8") as f:
            expected_result = json.load(f)
    
        results_as_string = json.dumps(results)
    
        for additional_file in test_item.additional_files:
            additional_path = str(pathlib.Path(test_dir_path, additional_file).absolute())
            additional_path = additional_path.replace("\\", "\\\\")
            results_as_string = results_as_string.replace(additional_path, GENERIC_PATH)
        test_file_path = test_file_path.replace("\\", "\\\\")
        results_as_string = results_as_string.replace(test_file_path, GENERIC_PATH)
        results = json.loads(results_as_string)
    
        diff = DeepDiff(results, expected_result, ignore_order=True, verbose_level=2)
        if diff:
            pprint(diff)
            diff_as_dict = diff.to_dict()
    
            if "iterable_item_added" in diff_as_dict:
                print("#### Findings added")
                for finding_added in diff_as_dict["iterable_item_added"].values():
                    print(finding_added["description"])
            if "iterable_item_removed" in diff_as_dict:
                print("#### Findings removed")
                for finding_added in diff_as_dict["iterable_item_removed"].values():
                    print(finding_added["description"])
>           assert False
E           assert False

tests/test_detectors.py:1391: AssertionError
------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------
{'values_changed': {"root[0][0]['id']": {'new_value': 'aceca400ce0b482809a70df612af22e24d154c5c89c24d630ec0ee5a366d09fe',
                                         'old_value': 'd85b90230632a30f7ffb5140a791d4a9ae8b0be045c5b27175f3c477e189c08c'}}}
_________________________________________ test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.6.11/Buggy.sol] _________________________________________

test_item = <tests.test_detectors.Test object at 0x7fba0cb164c0>

    @pytest.mark.parametrize("test_item", ALL_TESTS, ids=id_test)
    def test_detector(test_item: Test):
        test_dir_path = pathlib.Path(
            pathlib.Path().absolute(),
            "tests",
            "detectors",
            test_item.detector.ARGUMENT,
            test_item.solc_ver,
        )
        test_file_path = str(pathlib.Path(test_dir_path, test_item.test_file))
        expected_result_path = str(pathlib.Path(test_dir_path, test_item.expected_result).absolute())
    
        set_solc(test_item)
        sl = Slither(test_file_path)
        sl.register_detector(test_item.detector)
        results = sl.run_detectors()
    
        with open(expected_result_path, encoding="utf8") as f:
            expected_result = json.load(f)
    
        results_as_string = json.dumps(results)
    
        for additional_file in test_item.additional_files:
            additional_path = str(pathlib.Path(test_dir_path, additional_file).absolute())
            additional_path = additional_path.replace("\\", "\\\\")
            results_as_string = results_as_string.replace(additional_path, GENERIC_PATH)
        test_file_path = test_file_path.replace("\\", "\\\\")
        results_as_string = results_as_string.replace(test_file_path, GENERIC_PATH)
        results = json.loads(results_as_string)
    
        diff = DeepDiff(results, expected_result, ignore_order=True, verbose_level=2)
        if diff:
            pprint(diff)
            diff_as_dict = diff.to_dict()
    
            if "iterable_item_added" in diff_as_dict:
                print("#### Findings added")
                for finding_added in diff_as_dict["iterable_item_added"].values():
                    print(finding_added["description"])
            if "iterable_item_removed" in diff_as_dict:
                print("#### Findings removed")
                for finding_added in diff_as_dict["iterable_item_removed"].values():
                    print(finding_added["description"])
>           assert False
E           assert False

tests/test_detectors.py:1391: AssertionError
------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------
{'values_changed': {"root[0][0]['id']": {'new_value': 'aceca400ce0b482809a70df612af22e24d154c5c89c24d630ec0ee5a366d09fe',
                                         'old_value': 'd85b90230632a30f7ffb5140a791d4a9ae8b0be045c5b27175f3c477e189c08c'}}}
_________________________________________ test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.7.6/Buggy.sol] __________________________________________

test_item = <tests.test_detectors.Test object at 0x7fba0cb165e0>

    @pytest.mark.parametrize("test_item", ALL_TESTS, ids=id_test)
    def test_detector(test_item: Test):
        test_dir_path = pathlib.Path(
            pathlib.Path().absolute(),
            "tests",
            "detectors",
            test_item.detector.ARGUMENT,
            test_item.solc_ver,
        )
        test_file_path = str(pathlib.Path(test_dir_path, test_item.test_file))
        expected_result_path = str(pathlib.Path(test_dir_path, test_item.expected_result).absolute())
    
        set_solc(test_item)
        sl = Slither(test_file_path)
        sl.register_detector(test_item.detector)
        results = sl.run_detectors()
    
        with open(expected_result_path, encoding="utf8") as f:
            expected_result = json.load(f)
    
        results_as_string = json.dumps(results)
    
        for additional_file in test_item.additional_files:
            additional_path = str(pathlib.Path(test_dir_path, additional_file).absolute())
            additional_path = additional_path.replace("\\", "\\\\")
            results_as_string = results_as_string.replace(additional_path, GENERIC_PATH)
        test_file_path = test_file_path.replace("\\", "\\\\")
        results_as_string = results_as_string.replace(test_file_path, GENERIC_PATH)
        results = json.loads(results_as_string)
    
        diff = DeepDiff(results, expected_result, ignore_order=True, verbose_level=2)
        if diff:
            pprint(diff)
            diff_as_dict = diff.to_dict()
    
            if "iterable_item_added" in diff_as_dict:
                print("#### Findings added")
                for finding_added in diff_as_dict["iterable_item_added"].values():
                    print(finding_added["description"])
            if "iterable_item_removed" in diff_as_dict:
                print("#### Findings removed")
                for finding_added in diff_as_dict["iterable_item_removed"].values():
                    print(finding_added["description"])
>           assert False
E           assert False

tests/test_detectors.py:1391: AssertionError
------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------
{'values_changed': {"root[0][0]['id']": {'new_value': 'aceca400ce0b482809a70df612af22e24d154c5c89c24d630ec0ee5a366d09fe',
                                         'old_value': 'd85b90230632a30f7ffb5140a791d4a9ae8b0be045c5b27175f3c477e189c08c'}}}
============================================================================================ warnings summary ============================================================================================
tests/test_detectors.py:19
  /home/kyle/code/forks/slither/tests/test_detectors.py:19: PytestCollectionWarning: cannot collect test class 'Test' because it has a __init__ constructor (from: tests/test_detectors.py)
    class Test:  # pylint: disable=too-few-public-methods

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================== short test summary info =========================================================================================
FAILED tests/test_detectors.py::test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.4.25/Buggy.sol] - assert False
FAILED tests/test_detectors.py::test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.5.16/Buggy.sol] - assert False
FAILED tests/test_detectors.py::test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.6.11/Buggy.sol] - assert False
FAILED tests/test_detectors.py::test_detector[<class 'slither.detectors.statements.unprotected_upgradeable.UnprotectedUpgradeable'>: 0.7.6/Buggy.sol] - assert False
=============================================================================== 4 failed, 287 passed, 1 warning in 24.65s ================================================================================

@CLAassistant
Copy link

CLAassistant commented Jun 15, 2022

CLA assistant check
All committers have signed the CLA.

@0xalpharush
Copy link
Member

Try python ./tests/test_detectors.py --overwrite

@kylebakerio
Copy link
Contributor Author

@0xalpharush, that fails, with what seems to be a very random error:

~/code/forks/slither$ python3 ./tests/test_detectors.py --overwrite
Traceback (most recent call last):
  File "/home/kyle/code/forks/slither/./tests/test_detectors.py", line 399, in <module>
    all_detectors.ArbitrarySendEth,
AttributeError: module 'slither.detectors.all_detectors' has no attribute 'ArbitrarySendEth'

seems-here
arbitrary-send-eth

everything seems fine and I don't know what would have been touched that would be relevant to that...?

@kylebakerio
Copy link
Contributor Author

don't think the intended block is getting hit, overwrite sysarg isn't picked up. identical results when removing the --overwrite.

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("To generate the json artifacts run\n\tpython tests/test_detectors.py --generate")
    elif sys.argv[1] == "--generate":
        for next_test in ALL_TESTS:
            _generate_test(next_test, skip_existing=True)
    elif sys.argv[1] == "--overwrite":
        for next_test in ALL_TESTS:
            _generate_test(next_test)

@0xalpharush
Copy link
Member

I would try working off of dev. It looks like there's some commits related to renaming this detector not merge into master yet.

@montyly montyly changed the base branch from master to dev July 25, 2022 13:54
@montyly montyly merged commit 6971f30 into crytic:dev Jul 26, 2022
@montyly
Copy link
Member

montyly commented Jul 26, 2022

Great catch, thanks @kylebakerio

montyly added a commit that referenced this pull request Jul 26, 2022
montyly added a commit that referenced this pull request Jul 26, 2022
* Fix broken tests introduced with #1239

* Disable etherlime from the CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants