test(events): added bounty pillar — apply / withdraw_application + c…#47
Conversation
📝 WalkthroughWalkthroughA new ChangesBounty Pillar Test Coverage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
contracts/events/src/tests/bounty_pillar.rscontracts/events/src/tests/cross_contract.rscontracts/events/src/tests/mod.rs
| 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"); | ||
| } |
There was a problem hiding this comment.
🎯 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.
| 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.
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:contracts/events/src/tests/mod.rs—mod bounty_pillar;Migrated from
cross_contract.rs— the 5 apply/withdraw tests now live inbounty_pillar.rswith explicitErrorassertions (viaexpect_op_errhelper).Snapshots — 22 new files under
test_snapshots/tests/bounty_pillar/; removed 5 orphanedcross_contractsnapshots.Test results
cargo test -p boundless-events— 93 passedcargo 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.Summary by CodeRabbit