Skip to content

Fix transfer_admin tests to validate auth behavior and chained state transitions - #280

Merged
chizzy192 merged 1 commit into
devfrom
copilot/fix-code-comments-review-thread
Jul 29, 2026
Merged

Fix transfer_admin tests to validate auth behavior and chained state transitions#280
chizzy192 merged 1 commit into
devfrom
copilot/fix-code-comments-review-thread

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This addresses the review-thread feedback on PR #273 by fixing the transfer_admin test cases that were not asserting the intended behavior. The update is scoped to the commented tests only, with no contract logic changes.

  • test_transfer_admin_fails_if_unauthorized now validates auth failure correctly

    • Removed env.mock_all_auths() from this test (which previously bypassed require_auth()).
    • Replaced unused variables / no-op flow with explicit mock_auths setup for:
      • initialize by admin
      • transfer_admin attempted by unauthorized_caller
    • Added direct failure assertion and retained admin-state invariant assertion.
  • test_transfer_admin_chain now executes and verifies the second transfer

    • Removed the misleading “new client as caller” pattern.
    • Switched to explicit per-call auth mocking:
      • admin -> new_admin_1
      • new_admin_1 -> new_admin_2
    • Added the missing second transfer_admin call before asserting final admin.
  • Test imports updated for explicit auth mocking

    • Added MockAuth, MockAuthInvoke, and IntoVal to support invocation-scoped auth setup.
let result = distributor
    .mock_auths(&[MockAuth {
        address: &unauthorized_caller,
        invoke: &MockAuthInvoke {
            contract: &distributor_id,
            fn_name: "transfer_admin",
            args: (&new_admin,).into_val(&env),
            sub_invokes: &[],
        },
    }])
    .try_transfer_admin(&new_admin);
assert!(result.is_err());
assert_eq!(distributor.get_admin().unwrap(), admin);

Copilot AI changed the title [WIP] Fix code based on all comments in review thread Fix transfer_admin tests to validate auth behavior and chained state transitions Jul 28, 2026
Copilot AI requested a review from chizzy192 July 28, 2026 14:06
@chizzy192
chizzy192 marked this pull request as ready for review July 29, 2026 16:34
@chizzy192
chizzy192 merged commit c284b3c into dev Jul 29, 2026
2 of 8 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.

2 participants