From 759a4fceadc640e87edb8ce18ac01bbb18009f30 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Thu, 28 Mar 2024 10:48:33 -0500 Subject: [PATCH] add test --- slither/core/declarations/function.py | 11 ----------- slither/solc_parsing/declarations/function.py | 2 +- tests/unit/core/test_data/virtual_overrides.sol | 7 +++++++ tests/unit/core/test_virtual_overrides.py | 12 ++++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/slither/core/declarations/function.py b/slither/core/declarations/function.py index b0f16750c..93d4039db 100644 --- a/slither/core/declarations/function.py +++ b/slither/core/declarations/function.py @@ -450,17 +450,6 @@ def payable(self, p: bool): ################################################################################### ################################################################################### - @property - def is_implemented(self) -> bool: - """ - bool: True if the function is implemented - """ - return self._is_implemented - - @is_implemented.setter - def is_implemented(self, is_implemented: bool): - self._is_implemented = is_implemented - @property def is_virtual(self) -> bool: """ diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py index 234072b88..7a5852324 100644 --- a/slither/solc_parsing/declarations/function.py +++ b/slither/solc_parsing/declarations/function.py @@ -262,7 +262,7 @@ def _analyze_attributes(self) -> None: if "overrides" in attributes and isinstance(attributes["overrides"], dict): for override in attributes["overrides"].get("overrides", []): refId = override["referencedDeclaration"] - overridden_contract = self.slither_parser._contracts_by_id.get(refId, None) + overridden_contract = self.slither_parser.contracts_by_id.get(refId, None) if overridden_contract: overridden_contract.add_reference_from_raw_source( override["src"], self.compilation_unit diff --git a/tests/unit/core/test_data/virtual_overrides.sol b/tests/unit/core/test_data/virtual_overrides.sol index 86e44cd29..fa9e1c388 100644 --- a/tests/unit/core/test_data/virtual_overrides.sol +++ b/tests/unit/core/test_data/virtual_overrides.sol @@ -56,3 +56,10 @@ contract A2 is Test2 { } } +abstract contract I { + function a() public virtual {} +} +contract J is I {} +contract K is J { + function a() public override {} +} \ No newline at end of file diff --git a/tests/unit/core/test_virtual_overrides.py b/tests/unit/core/test_virtual_overrides.py index 7a50d1730..b58e45b62 100644 --- a/tests/unit/core/test_virtual_overrides.py +++ b/tests/unit/core/test_virtual_overrides.py @@ -55,6 +55,18 @@ def test_overrides(solc_binary_path) -> None: ["Y.myVirtualFunction()", "X.myVirtualFunction()"] ) + k = slither.get_contract_from_name("K")[0] + k_virtual_func = k.get_function_from_full_name("a()") + assert not k_virtual_func.is_virtual + assert k_virtual_func.is_override + assert len(k_virtual_func.overrides) == 1 + + i = slither.get_contract_from_name("I")[0] + i_virtual_func = i.get_function_from_full_name("a()") + assert i_virtual_func.is_virtual + assert not i_virtual_func.is_override + assert len(i_virtual_func.overrides) == 0 + assert len(i_virtual_func.overridden_by) == 1 def test_virtual_override_references_and_implementations(solc_binary_path) -> None: solc_path = solc_binary_path("0.8.15")