This directory contains comprehensive test implementations for all Chioma smart contracts, addressing GitHub issues #645-#648.
The Chioma housing protocol consists of five core smart contracts, each with extensive test coverage:
- Agent Registry - Agent registration, verification, and rating
- Property Registry - Property registration and verification
- Escrow - Security deposit management with dispute resolution
- Payment - Rent payment processing with late fee calculation
- Rent Obligation - Tokenized rent obligation NFTs
- Rust 1.70+
- Soroban SDK 23
- Cargo
Run all contract tests:
cd contract
cargo test --libRun tests for a specific contract:
# Agent Registry
cargo test --lib agent_registry::tests
# Property Registry
cargo test --lib property_registry::tests
# Escrow
cargo test --lib escrow::tests
# Payment
cargo test --lib payment::tests
# Rent Obligation
cargo test --lib rent_obligation::testsRun a specific test:
cargo test --lib agent_registry::tests::test_successful_initializationStatus: ✓ Complete
Tests initialization logic for both registries:
- Successful initialization with admin address
- Authorization requirement verification
- Double initialization prevention
- Additional registration and verification tests
Files:
contract/contracts/agent_registry/src/tests.rs(23 tests)contract/contracts/property_registry/src/tests.rs(20 tests)
Documentation: See ISSUE_645_IMPLEMENTATION.md
Status: ✓ Complete
Tests complete escrow lifecycle including:
- Escrow creation and funding
- Multi-sig approval mechanism (2-of-3)
- Dispute initiation and resolution
- Partial releases and damage deductions
- Timeout handling and automatic refunds
Files:
contract/contracts/escrow/src/tests.rs(20 tests)
Documentation: See ISSUE_646_IMPLEMENTATION.md
Status: ✓ Complete
Tests payment processing including:
- Payment split calculations with agent commissions
- Late fee computation with various scenarios
- Recurring payment management
- Rate limiting enforcement
- Payment execution tracking
Files:
contract/contracts/payment/src/tests.rs(17+ tests)
Documentation: See ISSUE_647_IMPLEMENTATION.md
Status: ✓ Complete
Tests NFT functionality including:
- Rent obligation NFT minting and transfer
- NFT burning with valid reasons
- Agent registration and verification
- Agent rating and reputation tracking
- Event emission and history tracking
Files:
contract/contracts/rent_obligation/src/tests.rs(27 tests)contract/contracts/agent_registry/src/tests.rs(agent tests)
Documentation: See ISSUE_648_IMPLEMENTATION.md
| Contract | Tests | Status |
|---|---|---|
| Agent Registry | 23 | ✓ Complete |
| Property Registry | 20 | ✓ Complete |
| Escrow | 20 | ✓ Complete |
| Payment | 17+ | ✓ Complete |
| Rent Obligation | 27 | ✓ Complete |
| Total | 100+ | ✓ Complete |
Verify that all sensitive operations require proper authorization:
- Admin-only operations
- Owner-only operations
- Multi-sig requirements
- Authorization failure handling
Verify correct state changes:
- Initial state setup
- State progression through operations
- State immutability where required
- State rollback on errors
Verify proper error handling:
- Invalid input rejection
- Authorization failures
- Duplicate operation prevention
- Boundary condition handling
Verify interactions between components:
- Multi-contract workflows
- Token transfers
- Event emission
- History tracking
Verify handling of special scenarios:
- Zero amounts
- Maximum amounts
- Timeout scenarios
- Concurrent operations
#[test]
#[should_panic]
fn test_operation_requires_auth() {
let env = Env::default();
let client = create_contract(&env);
let user = Address::generate(&env);
// No auth mocking - should panic
client.sensitive_operation(&user);
}#[test]
fn test_state_transition() {
let env = Env::default();
env.mock_all_auths();
let client = create_contract(&env);
// Perform operation
client.operation();
// Verify state
let state = client.get_state();
assert_eq!(state.field, expected_value);
}#[test]
#[should_panic(expected = "Error(Contract, #1)")]
fn test_error_case() {
let env = Env::default();
env.mock_all_auths();
let client = create_contract(&env);
// Trigger error condition
client.operation_that_fails();
}#[test]
fn test_token_transfer() {
let env = Env::default();
env.mock_all_auths();
let token = create_token(&env, &admin);
let token_client = TokenClient::new(&env, &token);
// Mint tokens
token_admin.mint(&user, &amount);
assert_eq!(token_client.balance(&user), amount);
// Perform transfer
client.transfer(&user);
// Verify balances
assert_eq!(token_client.balance(&user), 0);
assert_eq!(token_client.balance(&recipient), amount);
}- Create test environment
- Register contract
- Create test addresses
- Setup tokens if needed
- Mock authentication
- Perform contract operations
- Verify state changes
- Check token transfers
- Validate events
- Assert expected outcomes
- Verify state consistency
- Check error conditions
- Validate history/events
fn create_contract(env: &Env) -> ContractClient<'_> {
let contract_id = env.register(Contract, ());
ContractClient::new(env, &contract_id)
}fn create_token(env: &Env, admin: &Address) -> Address {
env.register_stellar_asset_contract_v2(admin.clone()).address()
}let user = Address::generate(&env);env.ledger().with_mut(|ledger| {
ledger.timestamp = 1000;
});cargo test --lib -- --nocapturecargo test --lib test_name -- --nocapture --test-threads=1RUST_LOG=debug cargo test --lib- Clear Test Names: Use descriptive names that explain what is being tested
- Single Responsibility: Each test should verify one behavior
- Proper Setup: Use helper functions for common setup
- Comprehensive Coverage: Test both success and failure paths
- Clear Assertions: Use meaningful assertion messages
- Isolation: Tests should not depend on each other
- Documentation: Include comments explaining complex test logic
Tests are automatically run on:
- Pull requests
- Commits to main branch
- Release builds
See .github/workflows/contract-ci-cd.yml for CI configuration.
When adding new tests:
- Follow existing naming conventions
- Use helper functions for common operations
- Test both success and failure cases
- Include documentation comments
- Ensure tests are isolated and repeatable
- Run full test suite before submitting PR
# Clean and rebuild
cargo clean
cargo test --libEnsure env.mock_all_auths() is called before operations requiring auth.
Verify tokens are minted before transfer operations.
Increase test timeout or check for infinite loops in contract code.
- CONTRACT_TESTING_SUMMARY.md - Comprehensive test summary
- ISSUE_645_IMPLEMENTATION.md - Registry initialization tests
- ISSUE_646_IMPLEMENTATION.md - Escrow lifecycle tests
- ISSUE_647_IMPLEMENTATION.md - Payment processing tests
- ISSUE_648_IMPLEMENTATION.md - NFT and agent tests
For issues or questions about the tests:
- Check the relevant issue documentation
- Review test code comments
- Consult Soroban SDK documentation
- Open an issue on GitHub
All tests are part of the Chioma project and follow the same license.