Skip to content

test(content-access): Add unit tests for initialize and admin paths#1268

Open
NUMBER72857 wants to merge 1 commit into
MyFanss:mainfrom
NUMBER72857:feat/910-content-access-init-admin-tests
Open

test(content-access): Add unit tests for initialize and admin paths#1268
NUMBER72857 wants to merge 1 commit into
MyFanss:mainfrom
NUMBER72857:feat/910-content-access-init-admin-tests

Conversation

@NUMBER72857
Copy link
Copy Markdown

Summary

Adds 17 focused unit tests for the content-access contract's two most security-critical paths: initialization (once-only, admin stored) and admin authorization enforcement across all admin-gated functions.

Changes

  • src/tests/init_admin_tests.rs: 17 tests across 4 groups
  • src/lib.rs: mod init_admin_tests declaration added alongside existing test modules

Test coverage

Group Tests
initialize stores admin, stores token, double-init returns AlreadyInitialized (code 1), missing auth panics
admin() view returns configured admin, panics on uninitialized contract
set_admin transfers role, requires current-admin auth, chained transfers work, new admin gains powers
set_max_price (admin-gated) stores cap, None before set, clear via 0, non-admin rejected, price-above-cap rejected, price-at-cap accepted

Patterns used

  • try_initialize / try_set_admin / try_set_max_price with assert!(result.is_err()) for error-code checks
  • #[should_panic(expected = "Unauthorized function call")] where require_auth must fire
  • EMPTY_AUTHS sentinel (same as existing test modules) to disable auth mocking
  • MockToken and setup() helper following existing test conventions

Closes #910

…yFanss#910)

- init_admin_tests.rs: 17 tests across 4 groups
  - initialize: stores admin, stores token, double-init returns AlreadyInitialized (code 1),
    missing admin auth panics with Unauthorized
  - admin() view: returns configured admin, panics when uninitialized
  - set_admin: transfers role, requires current-admin auth, supports chained transfers;
    new admin can call set_max_price after transfer
  - set_max_price (admin-gated): stores cap, None before set, clear via 0,
    non-admin rejected, prices above cap rejected, prices at cap accepted
- Uses #[should_panic(expected = "Unauthorized function call")] where auth must fire
- Uses try_initialize / try_set_admin / try_set_max_price with assert!(result.is_err())
  for explicit error-code assertions
- Follows existing test patterns: MockToken, setup() helper, EMPTY_AUTHS sentinel

Closes MyFanss#910
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@NUMBER72857 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! 🚀

Learn more about application limits

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.

Contract content-access: Add unit tests for initialize and admin paths

1 participant