Skip to content

Validate batch distribution sizes#260

Open
kongwen686 wants to merge 1 commit into
Fundable-Protocol:mainfrom
kongwen686:fix/batch-distribution-validation
Open

Validate batch distribution sizes#260
kongwen686 wants to merge 1 commit into
Fundable-Protocol:mainfrom
kongwen686:fix/batch-distribution-validation

Conversation

@kongwen686
Copy link
Copy Markdown

@kongwen686 kongwen686 commented May 16, 2026

Summary

  • add a shared positive-integer guard for batch sizes
  • validate config.maxRecipientsPerBatch before preparing equal or weighted batch distributions
  • validate exported createBatches directly so zero, negative, and fractional sizes cannot hang or silently no-op
  • add Vitest coverage for invalid batch sizes and pre-RPC rejection

Closes #257

Validation

  • git diff --no-index --check for modified and new files
  • Could not run Vitest locally because the full repository could not be cloned over GitHub HTTPS in this environment and pnpm is not installed; the patch was prepared from the GitHub API copy of the target files.

Contact / payment

  • Email: chaoqiang.tian@gmail.com
  • EVM: 0x225b4bC64E051827c069312f82fA590Ec9632209
  • Stellar: GDYPL56JCCHD75ZB2I5Z4FT4WEWZFRD24LEC62XQ2MBL34653XKO65LA
  • RTC/ClawRTC: RTC02d8536941d636aee4012596afbcd8185e9f8283
  • Alipay: chaoqiang457963@126.com

Summary by CodeRabbit

  • Bug Fixes

    • Batch distribution utilities now validate batch size and recipient limits configuration to reject invalid values (zero, negative, or fractional numbers), preventing silent failures.
  • Tests

    • Added test suite for batch distribution utilities, covering validation scenarios, edge cases, and error handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 603c1050-dc6d-4413-8f49-6ca001ebbdfe

📥 Commits

Reviewing files that changed from the base of the PR and between f2c023e and c6d2724.

📒 Files selected for processing (2)
  • packages/sdk/src/__tests__/batchDistribution.test.ts
  • packages/sdk/src/utils/batchDistribution.ts

📝 Walkthrough

Walkthrough

Added input validation to prevent infinite loops and silent failures in batch distribution utilities. A new assertPositiveInteger helper validates that batch sizes are positive integers, applied to createBatches and both public distribution preparation functions. Comprehensive test coverage confirms all three functions correctly reject zero, negative, and fractional values.

Changes

Input validation for batch distribution

Layer / File(s) Summary
Input validation implementation
packages/sdk/src/utils/batchDistribution.ts
Introduced assertPositiveInteger(value, name) helper that throws when the input is not an integer or is ≤ 0. Applied to createBatches, prepareBatchEqualDistribution, and prepareBatchWeightedDistribution to validate batchSize and config.maxRecipientsPerBatch before any processing occurs.
Input validation test coverage
packages/sdk/src/__tests__/batchDistribution.test.ts
Added Vitest suite with mocked DistributorClient. Parameterized tests verify createBatches, prepareBatchEqualDistribution, and prepareBatchWeightedDistribution each throw on zero, negative, and fractional batch sizes, and confirm distribution methods are not invoked when validation fails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A batch without bounds causes loops unbound,
But now assertPositiveInteger keeps us sound.
Zero, negative, fractional foes all fall,
With tests standing guard and validation for all.
🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Validate batch distribution sizes' clearly and concisely describes the main change: adding validation for batch sizes in the batchDistribution utilities.
Linked Issues check ✅ Passed The PR implements all acceptance criteria from issue #257: validates createBatches for zero/negative/fractional batchSize, validates maxRecipientsPerBatch in both equal and weighted distribution functions, and includes test coverage for all rejection cases.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #257: adding assertPositiveInteger validation helper, integrating it into createBatches and batch preparation functions, and adding corresponding Vitest coverage.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

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.

sdk(batchDistribution): createBatches infinite-loops on batchSize <= 0; maxRecipientsPerBatch is never validated

1 participant