-
Notifications
You must be signed in to change notification settings - Fork 334
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
feat: add mock contracts for ERC20 and ERC721 #470
Conversation
Thanks for this! Only skimmed the code but lgtm so far, will take a closer look once we get CI passing. It seems we'll need to make a few changes so it compiles with older versions, see the run here or the screenshot below. The immutable fix is easy, we can just remove that The chain ID is a bit trickier but we found a good way to do that in For the constructor, I'm not sure if there's a solution offhand: We want to make sure there's no warnings regardless of the solc version used (you can of course test this easily by changing the |
@mds1, just wanted to let you know that I've pushed a commit to fix the incompatibilities with older solc versions (there were more 😁). Regarding the constructor, it's indeed a tricky one. I'm not entirely sure how to address it yet. For now, I've set the Another idea, aside from having two versions of the contracts, is to remove the constructor. We could then hard-code the metadata to default values like "Mock ERC20", "MOCK", decimals to 18, and add a wdyt? |
I was thinking something similar: remove the constructor and have an If the ignored error codes approach works though we should prefer that to keep the UX more familiar. It should be straightforward to test out the behavior and make sure it doesn’t suppress things for upstream users |
Here's a constructor workaround we used to use in forge-std which should work here /// @dev To hide constructor warnings across solc versions due to different constructor visibility requirements and
/// syntaxes, we put the constructor in a private method and assign an unused return value to a variable. This
/// forces the method to run during construction, but without declaring an explicit constructor.
uint256 private CONSTRUCTOR = _constructor();
function _constructor() private returns (uint256) {
// logic here
return 0;
} |
feat: add deployERC721Mock function in StdUtils refactor: remove constructor in mocks and add initialization function
It is a smart way of doing this, but I don't think it is entirely useful here, given that we also need to pass arguments in the constructor (name, symbol).
I ended up doing this way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call about the constructor, initialize
approach used here LGTM
chore: address grammar issues chore: add "I" prefix
@mds1 Addressed all your comments, lmk if there is anything else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you!
Would you mind adding a PR to the book's forge standard library reference documenting these mocks and deploy utils?
Closes #469