import * as z from 'zod/mini' import * as Schema from './Schema.js' describe('ChainId', () => { test('resolves aliases to their chain id', () => { expect(Schema.ChainId.parse('mainnet')).toMatchInlineSnapshot(`4217`) expect(Schema.ChainId.parse('testnet')).toMatchInlineSnapshot(`42431`) expect(Schema.ChainId.parse('1424310001')).toMatchInlineSnapshot(`1424310003`) expect(Schema.ChainId.parse(1_424_310_001)).toMatchInlineSnapshot(`1424310003`) }) test('accepts numeric chain ids as numbers or strings', () => { expect(Schema.ChainId.parse(4217)).toMatchInlineSnapshot(`4217`) expect(Schema.ChainId.parse('4217')).toMatchInlineSnapshot(`4217`) expect(Schema.ChainId.parse('42431')).toMatchInlineSnapshot(`42431`) }) test('accepts any positive integer chain id (e.g. a localnet)', () => { expect(Schema.ChainId.parse('31337')).toMatchInlineSnapshot(`31337`) expect(Schema.ChainId.parse(1)).toMatchInlineSnapshot(`1`) }) test('rejects non-positive, non-integer, and unknown-alias values', () => { expect(Schema.ChainId.safeParse('0').success).toMatchInlineSnapshot(`false`) expect(Schema.ChainId.safeParse('-1').success).toMatchInlineSnapshot(`false`) expect(Schema.ChainId.safeParse('1.5').success).toMatchInlineSnapshot(`false`) expect(Schema.ChainId.safeParse('bogus').success).toMatchInlineSnapshot(`false`) }) }) describe('ChainIdQuery', () => { test('is optional and accepts aliases or numbers', () => { expect(Schema.ChainIdQuery.parse(undefined)).toMatchInlineSnapshot(`undefined`) expect(Schema.ChainIdQuery.parse('mainnet')).toMatchInlineSnapshot(`4217`) expect(Schema.ChainIdQuery.parse('42431')).toMatchInlineSnapshot(`42431`) }) }) describe('Limit', () => { test('defaults to 10 and accepts page sizes through 50', () => { expect(Schema.Limit.parse(undefined)).toMatchInlineSnapshot(`10`) expect(Schema.Limit.parse('5')).toMatchInlineSnapshot(`5`) expect(Schema.Limit.parse('50')).toMatchInlineSnapshot(`50`) }) test('caps larger page sizes at 50', () => { expect(Schema.Limit.parse('51')).toMatchInlineSnapshot(`50`) expect(Schema.Limit.parse('200')).toMatchInlineSnapshot(`50`) expect(Schema.Limit.parse('10000')).toMatchInlineSnapshot(`50`) }) test('rejects page sizes below the minimum', () => { expect(Schema.Limit.safeParse('4').success).toMatchInlineSnapshot(`false`) }) }) describe('pageChecks', () => { const Query = z .object({ cursor: Schema.Cursor, limit: Schema.Limit, page: Schema.Page }) .check(...Schema.pageChecks()) test('accepts positional pages through the 500-row window', () => { expect(Query.safeParse({ limit: '10', page: '50' }).success).toMatchInlineSnapshot(`true`) }) test('rejects deeper positional pages', () => { expect(Query.safeParse({ limit: '10', page: '51' }).success).toMatchInlineSnapshot(`false`) }) }) describe('timestampBound', () => { test('normalizes RFC 3339 offsets to UTC', () => { const bound = Schema.timestampBound('swaps', 'from') expect(bound.parse('2026-06-04T12:00:00+05:30')).toMatchInlineSnapshot( `"2026-06-04T06:30:00.000Z"`, ) expect(bound.parse('2026-06-04T12:00:00-05:00')).toMatchInlineSnapshot( `"2026-06-04T17:00:00.000Z"`, ) }) })