Replaced public distribution with winner claim lifecycle - #445
Merged
Conversation
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.
Pull Request Template
Description
feat(giveaway): explicit winner claim flow + edge-case test coverage
Closes #405
Summary
Replaces the push-based prize distribution with an explicit pull-based claim lifecycle and expands test coverage across all claim lifecycle edge cases.
Changes
giveaway.rsGiveawayPrizeClaimedevent emitted on every successfulclaim_prizecall.Topics:
["giveaway", "claimed", <winner>]— data:[giveaway_id, net_amount].test.rssetup_giveaway_envtest helper to reduce boilerplate across new tests.test_pick_winner_twice_failspick_winneron aClaimablegiveaway panicstest_claim_prize_emits_eventGiveawayPrizeClaimedtopics andnet_amountare correcttest_claim_prize_zero_fee_pays_full_amountfee_bps=0— winner receives full gross sharetest_claim_prize_full_fee_pays_zero_netfee_bps=10000— winner gets 0, contract holds alltest_recover_on_completed_giveaway_failsCompletedgiveaway panicstest_recover_after_all_claimed_is_nooptest_recover_by_admin_after_expiry_succeedsrecover_unclaimed_prizetest_claim_at_deadline_boundarytimestamp == claim_deadlinesucceedstest_claim_one_second_past_deadline_failsdeadline + 1panics withClaimWindowExpiredtest_status_stays_claimable_after_first_of_two_claimsClaimableafter 1st claim,Completedafter 2ndtest_winner_gross_share_remainder_distributionamount=10, 3 winners— index-0 gets 4, 1 and 2 get 3test_pick_winner_insufficient_participants_failsparticipant_count < winner_countpanicstest_pick_winner_zero_participants_failsNoParticipantstest_multi_winner_equal_split400 tokens / 4 winners— each gets exactly 100test_create_giveaway_zero_winner_count_failswinner_count=0panics withInvalidWinnerCounttest_create_giveaway_zero_amount_acceptedamount=0is stored; zero-prize giveaway is validtest_recover_unclaimed_returns_full_gross_share_no_feetest_reputation_not_incremented_on_recoverytest_manual_winners_non_participant_failsfinalize_manual_winnerswith an outsider panicstest_manual_winners_duplicate_failstest_finalize_merit_winners_on_random_giveaway_failsfinalize_merit_winnerson aRandomgiveaway panicsAcceptance criteria
claim_prizecallswinner.require_auth()and validates against the stored winners listpick_winnersetsClaimable,claim_prizehandles the transferCollectedFeesTest results
CI
cargo fmt --all -- --check✅cargo clippy --workspace --all-targets --all-features --locked -- -D warnings✅cargo test --workspace --locked✅cargo build --workspace --target wasm32-unknown-unknown --release --locked✅Checklist
npx prisma generateafter schema changesnpx prisma migrate devornpx prisma migrate deployas appropriatePost-Merge Steps for Maintainers
If this PR includes changes to the Prisma schema:
Run the following command to apply the migration to your database:
or, for local development:
Ensure your CI pipeline runs the migration before tests (add this step if missing):
Make sure the database user in CI has permission to run migrations.
If you have any questions, please comment on this PR.
this PR closes #405