test(farming-pool): assert set_global_multiplier has zero effect on l… - #136
Open
Chigybillionz wants to merge 2 commits into
Open
test(farming-pool): assert set_global_multiplier has zero effect on l…#136Chigybillionz wants to merge 2 commits into
Chigybillionz wants to merge 2 commits into
Conversation
…ocked position accrual path
✅ Deploy Preview for sdcontracts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #130
Summary of the issue
The
farming-poolcontractmaintains 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 viaamount * credit_rate * elapsed. However, there were no dedicated unit tests asserting that mid-lockset_global_multiplierorset_boostoperations 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 onUserStakeandget_credits(). None exercisedlock_assets/calculate_creditsin conjunction withset_global_multiplierorset_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.rsthat explicitly construct scenarios where a user holds locked assets whileset_global_multiplierorset_boostoperations 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
test_global_multiplier_change_does_not_affect_locked_position_creditsinsoroban/contracts/farming-pool/src/test.rs:PositionandUserStakefor the same user across a 20-ledger period whereset_global_multiplierincreases from 1 to 5 mid-lock.1000 * 1 * 20 = 20,000, while stake credits retroactively adjust to100,000(per farming-pool: get_credits retroactively reprices a user's entire uncheckpointed accrual window when the admin changes the global multiplier #60).test_set_boost_has_zero_effect_on_locked_position_creditsinsoroban/contracts/farming-pool/src/test.rs:set_boosthas zero effect on openPositioncredit 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)
cd soroban/contracts/farming-poolcargo testPlease 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!