From 0e25a114efcdf00ef8ed55bd35bfed9bce81099e Mon Sep 17 00:00:00 2001 From: derekpierre Date: Mon, 28 Oct 2024 09:37:30 -0400 Subject: [PATCH] Fix linting. --- packages/shared/src/schemas.ts | 6 +++++- packages/shared/test/schemas.test.ts | 5 +++-- packages/taco/src/conditions/schemas/rpc.ts | 11 +++++++---- packages/taco/test/conditions/base/rpc.test.ts | 17 ++++++++++------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts index 1ca394a3..37dfa265 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas.ts @@ -18,4 +18,8 @@ const BlockNumber = z.number().int().nonnegative(); const BlockHash = z.string().regex(BLOCK_HASH_REGEXP, 'Invalid block hash'); const BlockTag = z.enum(['earliest', 'finalized', 'safe', 'latest', 'pending']); -export const BlockIdentifierSchema = z.union([BlockNumber, BlockHash, BlockTag]); \ No newline at end of file +export const BlockIdentifierSchema = z.union([ + BlockNumber, + BlockHash, + BlockTag, +]); diff --git a/packages/shared/test/schemas.test.ts b/packages/shared/test/schemas.test.ts index 86bc7dae..7b180394 100644 --- a/packages/shared/test/schemas.test.ts +++ b/packages/shared/test/schemas.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { EthAddressSchema, BlockIdentifierSchema } from '../src'; +import { BlockIdentifierSchema, EthAddressSchema } from '../src'; describe('ethereum address schema', () => { it('should accept valid ethereum address', () => { @@ -46,7 +46,8 @@ describe('block identifier address schema', () => { }); it('should accept valid block hashes', () => { - const validBlockHash = '0x1234567890123456789012345678901234567890123456789012345678901234'; + const validBlockHash = + '0x1234567890123456789012345678901234567890123456789012345678901234'; BlockIdentifierSchema.parse(validBlockHash); }); diff --git a/packages/taco/src/conditions/schemas/rpc.ts b/packages/taco/src/conditions/schemas/rpc.ts index 771c4d2f..a80a5956 100644 --- a/packages/taco/src/conditions/schemas/rpc.ts +++ b/packages/taco/src/conditions/schemas/rpc.ts @@ -15,9 +15,12 @@ export const RpcConditionType = 'rpc'; const EthAddressOrContextVariableSchema = z.union([ EthAddressSchema, UserAddressSchema, - contextParamSchema + contextParamSchema, +]); +const BlockOrContextParamSchema = z.union([ + BlockIdentifierSchema, + contextParamSchema, ]); -const BlockOrContextParamSchema = z.union([BlockIdentifierSchema, contextParamSchema]) // eth_getBalance schema specification // - Ethereum spec: https://ethereum.github.io/execution-apis/api-documentation/ @@ -29,8 +32,8 @@ export const rpcConditionSchema = baseConditionSchema.extend({ parameters: z.union([ // Spec requires 2 parameters: an address and a block identifier z.tuple([EthAddressOrContextVariableSchema, BlockOrContextParamSchema]), - // Block identifier can be omitted, since web3py (which runs on TACo exec layer) defaults to 'latest', - z.tuple([EthAddressOrContextVariableSchema]), + // Block identifier can be omitted, since web3py (which runs on TACo exec layer) defaults to 'latest', + z.tuple([EthAddressOrContextVariableSchema]), ]), returnValueTest: returnValueTestSchema, // Update to allow multiple return values after expanding supported methods }); diff --git a/packages/taco/test/conditions/base/rpc.test.ts b/packages/taco/test/conditions/base/rpc.test.ts index 35c0d22b..e1cb99cb 100644 --- a/packages/taco/test/conditions/base/rpc.test.ts +++ b/packages/taco/test/conditions/base/rpc.test.ts @@ -63,26 +63,26 @@ describe('validation', () => { it('accepts a single UserAddress as address', () => { const result = RpcCondition.validate(rpcConditionSchema, { ...testRpcConditionObj, - parameters: [":userAddress"], + parameters: [':userAddress'], }); expect(result.error).toBeUndefined(); expect(result.data).toEqual({ ...testRpcConditionObj, - parameters: [":userAddress"], + parameters: [':userAddress'], }); }); it('accepts a single context variable as address', () => { const result = RpcCondition.validate(rpcConditionSchema, { ...testRpcConditionObj, - parameters: [":testContextVar"], + parameters: [':testContextVar'], }); expect(result.error).toBeUndefined(); expect(result.data).toEqual({ ...testRpcConditionObj, - parameters: [":testContextVar"], + parameters: [':testContextVar'], }); }); @@ -102,13 +102,13 @@ describe('validation', () => { it('accepts context params for address and block number', () => { const result = RpcCondition.validate(rpcConditionSchema, { ...testRpcConditionObj, - parameters: [":testAddress", ":testBlockNumber"], + parameters: [':testAddress', ':testBlockNumber'], }); expect(result.error).toBeUndefined(); expect(result.data).toEqual({ ...testRpcConditionObj, - parameters: [":testAddress", ":testBlockNumber"], + parameters: [':testAddress', ':testBlockNumber'], }); }); @@ -143,7 +143,10 @@ describe('validation', () => { expect(result.data).toBeUndefined(); expect(result.error?.format()).toMatchObject({ parameters: { - _errors: ['Array must contain at least 2 element(s)', 'Array must contain at least 1 element(s)'], + _errors: [ + 'Array must contain at least 2 element(s)', + 'Array must contain at least 1 element(s)', + ], }, }); });