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

Fix inheritance printer rebase #2153

Merged
merged 5 commits into from
Jun 4, 2024
Merged

Conversation

0xPhaze
Copy link

@0xPhaze 0xPhaze commented Oct 2, 2023

This PR nows :

  • Adds a new include-interfaces command line switch if the user wants to include interface in the inheritance graph (default is False).
  • Checks for interfaces before displaying them
  • Removes virtual functions
  • Adds a test to ensure this works as appropriately

Summary by CodeRabbit

  • New Features

    • Added --include-interfaces argument to include interfaces in the inheritance-graph printer.
  • Bug Fixes

    • Excluded contracts with "mock" in their name from the inheritance graph.
    • Removed inherited interfaces when --include-interfaces is set to False.
    • Excluded virtual functions from the output.
  • Tests

    • Added tests for include/exclude interface behavior in printer output.

@DarkaMaul DarkaMaul force-pushed the fix-inheritance-printer-rebase branch from 77c67a0 to 4164039 Compare April 9, 2024 13:58
Copy link

coderabbitai bot commented Apr 9, 2024

Walkthrough

Walkthrough

The recent updates to the slither module introduce a new argument --include-interfaces to the inheritance-graph printer, allowing users to include or exclude interfaces in the output. Additionally, the inheritance graph now filters out contracts with "mock" in their names and virtual functions. The Slither class has been updated to handle the new argument, and tests have been added to validate the new functionality.

Changes

File Path Change Summary
slither/__main__.py Added --include-interfaces argument to include interfaces in the inheritance-graph printer.
slither/printers/inheritance/inheritance_graph.py Excluded contracts with "mock" in their name, removed inherited interfaces based on include_interfaces, and excluded virtual functions.
slither/slither.py Updated Slither class to initialize self.include_interfaces and removed an unnecessary line.
tests/e2e/printers/test_data/test_contract_names/C.sol Modified contract C to implement MyInterfaceX with new functions count() and increment().
tests/e2e/printers/test_printers.py Added tests for include/exclude interface behavior in the printer output.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Main as slither/__main__.py
    participant Slither as slither/slither.py
    participant Graph as inheritance_graph.py
    participant Test as test_printers.py

    User->>Main: Run with --include-interfaces
    Main->>Slither: Initialize with include_interfaces=True
    Slither->>Graph: Generate inheritance graph
    Graph->>Graph: Filter based on include_interfaces
    Graph->>User: Return filtered inheritance graph
    User->>Test: Run tests for interface inclusion
    Test->>Graph: Validate output with interfaces
    Graph->>Test: Return validation result
    Test->>User: Test results
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DarkaMaul
Copy link
Contributor

DarkaMaul commented Apr 9, 2024

This PR nows :

  • Adds a new include-interfaces command line switch if the user wants to include interface in the inheritance graph (default is False).
  • Checks for interfaces before displaying them
  • Removes virtual functions
  • Adds a test to ensure this works as appropriately

I think it is ready for review 🚀

Some picture before / after

Capture d’écran 2024-04-09 à 17 02 41

Capture d’écran 2024-04-10 à 11 14 30

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc767b1 and 8615b19.

Files selected for processing (5)
  • slither/main.py (1 hunks)
  • slither/printers/inheritance/inheritance_graph.py (3 hunks)
  • slither/slither.py (1 hunks)
  • tests/e2e/printers/test_data/test_contract_names/C.sol (1 hunks)
  • tests/e2e/printers/test_printers.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • slither/slither.py
Additional comments not posted (5)
tests/e2e/printers/test_data/test_contract_names/C.sol (2)

3-7: Interface MyInterfaceX is well-defined with appropriate function signatures.


9-20: Contract C correctly implements MyInterfaceX. Please confirm if the empty implementation of increment() is intentional.

slither/printers/inheritance/inheritance_graph.py (2)

101-115: The modifications to the inheritance list comprehension correctly implement the filtering of 'mock' contracts and conditional inclusion of interfaces based on the include_interfaces flag.


208-213: The changes to the output function to conditionally skip certain contracts are correctly implemented and align with the PR's objectives.

slither/__main__.py (1)

351-357: The addition of the --include-interfaces command-line argument is correctly implemented and well-documented. This new feature allows users to include interfaces in the inheritance graph as intended.

Comment on lines +37 to +48

# Lets also test the include/exclude interface behavior
# Check that the interface is not included
assert "MyInterfaceX" not in content

slither.include_interfaces = True
output = printer.output("test_printer.dot")
content = output.elements[0]["name"]["content"]
assert "MyInterfaceX" in content

# Remove test generated files
Path("test_printer.dot").unlink(missing_ok=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test structure for checking the inheritance printer's behavior with and without interfaces is well-implemented. Consider adding more comprehensive tests to cover additional edge cases.

Would you like assistance in drafting additional test cases?

@0xalpharush 0xalpharush merged commit ee7023c into dev Jun 4, 2024
83 checks passed
@0xalpharush 0xalpharush deleted the fix-inheritance-printer-rebase branch June 4, 2024 20:38
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.

4 participants