Skip to content

test(events): added bounty pillar — apply / withdraw_application + c…#47

Merged
0xdevcollins merged 1 commit into
boundlessfi:testnetfrom
ryzen-xp:test(event)--added-bounty-pillar--tests
Jun 24, 2026
Merged

test(events): added bounty pillar — apply / withdraw_application + c…#47
0xdevcollins merged 1 commit into
boundlessfi:testnetfrom
ryzen-xp:test(event)--added-bounty-pillar--tests

Conversation

@ryzen-xp

@ryzen-xp ryzen-xp commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Implemented issue #33: dedicated bounty pillar test module with full apply/withdraw coverage.

What was added

contracts/events/src/tests/bounty_pillar.rs — 22 tests covering:

Area | Tests -- | -- validate_create | Multi release rejected; application_credit_cost > 100 rejected apply_to_bounty | Credit bootstrap + spend; zero-cost apply; duplicate apply; insufficient credits (profile bubble); idempotent replay; not found / wrong pillar / cancelled / completed / past deadline / paused; applicant auth withdraw_application | 50% refund; zero-cost skip refund; not applied; after submit; idempotent replay; not found / paused; applicant auth

contracts/events/src/tests/mod.rs  mod bounty_pillar;

Migrated from cross_contract.rs — the 5 apply/withdraw tests now live in bounty_pillar.rs with explicit Error assertions (via expect_op_err helper).

Snapshots — 22 new files under test_snapshots/tests/bounty_pillar/; removed 5 orphaned cross_contract snapshots.

Test results

  • cargo test -p boundless-events  93 passed
  • cargo test --all  106 passed (93 events + 13 profile)

Note on coverage gap

TooManyApplicants (cap = 5,000) is not exercised — filling that many slots in a host test isn’t practical. Every other bounty-path error variant in scope is covered.

Screenshot From 2026-06-23 23-23-28 Screenshot From 2026-06-23 23-23-28

Summary by CodeRabbit

  • Tests
    • Added comprehensive integration tests for bounty event creation, application, and withdrawal workflows, including validation of error conditions, credit management, and user authorization requirements.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new bounty_pillar.rs test module is added to contracts/events/src/tests/, providing dedicated integration test coverage for Pillar::Bounty flows: event creation validation, apply_to_bounty, and withdraw_application. The previously existing bounty apply/withdraw tests are deleted from cross_contract.rs, and mod.rs gains the new submodule declaration.

Changes

Bounty Pillar Test Coverage

Layer / File(s) Summary
Test scaffolding, helpers, and module wiring
contracts/events/src/tests/mod.rs, contracts/events/src/tests/cross_contract.rs, contracts/events/src/tests/bounty_pillar.rs
Registers mod bounty_pillar; in the module index, updates the cross_contract.rs header comment to reflect the scope change, and establishes the shared Ctx/setup() harness, event/distribution builder helpers, and the expect_op_err utility in the new file.
create_event validation tests
contracts/events/src/tests/bounty_pillar.rs
Asserts that multi-release bounty types are rejected with InvalidReleaseKind and that out-of-bounds application_credit_cost is rejected with InvalidPillar.
apply_to_bounty happy path, guards, and auth
contracts/events/src/tests/bounty_pillar.rs
Covers credit deduction/bootstrap on happy path, zero-cost bootstrap, and all error/idempotency/lifecycle guards including duplicate apply, op replay, insufficient credits, missing event, wrong pillar, cancelled, completed, deadline expiry, paused state, and explicit auth assertion.
withdraw_application happy path, guards, and auth
contracts/events/src/tests/bounty_pillar.rs
Covers half-refund semantics and applicant removal on happy path, zero-cost no-refund path, and all error/idempotency/lifecycle guards including not-applied, post-submission block, op replay, missing event, paused state, and explicit auth assertion.
Remove bounty tests from cross_contract.rs
contracts/events/src/tests/cross_contract.rs
Deletes the prior bounty apply/withdraw/refund/idempotency test suite, leaving cross_contract.rs covering only select_winners, submit, and cancel.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐇 A new file hops in, tests all in a row,
Apply and withdraw, each path gets its show.
Credits deducted, then half given back,
The old cross-contract clears out the old stack.
With mod bounty_pillar declared just right,
Every error variant tested in sight!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is truncated and vague; it uses abbreviated terms like 'bounty pillar — apply / withdraw_application + c…' without conveying clear intent. Complete the title with the full message and ensure it clearly summarizes the main change, e.g., 'test(events): add bounty pillar tests for apply and withdraw_application operations'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed All acceptance criteria from issue #33 are met: new bounty_pillar.rs module covers apply/withdraw_application, includes happy path and error cases, includes auth validation, and cargo test passes.
Out of Scope Changes check ✅ Passed All changes are within scope: new bounty_pillar.rs test module, updates to cross_contract.rs test documentation, and mod.rs module declaration are all directly related to issue #33 requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/events/src/tests/bounty_pillar.rs`:
- Around line 252-261: The test insufficient_credits_reverts is currently too
permissive as it only asserts that res is an error using is_err(), which allows
the test to pass even if a different error variant occurs. Replace the generic
is_err() assertion with expect_op_err(...) to specifically assert and verify
that the returned error is the InsufficientCredits variant, ensuring the test
fails for the correct reason if an unexpected error type is returned instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 654c439b-62aa-46d0-b13a-0cea4b73f545

