set_stretch_goals(env: Env, milestones: Vec<i128>)(Auth: Organizer)- Validates
milestonesare strictly increasing. - Stores them in
DataKey::StretchGoals. - Bug found: It currently immediately publishes
StretchGoalReachedEventfor all milestones when setting them!
- Validates
check_stretch_goals(env: &Env, new_raised: i128)(Internal)- Called automatically during pledging.
- Checks if
new_raised >= thresholdfor each milestone. - Marks
DataKey::StretchTriggered(idx)as true. - Publishes
StretchGoalReachedEventfor newly crossed milestones.
DataKey::StretchGoals: Set byset_stretch_goals.DataKey::StretchTriggered(u32): Set totruebycheck_stretch_goalswhen crossed.
StretchGoalReachedEvent { milestone_index: u32, threshold: i128 }- Emitted (incorrectly) in
set_stretch_goals. - Emitted correctly in
check_stretch_goalswhen threshold is met.
- Emitted (incorrectly) in
NotInitialized:set_stretch_goalscalled before contract is initialized (Organizer missing).NotAuthorized: caller is not the organizer.InvalidGoal: if milestones are not strictly increasing (m <= prev).
milestoneselements arei128. Check againsti128::MAX.new_raisedcould be large, boundary values at exact threshold, threshold-1, threshold+1.
Create contracts/crowdfund/src/tests/test_feature_205.rs.
Test happy path (set goals, pledge to cross them, check state/events).
Test auth checks (non-organizer setting goals).
Test boundary conditions (overflow/underflow, off-by-one).
Test storage rollback on panic.