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.
-
Extracted
load_and_auth_adminHelper:- Introduced
fn load_and_auth_admin(env: &Env) -> Addressinsidecontracts/escrow/src/lib.rs. - The helper loads the admin address from persistent storage (panicking with
NotInitializedif missing) and callsrequire_auth()on it.
- Introduced
-
Replaced Boilerplate:
- Replaced duplicate storage fetch and authorization blocks in the following administrative functions with
load_and_auth_admin:pauseunpauseactivate_emergency_pauseresolve_emergency
- Replaced duplicate storage fetch and authorization blocks in the following administrative functions with
-
Dead Code Elimination:
- Removed the unused
require_admin(env, caller)helper which was never called in the contract.
- Removed the unused
-
Added Comprehensive Unit Tests:
- Created
contracts/escrow/src/test/admin_auth_helper.rswith extensive test coverage forload_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.
- Created
-
Updated Documentation:
- Updated
docs/escrow/access-control.mdto reflect the newload_and_auth_adminpattern, documented the security invariants, and described the dead-code cleanup.
- Updated
All checks, linters, and verification steps are fully passing:
-
Unit and Integration Tests:
- Ran
cargo testoncontracts/escrow. - All 74 tests passed successfully.
test result: ok. 74 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 13.41s
- Ran
-
Linting (Clippy):
- Ran
cargo clippy --testssuccessfully with zero errors or warnings.
- Ran
-
Formatting (rustfmt):
- Code is clean and matches the standard Rust formatting style.
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
EscrowErrorenum intypes.rsand added missing variants referenced by thedisputemodule. - Resolved argument mismatches (3-argument calls to
release_milestoneinstead of 2) in tests. - Replaced overflowing
symbol_short!topics (>9 characters) withSymbol::newingovernance.rsandlib.rs.