From e1caa4ae77349241426893f161953c316f54b2e5 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:42:41 -0300 Subject: [PATCH 1/5] test(ts-sdk): cover non-numeric string amount in hosted buildOrder --- sdks/typescript/tests/hosted-dispatch.test.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/sdks/typescript/tests/hosted-dispatch.test.ts b/sdks/typescript/tests/hosted-dispatch.test.ts index d860b129..c96b171a 100644 --- a/sdks/typescript/tests/hosted-dispatch.test.ts +++ b/sdks/typescript/tests/hosted-dispatch.test.ts @@ -23,7 +23,7 @@ import { Polymarket } from "../pmxt/client"; import { HOSTED_TRADING_BASE_URL, } from "../pmxt/hosted-routing"; -import { NotSupported } from "../pmxt/errors"; +import { NotSupported, InvalidOrder } from "../pmxt/errors"; import { MissingWalletAddress } from "../pmxt/hosted-errors"; const PMXT_API_KEY = "test_pmxt_key_xxx"; @@ -396,3 +396,34 @@ describe("hosted write dispatch", () => { expect(reqs[1].url).toContain("/v0/orders/cancel"); }); }); + +// -------------------------------------------------------------------------- +// Hosted build-order amount validation (issue #2423) +// -------------------------------------------------------------------------- + +describe("hosted buildOrder amount validation", () => { + const baseParams = { + marketId: "11111111-1111-4111-8111-111111111111", + outcomeId: "22222222-2222-4222-8222-222222222222", + side: "buy", + type: "market", + denom: "usdc", + }; + + // The amount guard runs before any network or wallet access, so these + // reject locally. `amount` is typed `number`, so malformed inputs are cast. + function expectAmountError(amount: unknown, message: string) { + const api = makePolymarket(); + return expect( + api.buildOrder({ ...baseParams, amount } as any), + ).rejects.toThrow(new InvalidOrder(message)); + } + + it("non-numeric string amount -> 'amount must be a finite positive number'", () => { + return expectAmountError("not-a-number", "amount must be a finite positive number"); + }); + + + + +}); From ca4bf97b9179aa79dda9a14f155e941efc9d2fde Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:42:41 -0300 Subject: [PATCH 2/5] test(ts-sdk): cover negative amount in hosted buildOrder --- sdks/typescript/tests/hosted-dispatch.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdks/typescript/tests/hosted-dispatch.test.ts b/sdks/typescript/tests/hosted-dispatch.test.ts index c96b171a..66486499 100644 --- a/sdks/typescript/tests/hosted-dispatch.test.ts +++ b/sdks/typescript/tests/hosted-dispatch.test.ts @@ -423,6 +423,9 @@ describe("hosted buildOrder amount validation", () => { return expectAmountError("not-a-number", "amount must be a finite positive number"); }); + it("negative numeric amount -> 'amount must be positive'", () => { + return expectAmountError(-5, "amount must be positive"); + }); From 57c0462c40fe9ade1f4ab99e96dd3d87b7559890 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:42:41 -0300 Subject: [PATCH 3/5] test(ts-sdk): cover zero amount in hosted buildOrder --- sdks/typescript/tests/hosted-dispatch.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdks/typescript/tests/hosted-dispatch.test.ts b/sdks/typescript/tests/hosted-dispatch.test.ts index 66486499..177024ef 100644 --- a/sdks/typescript/tests/hosted-dispatch.test.ts +++ b/sdks/typescript/tests/hosted-dispatch.test.ts @@ -427,6 +427,9 @@ describe("hosted buildOrder amount validation", () => { return expectAmountError(-5, "amount must be positive"); }); + it("zero amount -> 'amount must be positive'", () => { + return expectAmountError(0, "amount must be positive"); + }); }); From 41ad6a3ff4773c9defd19ceece2e73cc8f9fe2b2 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:42:41 -0300 Subject: [PATCH 4/5] test(ts-sdk): cover NaN and Infinity amounts in hosted buildOrder --- sdks/typescript/tests/hosted-dispatch.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdks/typescript/tests/hosted-dispatch.test.ts b/sdks/typescript/tests/hosted-dispatch.test.ts index 177024ef..21a3925e 100644 --- a/sdks/typescript/tests/hosted-dispatch.test.ts +++ b/sdks/typescript/tests/hosted-dispatch.test.ts @@ -431,5 +431,11 @@ describe("hosted buildOrder amount validation", () => { return expectAmountError(0, "amount must be positive"); }); + it("NaN amount -> 'amount must be a finite positive number'", () => { + return expectAmountError(NaN, "amount must be a finite positive number"); + }); + it("Infinity amount -> 'amount must be a finite positive number'", () => { + return expectAmountError(Infinity, "amount must be a finite positive number"); + }); }); From df6c0d6679153854b1b740dd07433824b1f2bb73 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Sat, 31 Oct 2026 14:42:41 -0300 Subject: [PATCH 5/5] fix(typescript): distinguish malformed amount from non-positive in hosted order build --- sdks/typescript/pmxt/client.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 04ddc27f..8fe6ce0b 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -2742,6 +2742,9 @@ export abstract class Exchange { resolvedDenom = "shares"; } + if (!Number.isFinite(Number(params.amount))) { + throw new InvalidOrder("amount must be a finite positive number"); + } if (!(Number(params.amount) > 0)) { throw new InvalidOrder("amount must be positive"); }