Add split-invariance tests for unlock_assets partial withdrawals - #138
Merged
prodbycorne merged 5 commits intoAug 18, 2026
Merged
Conversation
✅ Deploy Preview for sdcontracts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…d on how a withdrawal is partitioned
Smoothjane
force-pushed
the
test/unlock-split-invariance-123
branch
from
August 18, 2026 22:45
4b5a1b4 to
c7a39a1
Compare
Contributor
|
Nice workdone |
3 tasks
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.
Summary
Every existing partial-unlock test exercises exactly one fixed split of a withdrawal.
checkpoint_positionruns on everyunlock_assetscall and folds already-accrued credits intototal_credits— a genuinely different code path per partial call than a single full unlock — so whether the final outcome (token balance, credits, cleared position) is actually invariant to how a withdrawal is partitioned was asserted nowhere, only assumed fromcheckpoint_position's formula being linear inamount.test_unlock_assets_final_outcome_is_invariant_to_how_the_withdrawal_is_split: locks 1,000, advances 10 ledgers, then withdraws the full amount via 4 different partitions ([1000],[500, 500],[300, 200, 500],[1, 1, 998]) — varying both partition count and sizing per the acceptance criteria — with zero further ledger advance between calls within a partition (isolating this from farming-pool: no property-based test enforces that total accrued credits are independent of checkpoint frequency #75's already-covered time-invariance). Asserts identical final token balance,calculate_credits(), cleared position, and — since every call after the first has zero elapsed ledgers — an identical final cumulativetotal_creditsvalue in the last unlock's emitted event across every partition.test_unlock_assets_split_across_min_lock_period_boundary_reaches_same_final_state_as_single_unlock: covers the issue's explicit edge case — one scenario unlocks everything in a single call the moment the position matures; the other attempts (and correctly gets rejected for) an early partial unlock before maturity, then completes the withdrawal split across two calls once matured. Both reach an identical final state.setup/setup_with_lock_period/advance_ledgersharness, no new test infrastructure.checkpoint_position'scheckpoint_ledgerupdate (a real bug class — forgetting to advance the checkpoint after banking credits) and confirmed the[500, 500]partition diverges to15_000instead of the invariant10_000, while[1_000]alone stayed correct — exactly the kind of split-count-dependent bug this test exists to catch. Reverted before committing.Test plan
cargo test --workspace(mirroring CI's own steps) — 184/184 passing acrossfactory,farming-pool,vesting-walletcargo build --workspace --target wasm32v1-none --release— succeedscargo fmt --all -- --check— cleancargo clippy --workspace --all-targets -- -D warnings— cleanCloses #123