📥 Commits

Reviewing files that changed from the base of the PR and between d3a32bd and 2c3ee65.

📒 Files selected for processing (3)
  • contracts/events/src/tests/bounty_pillar.rs
  • contracts/events/src/tests/cross_contract.rs
  • contracts/events/src/tests/mod.rs

Comment on lines +252 to +261
fn insufficient_credits_reverts() {
let ctx = setup();
let bounty_id = create_bounty(&ctx, 100);

let op_id = BytesN::random(&ctx.env);
let res = ctx
.events
.try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id);
assert!(res.is_err(), "profile InsufficientCredits should bubble up");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the specific error variant for insufficient credits.

Line 260 currently accepts any failure, so this test can pass for the wrong reason. Use expect_op_err(...) and assert the exact expected error to lock behavior.

Proposed tightening
 #[test]
 fn insufficient_credits_reverts() {
     let ctx = setup();
     let bounty_id = create_bounty(&ctx, 100);

     let op_id = BytesN::random(&ctx.env);
-    let res = ctx
-        .events
-        .try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id);
-    assert!(res.is_err(), "profile InsufficientCredits should bubble up");
+    let err = expect_op_err(
+        ctx.events
+            .try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id),
+    );
+    assert_eq!(err, Error::InsufficientCredits);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn insufficient_credits_reverts() {
let ctx = setup();
let bounty_id = create_bounty(&ctx, 100);
let op_id = BytesN::random(&ctx.env);
let res = ctx
.events
.try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id);
assert!(res.is_err(), "profile InsufficientCredits should bubble up");
}
fn insufficient_credits_reverts() {
let ctx = setup();
let bounty_id = create_bounty(&ctx, 100);
let op_id = BytesN::random(&ctx.env);
let err = expect_op_err(
ctx.events
.try_apply_to_bounty(&bounty_id, &ctx.applicant, &op_id),
);
assert_eq!(err, Error::InsufficientCredits);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/events/src/tests/bounty_pillar.rs` around lines 252 - 261, The test
insufficient_credits_reverts is currently too permissive as it only asserts that
res is an error using is_err(), which allows the test to pass even if a
different error variant occurs. Replace the generic is_err() assertion with
expect_op_err(...) to specifically assert and verify that the returned error is
the InsufficientCredits variant, ensuring the test fails for the correct reason
if an unexpected error type is returned instead.

@0xdevcollins 0xdevcollins merged commit 3cde6cf into boundlessfi:testnet Jun 24, 2026
1 check 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.

test(events): bounty pillar — apply / withdraw_application + credit charge

2 participants