Overview
The contracts/ workspace contains five fully written Soroban smart contracts but zero Rust unit tests. The contracts handle identity mapping, reputation scoring, and document hashes — all of which are critical trust infrastructure. Without tests, changes to the contracts carry high regression risk. This issue adds comprehensive unit test suites for three contracts. The companion issue for Shipment and Escrow tests is [CONTRACT-02].
Technical Details
Environment
- Workspace root:
contracts/
- Run tests:
cargo test from contracts/
- Each contract crate already has a
[dev-dependencies] section in its Cargo.toml — add soroban-sdk = { version = "22.0.0", features = ["testutils"] } if not already present
- Use
soroban_sdk::Env::default() and contract_client::Client::new(&env, &contract_id) pattern
1. Identity Contract Tests (contracts/identity/src/test.rs)
The identity contract stores wallet_address → sha256(user_id) mappings.
Write tests for:
#[test] fn test_register_new_identity()
// Register a wallet, then get_user_id — should return the hash
#[test] fn test_register_duplicate_wallet_fails()
// Registering the same wallet twice should panic with AlreadyRegistered error
#[test] fn test_get_unregistered_wallet_returns_none()
// get_user_id for an unknown wallet should return None (or error per contract spec)
#[test] fn test_revoke_identity_by_admin()
// Admin revokes a registration; subsequent get_user_id returns None
#[test] fn test_revoke_by_non_admin_fails()
// Revoking as a non-admin wallet should panic with Unauthorized
#[test] fn test_is_registered_returns_correct_bool()
// is_registered returns true for a registered wallet and false for unregistered
2. Reputation Contract Tests (contracts/reputation/src/test.rs)
The reputation contract stores 1-5 star ratings and on-time booleans, and computes a composite score (0–1000).
Write tests for:
#[test] fn test_record_single_rating()
// Record one rating; get_stats should return count=1, correct totals
#[test] fn test_record_multiple_ratings_aggregates_correctly()
// Record 5 ratings (mix of star values + on_time); verify average and on_time_rate
#[test] fn test_composite_score_formula()
// Record known ratings and verify the composite score matches the expected formula
#[test] fn test_star_rating_out_of_range_fails()
// Recording a rating of 0 or 6 should panic with InvalidRating error
#[test] fn test_get_score_for_unrated_carrier()
// get_score for a wallet that has never been rated should return 0 or a specific default
#[test] fn test_cannot_rate_same_shipment_twice()
// Submitting the same shipment_id twice for the same ratee should panic
3. Document Registry Contract Tests (contracts/document/src/test.rs)
The document contract stores SHA-256 hashes + IPFS CIDs with optional admin verification.
Write tests for:
#[test] fn test_register_document_hash()
// Register a document; get_document returns the correct hash and CID
#[test] fn test_register_duplicate_hash_fails()
// Registering the same hash twice for the same owner should panic
#[test] fn test_verify_integrity_correct_hash()
// verify_integrity with the correct hash returns true
#[test] fn test_verify_integrity_wrong_hash()
// verify_integrity with a tampered hash returns false
#[test] fn test_admin_verify_document()
// Admin calls verify_document; document.is_verified becomes true
#[test] fn test_non_admin_cannot_verify()
// Non-admin calling verify_document should panic with Unauthorized
#[test] fn test_revoke_document()
// Revoking a document sets is_revoked = true; subsequent verify_integrity fails
Acceptance Criteria
Overview
The
contracts/workspace contains five fully written Soroban smart contracts but zero Rust unit tests. The contracts handle identity mapping, reputation scoring, and document hashes — all of which are critical trust infrastructure. Without tests, changes to the contracts carry high regression risk. This issue adds comprehensive unit test suites for three contracts. The companion issue for Shipment and Escrow tests is [CONTRACT-02].Technical Details
Environment
contracts/cargo testfromcontracts/[dev-dependencies]section in itsCargo.toml— addsoroban-sdk = { version = "22.0.0", features = ["testutils"] }if not already presentsoroban_sdk::Env::default()andcontract_client::Client::new(&env, &contract_id)pattern1. Identity Contract Tests (
contracts/identity/src/test.rs)The
identitycontract storeswallet_address → sha256(user_id)mappings.Write tests for:
2. Reputation Contract Tests (
contracts/reputation/src/test.rs)The
reputationcontract stores 1-5 star ratings and on-time booleans, and computes a composite score (0–1000).Write tests for:
3. Document Registry Contract Tests (
contracts/document/src/test.rs)The
documentcontract stores SHA-256 hashes + IPFS CIDs with optional admin verification.Write tests for:
Acceptance Criteria
cargo testincontracts/runs all tests without warnings or errors#[cfg(test)] mod tests { ... }insidesrc/test.rs.github/workflows/) includes a step to runcargo testin the contracts workspace