Skip to content

Feat/59 add natspec descriptions #549

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

mrscottyrose
Copy link

@mrscottyrose mrscottyrose commented May 14, 2025

Adds NatSpec descriptions to generated functions in the Contracts Wizard. This improves code documentation and maintainability by providing clear documentation for all generated functions.

Closes #59

Copy link
Contributor

github-actions bot commented May 14, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@mrscottyrose
Copy link
Author

I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement

@CoveMB
Copy link
Contributor

CoveMB commented May 15, 2025

Hey @mrscottyrose thanks for your MR ✨

Some considerations, when adding NatSpec we qwould probably want to align both content and formatting with what is found on the contract library here is an example
We might not want to add comments to overrides.

Let's wait for @OpenZeppelin/contracts input for defining the content of the comments.

@CoveMB CoveMB requested a review from a team May 15, 2025 20:51
@@ -0,0 +1,2 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing detailed change-set description

Copy link
Member

@ernestognw ernestognw left a comment

Choose a reason for hiding this comment

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

I like the idea at first. But I would prefer NatSpec documentation to be well thought and to provide useful information that's not available already in the documentation of the internal functions.

Since Wizard is a tool for developers, most of the information they'd need shows up on IDEs

Captura de pantalla 2025-05-15 a la(s) 2 56 01 p m

Concretely, I'd avoid using @param and @return tags since they bloat the result with things like

/// @dev Executes a call to target with value
/// @param target The target that is going to be called
/// @param value The value to be sent
/// @param data The data to call with
function execute(address target, uint256 value, bytes data)

Instead, I think developers would benefit if we have more insightful descriptions in strategic functions (those not obvious). For example

/// @dev Performs a `call` to the `target` address. Consider override this function
/// to check if the target has code (_execute allows calling EOAs)
function execute(address target, uint256 value, bytes data) {
  _execute(target, value, data);
}

Comment on lines 227 to 235
c.setFunctionComments(
[
`// IMPORTANT: Make sure Signer${opts.signer} is most derived than AccountERC7579`,
`// in the inheritance chain (i.e. contract ... is AccountERC7579, ..., Signer${opts.signer})`,
'// to ensure the correct order of function resolution.',
'// AccountERC7579 returns false for `_rawSignatureValidation`',
],
signerFunctions._rawSignatureValidation,
);
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to remove this? It's an important consideration for anyone copy pastes the code

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for that. I have reverted it back

@mrscottyrose
Copy link
Author

I've tried to resolve it according to the requirement could you please check and tell me if there's anything i could add or change?
Thank you.

],
},
initializeMultisig: {
kind: 'public' as const,
args: [
{ name: 'signers', type: 'bytes[] memory' },
{ name: 'threshold', type: 'uint256' },
Copy link
Contributor

Choose a reason for hiding this comment

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

threshold got removed, but should probably not

],
},
initializeMultisigWeighted: {
kind: 'public' as const,
args: [
{ name: 'signers', type: 'bytes[] memory' },
{ name: 'signers', type: 'address[] memory' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's revert all type changes has it they are out of scope for this MR

@CoveMB
Copy link
Contributor

CoveMB commented May 16, 2025

Thanks for making changes, please revert any type / number of arguments changes from the MR.
In it's current state it does not build the package properly.

@mrscottyrose
Copy link
Author

@CoveMB what about now? I couldn't understand why the netlify checks failed.

},
_rawSignatureValidation: {
kind: 'internal' as const,
args: [
{ name: 'hash', type: 'bytes32' },
{ name: 'signature', type: 'bytes calldata' },
{ name: 'signature', type: 'calldata' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Arguments change are out of scope of this MR

},

_baseURI: {
kind: 'internal' as const,
args: [],
returns: ['string memory'],
mutability: 'pure' as const,
mutability: 'view' as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this mutability be changed? Probably out of scope

@mrscottyrose
Copy link
Author

@CoveMB are these two changes are enough to merge the mr?? Or I have to change other things also?

@mrscottyrose
Copy link
Author

@CoveMB is there anything I need to change?

@@ -464,8 +498,9 @@ const functions = defineFunctions({
{ name: 'descriptionHash', type: 'bytes32' },
],
kind: 'internal',
returns: ['uint48'],
Copy link
Contributor

Choose a reason for hiding this comment

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

👆?

},

tokenURI: {
kind: 'public' as const,
args: [{ name: 'tokenId', type: 'uint256' }],
returns: ['string memory'],
mutability: 'view' as const,
mutability: 'pure' as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

👆?

],
},

mint: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why moving the functions orders here "mint"

],
},

_spendAllowance: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why adding this function?

],
},

_burn: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why adding this function?

@CoveMB
Copy link
Contributor

CoveMB commented May 21, 2025

@ernestognw could you validate/correct the comment's content?

…n ERC20 contract, updating arguments and comments for clarity
@@ -400,16 +400,6 @@ function addSuperchainERC20(c: ContractBuilder) {
functions._checkTokenBridge,
'pure',
);
c.setFunctionComments(
Copy link
Member

Choose a reason for hiding this comment

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

This comment text is still relevant for this scenario. It would be fine for it to overwrite the generic function comment for _checkTokenBridge

mrscottyrose and others added 2 commits May 22, 2025 05:30
…n ERC20 contract, updating arguments and comments for clarity
Co-authored-by: Eric Lau <ericglau@outlook.com>
@mrscottyrose
Copy link
Author

@ericglau sorry I was messing everything again and again. Could you please review the new commit? If there are any changes let me know thanks

@mrscottyrose
Copy link
Author

@CoveMB can you review it again?

Copy link
Contributor

@CoveMB CoveMB left a comment

Choose a reason for hiding this comment

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

Hi @mrscottyrose it seems some comments got added in multiple places for some function (like _rawSignatureValidation, CLOCL_MODE..), could you review those and consolidate the comments, in it's current state @openzeppelin/wizard does not build, to make sure it build you can run yarn prepare and it should build without errors

@mrscottyrose
Copy link
Author

@CoveMB can you check now? if everything is alright or not?

@CoveMB
Copy link
Contributor

CoveMB commented May 26, 2025

It seem that this comment has not been addressed? (seem like the specialised comment is deleted instead of overriding the general comment)

@CoveMB
Copy link
Contributor

CoveMB commented May 26, 2025

Thanks for making the code changes 🦾 you will also need to update the tests as the contract got modified (with the added natspecs)

@mrscottyrose
Copy link
Author

mrscottyrose commented May 28, 2025

@CoveMB I ran the test and some of the tests fails cuz I'm in windows. What should I do? Will I commit the generated test files?

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.

Add NatSpec description to generated functions
4 participants