Use this checklist when modifying or adding contracts to ensure regressions are caught by CI before merge.
- All contract modifications are in
contract/contracts/*/src/ - New public methods have corresponding tests
- Modified methods have test coverage for changes
- Authorization requirements are tested
- Run local tests:
cd contract && cargo test --all-features - All tests pass locally
- Test coverage includes:
- Happy path scenarios
- Error conditions with proper error codes
- Authorization checks (both allow and deny cases)
- State changes are verified
- Edge cases (zero amounts, max values, overflow)
- Cross-contract interactions (if applicable)
- Code is formatted:
cargo fmt --all --check - Linting passes:
cargo clippy --all-targets --all-features -- -D warnings - No compiler warnings
- Contract interface documentation updated if needed
- AUTH_MATRIX.md updated if auth rules changed
- Test function names are descriptive
- Complex test logic includes comments
- Update
contract/AUTH_MATRIX.mdwith new/modified methods - Document authorization requirements for each method
- Add integration test if another contract now calls this one
- Verify all related contracts' tests still pass
Include in your PR description:
### Contract Changes
- [ ] Added new contract: [name]
- [ ] Modified existing contract: [name]
- [ ] No contract changes (non-contract PR)
### Tests Added/Modified
- [ ] Unit tests for [functionality]
- [ ] Cross-contract tests for [interaction]
- [ ] Error condition tests for [scenario]
### Regression Impact
- No expected regressions / Regression prevention:
- [Specific test added for X]
- [Specific test added for Y]- Contract CI workflow starts automatically
- Workflow reaches the test step
- Tests pass in CI
- WASM artifacts build successfully
- All 5 WASM files verified:
- subscription.wasm
- myfans_token.wasm
- content_access.wasm
- creator_registry.wasm
- earnings.wasm
If CI fails at test step:
- Read the error message carefully
- Reproduce locally:
cargo test -- --nocapture - Debug the issue
- Fix the code or test
- Push new commit
- Verify CI passes on retry
If CI fails at other steps:
- Format:
cargo fmt --all && cargo test --all-features - Linting:
cargo clippy --all-targets --all-features -- -D warnings - WASM build:
cargo build --release --target wasm32-unknown-unknown
When adding a call from one contract to another:
- Setup both contracts in test
- Initialize the called contract properly
- Test successful call path
- Test error path (if caller contract should handle errors)
- Verify state changes in both contracts
- Test authorization requirements in called contract
Example test structure:
#[test]
fn test_cross_contract_success() {
let env = Env::default();
env.mock_all_auths();
// Setup contract A
let contract_a_id = env.register_contract(None, ContractA);
let contract_a = ContractAClient::new(&env, &contract_a_id);
// Setup contract B
let contract_b_id = env.register_contract(None, ContractB);
let contract_b = ContractBClient::new(&env, &contract_b_id);
// Initialize
contract_a.initialize(...);
contract_b.initialize(&contract_a_id, ...);
// Exercise interaction
let result = contract_b.method_calling_contract_a(...);
// Verify both contracts updated correctly
assert_eq!(contract_a.some_state(), expected);
assert_eq!(contract_b.other_state(), expected);
}- Test that initialization sets expected state
- Test that re-initialization fails appropriately
- Test that uninitialized contract properly errors
- Test that admin-only methods reject non-admins
- Test that user methods work with proper permissions
- Test that cross-contract calls respect authorization
- Test zero amount rejection (if applicable)
- Test insufficient balance scenarios
- Test amount precision handling
- Test overflow/underflow handling
- Test that ledger updates are atomic (or properly handle partial failures)
- Test that related state remains consistent
- Test that events properly reflect state changes
- Test that failed operations don't corrupt state
- Test that retrying valid operations works correctly
- Test idempotency where applicable
Track these to ensure quality:
- ✅ Number of tests per contract (target: ≥ 5-10)
- ✅ Test execution time (target: < 30 seconds for
cargo test) - ✅ Code coverage for contracts (target: > 80% for public APIs)
- ✅ Test pass rate (target: 100% on main)
If you find a contract regression:
- Create a failing test that demonstrates the regression
- Add test to the contract's test module
- Open an issue with details:
- When was it introduced? (commit/PR)
- What is the impact?
- How can it be reproduced?
- Commit fix with test passing
- Ensure test remains in codebase to prevent re-regression
# Test everything
cd contract && cargo test --all-features
# Test specific contract
cd contract/contracts/myfans-token && cargo test
# Test with output
cd contract && cargo test -- --nocapture
# Single test
cd contract && cargo test test_transfer -- --nocapture
# Watch mode (requires cargo-watch)
cd contract && cargo watch -x test
# Pre-commit hook (run before git commit)
./contract && cargo fmt --all --check && \
cargo clippy --all-targets --all-features -- -D warnings && \
cargo test --all-features- Testing Guide: contract/TESTING.md
- Regression Testing: contract/REGRESSION_TESTING.md
- Branch Protection: contract/docs/BRANCH_PROTECTION.md
- CI Workflow: .github/workflows/contract-ci.yml
- Soroban Docs: https://developers.stellar.org/docs/build/guides/testing