Skip to content

test(events): bounty pillar coverage — apply/withdraw + credit charge (#33)#36

Open
zeroknowledge0x wants to merge 2 commits into
boundlessfi:developfrom
zeroknowledge0x:bounty/33-test-events-bounty-pillar-apply-withdr
Open

test(events): bounty pillar coverage — apply/withdraw + credit charge (#33)#36
zeroknowledge0x wants to merge 2 commits into
boundlessfi:developfrom
zeroknowledge0x:bounty/33-test-events-bounty-pillar-apply-withdr

Conversation

@zeroknowledge0x

Copy link
Copy Markdown

Closes #33

Summary

Add contracts/events/src/tests/bounty_pillar.rs covering every code path
reachable from apply_to_bounty and withdraw_application — happy paths,
each Error variant, edge cases, idempotency, and auth-rejection.

What changed

  • New file: contracts/events/src/tests/bounty_pillar.rs (541 lines, 20 tests)
  • Wired in: contracts/events/src/tests/mod.rs — added mod bounty_pillar;
  • Snapshots: 21 test_snapshots/tests/bounty_pillar/*.json regenerated by cargo test

Coverage matrix

apply_to_bounty (10 tests)

  • happy path: profile bootstrapped, credits debited, applicant appended
  • duplicate apply (same op_id) → OpAlreadySeen
  • duplicate apply (new op_id) → ApplicantAlreadyApplied
  • apply to nonexistent bounty → EventNotFound
  • apply to non-bounty pillar → InvalidPillar
  • apply to cancelled bounty → EventActive
  • apply when contract paused → Paused
  • apply with insufficient credits → InsufficientCredits
  • auth: require_auth() requested for applicant (verified via env.auths() snapshot)

withdraw_application (9 tests)

  • happy path with odd cost: refund = cost / 2
  • happy path with zero cost: no refund
  • withdraw removes applicant from list
  • withdraw then re-apply succeeds
  • withdraw without prior apply → ApplicantNotApplied
  • withdraw after submit → SubmissionAlreadyExists
  • duplicate withdraw (same op_id) → OpAlreadySeen
  • withdraw when contract paused → Paused

Auth verification

mock_all_auths_allowing_non_root_auth() auto-approves every require_auth()
at the host level, so #[should_panic(expected = "Auth")] cannot fire. The
apply_records_applicant_auth_in_snapshot test instead checks env.auths()
to confirm the contract requested auth for the applicant (rather than
silently skipping the check).

Acceptance criteria

  • New tests/bounty_pillar.rs covering every function in scope
  • Happy path + each Error variant + edge cases + auth-rejection + idempotency
  • cargo test --all passes (96 events tests + 13 profile tests, 0 failures)
  • PR links this issue

Test evidence

$ cargo test -p boundless-events --lib bounty_pillar --no-fail-fast
running 20 tests
test tests::bounty_pillar::apply_duplicate_with_new_op_id_reverts ... ok
test tests::bounty_pillar::apply_happy_path_appends_to_applicants_list ... ok
test tests::bounty_pillar::apply_happy_path_credits_debited_and_profile_bootstrapped ... ok
test tests::bounty_pillar::apply_records_applicant_auth_in_snapshot ... ok
test tests::bounty_pillar::apply_replayed_with_same_op_id_reverts ... ok
test tests::bounty_pillar::apply_to_cancelled_bounty_reverts ... ok
test tests::bounty_pillar::apply_to_nonexistent_bounty_reverts ... ok
test tests::bounty_pillar::apply_when_paused_reverts ... ok
test tests::bounty_pillar::apply_to_non_bounty_pillar_reverts ... ok
test tests::bounty_pillar::apply_with_insufficient_credits_reverts ... ok
test tests::bounty_pillar::apply_with_higher_cost_debits_more_credits ... ok
test tests::bounty_pillar::apply_with_zero_cost_does_not_debit_credits ... ok
test tests::bounty_pillar::withdraw_after_submit_reverts ... ok
test tests::bounty_pillar::withdraw_refunds_half_credits_on_odd_cost ... ok
test tests::bounty_pillar::withdraw_replayed_with_same_op_id_reverts ... ok
test tests::bounty_pillar::withdraw_removes_applicant_from_list ... ok
test tests::bounty_pillar::withdraw_then_reapply_succeeds ... ok
test tests::bounty_pillar::withdraw_when_paused_reverts ... ok
test tests::bounty_pillar::withdraw_with_zero_cost_does_not_change_credits ... ok
test tests::bounty_pillar::withdraw_without_prior_apply_reverts ... ok

test result: ok. 20 passed; 0 failed
$ cargo test --all
... (profile)
test result: ok. 13 passed; 0 failed
... (events)
test result: ok. 96 passed; 0 failed

Refs #25 (parent epic: contract test-coverage push)

Signed-off-by: zeroknowledge0x [email protected]

…boundlessfi#33)

Add tests/bounty_pillar.rs covering every code path reachable from
apply_to_bounty and withdraw_application:

- happy path: profile bootstrapped, credits debited, applicant appended
- duplicate apply (same op_id)   -> OpAlreadySeen
- duplicate apply (new op_id)    -> ApplicantAlreadyApplied
- apply to nonexistent bounty     -> EventNotFound
- apply to non-bounty pillar      -> InvalidPillar
- apply to cancelled bounty       -> EventActive
- apply when contract paused      -> Paused
- apply with insufficient credits -> InsufficientCredits

withdraw:
- happy path with odd cost: refund = cost / 2
- happy path with zero cost: no refund
- withdraw without prior apply    -> ApplicantNotApplied
- withdraw after submit           -> SubmissionAlreadyExists
- duplicate withdraw (same op_id) -> OpAlreadySeen
- withdraw when contract paused   -> Paused

Auth: verify require_auth() is requested for the applicant via env.auths()
snapshot (mock_all_auths_allowing_non_root_auth auto-approves at the host
level, so should_panic auth tests are not reliable).

Refs boundlessfi#33
Signed-off-by: zeroknowledge0x <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 973b08c8-f6ec-4c43-a113-4cdbe750f8bc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…check)

CI run 27906733663 on commit c7b0799 failed the rustfmt job. Apply
cargo fmt across the affected contracts to clear the format check and
unblock merge. No semantic changes.
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.

1 participant