GitHub Issue: #48 – Implement Regression Test Suite for Critical Bugs
- Location: All tests in
src/test.rs(4783 lines) - Pattern: Hybrid approach with tests inside
src/using#[cfg(test)] - Test Harness: Native Soroban SDK testutils (
Env::default(),mock_all_auths()) - Snapshot System: JSON snapshots in
test_snapshots/test/*.json - Test Categories: Event verification, pagination, blacklist, concentration, fuzzing, boundary tests
- Helper functions:
make_client(),setup(),register_n() - Deterministic fuzzing with seeded PRNG
- Boundary testing with predefined constants
- Comprehensive event payload verification
- 247 existing tests with 36.36s runtime
Location: src/test.rs with dedicated mod regression { ... } section
- Consistency: Maintains existing repository pattern of keeping all tests in
src/test.rs - No Separate Directory: Repository has no
tests/directory; creating one would deviate from established conventions - Helper Sharing: Easy access to existing test utilities (
make_client(),setup(), etc.) - Soroban Pattern: Typical for Soroban contracts to use this structure
- Minimal Disruption: No changes to build configuration or CI pipelines required
#[cfg(test)]
mod regression {
use super::*;
// Template and future regression tests here
}- Name:
regression_template_example - Purpose: Demonstrates required documentation format
- Pattern: Arrange-Act-Assert with clear sections
- Documentation: Includes issue reference, bug description, expected behavior, fix applied
Each regression test MUST include:
/// Regression Test: [Brief Title]
///
/// **Related Issue:** #N or [Audit Report Reference]
///
/// **Original Bug:**
/// [Detailed description]
///
/// **Expected Behavior:**
/// [What should happen]
///
/// **Fix Applied:**
/// [Code change description]
- Predictable Environment:
Env::default()provides consistent test environment - Mocked Auth:
mock_all_auths()eliminates signature randomness - Deterministic Addresses:
Address::generate(&env)is deterministic within test scope - No External Dependencies: No network calls, file system access, or system time
- Fixed Seeds: Any pseudo-random data uses explicit seeds (see existing fuzz tests)
- No Time Dependencies: Ledger timestamps are mocked when needed
- Tests run identically on Linux, macOS, Windows
- No platform-specific behavior
- No race conditions or timing dependencies
- Snapshot tests validate against committed JSON files
- Template Test: 0.20s (single test)
- Full Suite: 36.36s (247 tests)
- Target: Individual regression tests <100ms
- Use helper functions to reduce setup overhead
- Minimal data sets that reproduce issues
- Focused scope (test only the specific bug)
- Avoid unnecessary contract deployments
- 247 tests covering all major contract functionality
- Event verification, pagination, blacklist, concentration, rounding, issuer transfer
- Boundary tests, fuzz tests, stress tests
- Minimum: 95% code coverage
- Validation:
cargo tarpaulin --out Html --output-dir coverage - Policy: Regression tests contribute to overall coverage goal
- Regression module is isolated at end of
src/test.rs - Uses same helper functions as existing tests
- No snapshot conflicts (regression tests don't use snapshots by default)
- No performance regression (fast, focused tests)
Regression tests can use:
make_client(&env)- Create contract clientsetup()- Returns (env, client, issuer)register_n(env, client, issuer, n)- Register N offerings- Existing constants:
BOUNDARY_AMOUNTS,BOUNDARY_PERIODS, etc.
- Bug Prevention: Captures critical bugs to prevent recurrence
- Audit Trail: Documents security issues and their fixes
- Regression Detection: CI catches if bugs are reintroduced
- Knowledge Transfer: New developers understand historical issues
- Compliance: Demonstrates due diligence for audits
When adding regression tests:
- Reference the issue/audit finding
- Document the bug clearly
- Verify the fix prevents recurrence
- Keep tests deterministic and fast
- Update README if new patterns emerge
Location: After "Build and test" section, before "Contributor guidelines"
Content:
- When to add regression tests
- Naming conventions
- Required documentation format
- Determinism requirements
- Performance expectations
- CI integration behavior
- Coverage requirement
- Example reference
$ cargo test regression_template_example
running 1 test
test test::regression::regression_template_example ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 246 filtered out; finished in 0.20s$ cargo test --lib
running 247 tests
test result: ok. 247 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 36.36s- All existing tests pass
- No snapshot conflicts
- No performance degradation
- No build warnings
-
src/test.rs
- Added
mod regressionsection at end - Includes comprehensive documentation header
- Template test with full documentation format
- Added
-
README.md
- New "Regression Testing Policy" section
- Detailed guidelines for contributors
- Examples and requirements
-
COMMIT_MESSAGE.txt
- Standard commit message format
- References issue #48
The regression test suite structure is now in place and ready for future critical bug cases. The implementation:
- Follows existing repository conventions
- Maintains determinism and CI safety
- Provides clear documentation guidelines
- Integrates seamlessly with existing tests
- Supports long-term contract safety goals
No fabricated bugs were added; the template serves as a structural guide for future real regression cases discovered through production incidents, audits, or security reviews.