This document provides comprehensive information about the testing setup and procedures for the Wuta-Wuta blockchain project.
The Wuta-Wuta project includes a comprehensive testing suite covering:
- Smart contract testing with Hardhat
- Frontend component testing with React Testing Library
- Integration testing across contracts
- Performance and gas optimization testing
- Security testing with Slither and Mythril
- End-to-end testing
Location: test/
MuseNFT.test.js- Tests for the NFT contractProjectManager.test.js- Tests for the project management contractintegration/integration.test.js- Cross-contract integration tests
helpers/hardhat-helper.js- Common testing utilities and helpers
performance/gas-benchmarks.test.js- Gas usage benchmarks
Location: src/components/__tests__/
CreateArt.test.js- Art creation form componentDashboard.test.js- User dashboard componentGallery.test.js- Art gallery component
Location: src/store/__tests__/
museStore.test.js- Main application storewalletStore.test.js- Wallet connection store
Ensure you have Node.js 18+ and npm installed:
node --version
npm --versionnpm installnpm run test:contractsnpm run test:contracts:coveragenpm run test:contracts:gasnpx hardhat test test/MuseNFT.test.jsnpm testnpm run test:coveragenpm run test:cinpm run test:integrationnpm run test:e2e- ✅ Deployment and initialization
- ✅ AI model registration
- ✅ Collaborative artwork creation
- ✅ Artwork evolution
- ✅ Royalty management
- ✅ Access control and permissions
- ✅ Reentrancy protection
- ✅ Edge cases and error handling
- ✅ Project creation and management
- ✅ Issue creation and tracking
- ✅ Status updates
- ✅ Access control
- ✅ Data retrieval functions
- ✅ Rendering and UI states
- ✅ User interactions
- ✅ Form validation
- ✅ Error handling
- ✅ Accessibility
- ✅ Responsive design
- ✅ State management
- ✅ API interactions
- ✅ Error handling
- ✅ Data persistence
The project includes comprehensive gas benchmarking:
npm run test:contracts:gas- AI Model Registration: < 50,000 gas
- Artwork Creation: < 300,000 gas
- Artwork Evolution: < 200,000 gas
- Project Creation: < 150,000 gas
- Issue Creation: < 100,000 gas
npm run test:loadnpm run security:slithernpm run security:mythril- ✅ Reentrancy attacks
- ✅ Integer overflow/underflow
- ✅ Access control vulnerabilities
- ✅ Business logic flaws
- ✅ Gas limit issues
Location: .github/workflows/test.yml
- Smart Contract Tests - Contract testing and coverage
- Frontend Tests - Component and store testing
- Integration Tests - Cross-contract testing
- Security Audit - Automated security analysis
- Performance Tests - Gas benchmarks and load testing
- Build Test - Application build verification
- Deploy Preview - Preview deployments for PRs
- Push to
mainanddevelopbranches - Pull requests to
mainanddevelopbranches
The test suite uses Hardhat's built-in network for testing:
- Local test network with instant mining
- Pre-funded test accounts
- Contract deployment utilities
jest.mock('../../store/museStore', () => ({
useMuseStore: () => ({
isConnected: true,
isLoading: false,
error: null,
artworks: [],
// ... other store properties
}),
}));jest.mock('ethers', () => ({
ethers: {
Contract: jest.fn(),
parseEther: (value) => BigInt(value * 1e18),
formatEther: (value) => (Number(value) / 1e18).toString(),
},
}));- Arrange, Act, Assert pattern
- Descriptive test names
- Test edge cases and error conditions
- Mock external dependencies
- Use helper utilities for common operations
- Group related tests with
describeblocks - Use
beforeEachfor test setup - Keep tests independent and isolated
- Use meaningful assertions
- Smart Contracts: > 90% line coverage
- Frontend Components: > 85% line coverage
- Store Logic: > 90% line coverage
# Run tests with verbose output
npx hardhat test --verbose
# Run specific test with console logs
npx hardhat test test/MuseNFT.test.js --show-stack-traces# Run tests with debug output
npm test -- --verbose
# Run tests in interactive mode
npm test -- --watch- Create test file in
test/directory - Use HardhatHelper for common operations
- Follow existing test patterns
- Include gas usage benchmarks for new functions
- Create test file in appropriate
__tests__/directory - Use React Testing Library
- Mock store dependencies
- Test user interactions and accessibility
- Increase gas limit in hardhat.config.js
- Optimize contract functions
- Check for infinite loops
- Use HardhatHelper time utilities
- Mock
block.timestampfor deterministic tests
- Use
awaitfor all async operations - Wrap async calls in
act()for React tests
Create a .env.test file for test-specific configurations:
# Test network configuration
TEST_NETWORK_URL=http://localhost:8545
TEST_PRIVATE_KEY=your_test_private_key
# API endpoints for testing
TEST_API_URL=http://localhost:3001/apiCoverage reports are generated in:
coverage/directory for smart contractscoverage/directory for frontend code
Test results are displayed in:
- Console output during test runs
- GitHub Actions workflow logs
- Coverage dashboard (if configured)
When contributing new features:
- Write tests for new functionality
- Ensure all existing tests pass
- Maintain or improve coverage percentages
- Update documentation as needed
- Add performance benchmarks for contract functions
- Fuzzing testing for smart contracts
- Visual regression testing for UI
- Performance monitoring in production
- Automated vulnerability scanning
- Contract formal verification
- Echidna for property-based testing
- Manticore for symbolic execution
- Storybook for component testing
- Cypress for advanced E2E testing
For questions or issues related to testing, please create an issue in the repository or contact the development team.