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

Show inherited functions in Debug (when deploying with hardhat) #564

Merged

Conversation

FilipHarald
Copy link
Contributor

@FilipHarald FilipHarald commented Oct 10, 2023

Description

This adds information in the Debug-view. It's now possible to see which functions are inherited, and from where they are inherited. Unfortunately, functions that use override show up with inherited tooltip.

Additional Information

Related Issues

Related discussion: #558

Your ENS/address: harmont.eth

@FilipHarald
Copy link
Contributor Author

I still need to add this to the view-vars and read-functions.

But I started the PR so I can get some feedback or tips on the UI.

@FilipHarald
Copy link
Contributor Author

The first two commits are implemented with tooltip and data-tip. But in the current branch I try to build my own tooltip. But it's a bit tricky.

function-origin2.mp4

@FilipHarald
Copy link
Contributor Author

Also, I don't think this will work when overriding functions.

@FilipHarald FilipHarald changed the title Show inherited functions in Debug (from hardhat) Show inherited functions in Debug (when deploying with hardhat) Oct 10, 2023
@carletex carletex marked this pull request as draft October 10, 2023 18:21
@FilipHarald
Copy link
Contributor Author

I made some modifications now. This is how it looks:

function-origin3.mp4

@FilipHarald
Copy link
Contributor Author

I don't know if I should split packages/hardhat/deploy/99_generateTsAbis.ts or keep it as is?

Also, the tooltip looks the same for all three (vars, readFunc and writeFunc) should I make that to a seperate component or keep them where they are now?

@FilipHarald FilipHarald marked this pull request as ready for review October 11, 2023 20:06
Copy link
Member

@carletex carletex left a comment

Choose a reason for hiding this comment

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

This is looking great @FilipHarald !!

Left some minor comments. Also tagging Shiv & Rinat so the can test and review.

Thanks!

@rin-st
Copy link
Member

rin-st commented Oct 12, 2023

Thank you for pr, @FilipHarald !

Noticed that color of tooltip in light mode the same as bg of methods list.
Снимок экрана 2023-10-12 в 23 14 33

And I'm not sure that we want to sort methods: own in alphabetical order -> inherited it alphabetical order. It's good but I think often inherited methods are main. You don't need to change it right now, I wrote it just to discuss

Other than that looks good, gj!

@FilipHarald
Copy link
Contributor Author

FilipHarald commented Oct 13, 2023

Thanks for the review @rin-st !

Noticed that color of tooltip in light mode the same as bg of methods list. ...

Oh, you're right. I can see if I there is an easy fix.

And I'm not sure that we want to sort methods: own in alphabetical order -> inherited it alphabetical order. It's good but I think often inherited methods are main. You don't need to change it right now, I wrote it just to discuss

OK, I would be happy to discuss this. I can tell you my reasoning and I'd be happy to hear yours! So for me this is a problem because I'm still new to Solidity. So when I extend some interface, like Ownable, I get some functions that I don't know what they're doing yet. For Ownable specifically, I'm not using any of the functions. I'm just using the modifier on my own defined functions. That's why I want them at the bottom :)

@rin-st
Copy link
Member

rin-st commented Oct 13, 2023

That's why I want them at the bottom

In some cases you need to use inherited methods often. But I think sorted is ok, at least it's easy to find what you need.

One more thing. Noticed that when you override inherited methods, it's still marked as inherited. Is it possible to mark that methods "overridden" or "inherited, overridden"?

And if possible sort: own -> overridden -> other inherited

@technophile-04
Copy link
Collaborator

Unfortunately, functions that use override show up with inherited tooltip

Noticed that when you override inherited methods, it's still marked as inherited. Is it possible to mark that methods "overridden" or "inherited, overridden"?

Also find a kind of edge case which is kidof related to above comments, when you just import a contract but don't inherit it it still gives inherited :

Screenshot 2023-10-15 at 9 11 54 PM

Example Contract :
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc)
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyContract {
	// State Variables
	address public immutable owner;

	constructor(address _owner) {
		owner = _owner;
	}
}

Also one thing I think it would be really great if we make inheritedFunctions: InheritedFunctions; optional in contract.ts
and handle the same case in Debug Contracts components.

