Skip to content

Enhancement/admin auth helper#365

Merged
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
Mrwicks00:enhancement/admin-auth-helper
May 28, 2026
Merged

Enhancement/admin auth helper#365
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
Mrwicks00:enhancement/admin-auth-helper

Conversation

@Mrwicks00
Copy link
Copy Markdown
Contributor

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.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@Mrwicks00 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Mrwicks00
Copy link
Copy Markdown
Contributor Author

@mikewheeleer

@mikewheeleer mikewheeleer merged commit 7de3af1 into Talenttrust:main May 28, 2026
1 check failed
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.

Refactor repeated admin-load boilerplate into a single helper

2 participants