Skip to content

test(settlement): pin admin-set guard on empty and duplicate recovery targets - #594

Merged
therealjhay merged 2 commits into
Betta-Pay:mainfrom
BigManly4:test/582-recovery-empty-duplicate-admin-set
Aug 21, 2026
Merged

test(settlement): pin admin-set guard on empty and duplicate recovery targets#594
therealjhay merged 2 commits into
Betta-Pay:mainfrom
BigManly4:test/582-recovery-empty-duplicate-admin-set

Conversation

@BigManly4

Copy link
Copy Markdown
Contributor

closes #582

Problem

execute_recovery writes DataKey::Admin directly rather than going through validate_admins_and_threshold, and the existing suite in settlement_contract/src/tests/admin_tests.rs only exercised the recovery happy path (recovery_executes_after_delay). Nothing asserted:

  • that the admin set execute_recovery installs is non-empty and duplicate-free,
  • that validate_admins_and_threshold actually rejects an empty or duplicate admin set, and
  • that a duplicate recovery/transfer target is rejected rather than silently accepted.

Changes

Added settlement_contract/src/tests/recovery_admin_set_tests.rs and wired it into settlement_contract/src/tests/mod.rs.

validate_admins_and_threshold — the guard itself

  • validate_rejects_empty_admin_set_with_threshold_one / ..._with_zero_threshold — empty admin vector is rejected with InvalidThreshold (Fix Settlement Rule Validation (Sum Limit) #26).
  • validate_rejects_duplicate_admins, validate_rejects_duplicate_admins_at_threshold_one, validate_rejects_non_adjacent_duplicate_admins — the duplicate-target test called out in the issue, covering adjacent and non-adjacent duplicates at threshold 1 and 2, all rejected with InvalidAdmin (Custom Error for Admin Authorization Failure #14).
  • validate_rejects_zero_address_in_admin_set — a zero-address entry anywhere in the set is rejected with ZeroAddress (Audit Event Publishing Payload in remove_anchor #21).
  • validate_accepts_distinct_admin_set — a legitimate distinct set is accepted (negative control).

Post-recovery admin set

  • recovery_settles_on_non_empty_single_admin_set — after initiate_recovery + execute_recovery, get_admin() holds exactly one address, get_threshold() is 1, and the resulting set passes validate_admins_and_threshold — pinning that recovery can never settle on an empty set.
  • recovery_to_existing_admin_does_not_duplicate_admin_set — recovering to an address that is already in the admin set collapses to a single entry rather than storing it twice.
  • initiate_recovery_rejects_zero_address_target — an invalid recovery target is rejected before it can ever reach the pending-recovery record.

transfer_admin from the recovered admin

  • recovered_admin_cannot_transfer_to_empty_admin_set — the freshly recovered lone admin cannot transfer to an empty set (InvalidThreshold, Fix Settlement Rule Validation (Sum Limit) #26).
  • recovered_admin_cannot_transfer_to_duplicate_admin_set — nor to a set with a duplicated target (InvalidAdmin, Custom Error for Admin Authorization Failure #14).
  • rejected_duplicate_transfer_leaves_recovered_admin_set_intact — uses try_transfer_admin to confirm both rejections leave get_admin()/get_threshold() untouched.

Testing

  • cargo test --workspace — all 62 tests pass (33 governance + 29 settlement, including the 12 new tests here).
  • cargo fmt --all -- --check — clean.
  • cargo clippy --all-targets -- -D warnings — clean.

This is test-only; no production code changes.

… targets

execute_recovery writes DataKey::Admin directly rather than going through
validate_admins_and_threshold, and the existing suite only covered the
recovery happy path. Nothing asserted that the post-recovery admin set is
non-empty and duplicate-free, or that the guard rejects those shapes.

Add settlement_contract/src/tests/recovery_admin_set_tests.rs covering:

- validate_admins_and_threshold directly: empty sets (threshold 0 and 1)
  are rejected with InvalidThreshold, duplicate entries (adjacent and
  non-adjacent, at threshold 1 and 2) with InvalidAdmin, and a zero-address
  member with ZeroAddress; a distinct set is accepted.
- The set execute_recovery installs: exactly one admin at threshold 1, and
  it passes validate_admins_and_threshold. Recovering to an address that is
  already an admin collapses to a single entry instead of duplicating it.
- initiate_recovery rejects a zero-address target, so an invalid admin can
  never reach the pending recovery record.
- transfer_admin from the recovered lone admin rejects both an empty target
  set and a duplicate target set, and a rejected transfer leaves the stored
  admin set and threshold untouched.
@therealjhay

Copy link
Copy Markdown
Contributor

Kindly resolve conflict

@therealjhay
therealjhay merged commit e4118d6 into Betta-Pay:main Aug 21, 2026
0 of 2 checks passed
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.

No get_admin-style settleing of empty admin set post-recovery regression test

2 participants