4bfdf23be116d682e3fc3865124ed10b4bff6aae
Cuna Finance Testing Suite
This is a clean, modern Hardhat project containing the CunaFinanceBsc contract with comprehensive testing.
Project Structure
cuna/
├── contracts/
│ ├── CunaFinanceBsc.sol # Main contract (non-upgradeable version)
│ └── mocks/
│ ├── MockERC20.sol # Mock token for testing
│ └── MockPriceOracle.sol # Mock oracle for testing
├── test/
│ └── CunaFinanceBsc.test.js # Comprehensive test suite (✅ 12/12 pass)
├── hardhat.config.js # Modern Hardhat v2 configuration
└── package.json # Clean modern dependencies
Key Features Implemented & Tested
✅ Epoch-Based Staking System
- Stake creation (individual and batch)
- NEW:
endEpochfunction withpaybackPercentparameter - Unlock percentage calculations based on TVL/liability ratios
- Unclaimed funds tracking and claiming
✅ Marketplace Functionality
- Listing stakes for sale by payback value
- Protocol share mechanism (50% of price/value difference)
- Cancellation fees
- Purchase mechanics
- History tracking
✅ Access Control
- Owner management (add/remove)
- Bot authorization
- Proper permission checks
✅ Admin Functions
- Parameter updates (lockup, delays, percentages)
- Fee configuration
Dependencies
- Hardhat v2.26 - Modern build system
- OpenZeppelin v5 - Latest security contracts
- Ethers v6 - Latest Ethereum library
- Chai v4 - Testing assertions
Running Tests
# Install dependencies
npm install
# Compile contracts
npm run compile
# Run tests
npm run test
# Clean build artifacts
npm run clean
Contract Changes from Original
- Removed Upgradeable Pattern: Converted from upgradeable to regular contract
- Dynamic Owner: Constructor uses
msg.senderinstead of hardcoded address - Fixed Access Control:
addBotfunction usesonlyOwnermodifier - Added Validation: Zero address checks for admin functions
- New Epoch Parameter:
endEpochnow acceptspaybackPercentparameter
Test Results
CunaFinanceBsc Basic Tests
Basic Functionality
✔ Should deploy and initialize correctly
✔ Should create user stakes
✔ Should batch create user stakes
✔ Should end epochs correctly
✔ Should handle access control correctly
✔ Should calculate net stakes correctly
✔ Should handle marketplace minimum correctly
✔ Should manage owners correctly
Marketplace Basic Tests
✔ Should list stakes for sale
✔ Should enforce minimum listing value
✔ Should handle cancellations correctly
Error Handling
✔ Should reject invalid operations
12 passing (717ms)
Next Steps
- Expand Test Coverage: Add more comprehensive marketplace and epoch scenarios
- Mock Token Integration: Add ERC20 token interaction tests
- Event Testing: Add comprehensive event emission verification
- Gas Optimization: Analyze gas costs and optimize
- Deployment Scripts: Add deployment and verification scripts
This project demonstrates the complete testing infrastructure for the CunaFinanceBsc contract with the new paybackPercent functionality working correctly.
Description
Languages
JavaScript
100%