diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 4e9e75ba6..cc47e0dde 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -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': [ @@ -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] diff --git a/ethereum_history_api/oracles/.eslintrc.cjs b/ethereum_history_api/oracles/.eslintrc.cjs index 4a37abda7..01bd109e0 100644 --- a/ethereum_history_api/oracles/.eslintrc.cjs +++ b/ethereum_history_api/oracles/.eslintrc.cjs @@ -1,3 +1,10 @@ +const unrestrictedTemplateExpressionsInNoirFixturesScripts = { + files: ['./src/script/noir_fixtures/**/*.ts'], + rules: { + '@typescript-eslint/restrict-template-expressions': 'off' + } +}; + module.exports = { parserOptions: { sourceType: 'module', @@ -16,5 +23,6 @@ module.exports = { ] } ] - } + }, + overrides: [unrestrictedTemplateExpressionsInNoirFixturesScripts] }; diff --git a/ethereum_history_api/oracles/src/ethereum/blockHeader.test.ts b/ethereum_history_api/oracles/src/ethereum/blockHeader.test.ts index 70661d1ed..2580d41f7 100644 --- a/ethereum_history_api/oracles/src/ethereum/blockHeader.test.ts +++ b/ethereum_history_api/oracles/src/ethereum/blockHeader.test.ts @@ -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); }); } }); diff --git a/ethereum_history_api/oracles/src/ethereum/mockClient.ts b/ethereum_history_api/oracles/src/ethereum/mockClient.ts index 88e052d30..50004ba37 100644 --- a/ethereum_history_api/oracles/src/ethereum/mockClient.ts +++ b/ethereum_history_api/oracles/src/ethereum/mockClient.ts @@ -14,7 +14,7 @@ export async function createMockClient( return mock(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)})`); return resultModifier(call).result; }); } diff --git a/ethereum_history_api/oracles/src/ethereum/recordingClient.test.ts b/ethereum_history_api/oracles/src/ethereum/recordingClient.test.ts index bec77b929..b886ae7d8 100644 --- a/ethereum_history_api/oracles/src/ethereum/recordingClient.test.ts +++ b/ethereum_history_api/oracles/src/ethereum/recordingClient.test.ts @@ -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 diff --git a/ethereum_history_api/oracles/src/ethereum/recordingClient.ts b/ethereum_history_api/oracles/src/ethereum/recordingClient.ts index 512bbfd58..f09003cb1 100644 --- a/ethereum_history_api/oracles/src/ethereum/recordingClient.ts +++ b/ethereum_history_api/oracles/src/ethereum/recordingClient.ts @@ -25,7 +25,7 @@ function createLoggingProxy>(target: Targ const originalMethod = target[method]; if (typeof originalMethod === 'function' && isEthereumApiMethod(method)) { return async (...args: unknown[]): Promise => { - const result = await originalMethod.apply(target, args); + const result = (await originalMethod.apply(target, args)) as unknown; calls.push({ method, arguments: args, diff --git a/ethereum_history_api/oracles/src/noir/oracles/accountOracle.int.test.ts b/ethereum_history_api/oracles/src/noir/oracles/accountOracle.int.test.ts index 0a53b7775..cdc4875a5 100644 --- a/ethereum_history_api/oracles/src/noir/oracles/accountOracle.int.test.ts +++ b/ethereum_history_api/oracles/src/noir/oracles/accountOracle.int.test.ts @@ -4,7 +4,7 @@ import { createMockClient } from '../../ethereum/mockClient.js'; describe( 'accountOracle', - async () => { + () => { const OFFSETS = { NONCE: 0, BALANCE: 1, diff --git a/ethereum_history_api/oracles/src/noir/oracles/accountOracle.test.ts b/ethereum_history_api/oracles/src/noir/oracles/accountOracle.test.ts index fdc476b23..27ca29c6a 100644 --- a/ethereum_history_api/oracles/src/noir/oracles/accountOracle.test.ts +++ b/ethereum_history_api/oracles/src/noir/oracles/accountOracle.test.ts @@ -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)); diff --git a/ethereum_history_api/oracles/src/noir/oracles/server.test.ts b/ethereum_history_api/oracles/src/noir/oracles/server.test.ts index bc74bdcda..accd70436 100644 --- a/ethereum_history_api/oracles/src/noir/oracles/server.test.ts +++ b/ethereum_history_api/oracles/src/noir/oracles/server.test.ts @@ -25,7 +25,7 @@ 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); @@ -33,7 +33,7 @@ describe('mock oracle server', async () => { }); 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'); }); diff --git a/ethereum_history_api/oracles/src/util/array.ts b/ethereum_history_api/oracles/src/util/array.ts index dbeec2016..11943f8c8 100644 --- a/ethereum_history_api/oracles/src/util/array.ts +++ b/ethereum_history_api/oracles/src/util/array.ts @@ -6,7 +6,7 @@ type PaddingDirection = 'left' | 'right'; export function padArray(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(len - array.length).fill(pad); switch (direction) { case 'left': return padding.concat(array); diff --git a/ethereum_history_api/oracles/src/util/object.test.ts b/ethereum_history_api/oracles/src/util/object.test.ts index f325713e9..e6080d7b6 100644 --- a/ethereum_history_api/oracles/src/util/object.test.ts +++ b/ethereum_history_api/oracles/src/util/object.test.ts @@ -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); }); }); diff --git a/ethereum_history_api/oracles/src/util/object.ts b/ethereum_history_api/oracles/src/util/object.ts index 4d8aa2846..ac4015932 100644 --- a/ethereum_history_api/oracles/src/util/object.ts +++ b/ethereum_history_api/oracles/src/util/object.ts @@ -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(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) => { diff --git a/ethereum_history_api/tests/src/proofDataReader.ts b/ethereum_history_api/tests/src/proofDataReader.ts index f85a55036..bf4b61cb4 100644 --- a/ethereum_history_api/tests/src/proofDataReader.ts +++ b/ethereum_history_api/tests/src/proofDataReader.ts @@ -17,7 +17,7 @@ async function readProof(path: string): Promise { async function readInputMap(path: string): Promise { const verifierData = await fs.readFile(path, 'utf-8'); - const inputMap = toml.parse(verifierData); + const inputMap = toml.parse(verifierData) as InputMap; return inputMap; } diff --git a/ethereum_history_api/tests/src/solidityVerifier.ts b/ethereum_history_api/tests/src/solidityVerifier.ts index 410e5a2be..0d86ee15a 100644 --- a/ethereum_history_api/tests/src/solidityVerifier.ts +++ b/ethereum_history_api/tests/src/solidityVerifier.ts @@ -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; }