Skip to content

test(redemption): verify emergency_withdraw does not corrupt yield snapshots#247

Open
Majormaxx wants to merge 4 commits into
StellarYield:mainfrom
Majormaxx:feat/emergency-withdraw-snapshot-test
Open

test(redemption): verify emergency_withdraw does not corrupt yield snapshots#247
Majormaxx wants to merge 4 commits into
StellarYield:mainfrom
Majormaxx:feat/emergency-withdraw-snapshot-test

Conversation

@Majormaxx
Copy link
Copy Markdown

Summary

  • Adds test_emergency_withdraw_does_not_affect_remaining_user_yield_snapshot to test_redemption.rs
  • Two users deposit equal amounts; yield distributed (epoch 1, 100k); vault paused; emergency_withdraw drains all assets to a recipient
  • Asserts:
    • Vault is fully drained; recipient receives all funds
    • Remaining users' share balances are unchanged (emergency_withdraw never burns shares)
    • pending_yield_for_epoch(1) still returns correct snapshot-based values for both users — snapshot storage is untouched
  • No non-test code changes

Test plan

  • New test passes: cargo test -p single_rwa_vault -- test_emergency_withdraw_does_not_affect_remaining_user_yield_snapshot
  • Full suite passes: cargo test -p single_rwa_vault — 263 passed, 0 failed

Closes #221

Majormaxx added 4 commits March 29, 2026 23:12
Add test_partial_early_redemption_then_full_redemption_at_maturity to
test_redemption.rs. The test covers:

- Stage 1: user redeems half their shares early via request_early_redemption
  and process_early_redemption; asserts payout equals assets minus 2% fee
- Yield distribution between the two redemption stages
- Stage 2: user redeems remaining shares at maturity via redeem_at_maturity;
  asserts payout includes pending yield
- Final state: user holds zero vault shares; total received >= deposited principal

No non-test code changes.

Closes StellarYield#194
…movals

Add test_vault_count_correct_after_multiple_removals to tests.rs.

Creates five vaults, removes the first, middle, and last vault in
sequence, and after each removal asserts:
- get_vault_count() decrements correctly
- get_all_vaults() excludes removed vaults and retains the rest
- get_single_rwa_vaults() reflects the same exclusions
- is_registered_vault() returns false for removed vaults
- instance-storage counter always equals the vault list length

No non-test code changes.

Closes StellarYield#192
Add test_transfer_during_active_epoch_yield_attribution to test_token.rs.

Timeline:
- Epoch 1 opens with 100 yield over 1_000 shares
- Alice (1_000 shares) transfers 400 to Bob mid-epoch
- Epoch 2 opens with 200 yield over 1_000 shares

Asserts:
- Alice epoch-1 yield = 100 (full; snapshot captured pre-transfer 1_000)
- Bob  epoch-1 yield =   0 (snapshot captured pre-transfer 0)
- Alice epoch-2 yield = 120 (600/1_000 * 200)
- Bob  epoch-2 yield =  80 (400/1_000 * 200)
- Combined = 300, equal to total distributed

No non-test code changes.

Closes StellarYield#197
…apshots

Add test_emergency_withdraw_does_not_affect_remaining_user_yield_snapshot
to test_redemption.rs.

Two users deposit equal amounts and yield is distributed (epoch 1).
The vault is then paused and emergency_withdraw drains all assets.

Asserts:
- Vault is empty and recipient received all funds
- Remaining users' share balances are unchanged
- pending_yield_for_epoch(1) still returns correct values for both users
  (snapshot storage is not touched by emergency_withdraw)

No non-test code changes.

Closes StellarYield#221
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Mar 29, 2026

@Majormaxx Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add Test for emergency_withdraw Not Affecting Snapshot-Based Yield for Remaining Users

1 participant