This project is a comprehensive testing framework designed to interact with and validate the functionality of ERC-721 (NFT) smart contracts. It uses Hardhat to simulate blockchain behavior and includes a wide range of test cases for commonly used ERC-721 methods.
- ✅ Automated Testing: Covers methods like
balanceOf,ownerOf,transferFrom,safeTransferFrom,approve,setApprovalForAll,getApproved, andisApprovedForAll. - 🛡️ Input Validation: Tests invalid and edge case inputs to ensure robust error handling.
- 🧑💻 Account Impersonation: Uses Hardhat’s impersonation feature to simulate actions from specific accounts.
- 📊 CSV Reporting: Outputs test results to a CSV file for easy analysis and review.
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Install dependencies:
npm install
Run all tests with:
node src/main.js- Input: Contract addresses should be listed in
input/addresses.csv. There are two scripts inside theinputdirectory that can fetch the addresses from CoinMarketCap and generate the csv file. - Execution: The main script iterates through each contract and runs relevant test suites.
- Output: Test results are saved to a CSV file for easy inspection.
src/
├── main.js # Entry point to execute all tests
├── tests/ # Contains test files for ERC721 methods
├── helpers/ # Utility functions used by tests
- balanceOf: Validates token balance queries and handles invalid addresses.
- ownerOf: Checks ownership of token IDs and validates error handling for invalid tokens.
- transferFrom / safeTransferFrom: Tests token transfers and edge cases.
- approve / setApprovalForAll: Ensures operator approvals are handled correctly.
- getApproved / isApprovedForAll: Verifies approval status queries for tokens and operators.
To test the setApprovalForAll method:
- Add the target contract address to
addresses.csv. - Run:
npx hardhat run src/main.js
- Check the output CSV for results.
This project is licensed under the MIT License. See the LICENSE file for more information.