Skip to content

Commit

Permalink
Fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Oct 28, 2024
1 parent e66dfcb commit 422a0f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/shared/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
export const BlockIdentifierSchema = z.union([
BlockNumber,
BlockHash,
BlockTag,
]);
5 changes: 3 additions & 2 deletions packages/shared/test/schemas.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -46,7 +46,8 @@ describe('block identifier address schema', () => {
});

it('should accept valid block hashes', () => {
const validBlockHash = '0x1234567890123456789012345678901234567890123456789012345678901234';
const validBlockHash =
'0x1234567890123456789012345678901234567890123456789012345678901234';
BlockIdentifierSchema.parse(validBlockHash);
});

Expand Down
11 changes: 7 additions & 4 deletions packages/taco/src/conditions/schemas/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
});
Expand Down
17 changes: 10 additions & 7 deletions packages/taco/test/conditions/base/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
});

Expand All @@ -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'],
});
});

Expand Down Expand Up @@ -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)',
],
},
});
});
Expand Down

0 comments on commit 422a0f9

Please sign in to comment.