This document summarizes the contract regression testing implementation in the MyFans CI/CD pipeline.
Catch contract regressions before merge by ensuring:
- ✅
cargo testruns on every PR - ✅ Job fails if tests fail
- ✅ Merge is blocked when tests fail (via branch protection)
- ✅ WASM artifacts build and verify successfully
- Contract CI workflow configured (
contract-ci.yml) - All contracts have comprehensive unit tests
- Tests run on all PRs
- WASM artifacts built and verified
- Documentation created for developers
- Testing guides and checklists created
- Development workflow documented
To enable merge blocking, configure GitHub branch protection for main and master branches:
Required Status Check: contract (from .github/workflows/contract-ci.yml)
Via GitHub UI:
- Go to Settings → Branches → Branch protection rules
- Edit or create rule for
mainandmaster - Under "Require status checks to pass before merging"
- Search for and select
contract
Via GitHub CLI:
gh api -X PUT /repos/MyFanss/MyFans/branches/main/protection \
-f required_status_checks='{"strict":true,"contexts":["contract"]}' \
-f enforce_admins=true
gh api -X PUT /repos/MyFanss/MyFans/branches/master/protection \
-f required_status_checks='{"strict":true,"contexts":["contract"]}' \
-f enforce_admins=true| Aspect | Detail |
|---|---|
| Trigger | All PRs, pushes to main/master, manual dispatch |
| Job Name | contract |
| Timeout | 30 minutes |
| Steps | 1. Format check 2. Linting 3. Tests 4. WASM build 5. Artifact verification |
| Status Check | YES - Blocks merge if fails |
Key Step: Run tests
cargo test --all-features --manifest-path Cargo.tomlKey Step: Verify WASM artifacts
- Ensures all 9 production contracts are built and verified (magic bytes + non-empty):
- myfans_token.wasm
- creator_registry.wasm
- creator_deposits.wasm
- creator_earnings.wasm
- subscription.wasm
- content_access.wasm
- content_likes.wasm
- earnings.wasm
- treasury.wasm
Part of the main CI pipeline for main/develop branches.
| Aspect | Detail |
|---|---|
| Trigger | PRs to main/develop, pushes to main/develop |
| Job Name | Contract (Rust) |
| Tests | Yes, same tests as contract-ci.yml |
| Status Check | Not set as required (redundant with contract-ci) |
| Also runs | wasm-size job for artifact size tracking |
All 12 contracts have comprehensive tests:
✅ myfans-token - 10+ tests ✅ subscription - 5+ tests ✅ content-access - 5+ tests ✅ creator-registry - 5+ tests ✅ earnings - 5+ tests ✅ creator-earnings - 5+ tests ✅ creator-deposits - 5+ tests ✅ content-likes - 5+ tests ✅ test-consumer - Tests for integration patterns ✅ treasury - 5+ tests ✅ myfans-lib - Library tests ✅ myfans-contract - 5+ tests
Each contract's tests cover:
- Unit tests: Individual method functionality
- Error handling: Invalid inputs, edge cases
- Authorization: Auth guards and permissions
- State changes: Ledger state consistency
- Cross-contract calls: Interactions between contracts
- Events: Proper event emission
cd contract
# Quick test
cargo test --all-features
# Full CI checks
cargo fmt --all --check && \
cargo clippy --all-targets --all-features -- -D warnings && \
cargo test --all-features && \
cargo build --release --target wasm32-unknown-unknowncd contract
# Watch mode (requires cargo-watch)
cargo watch -x test
# Verbose output
cargo test -- --nocapture
# Single test
cargo test test_transfer -- --nocapture| Document | Purpose |
|---|---|
| contract/TESTING.md | Testing patterns and best practices |
| contract/REGRESSION_TESTING.md | How regression testing is enforced |
| contract/REGRESSION_CHECKLIST.md | Developer PR checklist |
| contract/docs/BRANCH_PROTECTION.md | Technical branch protection setup |
When submitting a PR with contract changes:
- Add tests for new/modified functionality
- Run locally:
cargo test --all-features - Use checklist: REGRESSION_CHECKLIST.md
- Wait for CI: GitHub Actions will run contract tests
- Address failures: Fix tests and push new commits
- Every public method has test coverage
- Tests include happy path and error cases
- Auth requirements are tested
- State changes are verified
When contracts call each other:
#[test]
fn test_cross_contract_call() {
// Setup both contracts
// Initialize them
// Call from one to another
// Verify state in both
}- Tests run automatically on all PRs
- Merge blocked if tests fail
- No exceptions (all PRs checked)
- Status visible on GitHub
Monitor test execution time:
cd contract && time cargo test --all-featuresTarget: < 30 seconds total
| Issue | Solution |
|---|---|
| Tests pass locally but fail in CI | Run with CI's exact command: cargo test --all-features --manifest-path Cargo.toml |
| Test times out | Run single test with cargo test test_name -- --nocapture |
| Formatting error in CI | Run cargo fmt --all locally |
| Clippy warning in CI | Run cargo clippy --all-targets --all-features and fix warnings |
| WASM artifact missing | Ensure contract is in contract/Cargo.toml workspace members |
| PR blocked by failing CI | Check error message, reproduce locally, fix and push new commit |
- Review test coverage metrics
- Update branch protection rules if needed
- Check for outdated dependencies
- Verify all contracts still have tests
- Ensure all new contracts have tests
- Update AUTH_MATRIX.md if auth rules changed
- Verify all tests pass on release branch
- Check WASM artifact sizes for regressions
- Add tests for audit findings
- Verify fixes are regression-tested
- Consider adding property-based tests
- Update documentation as needed
The backend has integration tests that mock contract interactions:
These test backend behavior when interacting with contracts through the SorobanRpcService.
For full end-to-end testing:
- Deploy contracts to testnet
- Run backend against testnet contracts
- Test through frontend UI
See DEPLOYMENT.md for deployment procedures.
The contract regression testing implementation:
- ✅ Automatically runs tests on all PRs
- ✅ Fails the CI job if tests don't pass
- ✅ Requires branch protection configuration to block merges
- ✅ Has comprehensive test coverage across all contracts
- ✅ Includes WASM artifact verification
- ✅ Includes developer documentation and checklists
- ✅ Integrates with backend and frontend testing
To complete the implementation, configure branch protection as described in the "Branch Protection Setup" section above.