Skip to content

feat: add mock contract boilerplate for testing #5554

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

Conversation

sivaratrisrinivas
Copy link

This PR adds mock contract boilerplate code for usage in testing as requested in issue #5491. It includes:

  • MockERC20.sol: A simple ERC20 implementation with mint and burn functions
  • MockERC721.sol: A simple ERC721 implementation with mint, safeMint, and burn functions

These mock contracts are placed in the contracts/testing/token/ directory and are intended for developers to use in their tests without having to create their own implementations.

Motivation

As mentioned in the issue, this is a common testing pattern in Solidity. Developers frequently need to create mock token implementations for testing purposes. By providing these implementations in the library, we can reduce boilerplate code and make testing easier.

Testing

Comprehensive tests have been added for both mock contracts:

  • test/testing/token/MockERC20.test.js
  • test/testing/token/MockERC721.test.js

All tests are passing.

Documentation

Documentation has been added:

  • contracts/testing/README.md: General documentation for the testing utilities
  • contracts/testing/token/README.md: Specific documentation for the token mocks

Fixes #5491

sivaratrisrinivas and others added 3 commits February 27, 2025 00:33
This adds a uniquifySorted function to remove duplicates from sorted arrays. The function has O(n) time complexity and works with uint256, address, and bytes32 array types. This is particularly useful when mappings cannot be utilized, and provides an easy way to combine Array.sort() + Array.uniquifySorted().

Fixes OpenZeppelin#5520

Co-Authored-By: Srinivas Sivaratri <[email protected]>
This adds a uniquifySorted function that removes duplicates from sorted arrays. Implements functionality requested in issue OpenZeppelin#5520.

Co-Authored-By: Srinivas Sivaratri <[email protected]>
This commit adds MockERC20 and MockERC721 contracts in the testing/token directory. These contracts provide simple implementations that can be used by developers for testing purposes without having to create their own implementations.

Fixes OpenZeppelin#5491
Copy link

changeset-bot bot commented Mar 5, 2025

🦋 Changeset detected

Latest commit: 4a57d72

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openzeppelin-solidity Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

socket-security bot commented Mar 5, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected]2.22.19 Transitive: eval, unsafe +254 212 MB kanej
pypi/[email protected] None +2 48.6 MB certora, shellyg
pypi/[email protected] None 0 1.08 MB daejunpark, justin_gerard

View full report↗︎

@Amxx
Copy link
Collaborator

Amxx commented Mar 6, 2025

The hardhat expose plugin already provide all the mocks we need.

I'm sorry I have to say that, but if you continue submitting PR that do not follow the contributing guideliness, we'll have to block your account.

@Amxx Amxx closed this Mar 6, 2025
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.

Feature: add Mock Contract Boilerplate for usage in library
2 participants