From b3902d4fadeaabec87b754c57e18719a17f3c3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Fri, 25 Oct 2024 12:38:27 +0200 Subject: [PATCH] feat: actually, negative ints should be allowed parameters int256 (and other smaller variants) are valid and well-defined integer types in Solidity. Floats are much more restricted, so let's continue to disallow them. --- packages/taco/src/conditions/schemas/context.ts | 2 +- packages/taco/test/conditions/context.test.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/taco/src/conditions/schemas/context.ts b/packages/taco/src/conditions/schemas/context.ts index edfa17a4..c9ee7a3c 100644 --- a/packages/taco/src/conditions/schemas/context.ts +++ b/packages/taco/src/conditions/schemas/context.ts @@ -7,7 +7,7 @@ import { plainStringSchema } from './common'; export const contextParamSchema = z.string().regex(CONTEXT_PARAM_REGEXP); // TODO: This is too broad, but it's a start -const paramSchema = z.union([plainStringSchema, z.boolean(), z.number().int().nonnegative()]); +const paramSchema = z.union([plainStringSchema, z.boolean(), z.number().int()]); export const paramOrContextParamSchema: z.ZodSchema = z.union([ paramSchema, diff --git a/packages/taco/test/conditions/context.test.ts b/packages/taco/test/conditions/context.test.ts index 2e90bc50..863bdb5f 100644 --- a/packages/taco/test/conditions/context.test.ts +++ b/packages/taco/test/conditions/context.test.ts @@ -519,8 +519,10 @@ describe('param or context param schema', () => { expect(paramOrContextParamSchema.safeParse(':hello').success).toBe(true); }); - it('accepts an integer', () => { + it('accepts integers', () => { expect(paramOrContextParamSchema.safeParse(123).success).toBe(true); + expect(paramOrContextParamSchema.safeParse(0).success).toBe(true); + expect(paramOrContextParamSchema.safeParse(-123).success).toBe(true); }); it('accepts a string', () => { @@ -572,7 +574,7 @@ describe('param or context param schema', () => { 1, [ 2, - [true, [123, ':hi', '0xdeadbeef'], ':my_name_is', 1], + [true, [123, ':hi', '0xdeadbeef'], ':my_name_is', -1], ':slim_shady', false, ],