-
Notifications
You must be signed in to change notification settings - Fork 168
Add validation tests for create stream – duration minimum and amount … #658
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
Open
nanaabdul1172
wants to merge
2
commits into
ritik4ever:main
Choose a base branch
from
nanaabdul1172:Validation-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Boundary Tests Implementation Summary | ||
|
|
||
| ## Overview | ||
| Added comprehensive boundary tests for the POST /api/streams route validation rules, specifically for `durationSeconds` and `totalAmount` parameters. | ||
|
|
||
| ## Tests Added | ||
|
|
||
| ### Duration Boundary Tests | ||
| Located in: `backend/src/index.test.ts` (lines ~618-664) | ||
|
|
||
| 1. **Test: durationSeconds = 59 (below minimum)** | ||
| - Sends request with `durationSeconds: 59` | ||
| - Expects: `400` status code | ||
| - Expects: Error message "durationSeconds must be at least 60 seconds" | ||
| - Validates the lower boundary is enforced | ||
|
|
||
| 2. **Test: durationSeconds = 60 (minimum boundary)** | ||
| - Sends request with `durationSeconds: 60` | ||
| - Expects: `201` status code (success) | ||
| - Validates the exact minimum boundary is accepted | ||
|
|
||
| ### Amount Precision Boundary Tests | ||
| Located in: `backend/src/index.test.ts` (lines ~666-744) | ||
|
|
||
| 1. **Test: totalAmount = 0.0000001 (1 stroop - minimum valid)** | ||
| - Sends request with `totalAmount: 0.0000001` (7 decimal places) | ||
| - Expects: `201` status code (success) | ||
| - Validates that the smallest Stellar amount (1 stroop) is accepted | ||
|
|
||
| 2. **Test: totalAmount = 0** | ||
| - Sends request with `totalAmount: 0` | ||
| - Expects: `400` status code | ||
| - Expects: Error message "Amount must be greater than zero" | ||
| - Validates zero amounts are rejected | ||
|
|
||
| 3. **Test: totalAmount with 8 decimal places** | ||
| - Sends request with `totalAmount: 100.12345678` (8 decimal places) | ||
| - Expects: `400` status code | ||
| - Expects: Error message "Amount cannot have more than 7 decimal places" | ||
| - Validates precision limit is enforced | ||
|
|
||
| 4. **Test: totalAmount with exactly 7 decimal places** | ||
| - Sends request with `totalAmount: 100.1234567` (7 decimal places) | ||
| - Expects: `201` status code (success) | ||
| - Validates the maximum precision boundary is accepted | ||
|
|
||
| ## Validation Schema Reference | ||
| The validation logic tested here is implemented in: | ||
| - `backend/src/validation/schemas.ts` | ||
| - `durationSecondsSchema`: Enforces minimum of 60 seconds | ||
| - `totalAmountSchema`: Enforces positive values and maximum 7 decimal places | ||
|
|
||
| ## Acceptance Criteria ✅ | ||
| - ✅ Duration boundary (59 vs 60) is tested explicitly | ||
| - ✅ Stroop-level minimum amount (0.0000001) is accepted | ||
| - ✅ More than 7 decimal places is rejected with clear message "Amount cannot have more than 7 decimal places" | ||
| - ✅ Zero amount is rejected with clear message "Amount must be greater than zero" | ||
| - ✅ All tests follow the existing test pattern with proper assertions | ||
|
|
||
| ## Test Structure | ||
| All boundary tests are organized under the existing `describe("POST /api/streams")` block with two sub-describe blocks: | ||
| 1. `describe("Duration boundary tests")` | ||
| 2. `describe("Amount precision boundary tests")` | ||
|
|
||
| This organization makes it easy to find and maintain these specific boundary test cases. | ||
|
|
||
| ## Additional Fix | ||
| Fixed a syntax error in `backend/src/index.ts` (lines 1040-1090) where duplicate code was causing compilation failures. Removed the duplicate query parsing and filtering logic in the recipients route handler. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
What does JavaScriptNumber.prototype.toString()return for0.00000001, and when does it use exponential notation?💡 Result:
For the number 0.00000001 (which is 10⁻⁸), JavaScript's Number.prototype.toString returns the string "1e-8" [1][2]. Exponential (scientific) notation is used by Number.prototype.toString when the radix is 10 and the absolute value of the number is either greater than or equal to 10²¹ or strictly less than 10⁻⁶ [1][3]. Specifically, the ECMAScript specification defines this behavior based on the exponent n in the number's representation [4][5]. When formatting a number in base 10, if the number cannot be represented without exceeding the range -5 to 21 for the exponent n, the engine switches to exponential notation [4][5]. In summary: - Result for 0.00000001: "1e-8" [1][2] - Threshold for exponential notation: magnitude < 10⁻⁶ or ≥ 10²¹ [1][3]
Citations:
🏁 Script executed:
Repository: ritik4ever/stellar-stream
Length of output: 34506
🏁 Script executed:
Repository: ritik4ever/stellar-stream
Length of output: 2371
Cover the scientific-notation precision bypass.
totalAmountSchemacounts decimal places withvalue.toString().split(".")[1];0.00000001becomes1e-8, which has no fractional substring and passes the “no more than 7 decimal places” check. Add a sub-stroop rejection case and switch the schema to stroop-scale/decimal-safe validation; updateBOUNDARY_TESTS_SUMMARY.mdwhere it claims >7 decimal precision is fully rejected until that case is covered.📍 Affects 2 files
backend/src/index.test.ts#L663-L742(this comment)BOUNDARY_TESTS_SUMMARY.md#L36-L40🤖 Prompt for AI Agents