feat(admin): add verify_admin_handover() helper with typed error#1678
Merged
Baskarayelu merged 2 commits intoJun 27, 2026
Merged
Conversation
…ckLendX#1587) Adds AdminStorage::verify_admin_handover(env, proposed) — a pure, read-only guard that returns Err(OperationNotAllowed) when proposed == current admin, surfacing the identity violation as an explicit typed error without requiring callers to attempt a full transfer and interpret an ambiguous OperationNotAllowed from transfer_admin. Changes: - admin.rs: add verify_admin_handover() with doc-comment, behaviour table, and usage example; backed by existing is_initialized + get_admin helpers - test_admin_handover.rs: 9 deterministic tests covering: - proposed == current → Err(OperationNotAllowed) - proposed != current → Ok(()) - called before init → Err(OperationNotAllowed) - multiple unrelated addresses all pass - idempotent/read-only: no state mutation, no pending admin, no lock - transfer_admin self-transfer regression (no existing guard removed) - transfer_admin with valid candidate still succeeds - two-step self-target still rejected - full two-step flow with valid candidate still works - lib.rs: register test_admin_handover as always-on #[cfg(test)] module - docs/contracts/admin.md: document the new helper with purpose, signature, behaviour table, and usage example API is backwards-compatible: verify_admin_handover is additive; transfer_admin and initiate_admin_transfer retain their own guards. Closes QuickLendX#1587
|
@morelucks 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! 🚀 |
Contributor
|
add verify_admin_handover() helper with typed error — nice work, merging 👍 |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements issue #1587. Adds
AdminStorage::verify_admin_handover(env, proposed)— a pure, read-only pre-flight guard that returns a typedOperationNotAllowederror when the proposed new admin address is identical to the current admin.Motivation
Previously, callers had no clean way to detect a same-address handover before committing the full
transfer_admincall. The only feedback was an ambiguousOperationNotAllowedthat is also returned for other failure modes (uninitialized, transfer locked). This forced:verify_admin_handoverprovides one well-named entry point that makes the identity violation explicit and documentable.Changes
quicklendx-contracts/src/admin.rsNew public function added to the second
impl AdminStorageblock:Err(OperationNotAllowed)proposed == current adminErr(OperationNotAllowed)proposed != current adminOk(())The function is read-only: no storage writes, no auth calls, no events emitted.
quicklendx-contracts/src/test_admin_handover.rs(new)9 deterministic tests covering:
quicklendx-contracts/src/lib.rsRegistered
mod test_admin_handoverwith plain#[cfg(test)]— always-on, runs on every CI matrix entry.docs/contracts/admin.mdNew section documents the helper: purpose, signature, behaviour table, properties (read-only, idempotent, composable), usage example, and a note clarifying the helper is additive and does not remove existing guards.
Backwards compatibility
Fully backwards-compatible. The helper is additive. All existing transfer paths retain their own guards unchanged.
Testing
Closes #1587