Skip to content

refactor: change verification registry getters to return Option and u…#396

Open
ABEEGOLD wants to merge 1 commit into
HubDApp:mainfrom
ABEEGOLD:fix/349-standardize-getter-return-types
Open

refactor: change verification registry getters to return Option and u…#396
ABEEGOLD wants to merge 1 commit into
HubDApp:mainfrom
ABEEGOLD:fix/349-standardize-getter-return-types

Conversation

@ABEEGOLD

Copy link
Copy Markdown

Closes #349

##Summary

Context & Problem

Single-entity read-only query getters across the contract inconsistently handled "not found" scenarios:

  • ProjectRegistry::get_project, ReviewRegistry::get_review, DisputeRegistry::get_duplicate_dispute, TimelockManager::get_action, and AdminManager::get_proposal returned Option<T> (returning None for missing entities).
  • CollectionRegistry::get_collection and VerificationRegistry::get_verification, get_verification_record, get_renewal_request, and get_assigned_admin returned Result<T, ContractError> (returning Err(ContractError::...) for missing entities).

This inconsistency forced SDK/client consumers and frontend indexers to handle different lookup semantics for each single-entity query method.

Solution

Standardized all single-entity getters exposed via lib.rs and their module implementations to use Option<T>:

  • Found: Returns Some(entity)
  • Not Found: Returns None (without throwing an on-chain contract error)

Detailed Changes

1. Smart Contract Core Logic

  • collection_registry.rs:
    • CollectionRegistry::get_collection now returns Option<Collection>.
  • verification_registry.rs:
    • VerificationRegistry::get_verification -> Option<VerificationRecord>
    • VerificationRegistry::get_verification_record -> Option<VerificationRecord>
    • VerificationRegistry::get_renewal_request -> Option<VerificationRenewalRecord>
    • VerificationRegistry::get_assigned_admin -> Option<Address>
    • Internal state mutation functions (approve_verification, reject_verification, revoke_verification, assign_verification, update_verification_evidence, approve_renewal, reject_renewal, is_verification_expired) updated to use .ok_or(ContractError::VerificationNotFound) when fetching records internally.
  • admin_manager.rs:
    • Updated proposal execution branches for verification updates to handle Option<VerificationRecord> with .ok_or(...).
  • lib.rs:
    • Updated contract entrypoints get_collection, get_verification, get_verification_record, get_renewal_request, and get_assigned_admin to match Option<T> return signatures.

2. Test Suite Updates

Updated unit test assertions to match Option<T> (unwrap(), Some(...), None) across test suites:

  • src/tests/collections.rs
  • src/tests/renewal.rs
  • src/tests/verification.rs
  • src/tests/verification_features.rs
  • src/tests/verification_assignment.rs
  • src/tests/invariants.rs
  • src/tests/multisig_and_history.rs
  • src/tests/auth_matrix.rs
  • src/tests/atomicity.rs

3. Documentation

  • CONTRACT_INTERFACE.md:
    • Added an explicit Single-Entity Getter Convention section documenting Option<T> semantics across all single-entity lookups.
    • Updated parameter tables, return values, and code examples for get_collection, get_verification, get_verification_record, get_renewal_request, and get_assigned_admin.

Breaking Changes Notice

Warning

API Signature Change for SDK Clients:
Query getters get_collection, get_verification, get_verification_record, get_renewal_request, and get_assigned_admin now return Option<T> instead of Result<T, ContractError>. When querying non-existent entities, clients will receive null/None instead of a contract error response.


Verification & Testing

Automated Test Execution

Run the unit test suite:

cd dongle-smartcontract
cargo test

Results:

test result: ok. 500 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

WASM Build Verification

Build WASM contract target:

cargo build --target wasm32-unknown-unknown --release

…pdate dependent tests to handle results explicitly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-entity getters inconsistently return Option<T> vs Result<T, ContractError> for "not found"

1 participant