Skip to content

Commit

Permalink
Enable @typescript-eslint/recommended-type-checked config
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed Mar 4, 2024
1 parent a788e5f commit 9acfb8d
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
env: {
es2021: true
},
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
extends: ['plugin:@typescript-eslint/recommended-type-checked', 'prettier', 'plugin:prettier/recommended'],
rules: {
// Override specific rules
'@typescript-eslint/consistent-type-assertions': [
Expand All @@ -32,7 +32,6 @@ module.exports = {
objectLiteralTypeAssertions: 'allow'
}
],
'@typescript-eslint/no-floating-promises': 'error',
'no-magic-numbers': ['error', { ignore: [0, 1, 16, 256, '0n', '1n'] }]
},
overrides: [parseConfigFilesAsScripts, allowMagicNumbersInTests]
Expand Down
10 changes: 9 additions & 1 deletion ethereum_history_api/oracles/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const unrestrictedTemplateExpressionsInNoirFixturesScripts = {
files: ['./src/script/noir_fixtures/**/*.ts'],
rules: {
'@typescript-eslint/restrict-template-expressions': 'off'
}
};

module.exports = {
parserOptions: {
sourceType: 'module',
Expand All @@ -16,5 +23,6 @@ module.exports = {
]
}
]
}
},
overrides: [unrestrictedTemplateExpressionsInNoirFixturesScripts]
};
6 changes: 3 additions & 3 deletions ethereum_history_api/oracles/src/ethereum/blockHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ for (const header of blockHeaders) {
}

