fix: enforce campaign end_time in donate() (closes #5) - #49
Merged
P3az3 merged 1 commit intoJul 23, 2026
Merged
Conversation
Contributor
|
@Carlys17 resolve conflicts |
- Add end_time check in donate() to prevent donations past campaign deadline - Returns CampaignEnded error when adding funds after end_time - Add negative path & invariant tests coverage - Rebase onto upstream main, remove test snapshots
Carlys17
force-pushed
the
fix/issue-5-donate-end-time-enforcement
branch
from
July 23, 2026 11:40
e9d327b to
aff4375
Compare
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
Fixes the security gap where
donate()did not enforcecampaign.end_time. Donations could continue past the deadline until the creator manually calledend_campaign().Closes #5
Changes
campaign/src/lib.rsActive | GoalReachedmatch arm indonate():Error::CampaignEnded = 4(already defined, previously unused in production code)is_frozenbut beforemin_donation_amount— no state mutation on a doomed calldonateupdated to mention the deadline gatecampaign/src/test/negative_path_tests.rs(+4 tests)test_donate_fails_past_deadline_active— Active + past deadline → rejecttest_donate_fails_past_deadline_goal_reached— GoalReached + past deadline → rejecttest_donate_fails_at_exact_deadline_boundary— boundary:now == end_time→ reject (strict>=)test_donate_succeeds_just_before_deadline—now == end_time - 1→ succeedscampaign/src/test/integration_tests.rs(+1 test)test_lifecycle_donate_before_deadline_succeeds— positive lifecycle: donate before deadline acceptedcampaign/src/test/invariant_tests.rs(+2 tests)invariant_donate_before_deadline_always_succeeds— positive companion: Active & GoalReached before deadline → succeedsinvariant_donate_at_or_past_deadline_always_fails— negative companion:donate(clk >= end_time).is_err()(should_panic withError::CampaignEnded)docs/events.mddonation_receivedevent sectionAcceptance Criteria Checklist
Error::CampaignEnded = 4) whennow >= end_timewhile status is non-terminaldocs/events.mdand doc-comment ondonateupdatedImplementation Notes
Endedstatus on the first late call was considered but deemed out-of-scope for this security fix. The current approach (reject + panic) is the minimal safe change. A follow-up issue could add auto-transition if desired.Error::CampaignEnded = 4was already defined in theErrorenum but unused in any production code path — this PR puts it to its intended use.Test Results
All 158 tests pass. Clippy clean. Fmt clean.