Because there might a slight case where we couldn't get this data in foundry and it will break frontend for foundry when people use it through CLI(#436)

also if we people want to add external contracts which they already have deployed it might be hard from them to get this inheritedFunctions data if they want to manually put abi and address in deployedContracts.ts file

Tysm @FilipHarald great job!!

@FilipHarald
Copy link
Contributor Author

FilipHarald commented Oct 19, 2023

Replying to both of these:
@rin-st :

One more thing. Noticed that when you override inherited methods, it's still marked as inherited. Is it possible to mark that methods "overridden" or "inherited, overridden"?

And if possible sort: own -> overridden -> other inherited

@technophile-04 :

Also find a kind of edge case which is kidof related to above comments, when you just import a contract but don't inherit it it still gives inherited :

The problem is that I have not yet found any linking of what is an inherited function and not. The only thing I'm doing is looking at the imported contracts, and then cross-reference the functions in their contracts with the ones in the current one. But the current contract will not show if the function in the ABI if it is overridden or not. Maybe it's possible to get from when compiling the Solidity, but I have not yet found a solution to this.

@FilipHarald
Copy link
Contributor Author

Currently, the only "blocker" is the edge-cases that I summarized above. (#564 (comment))

@technophile-04
Copy link
Collaborator

I think this looks almost ready for merge 🙌

Currently, the only "blocker" is the edge-cases that I summarized above. (#564 (comment))

Yup to summarize, we get unwanted Inherited Tooltip from on functions :

  1. When we override a function
  2. When we have an unused Import contract which internally has the same name as our contract function (Show inherited functions in Debug (when deploying with hardhat) #564 (comment))

Even I tried debugging it but no luck finding a solution with all the available / generated / compiled files :(

Nevertheless, I think this is ready to merge since 1st edge case feels not that deal breaker and 2nd one is very less likely to happen

But let's see what others have to say 🙌, Tysm @FilipHarald for proposing and tackling it !!

@rin-st
Copy link
Member

rin-st commented Oct 26, 2023

Looks much better!

I found one more edge case, sorry 😄 . It's very rare and I don't know if someone will ever meet it.

See solidity-by-example . I copied contracts and everything works as expected, except contract E - it should show "inherited from contracts/B.sol" or "inherited from contracts/C.sol, contracts/B.sol"
Снимок экрана 2023-10-27 в 00 03 11

I'm not sure if we need to consider this, but if it's fixable I think we need to do it.
Branch with this case https://github.com/scaffold-eth/scaffold-eth-2/tree/inherited-edge-case

@technophile-04
Copy link
Collaborator

Tysm @rin-st great find 🙌

Created FilipHarald#1 which solves :

#564 (comment) and #564 (comment)

@FilipHarald
Copy link
Contributor Author

I think everything is merged now. Thanks again @rin-st and @technophile-04 for help with edge-cases.

@FilipHarald FilipHarald marked this pull request as draft November 3, 2023 13:16
@FilipHarald FilipHarald marked this pull request as ready for review November 3, 2023 13:20
Copy link
Member

@rin-st rin-st left a comment

Choose a reason for hiding this comment

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

lgtm!

@technophile-04
Copy link
Collaborator

Tysm @FilipHarald 🙌, I think this is really nice !!

Next steps :

  1. Let's get it working for foundry

  2. And try to solve pt.1 for Show inherited functions in Debug (when deploying with hardhat) #564 (comment)

Thanks again !!

@technophile-04 technophile-04 merged commit 3d4654a into scaffold-eth:main Nov 11, 2023
1 check passed
@FilipHarald FilipHarald deleted the feat/contract_function_origins branch November 11, 2023 15:56
@FilipHarald FilipHarald restored the feat/contract_function_origins branch November 11, 2023 15:56
@FilipHarald FilipHarald deleted the feat/contract_function_origins branch November 11, 2023 15:58
carletex pushed a commit that referenced this pull request Nov 15, 2023
* Fix typos in comments (#596)
* Show inherited functions in Debug (when deploying with `hardhat`) (#564)
@github-actions github-actions bot mentioned this pull request Nov 15, 2023
carletex pushed a commit that referenced this pull request Nov 15, 2023
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

 - Fix typos in comments (#596)
 - Show inherited functions in Debug (when deploying with hardhat) (#564)
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