describe('calculateBlockHash', async () => {
const blocks = parse(await readFile('./fixtures/blocks.json', 'utf-8'));
const blocks = parse(await readFile('./fixtures/blocks.json', 'utf-8')) as GetBlockReturnType[];
for (const block of blocks) {
it(`block #${block.number}`, async () => {
expect(calculateBlockHash(block as GetBlockReturnType)).toBe(block.hash);
it(`block #${block.number}`, () => {
expect(calculateBlockHash(block)).toBe(block.hash);
});
}
});
2 changes: 1 addition & 1 deletion ethereum_history_api/oracles/src/ethereum/mockClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function createMockClient(

return mock<PublicClient>(isEthereumApiMethod, (method: string, args: unknown): unknown => {
const call: Call | undefined = savedCalls.find((it) => it.method === method && isEqual(it.arguments, args));
assert(!!call, `call not found for: ${method}(${args})`);
assert(!!call, `call not found for: ${method}(${JSON.stringify(args)})`);

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/ethereum/mockClient.test.ts > recordingClient > record and mock

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ src/ethereum/recordingClient.test.ts:68:41 ❯ Module.withTempFile src/util/file.ts:18:12 ❯ src/ethereum/recordingClient.test.ts:59:5

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/ethereum/mockClient.test.ts > mockingClient > read recorded JSON-RPC API calls from file in mocking client

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ src/ethereum/mockClient.test.ts:12:39

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/ethereum/recordingClient.test.ts > recordingClient > record and mock

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ src/ethereum/recordingClient.test.ts:68:41 ❯ Module.withTempFile src/util/file.ts:18:12 ❯ src/ethereum/recordingClient.test.ts:59:5

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/noir/oracles/accountOracle.int.test.ts > accountOracle > getAccountOracle

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ Module.getAccountOracle src/noir/oracles/accountOracle.ts:25:37 ❯ src/noir/oracles/accountOracle.int.test.ts:22:29

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/noir/oracles/accountOracle.test.ts > recordingClient > record and mock

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ src/ethereum/recordingClient.test.ts:68:41 ❯ Module.withTempFile src/util/file.ts:18:12 ❯ src/ethereum/recordingClient.test.ts:59:5

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/noir/oracles/headerOracle.int.test.ts > headerOracle > getBlock

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ Module.getBlock src/noir/oracles/headerOracle.ts:26:51 ❯ src/noir/oracles/headerOracle.int.test.ts:13:46

Check failure on line 17 in ethereum_history_api/oracles/src/ethereum/mockClient.ts

View workflow job for this annotation

GitHub Actions / E2E Tests

src/noir/oracles/headerOracle.int.test.ts > headerOracle > getHeaderOracle

TypeError: Do not know how to serialize a BigInt ❯ src/ethereum/mockClient.ts:17:58 ❯ Proxy.<anonymous> src/util/mock.ts:8:39 ❯ getBlock src/noir/oracles/headerOracle.ts:26:51 ❯ Module.getHeaderOracle src/noir/oracles/headerOracle.ts:13:42 ❯ src/noir/oracles/headerOracle.int.test.ts:22:54
return resultModifier(call).result;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const EXPECTED_CALLS = [
}
];

describe('recordingClient', async () => {
describe('recordingClient', () => {
const publicClientMock: PublicClient = {
getBlock: () => EXPECTED_CALLS[0].result,
getProof: () => EXPECTED_CALLS[1].result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function createLoggingProxy<Target extends Record<string, unknown>>(target: Targ
const originalMethod = target[method];
if (typeof originalMethod === 'function' && isEthereumApiMethod(method)) {
return async (...args: unknown[]): Promise<unknown> => {
const result = await originalMethod.apply(target, args);
const result = (await originalMethod.apply(target, args)) as unknown;
calls.push({
method,
arguments: args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createMockClient } from '../../ethereum/mockClient.js';

describe(
'accountOracle',
async () => {
() => {
const OFFSETS = {
NONCE: 0,
BALANCE: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import account from '../../../fixtures/account.json';
import stateProof from '../../../fixtures/stateProof.json';
import { ADDRESS } from '../../ethereum/recordingClient.test.js';

describe('encodeAccount', async () => {
describe('encodeAccount', () => {
it('encode account', async () => {
const proof: GetProofReturnType = parse(await readFile('./fixtures/eth_getProof_response.json', 'utf-8'));
const proof = parse(await readFile('./fixtures/eth_getProof_response.json', 'utf-8')) as GetProofReturnType;

expect(encodeAccount(proof)).toStrictEqual(serializeAccount(account));
expect(encodeStateProof(proof)).toStrictEqual(serializeStateProof(stateProof));
Expand Down
4 changes: 2 additions & 2 deletions ethereum_history_api/oracles/src/noir/oracles/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ async function expectServerDown(serverUrl: string) {
await expect(async () => await fetch(serverUrl, GET_HEADER_POST_DATA)).rejects.toThrow('fetch failed');
}

describe('mock oracle server', async () => {
describe('mock oracle server', () => {
it('start server', async () => {
await withMockOracleServer(async (serverUrl) => {
await expectServerUp(serverUrl);
});
});

it('return callback value', async () => {
const result = await withMockOracleServer(async () => 'callback return value');
const result = await withMockOracleServer(() => Promise.resolve('callback return value'));

expect(result).toStrictEqual('callback return value');
});
Expand Down
2 changes: 1 addition & 1 deletion ethereum_history_api/oracles/src/util/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type PaddingDirection = 'left' | 'right';
export function padArray<T>(array: T[], len: number, pad: T, direction: PaddingDirection = 'right'): T[] {
assert(len >= array.length, `len param: ${len} should be greater than array length: ${array.length}`);

const padding = new Array(len - array.length).fill(pad);
const padding = new Array<T>(len - array.length).fill(pad);
switch (direction) {
case 'left':
return padding.concat(array);
Expand Down
2 changes: 1 addition & 1 deletion ethereum_history_api/oracles/src/util/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('updateNestedField', () => {
it('non-existing key', () => {
const object = { a: [{ bar: { c: 3 } }] };
updateNestedField(object, ['x', '0', 'y', 'z'], () => 5);
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
/* eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
expect((object as any).x[0]?.y?.z).to.eq(5);
});
});
Expand Down
1 change: 1 addition & 0 deletions ethereum_history_api/oracles/src/util/object.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */
export function updateNestedField<T, V>(obj: T, pathArray: string[], updater: (value: V) => V): void {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
pathArray.reduce((acc: any, key: string, i: number) => {
Expand Down
2 changes: 1 addition & 1 deletion ethereum_history_api/tests/src/proofDataReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function readProof(path: string): Promise<Uint8Array> {

async function readInputMap(path: string): Promise<InputMap> {
const verifierData = await fs.readFile(path, 'utf-8');
const inputMap = toml.parse(verifierData);
const inputMap = toml.parse(verifierData) as InputMap;
return inputMap;
}

Expand Down
2 changes: 1 addition & 1 deletion ethereum_history_api/tests/src/solidityVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function deploySolidityProofVerifier(artefact: FoundryArtefact): Pr

assert(!!txReceipt.contractAddress, 'Deployed contract address should not be empty');

const solidityProofVerifier = new SolidityProofVerifier(txReceipt.contractAddress!, artefact.abi);
const solidityProofVerifier = new SolidityProofVerifier(txReceipt.contractAddress, artefact.abi);
return solidityProofVerifier;
}

Expand Down

0 comments on commit 9acfb8d

Please sign in to comment.