Skip to content

Commit

Permalink
feat: actually, negative ints should be allowed parameters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cygnusv committed Oct 25, 2024
1 parent a87b214 commit b3902d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/taco/src/conditions/schemas/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
],
Expand Down

0 comments on commit b3902d4

Please sign in to comment.