feat(contracts/market): verify withdraw cooldown respects LastDepositTime (#565) - #628
Merged
Mimah97 merged 1 commit intoJul 28, 2026
Conversation
…Time (Vatix-Protocol#565) The WITHDRAW_COOLDOWN_SECONDS (3 600 s) guard has been present in withdraw_unused_collateral since issue Vatix-Protocol#413, but had no dedicated unit-test coverage and its interaction with LastDepositTime was not documented. This commit: 1. Adds a clear module-level doc section (## Withdrawal cooldown) to withdraw.rs describing the full deposit → timestamp → cooldown flow, including the data-flow diagram and the edge-case when no deposit has yet been recorded. 2. Adds three focused unit tests inside the existing #[cfg(test)] mod tests block that confirm the acceptance criteria for issue Vatix-Protocol#565: • test_withdraw_blocked_within_cooldown Sets LastDepositTime to the current ledger timestamp and asserts that an immediate withdrawal returns WithdrawCooldownActive. • test_withdraw_allowed_after_cooldown Sets LastDepositTime to (now − WITHDRAW_COOLDOWN_SECONDS), placing the user exactly at the boundary where elapsed >= cooldown, and asserts the withdrawal succeeds. • test_withdraw_no_deposit_record_bypasses_cooldown Asserts that a user with no LastDepositTime key does NOT receive WithdrawCooldownActive — the cooldown only fires after a deposit. The core implementation in withdraw_unused_collateral is unchanged: if let Some(last_deposit_time) = storage::get_last_deposit_time(...) elapsed = timestamp.saturating_sub(last_deposit_time) if elapsed < WITHDRAW_COOLDOWN_SECONDS → Err(WithdrawCooldownActive) Closes Vatix-Protocol#565
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
Closes #565
Documents and adds targeted unit tests confirming the withdrawal cooldown behaviour introduced in issue #413.
Problem
The
WITHDRAW_COOLDOWN_SECONDS(3 600 s / 1 hour) guard inwithdraw_unused_collateralwas readingLastDepositTimecorrectly, but:Without explicit test coverage, a future refactor could accidentally drop the check and CI would not catch it.
Changes
contracts/market/src/withdraw.rsDocumentation — new
## Withdrawal cooldown (#413 / #565)section in the module-level doc comment:deposit_collateral → set_last_deposit_time → withdraw checkTests — three new unit tests in the existing
#[cfg(test)] mod testsblock:test_withdraw_blocked_within_cooldownWithdrawCooldownActivewhenelapsed = 0 < 3 600test_withdraw_allowed_after_cooldownelapsed = 3 600 >= 3 600(exact boundary)test_withdraw_no_deposit_record_bypasses_cooldownLastDepositTime→ cooldown is not triggeredCore implementation (unchanged)
Acceptance criteria
WithdrawCooldownActiveNotes