Skip to content

test(farming-pool): assert set_global_multiplier has zero effect on l… - #136

Open
Chigybillionz wants to merge 6 commits into
SmartDropLabs:mainfrom
Chigybillionz:test/multiplier-lock-invariant-130
Open

test(farming-pool): assert set_global_multiplier has zero effect on l…#136
Chigybillionz wants to merge 6 commits into
SmartDropLabs:mainfrom
Chigybillionz:test/multiplier-lock-invariant-130

Conversation

@Chigybillionz

Copy link
Copy Markdown
Contributor

Close #130

Summary of the issue

The farming-pool contract
maintains two independent accrual systems: the lock system (Position) and the boost/stake system (UserStake). Boost allocations (UserBoost) and global multipliers (global_multiplier) intentionally apply ONLY to stakers, while locked positions accrue credits strictly via amount * credit_rate * elapsed. However, there were no dedicated unit tests asserting that mid-lock set_global_multiplier or set_boost operations have zero measurable effect on locked position credit calculations, leaving this design invariant exposed to regression during future refactoring (such as credit formula consolidation in #63).

Root cause

Existing multiplier tests (test_admin_sets_global_multiplier, test_admin_multiplier_change_applies_from_next_checkpoint, etc.) focused exclusively on UserStake and get_credits(). None exercised lock_assets/calculate_credits in conjunction with set_global_multiplier or set_boost, leaving the lock path's multiplier independence unverified by the test suite.

Solution implemented

Added comprehensive unit tests to soroban/contracts/farming-pool/src/test.rs that explicitly construct scenarios where a user holds locked assets while set_global_multiplier or set_boost operations occur mid-lock. The tests assert that locked position credits accrue with zero trace of multiplier or boost changes, and directly contrast this behavior with parallel staker accrual over identical elapsed windows.

Key changes made

  • Added test_global_multiplier_change_does_not_affect_locked_position_credits in soroban/contracts/farming-pool/src/test.rs:
  • Added test_set_boost_has_zero_effect_on_locked_position_credits in soroban/contracts/farming-pool/src/test.rs:
    • Asserts calling set_boost has zero effect on open Position credit accrual.

Any trade-offs or considerations

No runtime contract code changes were made; the changes are strictly test suite additions. The doc comments on the tests clearly explain the design invariant so any future refactors breaking formula isolation will fail loudly and legibly.

Testing steps (how to verify the fix)

  1. Navigate to the contract directory:
    cd soroban/contracts/farming-pool
  2. Run cargo unit tests:
    cargo test
  3. Confirm all 76 unit tests pass without errors.

Please kindly review this task. If there are any corrections, improvements, adjustments, or merge conflicts that you notice regarding my implementation, I'd really appreciate your feedback. I'd also love to hear your overall review of my work on this branch.Thank you!

@netlify

netlify Bot commented Aug 17, 2026

Copy link
Copy Markdown

Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit 8aaf3e3
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6a91c9682ce1440008f050b4
😎 Deploy Preview https://deploy-preview-136--sdcontracts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Chigybillionz

Copy link
Copy Markdown
Contributor Author

@jamilahmadzai please kindly review

@jamilahmadzai

Copy link
Copy Markdown
Contributor

@Chigybillionz thanks, but this PR currently only adds snapshot JSON files; please restore/include the actual src/test.rs test changes so issue #130’s acceptance criteria are satisfied.

@Chigybillionz

Copy link
Copy Markdown
Contributor Author

@Chigybillionz thanks, but this PR currently only adds snapshot JSON files; please restore/include the actual src/test.rs test changes so issue #130’s acceptance criteria are satisfied.

Alright so sorry am seeing this now..
Will send the update as soon as I get to work

Chigybillionz and others added 4 commits August 28, 2026 17:54
…nt tests lost in merge

The two acceptance-criteria tests for issue SmartDropLabs#130 were accidentally dropped
during the merge of main into this branch (977e2ef). The snapshot JSON
files survived but the actual src/test.rs functions did not, which is
what the maintainer flagged.

Restores:
- test_global_multiplier_change_does_not_affect_locked_position_credits
- test_set_boost_has_zero_effect_on_locked_position_credits

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
…t tests after merge dropped them

The merge of main (7f3ce8a) again dropped the two acceptance-criteria
tests for issue SmartDropLabs#130 from src/test.rs. Re-adding them.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Fixes multiple compilation errors introduced by other merged PRs that
left dangling references in types and lib files:

- Add `StakedUserCount` variant to farming-pool `DataKey` enum
- Add `InvalidWasmHash` variant to factory `FactoryError` enum
- Add `MinimumLockNotElapsed` variant to farming-pool `PoolError` enum
- Add `staked_user_count()` / `get_staked_user_count()` public methods
- Convert `unlock_assets` lock-period assert to typed error return
- Add `setup_without_mocked_auth()` helper to factory tests
- Fix `token_admin_client` → `token_sac` in farming-pool test
- Fix factory tests to use registered SAC assets for `validate_asset`

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants