Skip to content

Replaced public distribution with winner claim lifecycle - #445

Merged
3m1n3nc3 merged 3 commits into
geevapp:mainfrom
Birdmannn:main
Aug 30, 2026
Merged

Replaced public distribution with winner claim lifecycle#445
3m1n3nc3 merged 3 commits into
geevapp:mainfrom
Birdmannn:main

Conversation

@Birdmannn

@Birdmannn Birdmannn commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

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.rs

  • Added GiveawayPrizeClaimed event emitted on every successful claim_prize call.
    Topics: ["giveaway", "claimed", <winner>] — data: [giveaway_id, net_amount].

test.rs

  • Added setup_giveaway_env test helper to reduce boilerplate across new tests.
  • Added 20 new tests:
Test What it covers
test_pick_winner_twice_fails pick_winner on a Claimable giveaway panics
test_claim_prize_emits_event GiveawayPrizeClaimed topics and net_amount are correct
test_claim_prize_zero_fee_pays_full_amount fee_bps=0 — winner receives full gross share
test_claim_prize_full_fee_pays_zero_net fee_bps=10000 — winner gets 0, contract holds all
test_recover_on_completed_giveaway_fails Recovery on a Completed giveaway panics
test_recover_after_all_claimed_is_noop Same panic path when all winners already claimed
test_recover_by_admin_after_expiry_succeeds Admin (not creator) can call recover_unclaimed_prize
test_claim_at_deadline_boundary Claim at timestamp == claim_deadline succeeds
test_claim_one_second_past_deadline_fails Claim at deadline + 1 panics with ClaimWindowExpired
test_status_stays_claimable_after_first_of_two_claims Status is Claimable after 1st claim, Completed after 2nd
test_winner_gross_share_remainder_distribution amount=10, 3 winners — index-0 gets 4, 1 and 2 get 3
test_pick_winner_insufficient_participants_fails participant_count < winner_count panics
test_pick_winner_zero_participants_fails Zero participants panics with NoParticipants
test_multi_winner_equal_split 400 tokens / 4 winners — each gets exactly 100
test_create_giveaway_zero_winner_count_fails winner_count=0 panics with InvalidWinnerCount
test_create_giveaway_zero_amount_accepted amount=0 is stored; zero-prize giveaway is valid
test_recover_unclaimed_returns_full_gross_share_no_fee Recovery sends full gross share — no fee deducted
test_reputation_not_incremented_on_recovery Creator reputation stays 0 when recovery (not claim) finalizes
test_manual_winners_non_participant_fails finalize_manual_winners with an outsider panics
test_manual_winners_duplicate_fails Duplicate address in manual winner list panics
test_finalize_merit_winners_on_random_giveaway_fails finalize_merit_winners on a Random giveaway panics

Acceptance criteria

  • ✅ Only the selected winner can claim — claim_prize calls winner.require_auth() and validates against the stored winners list
  • ✅ Winner selection and payout are separate actions — pick_winner sets Claimable, claim_prize handles the transfer
  • ✅ Fee accounting preserved — fees deducted per claim, tracked in CollectedFees
  • ✅ Reputation updated — creator rep incremented when the last winner claims

Test results

Count
Before 97 passing
After 143 passing, 0 failing

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

  • I have tested my changes locally
  • I have updated documentation as needed
  • I have run npx prisma generate after schema changes
  • I have run npx prisma migrate dev or npx prisma migrate deploy as appropriate

Post-Merge Steps for Maintainers

If this PR includes changes to the Prisma schema:

  1. Run the following command to apply the migration to your database:

    npx prisma migrate deploy

    or, for local development:

    npx prisma migrate dev
  2. Ensure your CI pipeline runs the migration before tests (add this step if missing):

    - name: Run Prisma Migrate
      run: npx prisma migrate deploy
  3. 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

@3m1n3nc3
3m1n3nc3 merged commit 212070a into geevapp:main Aug 30, 2026
2 checks passed
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.

[Giveaway] Replace public distribution with winner claim lifecycle

2 participants