Skip to content

Add comprehensive contract test suite (unit + fuzz tests) - Issue #39#51

Open
paulinaapeh8 wants to merge 1 commit into
Kalebtron1:mainfrom
paulinaapeh8:feature/issue-39-contract-tests
Open

Add comprehensive contract test suite (unit + fuzz tests) - Issue #39#51
paulinaapeh8 wants to merge 1 commit into
Kalebtron1:mainfrom
paulinaapeh8:feature/issue-39-contract-tests

Conversation

@paulinaapeh8
Copy link
Copy Markdown
Contributor

Summary

Closes #39: Suite de tests para contratos (unit + fuzz)

Implemented comprehensive unit and property-based test coverage for all three Soroban smart contracts with 110 total tests:

  • staking_pool: 42 tests (23 unit + 19 fuzz-like property tests)
  • vinculo_lending: 37 tests (21 unit + 16 fuzz-like property tests)
  • vinculo_sbt: 31 tests (16 unit + 15 fuzz-like property tests)

Key Invariants Protected

Staking Pool

✅ Balance never goes negative
✅ Only valid months (1, 3, 6, 12) accepted
✅ Correct APY mapping (4%, 7%, 11%, 18%)
✅ Interest calculation: (principal × APY × months) / 1200
✅ Unlock time strictly monotonic with duration
✅ Stake info properly cleared after unstaking

Vinculo Lending

✅ Tier limits strictly increase (300M < 600M < 1.5B < 5B XLM)
✅ APY rates decrease with tier (12% > 8% > 5% > 4%)
✅ Loan amount never exceeds tier limit
✅ Total owed always ≥ principal
✅ Repayment correctly handled (partial, full, overpayment)

Vinculo SBT

✅ Tier values strictly in range 1-4
✅ Tier 0 is default/revoked state
✅ Only admin can mint/revoke (SBT non-transferable)
✅ Metadata (name, symbol) constant
✅ Tier immutability without operations

Implementation Details

Test Location

All tests are embedded in contract source files using Rust's #[cfg(test)] modules:

  • Tests next to implementation for easy review
  • Consistent naming: test_[category]_[specific_case]
  • Property-based coverage with fuzz-like edge cases

Running Tests

# All contracts
./backend/contracts/run-tests.sh

# Individual contract
cd backend/contracts/staking_pool && cargo test --lib

# Specific test
cargo test --lib test_apy_mapping_1_month

Test Data & Reproducibility

  • All amounts deterministic and reproducible
  • Coverage ranges: 1 unit to i128::MAX/2
  • No external dependencies or network calls
  • Each test <1ms (total suite ~1s)

Files Changed

  • backend/contracts/staking_pool/src/lib.rs - Added 42 tests
  • backend/contracts/vinculo_lending/src/lib.rs - Added 37 tests
  • backend/contracts/vinculo_sbt/src/lib.rs - Added 31 tests
  • backend/contracts/TEST_SUITE.md - Comprehensive test documentation
  • backend/contracts/README_TESTS.md - Quick start guide
  • backend/contracts/run-tests.sh - Unified test runner script

Acceptance Criteria Met

✅ PR includes reproducible test commands
✅ Reviewer can run tests locally and verify results
✅ PR description states which invariants are tested
✅ Consistent test naming and setup across contracts
✅ Tests embedded next to implementation
✅ Both unit and property-based (fuzz) coverage
✅ Deterministic test setup and data

…lebtron1#39

## Summary
Implemented complete test coverage for all three Soroban smart contracts:
- staking_pool: 42 tests (23 unit + 19 fuzz-like property tests)
- vinculo_lending: 37 tests (21 unit + 16 fuzz-like property tests)
- vinculo_sbt: 31 tests (16 unit + 15 fuzz-like property tests)
Total: 110 comprehensive tests

## Key Invariants Protected

### Staking Pool
- Balance never goes negative
- Only valid months (1, 3, 6, 12) accepted
- Correct APY mapping (4%, 7%, 11%, 18%)
- Interest calculation: (principal × APY × months) / 1200
- Unlock time strictly monotonic with duration

### Lending Contract
- Tier limits strictly increase (300M < 600M < 1.5B < 5B XLM)
- APY rates decrease with tier (12% > 8% > 5% > 4%)
- Loan amount never exceeds tier limit
- Total owed always >= principal
- Repayment capped at total_owed

### SBT Contract
- Tier values in range 1-4 (Plata, Oro, Diamante, Platino)
- Tier 0 is default/revoked state
- Only admin can mint/revoke (SBT non-transferable)
- Metadata (name, symbol) constant

## Test Coverage
- All tests embedded next to implementation for easy review
- Deterministic test data (reproducible every run)
- Fast execution (<1ms per test, ~1s total)
- Unit tests + property-based edge case coverage

## Running Tests
```bash
cd backend/contracts/staking_pool && cargo test --lib
cd ../vinculo_lending && cargo test --lib
cd ../vinculo_sbt && cargo test --lib
```

## Documentation
- TEST_SUITE.md: Comprehensive test documentation with examples
- README_TESTS.md: Quick start guide for test execution
- run-tests.sh: Unified test runner script with color output
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@paulinaapeh8 is attempting to deploy a commit to the alankcr1-6443's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@paulinaapeh8 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Suite de tests para contratos (unit + fuzz)

1 participant