Skip to content

refactor(quest-engine): unify batch and single review payout logic - #110

Merged
3m1n3nc3 merged 1 commit into
learnault:mainfrom
Muhammadjazuli:feat/batch-review-parity
Aug 21, 2026
Merged

refactor(quest-engine): unify batch and single review payout logic#110
3m1n3nc3 merged 1 commit into
learnault:mainfrom
Muhammadjazuli:feat/batch-review-parity

Conversation

@Muhammadjazuli

Copy link
Copy Markdown
Contributor

Summary

Resolves the parity gap between review_submission and batch_review_submissions in the QuestEngine contract.

Previously, batch_review_submissions used a flat payout (fee + base amount) with no staking-multiplier logic. This meant bulk approvals behaved differently from individual approvals, violating the contract's intended invariants.

Changes

contracts/quest-engine/src/lib.rs

  • Extracted approve_submission_inner — an internal helper that encapsulates the full approval flow:
    • 15 % platform fee transferred to the reward pool
    • StakeVault multiplier query
    • Boost path (multiplier ≥ 100): pays base from escrow, draws delta from reward pool via distribute_reward
    • Penalty path (multiplier < 100): pays reduced amount from escrow, penalty goes to reward pool
    • Sets submission.status = Approved
  • review_submission delegates the approval branch to the helper (no behaviour change)
  • batch_review_submissions replaces the old inline flat-payout loop with a call to the helper per learner

contracts/quest-engine/src/test.rs

  • Added MockStakeVaultPerLearner: stores per-learner multipliers so mixed-tier batch tests work
  • New tests:
    • test_batch_review_with_120_multiplier — boost path verified in batch
    • test_batch_review_with_200_multiplier — larger boost verified in batch
    • test_batch_review_with_80_multiplier — penalty path verified in batch
    • test_batch_review_mixed_multiplier_tiers — three learners each with a different tier (120×, 80×, 100×) in the same batch run
    • test_batch_review_fails_when_pool_cannot_cover_boost — panics when pool has insufficient balance
    • test_batch_review_paused_panics — pause check propagated to batch
    • test_batch_review_already_reviewed_panics — double-approval guard in batch

Acceptance criteria

  • Batch approval applies the same fee and multiplier behaviour as single approval
  • A change to single-review payout rules does not require duplicating the logic
  • Batch review tests cover mixed multiplier tiers and failure cases

Verification

cargo fmt --all -- --check  ✓
cargo clippy --all-targets --all-features -- -D warnings  ✓
cargo test -p quest-engine   61 passed; 0 failed  ✓

closes #88

Extract approve_submission_inner as a shared internal helper that
applies the 15% platform fee, queries the StakeVault multiplier,
handles both boost (>= 100) and penalty (< 100) paths, and marks
the submission Approved.

review_submission and batch_review_submissions now both delegate the
approval path to this helper, eliminating the duplicated flat-payout
logic that previously existed in batch_review_submissions and ensuring
the two paths can never drift apart.

New tests added to test.rs:
- test_batch_review_with_120_multiplier  (boost path in batch)
- test_batch_review_with_200_multiplier  (large boost in batch)
- test_batch_review_with_80_multiplier   (penalty path in batch)
- test_batch_review_mixed_multiplier_tiers (multiple learners, different tiers)
- test_batch_review_fails_when_pool_cannot_cover_boost (failure case)
- test_batch_review_paused_panics
- test_batch_review_already_reviewed_panics

All 61 tests pass; cargo fmt and clippy -D warnings clean.

closes learnault#88
@3m1n3nc3
3m1n3nc3 merged commit a898180 into learnault:main Aug 21, 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.

[QuestEngine] Make batch review payout logic match single review

2 participants