-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Description:
The savings_goals contract creates every new goal with locked: true so that funds cannot be withdrawn until the owner explicitly calls unlock_goal. This prevents accidental withdrawals and enforces the intended flow (create -> add funds -> unlock when ready -> withdraw). If this default were changed or the field misinterpreted, users could withdraw from goals that should still be locked. This issue adds a test that immediately after create_goal the goal is returned with locked == true, and that withdraw_from_goal fails with the expected panic or error before unlock_goal is called.
Requirements
Test scenario: Create a goal as owner (e.g. create_goal(env, owner, name, target_amount, target_date)). Call get_goal(goal_id) and assert goal.locked == true. Without calling unlock_goal, call withdraw_from_goal(owner, goal_id, amount) (after adding some funds to the goal so balance is sufficient); assert the call fails (panic "Cannot withdraw from a locked goal" or equivalent). Optionally call unlock_goal, then withdraw_from_goal, and assert it succeeds and balance decreases.
Acceptance Criteria
- Test creates a goal and asserts
get_goal(...).locked == true. - Test asserts
withdraw_from_goalfails when the goal is still locked. - Test is in savings_goals test suite and runs in CI.