Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions slither/printers/inheritance/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,42 @@ def output(self, filename):
result = {"child_to_base": {}, "paths": {}}

for child in self.contracts:
info += blue(f"\n+ {child.name}")
info += blue(f"\n+ {child.name}\n")
result["paths"][child.name] = child.source_mapping.filename.absolute
result["child_to_base"][child.name] = {"immediate": [], "not_immediate": []}
if child.inheritance:
immediate = child.immediate_inheritance
not_immediate = [i for i in child.inheritance if i not in immediate]

info += " -> " + green(", ".join(map(str, immediate)))
info += " -> " + green(", ".join(map(str, immediate))) + "\n"
result["child_to_base"][child.name]["immediate"] = list(map(str, immediate))
if not_immediate:
info += ", [" + green(", ".join(map(str, not_immediate))) + "]"
info += ", [" + green(", ".join(map(str, not_immediate))) + "]\n"
result["child_to_base"][child.name]["not_immediate"] = list(
map(str, not_immediate)
)

info += green("\n\nBase_Contract -> ") + blue("Immediate_Child_Contracts")
info += blue(" [Not_Immediate_Child_Contracts]")
info += green("\n\nBase_Contract -> ") + blue("Immediate_Child_Contracts") + "\n"
info += blue(" [Not_Immediate_Child_Contracts]") + "\n"

result["base_to_child"] = {}
for base in self.contracts:
info += green(f"\n+ {base.name}")
info += green(f"\n+ {base.name}") + "\n"
children = list(self._get_child_contracts(base))

result["base_to_child"][base.name] = {"immediate": [], "not_immediate": []}
if children:
immediate = [child for child in children if base in child.immediate_inheritance]
not_immediate = [child for child in children if child not in immediate]

info += " -> " + blue(", ".join(map(str, immediate)))
info += " -> " + blue(", ".join(map(str, immediate))) + "\n"
result["base_to_child"][base.name]["immediate"] = list(map(str, immediate))
if not_immediate:
info += ", [" + blue(", ".join(map(str, not_immediate))) + "]"
info += ", [" + blue(", ".join(map(str, not_immediate))) + "]\n"
result["base_to_child"][base.name]["not_immediate"] = list(
map(str, not_immediate)
)

info += "\n"
self.info(info)

res = self.generate_output(info, additional_fields=result)
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/printers/test_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def test_inheritance_text_printer(solc_binary_path) -> None:
output = printer.output("test_inheritance.txt")

# Data is nested under additional_fields
assert "\r" not in output.data["description"]

data = output.data["additional_fields"]

# Verify JSON structure has expected keys
Expand Down