Skip to content

Add split-invariance tests for unlock_assets partial withdrawals - #138

Merged
prodbycorne merged 5 commits into
SmartDropLabs:mainfrom
Smoothjane:test/unlock-split-invariance-123
Aug 18, 2026
Merged

Add split-invariance tests for unlock_assets partial withdrawals#138
prodbycorne merged 5 commits into
SmartDropLabs:mainfrom
Smoothjane:test/unlock-split-invariance-123

Conversation

@Smoothjane

Copy link
Copy Markdown
Contributor

Summary

Every existing partial-unlock test exercises exactly one fixed split of a withdrawal. checkpoint_position runs on every unlock_assets call and folds already-accrued credits into total_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 from checkpoint_position's formula being linear in amount.

  • 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 cumulative total_credits value 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.
  • Both use the existing setup/setup_with_lock_period/advance_ledgers harness, no new test infrastructure.
  • Verified the first test actually catches a regression: temporarily removed checkpoint_position's checkpoint_ledger update (a real bug class — forgetting to advance the checkpoint after banking credits) and confirmed the [500, 500] partition diverges to 15_000 instead of the invariant 10_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

  • Both new tests pass; confirmed one of them genuinely fails under an injected regression (see above), not just tautologically green
  • cargo test --workspace (mirroring CI's own steps) — 184/184 passing across factory, farming-pool, vesting-wallet
  • cargo build --workspace --target wasm32v1-none --release — succeeds
  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean

Closes #123

@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit c7a39a1
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6a84e070b954cd00095603fd
😎 Deploy Preview https://deploy-preview-138--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.

@Smoothjane
Smoothjane force-pushed the test/unlock-split-invariance-123 branch from 4b5a1b4 to c7a39a1 Compare August 18, 2026 22:45
@prodbycorne

Copy link
Copy Markdown
Contributor

Nice workdone

@prodbycorne
prodbycorne merged commit 2897811 into SmartDropLabs:main Aug 18, 2026
5 checks passed
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.

farming-pool: no test proves unlock_assets's final balances/credits are invariant to how a withdrawal is split across multiple partial unlocks

2 participants