Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalpharush committed Mar 28, 2024
1 parent 0933dfa commit 759a4fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
11 changes: 0 additions & 11 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/core/test_data/virtual_overrides.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
12 changes: 12 additions & 0 deletions tests/unit/core/test_virtual_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 759a4fc

Please sign in to comment.