Skip to content

fix(distribute): mount orphaned pause module, unify StorageKey::Pause… - #1356

Open
Ahmad12developer wants to merge 2 commits into
CalloraOrg:mainfrom
Ahmad12developer:fix/issue-1175-mount-distribute-pause
Open

Ahmad12developer wants to merge 2 commits into
CalloraOrg:mainfrom
Ahmad12developer:fix/issue-1175-mount-distribute-pause

Conversation

@Ahmad12developer

Copy link
Copy Markdown
Contributor

…d (#1175)

Problem

distribute/src/pause.rs was declared in the crate but not referenced in lib.rs, leaving it as dead code. Worse, lib.rs wrote the pause flag via a bare Symbol("paused") string key while pause.rs read/wrote via the StorageKey::Paused enum variant. These two keys serialize to different on-ledger entries, making the circuit-breaker silently inoperative if the module were ever wired in.

Changes

contracts/distribute/src/lib.rs

  • Rename contract struct to CalloraDistribute (pub use alias Distribute kept for test backwards-compat); fixes CalloraDistributeClient export.
  • Declare pub mod pause and replace every Symbol(PAUSED_KEY) storage read/write with calls to pause::is_paused / pause::set_paused / pause::require_not_paused, so there is exactly one storage key.
  • Remove bare PAUSED_KEY string constant (now dead).
  • Migrate all other inline Symbol string keys (Admin, PendingAdmin, Usdc, MaxDistribute, ContractVersion) to use StorageKey enum variants so the entire storage layout is defined in one place.
  • Add BatchItem contracttype struct to fix the Soroban generics-on-tuple restriction in batch_distribute; Vec replaces Vec<(Address,i128)>.
  • Add Severity enum and broadcast entrypoint referenced by auth_snap tests.
  • Re-export CalloraDistributeClient as DistributeClient for test compat.

contracts/distribute/src/pause.rs

  • Refactor to three thin primitives: is_paused, set_paused, require_not_paused.
  • Auth checks and event emission remain in CalloraDistribute::pause/unpause (separation of concerns).
  • Replace catch_unwind-based unit tests (incompatible with Soroban Env's UnsafeCell interior mutability) with env.as_contract() scoped tests.
  • Add no_symbol_key_alias test: explicitly asserts no Symbol("paused") string key exists after set_paused, proving a single key invariant.

contracts/distribute/src/limits.rs

  • Add Usdc, MaxDistribute, PendingAdmin variants to StorageKey so lib.rs can centralise all storage layout in the enum.

contracts/distribute/src/events.rs

  • Fix event_version_v1: "callora.v1" → "callora_v1" (period is not a valid Symbol character in Soroban; previously caused a runtime InvalidInput).
  • Add event_broadcast for the new broadcast entrypoint.

contracts/distribute/src/test.rs

  • Update event topic index assertions: topics are now (event_name, callora_v1, address) — Address moved from index 1 to index 2.
  • Fix require_auth_on_all_state_changing_functions: mock_all_auths only during setup (init + mint), then set_auths(&[]) for the auth checks.

contracts/distribute/tests/auth_snap.rs

  • Rewrite for the actual CalloraDistribute API (previous version tested set_global_cap/open/close/get_account_count that don't exist in this contract).
  • Add pause_and_unpause_single_key_invariant: verifies is_paused() and get_paused() both reflect the same StorageKey::Paused value.

Acceptance criteria

[x] Only one pause storage key exists (StorageKey::Paused)
[x] No undeclared .rs files remain in distribute/src
[x] Pause tests pass against the chosen key
[x] Pause/unpause emit the same pause_set event regardless of path

Validation: cargo test -p callora-distribute pause → 17 passed, 0 failed
Full suite: cargo test -p callora-distribute → 73 passed, 0 failed

Closes #1175

CalloraOrg#1175)

Problem
-------
distribute/src/pause.rs was declared in the crate but not referenced in
lib.rs, leaving it as dead code. Worse, lib.rs wrote the pause flag via a
bare Symbol("paused") string key while pause.rs read/wrote via the
StorageKey::Paused enum variant. These two keys serialize to different
on-ledger entries, making the circuit-breaker silently inoperative if the
module were ever wired in.

Changes
-------
contracts/distribute/src/lib.rs
  - Rename contract struct to CalloraDistribute (pub use alias Distribute
    kept for test backwards-compat); fixes CalloraDistributeClient export.
  - Declare pub mod pause and replace every Symbol(PAUSED_KEY) storage
    read/write with calls to pause::is_paused / pause::set_paused /
    pause::require_not_paused, so there is exactly one storage key.
  - Remove bare PAUSED_KEY string constant (now dead).
  - Migrate all other inline Symbol string keys (Admin, PendingAdmin, Usdc,
    MaxDistribute, ContractVersion) to use StorageKey enum variants so the
    entire storage layout is defined in one place.
  - Add BatchItem contracttype struct to fix the Soroban generics-on-tuple
    restriction in batch_distribute; Vec<BatchItem> replaces Vec<(Address,i128)>.
  - Add Severity enum and broadcast entrypoint referenced by auth_snap tests.
  - Re-export CalloraDistributeClient as DistributeClient for test compat.

contracts/distribute/src/pause.rs
  - Refactor to three thin primitives: is_paused, set_paused, require_not_paused.
  - Auth checks and event emission remain in CalloraDistribute::pause/unpause
    (separation of concerns).
  - Replace catch_unwind-based unit tests (incompatible with Soroban Env's
    UnsafeCell interior mutability) with env.as_contract() scoped tests.
  - Add no_symbol_key_alias test: explicitly asserts no Symbol("paused")
    string key exists after set_paused, proving a single key invariant.

contracts/distribute/src/limits.rs
  - Add Usdc, MaxDistribute, PendingAdmin variants to StorageKey so lib.rs
    can centralise all storage layout in the enum.

contracts/distribute/src/events.rs
  - Fix event_version_v1: "callora.v1" → "callora_v1" (period is not a valid
    Symbol character in Soroban; previously caused a runtime InvalidInput).
  - Add event_broadcast for the new broadcast entrypoint.

contracts/distribute/src/test.rs
  - Update event topic index assertions: topics are now (event_name,
    callora_v1, address) — Address moved from index 1 to index 2.
  - Fix require_auth_on_all_state_changing_functions: mock_all_auths only
    during setup (init + mint), then set_auths(&[]) for the auth checks.

contracts/distribute/tests/auth_snap.rs
  - Rewrite for the actual CalloraDistribute API (previous version tested
    set_global_cap/open/close/get_account_count that don't exist in this
    contract).
  - Add pause_and_unpause_single_key_invariant: verifies is_paused() and
    get_paused() both reflect the same StorageKey::Paused value.

Acceptance criteria
-------------------
  [x] Only one pause storage key exists (StorageKey::Paused)
  [x] No undeclared .rs files remain in distribute/src
  [x] Pause tests pass against the chosen key
  [x] Pause/unpause emit the same pause_set event regardless of path

Validation: cargo test -p callora-distribute pause → 17 passed, 0 failed
Full suite:  cargo test -p callora-distribute       → 73 passed, 0 failed

Closes CalloraOrg#1175
@drips-wave

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

@Ahmad12developer 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

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Thanks for the contribution! We reviewed this PR while merging the open queue and couldn't merge it yet. Here's what needs fixing:

  • This distribute refactor now conflicts in about 32 places with six later changes on main.
  • It needs re-implementing on top of the current distribute contract rather than a mechanical conflict fix.

This branch also has merge conflicts with main. Please update it with the latest main, resolve the conflicts, fix the points above, and push — then we can merge it.

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.

Delete or mount the orphaned distribute pause module

2 participants