Skip to content

Commit

Permalink
refactor: add json rpc spec
Browse files Browse the repository at this point in the history
refactor: added ref to rpc spec for schemas same as rpc
  • Loading branch information
Fabián Valverde authored and Fabián Valverde committed Jun 9, 2024
1 parent 66a5c03 commit 35796ab
Show file tree
Hide file tree
Showing 10 changed files with 4,950 additions and 71 deletions.
19 changes: 17 additions & 2 deletions __tests__/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ import ajvKeywords from 'ajv-keywords';
import { matchersWithOptions } from 'jest-json-schema';

import accountSchemas from '../schemas/account.json';
import componentSchemas from '../schemas/component.json';
import componentSchemas from '../schemas/rpc/component.json';
import starknet_api_openrpc from '../schemas/rpc/starknet_api_openrpc.json';
import starknet_metadata from '../schemas/rpc/starknet_metadata.json';
import starknet_trace_api_openrpc from '../schemas/rpc/starknet_trace_api_openrpc.json';
import starknet_write_api from '../schemas/rpc/starknet_write_api.json';
import libSchemas from '../schemas/lib.json';
import providerSchemas from '../schemas/provider.json';
import rpcSchemas from '../schemas/rpc.json';
import { isBigInt } from '../../src/utils/num';

const matcherSchemas = [accountSchemas, libSchemas, providerSchemas, rpcSchemas];
const schemas = [...matcherSchemas, componentSchemas];
const schemas = [
...matcherSchemas,
componentSchemas,
starknet_api_openrpc,
starknet_metadata,
starknet_trace_api_openrpc,
starknet_write_api,
];
const jestJsonMatchers = matchersWithOptions({ schemas }, (ajv: any) => {
// @ts-ignore
ajv.addKeyword({
Expand All @@ -35,6 +46,10 @@ export const initializeMatcher = (expect: jest.Expect) => {
});
expect(accountSchemas).toBeValidSchema();
expect(componentSchemas).toBeValidSchema();
expect(starknet_api_openrpc).toBeValidSchema();
expect(starknet_metadata).toBeValidSchema();
expect(starknet_trace_api_openrpc).toBeValidSchema();
expect(starknet_write_api).toBeValidSchema();
expect(libSchemas).toBeValidSchema();
expect(providerSchemas).toBeValidSchema();
expect(rpcSchemas).toBeValidSchema();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schemas/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"properties": {
"transaction_trace": {
"title": "the transaction's trace",
"$ref": "sequencerSchemas#/definitions/TransactionTraceResponse"
"$ref": "starknet_trace_api_openrpc#/components/schemas/TRANSACTION_TRACE"
},
"fee_estimation": {
"title": "the transaction's resources and fee",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schemas/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"type": "object"
},
"abi": {
"type": "array"
"$ref": "starknet_metadata#/components/schemas/ABI"
}
},
"required": ["sierra_program", "contract_class_version", "entry_points_by_type", "abi"]
Expand Down
6 changes: 3 additions & 3 deletions __tests__/schemas/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@
"required": ["transaction_hash"]
},
"getTransactionTrace": {
"$ref": "componentSchemas#/components/schemas/TRANSACTION_TRACE"
"$ref": "starknet_trace_api_openrpc#/components/schemas/TRANSACTION_TRACE"
},
"BlockWithTxReceipts": {
"oneOf": [
{
"$ref": "componentSchemas#/components/schemas/BLOCK_WITH_RECEIPTS"
"$ref": "starknet_api_openrpc#/components/schemas/BLOCK_WITH_RECEIPTS"
},
{
"$ref": "componentSchemas#/components/schemas/PENDING_BLOCK_WITH_RECEIPTS"
"$ref": "starknet_api_openrpc#/components/schemas/PENDING_BLOCK_WITH_RECEIPTS"
}
]
}
Expand Down
66 changes: 2 additions & 64 deletions __tests__/schemas/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,10 @@
"$id": "rpcSchemas",
"definitions": {
"GetSyncingStatsResponse": {
"oneOf": [
{
"type": "object",
"properties": {
"current_block_hash": {
"type": "string"
},
"current_block_num": {
"type": "number"
},
"highest_block_hash": {
"type": "string"
},
"highest_block_num": {
"type": "number"
},
"starting_block_hash": {
"type": "string"
},
"starting_block_num": {
"type": "number"
}
},
"required": [
"current_block_hash",
"current_block_num",
"highest_block_hash",
"highest_block_num",
"starting_block_hash",
"starting_block_num"
]
},
{
"type": "boolean"
}
]
"$ref": "starknet_api_openrpc#/components/schemas/SYNC_STATUS"
},
"StarknetEmittedEvent": {
"type": "object",
"properties": {
"from_address": {
"type": "string"
},
"keys": {
"type": "array",
"items": {
"type": "string"
}
},
"data": {
"type": "array",
"items": {
"type": "string"
}
},
"block_hash": {
"type": "string"
},
"block_number": {
"type": "number"
},
"transaction_hash": {
"type": "string"
}
},
"required": ["from_address", "keys", "data", "block_hash", "block_number", "transaction_hash"]
"$ref": "starknet_api_openrpc#/components/schemas/EMITTED_EVENT"
}
}
}
File renamed without changes.
Loading

0 comments on commit 35796ab

Please sign in to comment.