Skip to content

Conversation

@Otaiki1
Copy link

@Otaiki1 Otaiki1 commented Oct 25, 2025

Summary

Added comprehensive Foundry tests for ERC721 implementations covering both basic ERC721Facet and ERC721EnumerableFacet functionality.

Changes Made

  • Created test/ERC721/ERC721.t.sol - 34 tests for ERC721Facet covering minting, burning, transfers, approvals, safe transfers, error handling, and events
  • Created test/ERC721/ERC721Enumerable.t.sol - 34 tests for ERC721EnumerableFacet covering enumeration features, token indexing, and complex transfer scenarios
  • Added test helper contracts - TestableERC721Facet and TestableERC721EnumerableFacet with custom mint/burn functions
  • Created ERC721ReceiverMock - Mock contract for testing safe transfers with configurable behavior
  • Fixed ERC721Enumerable library bug - Missing ownerOf mapping assignment in mint function
  • Added fuzz tests - 5 randomized tests for comprehensive input validation

Checklist

Before submitting this PR, please ensure:

  • Code follows the Solidity feature ban - No inheritance, constructors, modifiers, public/private variables, external library functions, using for directives, or selfdestruct

  • Code follows Design Principles - Readable, uses diamond storage, favors composition over inheritance

  • Code matches the codebase style - Consistent formatting, documentation, and patterns (e.g. ERC20Facet.sol)

  • Code is formatted with forge fmt

  • Tests are included - All new functionality has comprehensive tests

  • All tests pass - Run forge test and ensure everything works

  • Documentation updated - If applicable, update relevant documentation

Make sure to follow the CONTRIBUTING.md guidelines.

Additional Notes

  • 73 total tests (34 ERC721 + 34 ERC721Enumerable + 5 fuzz tests) all passing
  • Test coverage includes: minting, burning, transfers, approvals, enumeration, error conditions, events, and edge cases
  • Fixed storage structure mismatch between ERC721EnumerableFacet and its library
  • Tests use proper diamond storage patterns
    This PR closes Add foundry tests for the ERC721 implementations #11

@mudgen
Copy link
Contributor

mudgen commented Oct 26, 2025

@Otaiki1 Thank you! We recently added tests for ERC20 functionality. Can you please review the tests for the ERC20 functionality and see that your new tests are consistent with them. It looks like you took the same/similar approach which is good. Also please review this new testing documentation for the project: https://github.com/Perfect-Abstractions/Compose/blob/main/test/README.md and make any changes you think are necessary to follow that.

@panditdhamdhere
Copy link
Collaborator

Great work legend! 👏🏼

Can you do following before merging?

  • Create test/README.md documentation
  • Add specific tests for the enumeration bug fix

@Otaiki1
Copy link
Author

Otaiki1 commented Oct 26, 2025

@mudgen , i have made all appropriate changes

Copy link
Collaborator

@panditdhamdhere panditdhamdhere left a comment

Choose a reason for hiding this comment

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

Excellent job!

@mudgen
Copy link
Contributor

mudgen commented Oct 26, 2025

Looks good. @adamgall, can you review this pull request?

@github-actions
Copy link

github-actions bot commented Oct 26, 2025

Coverage Report

Coverage

Metric Coverage Details
Lines 68% 817/1195 lines
Functions 80% 181/227 functions
Branches 51% 95/186 branches

Last updated: Wed, 29 Oct 2025 01:12:46 GMT for commit 13b099c

Copy link
Collaborator

@adamgall adamgall left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @Otaiki1! Some feedback:

  • We don't need an ERC721-specific README file; you can delete that please.
  • this PR is missing harnesses and tests for LibERC721 and LibERC721Enumerable. Please look at the existing test files in this repo for more inspiration and patterns.
  • ideally could include some tests which include gas benchmarks (confirm some function doesn't use more than x gas).

@Otaiki1
Copy link
Author

Otaiki1 commented Oct 28, 2025

@adamgall , i have made the specified changes

@maxnorm maxnorm requested a review from adamgall October 28, 2025 23:56
@adamgall
Copy link
Collaborator

@Otaiki1 can you please run forge fmt?

Copy link
Collaborator

@adamgall adamgall left a comment

Choose a reason for hiding this comment

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

Just a couple of comments. Also, please run forge fmt. Thank you!

Comment on lines 19 to 26
/// @notice Exposes LibERC721Enumerable.mint as an external function
/// @dev Note: This fixes the library bug by manually setting ownerOf
function mint(address _to, uint256 _tokenId) external {
LibERC721Enumerable.mint(_to, _tokenId);
// Fix the library bug by manually setting ownerOf
LibERC721Enumerable.ERC721EnumerableStorage storage s = LibERC721Enumerable.getStorage();
s.ownerOf[_tokenId] = _to;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should probably just fix the bug in this PR... what do you think @mudgen @maxnorm ?

Seems like the mint function in LibERC721Enumerable doesn't set ownerOf for the new token being minted.

Copy link
Contributor

@mudgen mudgen Oct 31, 2025

Choose a reason for hiding this comment

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

@adamgall
Oh yea, that is a bug. We need to fix that. I added a bug issue: #159

Copy link
Collaborator

@maxnorm maxnorm Oct 31, 2025

Choose a reason for hiding this comment

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

@mudgen @adamgall Since you are more aware for this PR, 2 new PRs were submitted for the fix.

#160
#161

PR #160 provide only the fix and #161 also implemented tests for ERC721Enumerable.

Can be worth to compare the tests between this PR and the other.

Copy link
Collaborator

@adamgall adamgall Oct 31, 2025

Choose a reason for hiding this comment

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

@Otaiki1 #160 has been merged, so can you please merge main into your branch and update the LibERC721EnumerableHarness to remove the "fix" for the ownerOf bug.

@Otaiki1
Copy link
Author

Otaiki1 commented Oct 30, 2025

@adamgall , all implemented

@adamgall
Copy link
Collaborator

adamgall commented Nov 1, 2025

@Otaiki1 #111 (comment)

@mudgen
Copy link
Contributor

mudgen commented Nov 3, 2025

@Otaiki1 I think we have some failing tests. I am eager to get this pull request merged. I appreciate your work.

@mudgen
Copy link
Contributor

mudgen commented Nov 7, 2025

@Otaiki1 bump

@mudgen mudgen closed this Nov 16, 2025
@mudgen mudgen reopened this Nov 16, 2025
@mudgen mudgen added the Stale Work needs an update from the person working on it. label Nov 16, 2025
@mudgen mudgen added the Request Status Update Requesting the author to give an update on the status of the work. label Nov 16, 2025
@mudgen mudgen closed this Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Request Status Update Requesting the author to give an update on the status of the work. Stale Work needs an update from the person working on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add foundry tests for the ERC721 implementations

5 participants