Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 2.54 KB

File metadata and controls

56 lines (41 loc) · 2.54 KB

Pull Request: Refactor Repeated Admin-Load Boilerplate into Single Helper (#337)

Description

Closes #337

This pull request refactors the repetitive admin authorization and validation logic in the TalentTrust Escrow contract (contracts/escrow) into a single, clean helper function.

Key Changes

  1. Extracted load_and_auth_admin Helper:

    • Introduced fn load_and_auth_admin(env: &Env) -> Address inside contracts/escrow/src/lib.rs.
    • The helper loads the admin address from persistent storage (panicking with NotInitialized if missing) and calls require_auth() on it.
  2. Replaced Boilerplate:

    • Replaced duplicate storage fetch and authorization blocks in the following administrative functions with load_and_auth_admin:
      • pause
      • unpause
      • activate_emergency_pause
      • resolve_emergency
  3. Dead Code Elimination:

    • Removed the unused require_admin(env, caller) helper which was never called in the contract.
  4. Added Comprehensive Unit Tests:

    • Created contracts/escrow/src/test/admin_auth_helper.rs with extensive test coverage for load_and_auth_admin.
    • Verified paused/emergency state transitions, atomic round-trips, and initialization safeguards.
    • Declared the test module inside contracts/escrow/src/test/mod.rs.
  5. Updated Documentation:

    • Updated docs/escrow/access-control.md to reflect the new load_and_auth_admin pattern, documented the security invariants, and described the dead-code cleanup.

Verification Status

All checks, linters, and verification steps are fully passing:

  1. Unit and Integration Tests:

    • Ran cargo test on contracts/escrow.
    • All 74 tests passed successfully.
    test result: ok. 74 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 13.41s
  2. Linting (Clippy):

    • Ran cargo clippy --tests successfully with zero errors or warnings.
  3. Formatting (rustfmt):

    • Code is clean and matches the standard Rust formatting style.

Pre-existing Codebase Fixes

In order to successfully run cargo test and verify our refactoring, we also resolved a few pre-existing compiler errors that were blocking the build on main:

  • Resolved duplicate discriminants in the EscrowError enum in types.rs and added missing variants referenced by the dispute module.
  • Resolved argument mismatches (3-argument calls to release_milestone instead of 2) in tests.
  • Replaced overflowing symbol_short! topics (>9 characters) with Symbol::new in governance.rs and lib.rs.