Skip to content

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

Open
Chigybillionz wants to merge 2 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 2 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 977e2ef
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6a834aca20eb73000880d122
😎 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.
🤖 Make changes Run an agent on this branch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant