Skip to content

feat(payment-distributor): implement two-step admin role rotation (transfer_admin/accept_admin) and authorization test suite #380

Description

@chizzy192

Context & Problem Statement

The payment-distributor contract in contracts/payment-distributor/src/lib.rs stores a single static admin initialized at contract deployment. Transferring contract ownership directly in a single step introduces high risk of permanent lockout if a typo or incorrect address is passed.

This issue implements a secure two-step admin ownership transfer pattern (transfer_admin proposes a PendingAdmin, and the new address must call accept_admin to finalize), accompanied by comprehensive negative authorization unit tests.

Architectural Motivation & Technical Requirements

  • In contracts/payment-distributor/src/storage.rs:
    • Add StorageKey::PendingAdmin.
    • Add get_pending_admin, set_pending_admin, and clear_pending_admin storage helpers.
  • In contracts/payment-distributor/src/lib.rs:
    • Implement transfer_admin(env, current_admin: Address, new_admin: Address):
      • Asserts current_admin.require_auth().
      • Writes new_admin to PendingAdmin.
    • Implement accept_admin(env, new_admin: Address):
      • Asserts new_admin.require_auth().
      • Validates new_admin == get_pending_admin().
      • Promotes new_admin to Admin, clears PendingAdmin, and emits AdminTransferred event.
  • In contracts/payment-distributor/src/test.rs:
    • Test successful two-step transfer.
    • Test unauthorized caller on transfer_admin.
    • Test unauthorized caller on accept_admin.
    • Test chained transfers and event log emission.

Acceptance Criteria

  • Two-step admin transfer fully implemented.
  • AdminTransferred event emitted with previous and new admin addresses.
  • All authorization failure branches assert Error::Unauthorized.
  • cargo test -p payment-distributor passes cleanly.

Target Branch: dev
Estimated Effort: 5–12 hours | Delivery: 3–5 days
Difficulty: Medium

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions