Skip to content

fix: reject zero numerator in toXdrPrice fraction form - #1772

Open
rubenmarcus wants to merge 1 commit into
stellar:mainfrom
rubenmarcus:fix/toxdrprice-zero-n
Open

rubenmarcus wants to merge 1 commit into
stellar:mainfrom
rubenmarcus:fix/toxdrprice-zero-n

Conversation

@rubenmarcus

Copy link
Copy Markdown

Fixes #1750.

toXdrPrice({ n: 0, d: 1 }) builds the Price without complaint: the fraction form only checks xdrObject.n < 0, so a zero numerator passes while every other way of expressing a zero price (numeric 0, string "0") throws price must be positive. The operation only fails later, when Stellar Core rejects it at submission, far from the invalid input.

The fix aligns the numerator check with the denominator check on the next line: n <= 0 || d <= 0.

Verification:

$ npx vitest run test/unit/base/operation.test.ts --config config/vitest.config.ts -t 'zero numeric price'
# on main: x throws 'price must be positive' for zero numeric price
#          AssertionError: expected [Function] to throw an error   <- toXdrPrice({ n: 0, d: 1 })

$ npx vitest run test/unit --config config/vitest.config.ts
Tests  6898 passed | 4 skipped | 9 todo (6911)

$ pnpm run typecheck:tests && pnpm run test:types
# both clean

Prepared with AI assistance (GLM 5.3 via Oh My Pi) and reviewed before submission.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

toXdrPrice({n:0, d:1}) silently accepts zero price that core rejects

1 participant