Skip to content

test: add can_withdraw default behaviour tests - #572

Open
ghg001 wants to merge 8 commits into
Axionvera:mainfrom
ghg001:fix/issue-100-add-tests-for-can-withdraw-default-behaviour
Open

test: add can_withdraw default behaviour tests#572
ghg001 wants to merge 8 commits into
Axionvera:mainfrom
ghg001:fix/issue-100-add-tests-for-can-withdraw-default-behaviour

Conversation

@ghg001

@ghg001 ghg001 commented Aug 30, 2026

Copy link
Copy Markdown

Overview

This PR adds explicit tests for can_withdraw default behaviour in the savings vault. It verifies the function returns predictable values for a new user with no balance, a user with an available balance but no lock, and a user after a lock has been set up where applicable. The default logic in contracts/savings_vault/src/lib.rs is also made explicit so the tested defaults are intentional rather than incidental.

Related Issue

Closes the bounty issue: Add tests for can_withdraw default behaviour

Changes

🧪 Explicit can_withdraw Default Tests

  • [ADD] contracts/savings_vault/src/test/mod.rs

    • Registers the new default-behaviour test modules.
  • [ADD] contracts/savings_vault/src/test/withdraw_lock.rs

    • Test: can_withdraw_new_user_returns_false — no balance, no lock, expected default false.
    • Test: can_withdraw_available_balance_no_lock_returns_true — funds available, no lock, expected default true.
  • [ADD] contracts/savings_vault/src/test/lock_maturity_boundary.rs

    • Test: can_withdraw_locked_balance_before_unlock_returns_false — lock created but not yet mature, expected false.
    • Test: can_withdraw_after_unlock_returns_true — boundary check for comparison.
  • [MODIFY] contracts/savings_vault/src/lib.rs

    • Makes default can_withdraw handling explicit for zero-balance and no-lock cases.
    • Keeps existing lock/unlock behaviour unchanged.
  • [MODIFY] contracts/savings_vault/src/test/test_helpers.rs

    • Adds deterministic helper setup for users with and without balances/locks.

Verification Results

cargo test -p savings_vault can_withdraw
✅ 4/4 passed

Manual expectations:
✅ New user no balance → can_withdraw = false
✅ Available balance, no lock → can_withdraw = true
✅ Locked balance before unlock → can_withdraw = false
✅ Deterministic setup with fixed timestamps
Acceptance Criteria Status
can_withdraw for a new user is tested can_withdraw_new_user_returns_false
can_withdraw for a user with available balance and no lock is tested can_withdraw_available_balance_no_lock_returns_true
Expected default result is asserted ✅ Asserted on every new default-state test
Tests use deterministic setup ✅ Helper-created balances and blocks with fixed timestamps
Test names describe each state clearly ✅ Names encode user state and expected result

Closes #100

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 tests for can_withdraw default behaviour

1 participant