Skip to content

Commit 09ec07e

Browse files
committed
Fix TS tests.
1 parent a39a206 commit 09ec07e

File tree

7 files changed

+2827
-2990
lines changed

7 files changed

+2827
-2990
lines changed

typescript/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/src/utils/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const WS_CONSTANTS = {
2222
export const VALIDATION_REGEX = {
2323
/** Matches valid feed IDs (0x followed by 64 hex characters) */
2424
FEED_ID: /^0x[0-9a-fA-F]{64}$/,
25-
/** Matches valid schema versions (0x0002-0x0009, 0x000a) */
26-
SCHEMA_VERSION: /^0x000([2-9]|a)$/,
25+
/** Matches valid schema versions (0x0002-0x0009, 0x000a, 0x000d) */
26+
SCHEMA_VERSION: /^0x000([2-9]|a|d)$/,
2727
} as const;
2828

2929
// Request timeout constants

typescript/src/utils/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function validateFeedId(feedId: string): void {
1616
const version = feedId.slice(2, 6);
1717
if (!VALIDATION_REGEX.SCHEMA_VERSION.test(`0x${version}`)) {
1818
throw new ValidationError(
19-
"Invalid feed ID version. Must start with 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, or 0x000a"
19+
"Invalid feed ID version. Must start with 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a or 0x000d"
2020
);
2121
}
2222
}

typescript/tests/unit/decoder/decoder.test.ts

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,17 @@ const mockV10ReportBlob = abiCoder.encode(
212212
// Create V13 report blob
213213
const mockV13ReportBlob = abiCoder.encode(
214214
[
215-
"bytes32",
216-
"uint32",
217-
"uint32",
218-
"uint192",
219-
"uint192",
220-
"uint32",
221-
"uint64",
222-
"int192",
223-
"int192",
224-
"uint64",
225-
"uint64",
226-
"int192",
215+
"bytes32", // feed id
216+
"uint32", // valid from ts
217+
"uint32", // observation ts
218+
"uint192", // native fee
219+
"uint192", // link fee
220+
"uint32", // expires at
221+
"int192", // best ask
222+
"int192", // best bid
223+
"uint64", // ask volume
224+
"uint64", // bid volume
225+
"int192", // last traded price
227226
],
228227
[
229228
mockV13FeedId,
@@ -694,58 +693,10 @@ describe("Report Decoder", () => {
694693
expect(() => decodeReport(malformedReport, mockV13FeedId)).toThrow();
695694
});
696695

697-
it("should validate market status for v13 reports", () => {
698-
// Create invalid market status blob
699-
const invalidMarketStatusBlob = abiCoder.encode(
700-
[
701-
"bytes32",
702-
"uint32",
703-
"uint32",
704-
"uint192",
705-
"uint192",
706-
"uint32",
707-
"uint64",
708-
"int192",
709-
"int192",
710-
"uint64",
711-
"uint64",
712-
"int192",
713-
],
714-
[
715-
mockV13FeedId,
716-
Math.floor(Date.now() / 1000),
717-
Math.floor(Date.now() / 1000),
718-
1000000000000000000n,
719-
2000000000000000000n,
720-
Math.floor(Date.now() / 1000) + 3600,
721-
BigInt(Math.floor(Date.now() / 1000)),
722-
75000000000000000000n, // best ask $75
723-
78000000000000000000n, // best bid $78
724-
10000, // ask volume
725-
11000, // bid volume
726-
76000000000000000000n, // last traded price $76
727-
]
728-
);
729-
730-
const invalidFullReport = abiCoder.encode(
731-
["bytes32[3]", "bytes", "bytes32[]", "bytes32[]", "bytes32"],
732-
[
733-
mockReportContext,
734-
invalidMarketStatusBlob,
735-
["0x0000000000000000000000000000000000000000000000000000000000000010"],
736-
["0x0000000000000000000000000000000000000000000000000000000000000011"],
737-
"0x0000000000000000000000000000000000000000000000000000000000000012",
738-
]
739-
);
740-
741-
expect(() => decodeReport(invalidFullReport, mockV13FeedId)).toThrow("Invalid market status");
742-
});
743-
744696
it("should decode all v13 fields correctly", () => {
745697
const decoded = decodeReport(mockV13FullReport, mockV13FeedId) as DecodedV13Report;
746698

747699
// Verify all numeric fields are properly parsed
748-
expect(typeof decoded.lastUpdateTimestamp).toBe("number");
749700
expect(typeof decoded.bestAsk).toBe("bigint");
750701
expect(typeof decoded.bestBid).toBe("bigint");
751702
expect(typeof decoded.askVolume).toBe("number");

typescript/tests/unit/utils/validation/feed-validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ describe("Feed ID Validation Tests", () => {
332332

333333
it("should provide specific error for unsupported version", () => {
334334
expect(() => validateFeedId(VALID_FEED_IDS.V1)).toThrow(
335-
"Invalid feed ID version. Must start with 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, or 0x000a"
335+
"Invalid feed ID version. Must start with 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a or 0x000d"
336336
);
337337
});
338338

typescript/tests/unit/utils/validation/report-validation.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ describe("Report Validation Tests", () => {
268268
"uint192",
269269
"uint192",
270270
"uint32",
271-
"uint64",
272271
"int192",
273272
"int192",
274273
"uint64",
@@ -282,7 +281,6 @@ describe("Report Validation Tests", () => {
282281
"1000000000000000000",
283282
"500000000000000000",
284283
1640995400,
285-
1640995250,
286284
"75000000000000000000",
287285
"78000000000000000000",
288286
10000,
@@ -384,6 +382,7 @@ describe("Report Validation Tests", () => {
384382
expect(decoded.version).toBe("V13");
385383
expect((decoded as any).bestAsk).toBe(75000000000000000000n);
386384
expect((decoded as any).bestBid).toBe(78000000000000000000n);
385+
expect((decoded as any).lastTradedPrice).toBe(76000000000000000000n);
387386
});
388387

389388
it("should handle reports without 0x prefix", () => {

0 commit comments

Comments
 (0)