-
Notifications
You must be signed in to change notification settings - Fork 6
fix: add shared guard to prevent zero pricing #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add shared guard to prevent zero pricing #237
Conversation
SgtPooki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm but needs a rebase?
… and storage calculations - Introduced assertPriceNonZero() in core/utils/validate-pricing.ts - Integrated into calculateActualCapacity() and calculateStorageFromUSDFC() - Updated tests to expect throws on zero pricing - Prevents Infinity / unsafe deposit calculations
375c8ce to
1aa4132
Compare
Aye aye, sir! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses issue #38 by adding input validation to prevent zero pricing values from causing division-by-zero errors or producing unsafe capacity calculations. The solution introduces a shared validation guard function that is integrated into capacity calculation functions.
Key changes:
- Added
assertPriceNonZero()validation utility that throws on zero or negative pricing - Replaced silent zero-price handling with explicit error throwing in
calculateActualCapacity()andcalculateStorageFromUSDFC() - Updated tests to verify error throwing behavior instead of expecting silent zero returns
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/core/utils/validate-pricing.ts |
New validation utility module with assertPriceNonZero() function |
src/core/payments/index.ts |
Integrated validation guard into two capacity calculation functions, removing previous zero-price checks |
src/test/unit/payments-setup.test.ts |
Added tests for validation function and updated existing tests to expect thrown errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
|
@entuziaz looks like you need to run |
Done, @SgtPooki |
Fixes #38. Prevents zero pricePerTiBPerEpoch in capacity and storage calculations.
Changes
core/utils/validate-pricing.tswithassertPriceNonZero()calculateActualCapacity()calculateStorageFromUSDFC()Check this out @SgtPooki.