Test Explanations
π Understanding Every Test
This page explains what each test does and why it matters for your security.
Total Tests: 950 (753 Hardhat + 181 Foundry + 12 Echidna + 4 Manticore)
Test Categories
1. Token Core Tests (45 tests)
Purpose: Verify the fundamental token operations work correctly.
Deployment Tests (5 tests)
β Should deploy with correct initial supplyWhat it tests: Token starts with exactly 1,296,000,000 S360
Why it matters: Prevents unauthorized token creation
Attack prevented: Infinite token minting exploit
β Should distribute to 14 initial walletsWhat it tests: Initial allocation goes to correct addresses
Why it matters: Ensures fair launch, no hidden allocations
Attack prevented: Developer backdoor tokens
Transfer Tests (10 tests)
β Should allow transfers between accounts
β Should fail transfer with insufficient balance
β Should prevent transfers to zero addressWhat they test: Tokens move correctly, balances update, edge cases handled
Why it matters: Core functionality must be bulletproof
Attacks prevented:
- Double spending
- Balance manipulation
- Token burning via zero address
Emergency Pause Tests (4 tests)
β Should allow owner to pause
β Should prevent transfers when paused
β Should allow owner to unpauseWhat they test: Emergency stop mechanism works
Why it matters: Can halt operations if exploit discovered
Attack prevented: Continuing losses during active attack
2. Staking Security Tests (58 tests)
Purpose: Ensure staking is safe and rewards are fair.
Staking Core (15 tests)
β Should allow staking tokens
β Should update staked balance
β Should prevent staking zero amountWhat they test: Users can stake, balances tracked correctly
Why it matters: Users' tokens must be safe when staked
Attacks prevented:
- Stake without tokens
- Double staking
- Stake overflow
Reward Calculation (12 tests)
β Should calculate rewards correctly
β Should handle compound rewards
β Should prevent reward overflowWhat they test: Reward math is accurate and safe
Why it matters: Wrong math = stolen rewards or contract drain
Attacks prevented:
- Reward manipulation
- Integer overflow to steal funds
- Reward pool drainage
Reentrancy Protection (8 tests)
β Should prevent reentrancy on stake
β Should prevent reentrancy on unstake
β Should prevent reentrancy on claimWhat they test: Functions can't be called recursively
Why it matters: Reentrancy = THE most common DeFi hack
Real-world example: DAO hack (2016) - $60M stolen
Attack prevented: Recursive calls to drain contract
Emergency Withdraw (6 tests)
β Should allow emergency withdraw
β Should return all staked tokens
β Should forfeit rewards on emergencyWhat they test: Users can always get their principal back
Why it matters: Even if rewards break, principal is safe
Attack prevented: Funds locked forever (rugpull)
3. Bonding Curve Attack Tests (52 tests)
Purpose: Ensure the price mechanism can't be exploited.
Flash Loan Protection (8 tests)
β Should enforce MAX_PURCHASE_PER_BLOCK
β Should prevent same-block buy and sellWhat they test: Can't buy and sell in same transaction
Why it matters: Flash loans can manipulate price
Real-world example: Harvest Finance hack - $34M stolen
Attack prevented: Price manipulation via flash loans
Price Manipulation (12 tests)
β Should prevent artificial price pumping
β Should enforce slippage protection
β Should prevent sandwich attacksWhat they test: Price moves fairly, no manipulation
Why it matters: Fair price = fair market
Attacks prevented:
- Front-running
- Sandwich attacks
- MEV extraction
Reserve Backing (10 tests)
β Should maintain reserve >= backing_value
β Should prevent reserve drainWhat they test: Always enough collateral for tokens
Why it matters: Prevents insolvency
Real-world example: Iron Finance collapse - $2B lost
Attack prevented: Bank run / reserve drain
4. Governance Attack Tests (89 tests)
Purpose: Ensure governance can't be hijacked.
Proposal Attacks (25 tests)
β Should prevent proposal execution without quorum
β Should enforce voting delay
β Should enforce timelock on executionWhat they test: Can't execute proposals without proper voting
Why it matters: Prevents governance takeover
Real-world example: Beanstalk Farms - $182M stolen via governance
Attacks prevented:
- Flash loan governance attack
- Malicious proposal execution
- Timelock bypass
Voting Manipulation (18 tests)
β Should prevent double voting
β Should prevent delegation loops
β Should prevent vote buyingWhat they test: Votes are counted correctly, can't be duplicated
Why it matters: One token = one vote (democracy)
Attacks prevented:
- Sybil attacks
- Vote manipulation
- Delegation chain exploits
Timelock Attacks (12 tests)
β Should enforce minimum delay
β Should prevent timelock bypass
β Should prevent queue manipulationWhat they test: Proposals can't execute immediately
Why it matters: Gives community time to react
Attack prevented: Instant malicious proposal execution
Sandwich Attacks (8 tests)
β Should prevent proposal state manipulation
β Should prevent execution frontrunningWhat they test: Can't manipulate proposal execution order
Why it matters: Fair execution = fair governance
Attack prevented: MEV on governance actions
5. Economic Invariant Tests (28 tests)
Purpose: Mathematical properties that MUST always be true.
Token Conservation
β Total supply = sum of all balancesWhat it tests: Tokens don't appear or disappear
Why it matters: Conservation of value
If this breaks: Tokens being created from nothing
Staking Invariants
β Rewards pool β₯ pending rewards
β Total staked β€ contract balanceWhat they test: Can't pay out more than pool has
Why it matters: Contract must remain solvent
If this breaks: Unable to pay rewards (bankrupt)
Bonding Curve Invariants
β Reserve β₯ backing_value(supply)
β Price = f(supply) is monotonicWhat they test: Price follows curve, reserve sufficient
Why it matters: Mathematical guarantees
If this breaks: Price manipulation or insolvency
6. Foundry Tests (181 tests)
Purpose: Test with 1.00M+ random inputs to find edge cases.
Property-Based Testing
β testFuzz_TransferPreservesTotalSupply (10,000 runs)What it tests: ANY transfer amount, from/to address = supply unchanged
Why it matters: Catches edge cases humans miss
How it works: Runs 10,000 random scenarios
Invariant Testing
β testInvariant_BalancesAlwaysNonNegative (10,000 runs)What it tests: Balances can NEVER go negative
Why it matters: Negative balance = broken accounting
How it works: Tries to break it 10,000 different ways
Real-World Impact
Why Each Category Matters
| Category | Tests | Real Hacks Prevented |
|---|---|---|
| Token Core | 45 | Infinite mint exploits |
| Staking | 58 | Reentrancy attacks ($60M+ saved) |
| Bonding Curve | 52 | Flash loan attacks ($34M+ saved) |
| Governance | 89 | Governance takeovers ($182M+ saved) |
| Invariants | 28 | Accounting exploits (countless) |
| Fuzz Tests | 79 | Edge cases (unknown losses) |
Total value protected: $276M+ (based on similar past exploits)
Test Methodology
How We Write Tests
-
Identify Attack Vector
- Research real hacks
- Analyze vulnerability reports
- Study attack patterns
-
Write Exploit Test
- Code the actual attack
- Try to steal/manipulate/break
-
Verify Protection
- Test should FAIL (attack blocked)
- If test passes = vulnerability found
-
Document
- Explain what it prevents
- Link to real-world examples
Example: Reentrancy Test
it("Should prevent reentrancy on unstake", async function() {
// Setup: Attacker deploys malicious contract
const attacker = await MaliciousContract.deploy(staking);
// Step 1: Attacker stakes tokens
await staking.connect(attacker).stake(ethers.parseEther("1000"));
// Step 2: Attacker tries to unstake recursively
// (calls unstake() again before first call finishes)
await expect(
attacker.attackUnstake()
).to.be.reverted; // β
Attack blocked
// Verify: Attacker only gets their stake once
const balance = await token.balanceOf(attacker.address);
expect(balance).to.equal(ethers.parseEther("1000")); // Not 2000
});What this prevents: The DAO hack (2016) that stole $60M
Coverage Analysis
What Gets Tested
Coverage (current):
- Overall (incl. mocks): 61.22%
- Core contracts avg: 84.41%
Breakdown details are available in the contracts repo coverage outputs.Uncovered Code (1.5%)
The 1.5% uncovered consists of:
- Emergency circuit breakers - Can't test without breaking production
- Governance emergency pause - Requires multisig (tested manually)
- Self-destruct prevention - Solidity 0.8+ prevents this by default
Uncovered code is reviewed manually; core contracts are additionally validated with invariant-style tests and extensive attack scenarios.
How to Verify Tests Yourself
# Clone repo
git clone https://github.com/JaisonKeiver/seal360-contracts.git
cd seal360-contracts
# Install dependencies
npm install
# Run specific test
npx hardhat test test/SEAL360Token.exhaustive.test.cjs
# Run all tests
npm test
# Run with gas reporting
npm run test:gas
# Run coverage
npm run coverageTest Evolution
| Version | Tests | New Tests | Focus |
|---|---|---|---|
| v3.3.5 | 950 | updated | Added Echidna + Manticore + test count refresh |
| v3.3.3 | 443 | +30 | Bonding curve edge cases |
| v3.3.2 | 413 | +16 | Security fixes validation |
| v3.3.0 | 397 | +84 | Fee distribution system |
| v3.2.0 | 313 | +52 | Reentrancy protection |
Questions?
Want to Understand a Specific Test?
- View test source code on GitHub β (opens in a new tab)
- Ask in Discord β (opens in a new tab)
- Open a discussion β (opens in a new tab)
Report a Test Gap?
Found a scenario we're not testing?