From 91ea7b7c6a941cd16f12d98705ff3c2b5a5e29f2 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Mon, 13 Jan 2025 10:20:50 +1300 Subject: [PATCH] lint fix --- biome.json | 36 ++++++++++++++-- loader.js | 4 +- package.json | 8 ++-- packages/chopsticks/package.json | 6 ++- packages/chopsticks/src/cli.ts | 13 +++--- packages/chopsticks/src/context.ts | 20 ++++++--- packages/chopsticks/src/logger.ts | 2 +- .../chopsticks/src/plugins/decode-key/cli.ts | 6 +-- .../chopsticks/src/plugins/dry-run/cli.ts | 6 +-- .../src/plugins/dry-run/dry-run-extrinsic.ts | 22 +++++----- .../src/plugins/dry-run/dry-run-preimage.ts | 24 +++++------ .../chopsticks/src/plugins/dry-run/index.ts | 4 +- .../chopsticks/src/plugins/dry-run/rpc.ts | 4 +- .../src/plugins/fetch-storage/cli.ts | 2 +- .../src/plugins/follow-chain/cli.ts | 10 ++--- packages/chopsticks/src/plugins/index.ts | 4 +- .../chopsticks/src/plugins/run-block/cli.ts | 8 ++-- .../src/plugins/run-block/index.test.ts | 2 +- .../chopsticks/src/plugins/run-block/rpc.ts | 14 +++--- .../__tests__/trace-call.test.ts | 2 +- .../__tests__/trace-vm.test.ts | 2 +- .../src/plugins/trace-transaction/index.ts | 10 ++--- .../src/plugins/trace-transaction/types.ts | 4 +- .../src/plugins/trace-transaction/utils.ts | 16 ++++--- .../src/plugins/try-runtime/index.ts | 12 +++--- packages/chopsticks/src/rpc/index.ts | 6 +-- packages/chopsticks/src/schema/index.ts | 12 +++--- .../chopsticks/src/schema/options.test.ts | 2 +- packages/chopsticks/src/schema/parse.test.ts | 6 +-- packages/chopsticks/src/server.ts | 8 ++-- packages/chopsticks/src/setup-with-server.ts | 6 +-- packages/chopsticks/src/utils/decoder.ts | 8 ++-- .../src/utils/fetch-storages-worker.js | 2 +- .../src/utils/fetch-storages.test.ts | 16 +++---- .../chopsticks/src/utils/fetch-storages.ts | 20 ++++----- .../src/utils/generate-html-diff.ts | 6 +-- packages/chopsticks/src/utils/open-html.ts | 4 +- packages/chopsticks/src/utils/override.ts | 6 +-- packages/core/package.json | 5 ++- packages/core/src/api.test.ts | 2 +- packages/core/src/api.ts | 43 +++++++++---------- packages/core/src/blockchain/block-builder.ts | 37 ++++++++-------- packages/core/src/blockchain/block.ts | 20 ++++----- .../src/blockchain/get-keys-paged.test.ts | 18 ++++---- packages/core/src/blockchain/head-state.ts | 2 +- packages/core/src/blockchain/index.ts | 36 +++++++++------- .../core/src/blockchain/inherent/index.ts | 8 ++-- .../src/blockchain/inherent/para-enter.ts | 8 ++-- .../inherent/parachain/babe-randomness.ts | 8 ++-- .../parachain/nimbus-author-inherent.ts | 8 ++-- .../inherent/parachain/validation-data.ts | 18 ++++---- .../core/src/blockchain/inherent/timestamp.ts | 6 +-- packages/core/src/blockchain/storage-layer.ts | 17 ++++---- packages/core/src/blockchain/txpool.ts | 14 +++--- packages/core/src/chopsticks-provider.ts | 15 +++---- packages/core/src/database.ts | 2 +- packages/core/src/genesis-provider.ts | 14 +++--- packages/core/src/index.ts | 2 +- packages/core/src/logger.ts | 5 +-- packages/core/src/offchain.ts | 6 +-- packages/core/src/rpc/dev/new-block.ts | 4 +- .../core/src/rpc/dev/set-block-build-mode.ts | 2 +- packages/core/src/rpc/dev/set-head.ts | 4 +- .../core/src/rpc/dev/set-runtime-log-level.ts | 2 +- packages/core/src/rpc/dev/set-storage.ts | 6 +-- packages/core/src/rpc/dev/time-travel.ts | 2 +- packages/core/src/rpc/index.ts | 2 +- .../core/src/rpc/rpc-spec/chainHead_v1.ts | 6 +-- .../core/src/rpc/rpc-spec/chainSpec_v1.ts | 6 +-- .../core/src/rpc/rpc-spec/transaction_v1.ts | 4 +- packages/core/src/rpc/shared.ts | 4 +- packages/core/src/rpc/substrate/archive.ts | 4 +- packages/core/src/rpc/substrate/author.ts | 8 ++-- packages/core/src/rpc/substrate/chain.ts | 6 +-- packages/core/src/rpc/substrate/payment.ts | 4 +- packages/core/src/rpc/substrate/state.ts | 8 ++-- packages/core/src/rpc/substrate/system.ts | 8 ++-- packages/core/src/setup.ts | 14 +++--- packages/core/src/utils/decoder.ts | 16 +++---- packages/core/src/utils/index.ts | 12 +++--- packages/core/src/utils/key-cache.ts | 2 +- packages/core/src/utils/proof.ts | 6 +-- packages/core/src/utils/set-storage.ts | 8 ++-- packages/core/src/utils/time-travel.ts | 6 +-- packages/core/src/utils/well-known-keys.ts | 8 ++-- .../wasm-executor/browser-wasm-executor.js | 2 +- .../core/src/wasm-executor/executor.test.ts | 10 ++--- packages/core/src/wasm-executor/index.ts | 40 ++++++++--------- .../src/wasm-executor/node-wasm-executor.js | 2 +- .../core/src/wasm-executor/node-worker.ts | 2 +- packages/core/src/xcm/downward.ts | 4 +- packages/core/src/xcm/horizontal.ts | 4 +- packages/core/src/xcm/index.ts | 6 +-- packages/core/src/xcm/upward.ts | 2 +- packages/db/package.json | 5 ++- packages/db/src/base-sql.ts | 6 +-- packages/db/src/browser.ts | 4 +- packages/db/src/db/entities.ts | 2 +- packages/db/src/index.ts | 2 +- packages/e2e/src/author-inherent-mock.test.ts | 2 +- packages/e2e/src/author.test.ts | 2 +- packages/e2e/src/batch-request.test.ts | 2 +- .../e2e/src/build-parachain-block.test.ts | 6 +-- packages/e2e/src/chainHead_v1.test.ts | 6 +-- packages/e2e/src/chopsticks-provider.test.ts | 2 +- packages/e2e/src/crowdloan.redeem.test.ts | 2 +- packages/e2e/src/decoder.test.ts | 2 +- packages/e2e/src/dev.test.ts | 2 +- packages/e2e/src/environment.test.ts | 2 +- packages/e2e/src/genesis-provider.test.ts | 2 +- packages/e2e/src/helper.ts | 26 +++++------ packages/e2e/src/hrmp.test.ts | 2 +- packages/e2e/src/http.test.ts | 2 +- packages/e2e/src/import-storage/index.test.ts | 4 +- packages/e2e/src/metadata.test.ts | 2 +- packages/e2e/src/migration.test.ts | 2 +- packages/e2e/src/mock-signature.test.ts | 2 +- packages/e2e/src/networks.ts | 2 +- packages/e2e/src/resume.test.ts | 6 +-- .../e2e/src/rpc-extention-methods.test.ts | 4 +- packages/e2e/src/rpc-methods-test-scripts.js | 2 - packages/e2e/src/rpc-spec.test.ts | 4 +- packages/e2e/src/state.test.ts | 6 +-- packages/e2e/src/time-travel.test.ts | 2 +- packages/e2e/src/upgrade.test.ts | 2 +- packages/e2e/src/xcm.test.ts | 6 +-- packages/node-test/index.mjs | 2 +- packages/testing/package.json | 5 ++- packages/testing/src/check.ts | 13 +++--- packages/utils/package.json | 5 ++- packages/utils/src/index.ts | 14 +++--- packages/utils/src/signFake.ts | 6 +-- packages/web-test/src/App.tsx | 22 +++++----- packages/web-test/src/index.tsx | 2 +- packages/web-test/src/vite-env.d.ts | 4 +- packages/web-test/tests/index.spec.ts | 2 +- packages/web-test/vite.config.mjs | 2 +- vitest.config.mts | 2 +- 138 files changed, 556 insertions(+), 507 deletions(-) diff --git a/biome.json b/biome.json index 943dfb8e..79726c50 100644 --- a/biome.json +++ b/biome.json @@ -1,9 +1,10 @@ { "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", - "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, + "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true }, "files": { "ignoreUnknown": false, "ignore": [ + "*.json", "*.txt", "*.snap", "*.wasm", @@ -15,7 +16,8 @@ "**/executor/**", "**/vendor/**", "**/dist/**", - "**/node_modules/**" + "**/node_modules/**", + "packages/e2e/src/rpc-methods-test-scripts.js" ] }, "formatter": { @@ -53,7 +55,21 @@ "organizeImports": { "enabled": true }, "linter": { "enabled": true, - "rules": { "recommended": true }, + "rules": { + "recommended": true, + "suspicious": { + "noExplicitAny": "off", + "noAssignInExpressions": "off" + }, + "style": { + "noUnusedTemplateLiteral": "off", + "noNonNullAssertion": "off", + "noParameterAssign": "off" + }, + "complexity": { + "noForEach": "off" + } + }, "ignore": [ "**/.eslintrc.js", "**/node_modules/", @@ -80,5 +96,17 @@ "attributePosition": "auto", "bracketSpacing": true } - } + }, + "overrides": [ + { + "include": ["**/*.test.ts", "packages/web-test"], + "linter": { + "rules": { + "style": { + "noNonNullAssertion": "off" + } + } + } + } + ] } diff --git a/loader.js b/loader.js index e642f2c1..f20c00b4 100644 --- a/loader.js +++ b/loader.js @@ -1,6 +1,6 @@ -import * as tsConfigPaths from 'tsconfig-paths' -import { pathToFileURL } from 'url' +import { pathToFileURL } from 'node:url' import { resolve as resolveTs } from 'ts-node/esm' +import * as tsConfigPaths from 'tsconfig-paths' const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig() const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths) diff --git a/package.json b/package.json index 24e4a7db..bf0a64df 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "packageManager": "yarn@4.5.3", "private": true, "type": "module", - "workspaces": ["packages/*", "executor"], + "workspaces": [ + "packages/*", + "executor" + ], "scripts": { "lint": "tsc --noEmit --project tsconfig.lint.json && biome check .", "fix": "biome check --write .", @@ -32,8 +35,7 @@ "node": ">=v20" }, "lint-staged": { - "*.{js,ts}": "eslint --cache --fix", - "*.{js,ts,css,md}": "prettier --write" + "*.{js,ts}": "biome check --write --no-errors-on-unmatched" }, "devDependencies": { "@biomejs/biome": "1.9.4", diff --git a/packages/chopsticks/package.json b/packages/chopsticks/package.json index efa010cd..b2929b4f 100644 --- a/packages/chopsticks/package.json +++ b/packages/chopsticks/package.json @@ -46,7 +46,11 @@ "@types/yargs": "^17.0.33", "typescript": "^5.7.2" }, - "files": ["dist/esm/**", "dist/cjs/**", "chopsticks.cjs"], + "files": [ + "dist/esm/**", + "dist/cjs/**", + "chopsticks.cjs" + ], "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "exports": { diff --git a/packages/chopsticks/src/cli.ts b/packages/chopsticks/src/cli.ts index 2ad95fdd..c2f6fb0e 100644 --- a/packages/chopsticks/src/cli.ts +++ b/packages/chopsticks/src/cli.ts @@ -1,14 +1,14 @@ import { config as dotenvConfig } from 'dotenv' -import { hideBin } from 'yargs/helpers' -import { z } from 'zod' import _ from 'lodash' import yargs from 'yargs' import type { MiddlewareFunction } from 'yargs' +import { hideBin } from 'yargs/helpers' +import { z } from 'zod' -import { Blockchain, connectParachains, connectVertical, environment } from '@acala-network/chopsticks-core' -import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js' -import { loadRpcMethodsByScripts, pluginExtendCli } from './plugins/index.js' +import { type Blockchain, connectParachains, connectVertical, environment } from '@acala-network/chopsticks-core' import { setupWithServer } from './index.js' +import { loadRpcMethodsByScripts, pluginExtendCli } from './plugins/index.js' +import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js' dotenvConfig() @@ -26,9 +26,8 @@ const processArgv: MiddlewareFunction<{ config?: string; port?: number; unsafeRp } catch (error) { if (error instanceof z.ZodError) { throw new Error('Bad argv', { cause: error.flatten().fieldErrors }) - } else { - throw error } + throw error } } diff --git a/packages/chopsticks/src/context.ts b/packages/chopsticks/src/context.ts index 0c4e81e6..e63ea999 100644 --- a/packages/chopsticks/src/context.ts +++ b/packages/chopsticks/src/context.ts @@ -1,12 +1,19 @@ import './utils/tunnel.js' -import { BlockEntry, GenesisProvider, defaultLogger, isUrl, setup, timeTravel } from '@acala-network/chopsticks-core' -import { Config } from './schema/index.js' -import { HexString } from '@polkadot/util/types' +import { + type BlockEntry, + GenesisProvider, + defaultLogger, + isUrl, + setup, + timeTravel, +} from '@acala-network/chopsticks-core' import { SqliteDatabase } from '@acala-network/chopsticks-db' +import type { HexString } from '@polkadot/util/types' +import axios from 'axios' import { apiFetching } from './logger.js' -import { overrideStorage, overrideWasm } from './utils/override.js' +import type { Config } from './schema/index.js' import { startFetchStorageWorker } from './utils/fetch-storages.js' -import axios from 'axios' +import { overrideStorage, overrideWasm } from './utils/override.js' const logger = defaultLogger.child({ name: 'setup-context' }) @@ -14,7 +21,8 @@ export const genesisFromUrl = async (url: string) => { const getFile = async (url: string) => { if (isUrl(url)) { return axios.get(url).then((x) => x.data) - } else if (typeof process === 'object') { + } + if (typeof process === 'object') { const { lstatSync, readFileSync } = await import('node:fs') if (lstatSync(url).isFile()) { return JSON.parse(String(readFileSync(url))) diff --git a/packages/chopsticks/src/logger.ts b/packages/chopsticks/src/logger.ts index 0c6a366c..310d4b7d 100644 --- a/packages/chopsticks/src/logger.ts +++ b/packages/chopsticks/src/logger.ts @@ -2,7 +2,7 @@ import _ from 'lodash' export { defaultLogger, truncate } from '@acala-network/chopsticks-core' -const showProgress = process.stdout.isTTY && !process.env['CI'] && !process.env['TEST'] +const showProgress = process.stdout.isTTY && !process.env.CI && !process.env.TEST export const spinnerFrames = process.platform === 'win32' ? ['-', '\\', '|', '/'] : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] diff --git a/packages/chopsticks/src/plugins/decode-key/cli.ts b/packages/chopsticks/src/plugins/decode-key/cli.ts index b427d032..50bce8c0 100644 --- a/packages/chopsticks/src/plugins/decode-key/cli.ts +++ b/packages/chopsticks/src/plugins/decode-key/cli.ts @@ -1,8 +1,8 @@ -import { HexString } from '@polkadot/util/types' -import { configSchema, getYargsOptions } from '../../schema/index.js' import { decodeKey } from '@acala-network/chopsticks-core' -import { setupContext } from '../../context.js' +import type { HexString } from '@polkadot/util/types' import type { Argv } from 'yargs' +import { setupContext } from '../../context.js' +import { configSchema, getYargsOptions } from '../../schema/index.js' export const cli = (y: Argv) => { y.command( diff --git a/packages/chopsticks/src/plugins/dry-run/cli.ts b/packages/chopsticks/src/plugins/dry-run/cli.ts index ac4ac4e6..7e99ef11 100644 --- a/packages/chopsticks/src/plugins/dry-run/cli.ts +++ b/packages/chopsticks/src/plugins/dry-run/cli.ts @@ -1,8 +1,8 @@ +import type { Argv } from 'yargs' +import { z } from 'zod' import { configSchema, getYargsOptions } from '../../schema/index.js' import { dryRunExtrinsic } from './dry-run-extrinsic.js' import { dryRunPreimage } from './dry-run-preimage.js' -import { z } from 'zod' -import type { Argv } from 'yargs' const schema = z.object({ ...configSchema.shape, @@ -26,7 +26,7 @@ const schema = z.object({ description: 'Block hash to dry run', }) .optional(), - ['output-path']: z + 'output-path': z .string({ description: 'File path to print output', }) diff --git a/packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts b/packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts index 66fc4fd6..5ed24521 100644 --- a/packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts +++ b/packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts @@ -1,12 +1,12 @@ -import { HexString } from '@polkadot/util/types' -import { blake2AsHex } from '@polkadot/util-crypto' import { writeFileSync } from 'node:fs' +import { blake2AsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' -import { DryRunSchemaType } from './index.js' +import { setupContext } from '../../context.js' import { defaultLogger } from '../../logger.js' import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js' import { openHtml } from '../../utils/open-html.js' -import { setupContext } from '../../context.js' +import type { DryRunSchemaType } from './index.js' export const dryRunExtrinsic = async (argv: DryRunSchemaType) => { const context = await setupContext(argv) @@ -15,10 +15,10 @@ export const dryRunExtrinsic = async (argv: DryRunSchemaType) => { throw new Error('Extrinsic is required') } - const input = argv['address'] - ? { call: argv['extrinsic'] as HexString, address: argv['address'] } - : (argv['extrinsic'] as HexString) - const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at'] as HexString) + const input = argv.address + ? { call: argv.extrinsic as HexString, address: argv.address } + : (argv.extrinsic as HexString) + const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv.at as HexString) if (outcome.isErr) { throw new Error(outcome.asErr.toString()) @@ -26,14 +26,14 @@ export const dryRunExtrinsic = async (argv: DryRunSchemaType) => { defaultLogger.info(outcome.toHuman(), 'dry_run_outcome') - if (argv['html']) { + if (argv.html) { const filePath = await generateHtmlDiffPreviewFile( context.chain.head, storageDiff, - blake2AsHex(argv['extrinsic'], 256), + blake2AsHex(argv.extrinsic, 256), ) console.log(`Generated preview ${filePath}`) - if (argv['open']) { + if (argv.open) { openHtml(filePath) } } else if (argv['output-path']) { diff --git a/packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts b/packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts index 5d43a6fc..51e3d524 100644 --- a/packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts +++ b/packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts @@ -1,18 +1,18 @@ -import { HexString } from '@polkadot/util/types' -import { blake2AsHex } from '@polkadot/util-crypto' import { compactAddLength, hexToU8a } from '@polkadot/util' +import { blake2AsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' import { Block, newHeader, runTask, setStorage, taskHandler } from '@acala-network/chopsticks-core' -import { DryRunSchemaType } from './index.js' +import { setupContext } from '../../context.js' import { defaultLogger } from '../../logger.js' import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js' import { openHtml } from '../../utils/open-html.js' -import { setupContext } from '../../context.js' +import type { DryRunSchemaType } from './index.js' export const dryRunPreimage = async (argv: DryRunSchemaType) => { const context = await setupContext(argv) - const extrinsic = argv['preimage'] + const extrinsic = argv.preimage const block = context.chain.head const registry = await block.registry @@ -103,17 +103,17 @@ export const dryRunPreimage = async (argv: DryRunSchemaType) => { const filePath = await generateHtmlDiffPreviewFile(block, result.Call.storageDiff, hash) console.log(`Generated preview ${filePath}`) - if (argv['open']) { + if (argv.open) { openHtml(filePath) } // if dry-run preimage has extrinsic arguments then dry-run extrinsic // this is useful to test something after preimage is applied - if (argv['extrinsic']) { + if (argv.extrinsic) { await context.chain.newBlock() - const input = argv['address'] - ? { call: argv['extrinsic'] as HexString, address: argv['address'] } - : (argv['extrinsic'] as HexString) + const input = argv.address + ? { call: argv.extrinsic as HexString, address: argv.address } + : (argv.extrinsic as HexString) const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input) if (outcome.isErr) { throw new Error(outcome.asErr.toString()) @@ -124,10 +124,10 @@ export const dryRunPreimage = async (argv: DryRunSchemaType) => { const filePath = await generateHtmlDiffPreviewFile( context.chain.head, storageDiff, - blake2AsHex(argv['extrinsic'], 256), + blake2AsHex(argv.extrinsic, 256), ) console.log(`Generated preview ${filePath}`) - if (argv['open']) { + if (argv.open) { openHtml(filePath) } } diff --git a/packages/chopsticks/src/plugins/dry-run/index.ts b/packages/chopsticks/src/plugins/dry-run/index.ts index 3ebfd301..bad5b36f 100644 --- a/packages/chopsticks/src/plugins/dry-run/index.ts +++ b/packages/chopsticks/src/plugins/dry-run/index.ts @@ -1,5 +1,5 @@ -import { configSchema } from '../../schema/index.js' import { z } from 'zod' +import { configSchema } from '../../schema/index.js' export const dryRunSchema = z.object({ ...configSchema.shape, @@ -23,7 +23,7 @@ export const dryRunSchema = z.object({ description: 'Block hash to dry run', }) .optional(), - ['output-path']: z + 'output-path': z .string({ description: 'File path to print output', }) diff --git a/packages/chopsticks/src/plugins/dry-run/rpc.ts b/packages/chopsticks/src/plugins/dry-run/rpc.ts index c995e519..0917a832 100644 --- a/packages/chopsticks/src/plugins/dry-run/rpc.ts +++ b/packages/chopsticks/src/plugins/dry-run/rpc.ts @@ -1,9 +1,9 @@ import { z } from 'zod' -import { Context, ResponseError } from '@acala-network/chopsticks-core' +import { type Context, ResponseError } from '@acala-network/chopsticks-core' +import { zHash, zHex } from '../../schema/index.js' import { decodeStorageDiff } from '../../utils/decoder.js' import { generateHtmlDiff } from '../../utils/generate-html-diff.js' -import { zHash, zHex } from '../../schema/index.js' const zParaId = z.string().regex(/^\d+$/).transform(Number) diff --git a/packages/chopsticks/src/plugins/fetch-storage/cli.ts b/packages/chopsticks/src/plugins/fetch-storage/cli.ts index eac63e39..36bdf801 100644 --- a/packages/chopsticks/src/plugins/fetch-storage/cli.ts +++ b/packages/chopsticks/src/plugins/fetch-storage/cli.ts @@ -1,6 +1,6 @@ -import { z } from 'zod' import _ from 'lodash' import type { Argv } from 'yargs' +import { z } from 'zod' import { configSchema, getYargsOptions } from '../../schema/index.js' import { fetchStorages, logger } from '../../utils/fetch-storages.js' diff --git a/packages/chopsticks/src/plugins/follow-chain/cli.ts b/packages/chopsticks/src/plugins/follow-chain/cli.ts index 984e8c60..e521d448 100644 --- a/packages/chopsticks/src/plugins/follow-chain/cli.ts +++ b/packages/chopsticks/src/plugins/follow-chain/cli.ts @@ -1,14 +1,14 @@ import { Block, defaultLogger, runTask, taskHandler } from '@acala-network/chopsticks-core' -import { Header } from '@polkadot/types/interfaces' -import { HexString } from '@polkadot/util/types' -import { z } from 'zod' +import type { Header } from '@polkadot/types/interfaces' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' import type { Argv } from 'yargs' +import { z } from 'zod' +import { setupContext } from '../../context.js' +import { handler } from '../../rpc/index.js' import { configSchema, getYargsOptions } from '../../schema/index.js' import { createServer } from '../../server.js' -import { handler } from '../../rpc/index.js' -import { setupContext } from '../../context.js' const logger = defaultLogger.child({ name: 'follow-chain' }) diff --git a/packages/chopsticks/src/plugins/index.ts b/packages/chopsticks/src/plugins/index.ts index 8befbf20..695d4d41 100644 --- a/packages/chopsticks/src/plugins/index.ts +++ b/packages/chopsticks/src/plugins/index.ts @@ -1,10 +1,10 @@ -import { Handlers, environment } from '@acala-network/chopsticks-core' import { lstatSync, readFileSync, readdirSync } from 'node:fs' +import { type Handlers, environment } from '@acala-network/chopsticks-core' import _ from 'lodash' import type { Argv } from 'yargs' -import { defaultLogger } from '../logger.js' import { resolve } from 'node:path' +import { defaultLogger } from '../logger.js' const logger = defaultLogger.child({ name: 'plugin' }) diff --git a/packages/chopsticks/src/plugins/run-block/cli.ts b/packages/chopsticks/src/plugins/run-block/cli.ts index ee14a64b..9631698b 100644 --- a/packages/chopsticks/src/plugins/run-block/cli.ts +++ b/packages/chopsticks/src/plugins/run-block/cli.ts @@ -1,19 +1,19 @@ -import { HexString } from '@polkadot/util/types' import { writeFileSync } from 'node:fs' -import { z } from 'zod' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' import type { Argv } from 'yargs' +import { z } from 'zod' import { runTask, taskHandler } from '@acala-network/chopsticks-core' +import { setupContext } from '../../context.js' import { configSchema, getYargsOptions } from '../../schema/index.js' import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js' import { openHtml } from '../../utils/open-html.js' -import { setupContext } from '../../context.js' const schema = z.object({ ...configSchema.shape, - ['output-path']: z + 'output-path': z .string({ description: 'File path to print output', }) diff --git a/packages/chopsticks/src/plugins/run-block/index.test.ts b/packages/chopsticks/src/plugins/run-block/index.test.ts index 40a69b30..d994f4d3 100644 --- a/packages/chopsticks/src/plugins/run-block/index.test.ts +++ b/packages/chopsticks/src/plugins/run-block/index.test.ts @@ -1,6 +1,6 @@ +import { setup } from '@acala-network/chopsticks-core' import { SqliteDatabase } from '@acala-network/chopsticks-db' import { describe, expect, it } from 'vitest' -import { setup } from '@acala-network/chopsticks-core' import { rpc } from './index.js' diff --git a/packages/chopsticks/src/plugins/run-block/rpc.ts b/packages/chopsticks/src/plugins/run-block/rpc.ts index 077ec4a4..1989a26c 100644 --- a/packages/chopsticks/src/plugins/run-block/rpc.ts +++ b/packages/chopsticks/src/plugins/run-block/rpc.ts @@ -1,14 +1,14 @@ -import { GenericExtrinsic } from '@polkadot/types' -import { Header } from '@polkadot/types/interfaces' -import { HexString } from '@polkadot/util/types' +import type { GenericExtrinsic } from '@polkadot/types' +import type { Header } from '@polkadot/types/interfaces' import { u8aToHex } from '@polkadot/util' -import { z } from 'zod' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' +import { z } from 'zod' import { Block, - Context, - RuntimeLog, + type Context, + type RuntimeLog, compactHex, decodeKeyValue, runTask, @@ -244,7 +244,7 @@ export const rpc = async ({ chain }: Context, [params]: [RunBlockParams]): Promi if (len > 0) { argObj = {} for (let i = 0; i < len; i++) { - argObj[event.event.data.names![i]] = event.event.data[i].toJSON() + argObj[event.event.data.names?.[i]] = event.event.data[i].toJSON() } } diff --git a/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-call.test.ts b/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-call.test.ts index 767dcb28..fcb2712a 100644 --- a/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-call.test.ts +++ b/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-call.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' -import { prepareBlock, traceCalls } from '../utils.js' import { setup } from '../../../index.js' +import { prepareBlock, traceCalls } from '../utils.js' describe.runIf(process.env.CI || process.env.RUN_ALL)('trace-call', () => { it('Acala', async () => { diff --git a/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-vm.test.ts b/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-vm.test.ts index 756db9d0..a25acb08 100644 --- a/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-vm.test.ts +++ b/packages/chopsticks/src/plugins/trace-transaction/__tests__/trace-vm.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' -import { prepareBlock, traceVM } from '../utils.js' import { setup } from '../../../index.js' +import { prepareBlock, traceVM } from '../utils.js' describe('trace-vm', async () => { const acala = await setup({ diff --git a/packages/chopsticks/src/plugins/trace-transaction/index.ts b/packages/chopsticks/src/plugins/trace-transaction/index.ts index 24320fbf..85772511 100644 --- a/packages/chopsticks/src/plugins/trace-transaction/index.ts +++ b/packages/chopsticks/src/plugins/trace-transaction/index.ts @@ -1,12 +1,12 @@ -import { Argv } from 'yargs' -import { pinoLogger } from '@acala-network/chopsticks-core' import { writeFileSync } from 'node:fs' -import { z } from 'zod' +import { pinoLogger } from '@acala-network/chopsticks-core' import _ from 'lodash' +import type { Argv } from 'yargs' +import { z } from 'zod' +import { setupContext } from '../../context.js' import { configSchema, getYargsOptions } from '../../schema/index.js' import { fetchEVMTransaction, prepareBlock, traceCalls, traceVM } from './utils.js' -import { setupContext } from '../../context.js' const schema = configSchema.extend({ vm: z.boolean({ description: 'Trace VM opcode' }).optional(), @@ -29,7 +29,7 @@ export const cli = (y: Argv) => { async (argv) => { const config = schema.parse(argv) const wasmPath = config['wasm-override'] - delete config['wasm-override'] + config['wasm-override'] = undefined const context = await setupContext(config, false) const txHash = argv['tx-hash'] diff --git a/packages/chopsticks/src/plugins/trace-transaction/types.ts b/packages/chopsticks/src/plugins/trace-transaction/types.ts index a17dfe92..58054303 100644 --- a/packages/chopsticks/src/plugins/trace-transaction/types.ts +++ b/packages/chopsticks/src/plugins/trace-transaction/types.ts @@ -1,5 +1,5 @@ -import { HexString } from '@polkadot/util/types' -import { Registry } from '@polkadot/types/types' +import type { Registry } from '@polkadot/types/types' +import type { HexString } from '@polkadot/util/types' export type CallTrace = { type: 'CALL' | 'CALLCODE' | 'STATICCALL' | 'DELEGATECALL' | 'CREATE' | 'SUICIDE' diff --git a/packages/chopsticks/src/plugins/trace-transaction/utils.ts b/packages/chopsticks/src/plugins/trace-transaction/utils.ts index 1f5f6e7e..89ede0df 100644 --- a/packages/chopsticks/src/plugins/trace-transaction/utils.ts +++ b/packages/chopsticks/src/plugins/trace-transaction/utils.ts @@ -1,11 +1,11 @@ -import { Block, Blockchain, RuntimeVersion, pinoLogger } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' +import { Block, type Blockchain, type RuntimeVersion, pinoLogger } from '@acala-network/chopsticks-core' import { blake2AsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' -import { Step, TraceOutcome, registerTypes } from './types.js' -import { opName } from './table.js' import { overrideWasm } from '../../utils/override.js' +import { opName } from './table.js' +import { type Step, type TraceOutcome, registerTypes } from './types.js' /** * Fetches the runtime with tracing feature from Github releases. @@ -113,7 +113,7 @@ export const traceVM = async ( // remove 0x prefix const slice = chunk.slice(2) // make sure each chunk is 64 bytes - if (slice.length < 64 && idx + 1 < step.memory!.length) { + if (slice.length < 64 && idx + 1 < step.memory?.length) { return slice.padStart(64, '0') } return slice @@ -124,7 +124,7 @@ export const traceVM = async ( page += 1 - traceNextPage = outcome.steps.length == pageSize + traceNextPage = outcome.steps.length === pageSize } return steps } @@ -168,7 +168,9 @@ export const prepareBlock = async ( ) => { let wasm: string | Buffer | undefined = wasmPath const block = - typeof blockHashNumber == 'number' ? await chain.getBlockAt(blockHashNumber) : await chain.getBlock(blockHashNumber) + typeof blockHashNumber === 'number' + ? await chain.getBlockAt(blockHashNumber) + : await chain.getBlock(blockHashNumber) if (!block) { throw new Error(`Block not found ${blockHashNumber}`) } diff --git a/packages/chopsticks/src/plugins/try-runtime/index.ts b/packages/chopsticks/src/plugins/try-runtime/index.ts index 1df26b1a..f60ac743 100644 --- a/packages/chopsticks/src/plugins/try-runtime/index.ts +++ b/packages/chopsticks/src/plugins/try-runtime/index.ts @@ -1,24 +1,24 @@ -import { BuildBlockMode } from '@acala-network/chopsticks-core' import { writeFileSync } from 'node:fs' -import { z } from 'zod' +import { BuildBlockMode } from '@acala-network/chopsticks-core' import type { Argv } from 'yargs' +import { z } from 'zod' +import { setupContext } from '../../context.js' import { configSchema, getYargsOptions } from '../../schema/index.js' import { overrideWasm } from '../../utils/override.js' -import { setupContext } from '../../context.js' const schema = z.object({ endpoint: configSchema.shape.endpoint, block: configSchema.shape.block, db: configSchema.shape.db, - ['runtime-log-level']: configSchema.shape['runtime-log-level'].default(5), - ['runtime']: z.string({ + 'runtime-log-level': configSchema.shape['runtime-log-level'].default(5), + runtime: z.string({ description: 'Path to WASM built with feature `try-runtime` enabled', }), 'import-storage': configSchema.shape['import-storage'], checks: z.enum(['None', 'All', 'PreAndPost', 'TryState']), 'disable-spec-check': z.boolean({ description: 'Disable spec name/version check' }).optional(), - ['output-path']: z + 'output-path': z .string({ description: 'File path to print output', }) diff --git a/packages/chopsticks/src/rpc/index.ts b/packages/chopsticks/src/rpc/index.ts index 6ef7a94c..346f6ba5 100644 --- a/packages/chopsticks/src/rpc/index.ts +++ b/packages/chopsticks/src/rpc/index.ts @@ -1,8 +1,8 @@ import { - Context, - Handlers, + type Context, + type Handlers, ResponseError, - SubscriptionManager, + type SubscriptionManager, allHandlers as coreHandlers, defaultLogger, } from '@acala-network/chopsticks-core' diff --git a/packages/chopsticks/src/schema/index.ts b/packages/chopsticks/src/schema/index.ts index 04dfd7da..227b054e 100644 --- a/packages/chopsticks/src/schema/index.ts +++ b/packages/chopsticks/src/schema/index.ts @@ -1,12 +1,12 @@ -import { BuildBlockMode, defaultLogger, genesisSchema, isUrl } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' -import { Options } from 'yargs' -import { ZodNativeEnum, ZodRawShape, ZodTypeAny, z } from 'zod' -import { basename, extname } from 'node:path' import { readFileSync } from 'node:fs' -import _ from 'lodash' +import { basename, extname } from 'node:path' +import { BuildBlockMode, defaultLogger, genesisSchema, isUrl } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' import axios from 'axios' import yaml from 'js-yaml' +import _ from 'lodash' +import type { Options } from 'yargs' +import { ZodNativeEnum, type ZodRawShape, type ZodTypeAny, z } from 'zod' export const zHex = z.custom((val: any) => /^0x\w+$/.test(val)) export const zHash = z.string().length(66).and(zHex) diff --git a/packages/chopsticks/src/schema/options.test.ts b/packages/chopsticks/src/schema/options.test.ts index 5e1cb939..ecc1ed54 100644 --- a/packages/chopsticks/src/schema/options.test.ts +++ b/packages/chopsticks/src/schema/options.test.ts @@ -1,5 +1,5 @@ -import { configSchema, getYargsOptions } from './index.js' import { expect, it } from 'vitest' +import { configSchema, getYargsOptions } from './index.js' it('get yargs options from zod schema', () => { expect(getYargsOptions(configSchema.shape)).toMatchInlineSnapshot(` diff --git a/packages/chopsticks/src/schema/parse.test.ts b/packages/chopsticks/src/schema/parse.test.ts index 23ce802f..8d58ab64 100644 --- a/packages/chopsticks/src/schema/parse.test.ts +++ b/packages/chopsticks/src/schema/parse.test.ts @@ -1,14 +1,14 @@ -import { describe, expect, it } from 'vitest' import { readdirSync } from 'node:fs' -import _ from 'lodash' import path from 'node:path' +import _ from 'lodash' +import { describe, expect, it } from 'vitest' import { configSchema, fetchConfig } from './index.js' function getAllFiles(dirPath: string) { const files = readdirSync(dirPath) const arrayOfFiles: string[] = [] - files.forEach(function (file) { + files.forEach((file) => { arrayOfFiles.push(path.join(dirPath, '/', file)) }) diff --git a/packages/chopsticks/src/server.ts b/packages/chopsticks/src/server.ts index 2cfb2875..2a2f1ea2 100644 --- a/packages/chopsticks/src/server.ts +++ b/packages/chopsticks/src/server.ts @@ -1,7 +1,7 @@ -import { AddressInfo, WebSocket, WebSocketServer } from 'ws' -import { ResponseError, SubscriptionManager } from '@acala-network/chopsticks-core' -import { z } from 'zod' import http from 'node:http' +import { ResponseError, type SubscriptionManager } from '@acala-network/chopsticks-core' +import { type AddressInfo, WebSocket, WebSocketServer } from 'ws' +import { z } from 'zod' import { defaultLogger, truncate } from './logger.js' @@ -121,7 +121,7 @@ export const createServer = async (handler: Handler, port: number, host?: string if (!parsed.success) { httpLogger.error('Invalid request: %s', body) - throw new Error('Invalid request: ' + body) + throw new Error(`Invalid request: ${body}`) } httpLogger.trace({ req: parsed.data }, 'Received request') diff --git a/packages/chopsticks/src/setup-with-server.ts b/packages/chopsticks/src/setup-with-server.ts index 95d04d17..46e22106 100644 --- a/packages/chopsticks/src/setup-with-server.ts +++ b/packages/chopsticks/src/setup-with-server.ts @@ -1,8 +1,8 @@ -import { Config } from './schema/index.js' -import { createServer } from './server.js' import { defaultLogger } from '@acala-network/chopsticks-core' -import { handler } from './rpc/index.js' import { setupContext } from './context.js' +import { handler } from './rpc/index.js' +import type { Config } from './schema/index.js' +import { createServer } from './server.js' export const setupWithServer = async (argv: Config) => { if (argv.addr) { diff --git a/packages/chopsticks/src/utils/decoder.ts b/packages/chopsticks/src/utils/decoder.ts index 6bef7a4a..27916906 100644 --- a/packages/chopsticks/src/utils/decoder.ts +++ b/packages/chopsticks/src/utils/decoder.ts @@ -1,5 +1,5 @@ -import { Block, decodeBlockStorageDiff } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' +import { type Block, decodeBlockStorageDiff } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' import { create } from 'jsondiffpatch' import _ from 'lodash' @@ -11,8 +11,8 @@ const diffPatcher = create({ export const decodeStorageDiff = async (block: Block, diff: [HexString, HexString | null][]) => { const [oldState, newState] = await decodeBlockStorageDiff(block, diff) const oldStateWithoutEvents = _.cloneDeep(oldState) - if (oldStateWithoutEvents['system']?.['events']) { - oldStateWithoutEvents['system']['events'] = [] + if (oldStateWithoutEvents.system?.events) { + oldStateWithoutEvents.system.events = [] } return { oldState, newState, delta: diffPatcher.diff(oldStateWithoutEvents, newState) } } diff --git a/packages/chopsticks/src/utils/fetch-storages-worker.js b/packages/chopsticks/src/utils/fetch-storages-worker.js index 999e4b60..0b63835e 100644 --- a/packages/chopsticks/src/utils/fetch-storages-worker.js +++ b/packages/chopsticks/src/utils/fetch-storages-worker.js @@ -1,5 +1,5 @@ -import * as Comlink from 'comlink' import { parentPort } from 'node:worker_threads' +import * as Comlink from 'comlink' import nodeEndpoint from 'comlink/dist/umd/node-adapter.js' import { fetchStorages } from './fetch-storages.js' diff --git a/packages/chopsticks/src/utils/fetch-storages.test.ts b/packages/chopsticks/src/utils/fetch-storages.test.ts index 776f11b8..79a4cff0 100644 --- a/packages/chopsticks/src/utils/fetch-storages.test.ts +++ b/packages/chopsticks/src/utils/fetch-storages.test.ts @@ -1,15 +1,15 @@ -import { ApiPromise } from '@polkadot/api' -import { HexString } from '@polkadot/util/types' -import { Like } from 'typeorm' -import { ProviderInterface } from '@polkadot/rpc-provider/types' +import { tmpdir } from 'node:os' +import { resolve } from 'node:path' import { SqliteDatabase } from '@acala-network/chopsticks-db' +import { ApiPromise } from '@polkadot/api' import { WsProvider } from '@polkadot/rpc-provider' -import { afterAll, beforeAll, describe, expect, it } from 'vitest' -import { resolve } from 'node:path' -import { tmpdir } from 'node:os' +import type { ProviderInterface } from '@polkadot/rpc-provider/types' import { xxhashAsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' +import { Like } from 'typeorm' +import { afterAll, beforeAll, describe, expect, it } from 'vitest' -import { FetchStorageConfig, fetchStorages, getPrefixesFromConfig } from './fetch-storages.js' +import { type FetchStorageConfig, fetchStorages, getPrefixesFromConfig } from './fetch-storages.js' describe('fetch-storages', () => { let api: ApiPromise diff --git a/packages/chopsticks/src/utils/fetch-storages.ts b/packages/chopsticks/src/utils/fetch-storages.ts index 7aeccd64..bd0d56df 100644 --- a/packages/chopsticks/src/utils/fetch-storages.ts +++ b/packages/chopsticks/src/utils/fetch-storages.ts @@ -1,18 +1,18 @@ +import threads from 'node:worker_threads' import { Api, defaultLogger } from '@acala-network/chopsticks-core' -import { ApiPromise } from '@polkadot/api' -import { DecoratedMeta, ModuleStorage } from '@polkadot/types/metadata/decorate/types' -import { HexString } from '@polkadot/util/types' import { SqliteDatabase } from '@acala-network/chopsticks-db' -import { StorageEntry } from '@polkadot/types/primitive/types' -import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces' +import { ApiPromise } from '@polkadot/api' import { WsProvider } from '@polkadot/rpc-provider' -import { compactStripLength, stringCamelCase, u8aToHex } from '@polkadot/util' import { expandMetadata } from '@polkadot/types' -import { releaseProxy, wrap } from 'comlink' +import type { StorageEntryMetadataLatest } from '@polkadot/types/interfaces' +import type { DecoratedMeta, ModuleStorage } from '@polkadot/types/metadata/decorate/types' +import type { StorageEntry } from '@polkadot/types/primitive/types' +import { compactStripLength, stringCamelCase, u8aToHex } from '@polkadot/util' import { xxhashAsHex } from '@polkadot/util-crypto' -import _ from 'lodash' +import type { HexString } from '@polkadot/util/types' +import { releaseProxy, wrap } from 'comlink' import nodeEndpoint from 'comlink/dist/umd/node-adapter.js' -import threads from 'node:worker_threads' +import _ from 'lodash' const BATCH_SIZE = 1000 @@ -43,7 +43,7 @@ const checkPalletStorageByName = ( const pallet = meta.query[stringCamelCase(palletName)] if (!pallet) throw Error(`Cannot find pallet ${palletName}`) - let storage + let storage: any if (storageName) { storage = pallet[stringCamelCase(storageName)] if (!storage) throw Error(`Cannot find storage ${storageName} in pallet ${palletName}`) diff --git a/packages/chopsticks/src/utils/generate-html-diff.ts b/packages/chopsticks/src/utils/generate-html-diff.ts index 33ba1a5f..43fb3c84 100644 --- a/packages/chopsticks/src/utils/generate-html-diff.ts +++ b/packages/chopsticks/src/utils/generate-html-diff.ts @@ -1,8 +1,8 @@ -import { Block } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' -import { decodeStorageDiff } from './decoder.js' import { mkdirSync, readFileSync, writeFileSync } from 'node:fs' +import type { Block } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' +import { decodeStorageDiff } from './decoder.js' export const generateHtmlDiff = async (block: Block, diff: [HexString, HexString | null][]) => { const { oldState, delta } = await decodeStorageDiff(block, diff) diff --git a/packages/chopsticks/src/utils/open-html.ts b/packages/chopsticks/src/utils/open-html.ts index cffb1beb..2c352db5 100644 --- a/packages/chopsticks/src/utils/open-html.ts +++ b/packages/chopsticks/src/utils/open-html.ts @@ -1,6 +1,6 @@ import { execSync } from 'node:child_process' export const openHtml = (filePath: string) => { - const start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open' - execSync(start + ' ' + filePath) + const start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open' + execSync(`${start} ${filePath}`) } diff --git a/packages/chopsticks/src/utils/override.ts b/packages/chopsticks/src/utils/override.ts index 914a8c6e..4dae6001 100644 --- a/packages/chopsticks/src/utils/override.ts +++ b/packages/chopsticks/src/utils/override.ts @@ -1,6 +1,6 @@ -import { Blockchain, StorageValues, isUrl, setStorage } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' import { existsSync, readFileSync } from 'node:fs' +import { type Blockchain, type StorageValues, isUrl, setStorage } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' import axios from 'axios' import yaml from 'js-yaml' @@ -37,7 +37,7 @@ export const overrideWasm = async (chain: Blockchain, wasmPath?: string, at?: He // starts with 0x wasmHex = wasm.toString().trim() } else { - wasmHex = '0x' + wasm.toString('hex') + wasmHex = `0x${wasm.toString('hex')}` } if (at) { const block = await chain.getBlock(at) diff --git a/packages/core/package.json b/packages/core/package.json index 543482ea..85179170 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -37,7 +37,10 @@ "typescript": "^5.7.2", "vitest": "^2.1.8" }, - "files": ["dist/esm/**", "dist/cjs/**"], + "files": [ + "dist/esm/**", + "dist/cjs/**" + ], "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "exports": { diff --git a/packages/core/src/api.test.ts b/packages/core/src/api.test.ts index 2d8b6afa..274f3ca0 100644 --- a/packages/core/src/api.test.ts +++ b/packages/core/src/api.test.ts @@ -1,6 +1,6 @@ -import { Api } from './api.js' import { WsProvider } from '@polkadot/rpc-provider' import { expect, test } from 'vitest' +import { Api } from './api.js' test('handle invalid block hash', async () => { const api = new Api(new WsProvider('wss://acala-rpc.aca-api.network', 3_000)) diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index cae493f1..3428739c 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,9 +1,9 @@ -import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types' -import { HexString } from '@polkadot/util/types' -import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types' +import type { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types' +import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' -import { ChainProperties, Header, SignedBlock } from './index.js' +import type { ChainProperties, Header, SignedBlock } from './index.js' import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index.js' /** @@ -41,8 +41,8 @@ export class Api { get isReady() { if (!this.#ready) { - if (this.#provider['isReady']) { - this.#ready = this.#provider['isReady'] + if (this.#provider.isReady) { + this.#ready = this.#provider.isReady } else { this.#ready = new Promise((resolve): void => { if (this.#provider.hasSubscriptions) { @@ -117,12 +117,11 @@ export class Api { const params = [child, storageKey] if (hash) params.push(hash as HexString) return this.send('childstate_getStorage', params, !!hash) - } else { - // main storage key, use state_getStorage - const params = [key] - if (hash) params.push(hash) - return this.send('state_getStorage', params, !!hash) } + // main storage key, use state_getStorage + const params = [key] + if (hash) params.push(hash) + return this.send('state_getStorage', params, !!hash) } async getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string) { @@ -135,12 +134,11 @@ export class Api { return this.#provider .send('childstate_getKeysPaged', params, !!hash) .then((keys) => keys.map((key) => prefixedChildKey(child, key))) - } else { - // main storage key, use state_getKeysPaged - const params = [prefix, pageSize, startKey] - if (hash) params.push(hash) - return this.send('state_getKeysPaged', params, !!hash) } + // main storage key, use state_getKeysPaged + const params = [prefix, pageSize, startKey] + if (hash) params.push(hash) + return this.send('state_getKeysPaged', params, !!hash) } async getStorageBatch(prefix: HexString, keys: HexString[], hash?: HexString) { @@ -153,14 +151,13 @@ export class Api { return this.#provider .send('childstate_getStorageEntries', params, !!hash) .then((values) => _.zip(keys, values) as [HexString, HexString | null][]) - } else { - // main storage key, use state_getStorageAt - const params: any[] = [keys] - if (hash) params.push(hash) - return this.#provider - .send('state_queryStorageAt', params, !!hash) - .then((result) => (result[0]?.['changes'] as [HexString, HexString | null][]) || []) } + // main storage key, use state_getStorageAt + const params: any[] = [keys] + if (hash) params.push(hash) + return this.#provider + .send('state_queryStorageAt', params, !!hash) + .then((result) => (result[0]?.changes as [HexString, HexString | null][]) || []) } async subscribeRemoteNewHeads(cb: ProviderInterfaceCallback) { diff --git a/packages/core/src/blockchain/block-builder.ts b/packages/core/src/blockchain/block-builder.ts index 653da9ad..db171e22 100644 --- a/packages/core/src/blockchain/block-builder.ts +++ b/packages/core/src/blockchain/block-builder.ts @@ -1,4 +1,5 @@ -import { +import type { GenericExtrinsic } from '@polkadot/types' +import type { AccountInfo, ApplyExtrinsicResult, Call, @@ -8,17 +9,16 @@ import { RawBabePreDigest, TransactionValidityError, } from '@polkadot/types/interfaces' -import { Block } from './block.js' -import { BuildBlockParams } from './txpool.js' -import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' -import { InherentProvider } from './inherent/index.js' -import { StorageLayer, StorageValueKind } from './storage-layer.js' -import { TaskCallResponse } from '../wasm-executor/index.js' -import { blake2AsU8a } from '@polkadot/util-crypto' import { compactAddLength, hexToU8a, stringToHex, u8aConcat } from '@polkadot/util' -import { compactHex, getCurrentSlot } from '../utils/index.js' +import { blake2AsU8a } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' import { defaultLogger, truncate } from '../logger.js' +import { compactHex, getCurrentSlot } from '../utils/index.js' +import type { TaskCallResponse } from '../wasm-executor/index.js' +import { Block } from './block.js' +import type { InherentProvider } from './inherent/index.js' +import { StorageLayer, StorageValueKind } from './storage-layer.js' +import type { BuildBlockParams } from './txpool.js' const logger = defaultLogger.child({ name: 'block-builder' }) @@ -41,14 +41,13 @@ export const genesisDigestLogs = async (head: Block) => { PreRuntime: [consensusEngine, compactAddLength(preDigest.toU8a())], }) return [digest] - } else { - const newSlot = meta.registry.createType('Slot', currentSlot + 1) - const consensusEngine = meta.registry.createType('ConsensusEngineId', 'aura') - const digest = meta.registry.createType('DigestItem', { - PreRuntime: [consensusEngine, compactAddLength(newSlot.toU8a())], - }) - return [digest] } + const newSlot = meta.registry.createType('Slot', currentSlot + 1) + const consensusEngine = meta.registry.createType('ConsensusEngineId', 'aura') + const digest = meta.registry.createType('DigestItem', { + PreRuntime: [consensusEngine, compactAddLength(newSlot.toU8a())], + }) + return [digest] } const getConsensus = (header: Header) => { @@ -108,7 +107,7 @@ export const newHeader = async (head: Block, unsafeBlockHeight?: number) => { meta.registry.createType('DigestItem', { PreRuntime: [consensus.consensusEngine, newSlot] }), ...consensus.rest, ] - } else if (consensus?.consensusEngine?.toString() == 'nmbs') { + } else if (consensus?.consensusEngine?.toString() === 'nmbs') { const nmbsKey = stringToHex('nmbs') newLogs = [ meta.registry.createType('DigestItem', { @@ -116,7 +115,7 @@ export const newHeader = async (head: Block, unsafeBlockHeight?: number) => { PreRuntime: [ consensus.consensusEngine, parentHeader.digest.logs - .find((log) => log.isPreRuntime && log.asPreRuntime[0].toHex() == nmbsKey) + .find((log) => log.isPreRuntime && log.asPreRuntime[0].toHex() === nmbsKey) ?.asPreRuntime[1].toHex(), ], }), diff --git a/packages/core/src/blockchain/block.ts b/packages/core/src/blockchain/block.ts index 606677dd..984c9e10 100644 --- a/packages/core/src/blockchain/block.ts +++ b/packages/core/src/blockchain/block.ts @@ -1,22 +1,22 @@ -import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' -import { Header } from '@polkadot/types/interfaces' -import { Metadata, TypeRegistry } from '@polkadot/types' -import { StorageEntry } from '@polkadot/types/primitive/types' +import { Metadata, type TypeRegistry } from '@polkadot/types' +import type { Header } from '@polkadot/types/interfaces' import { expandMetadata } from '@polkadot/types/metadata' +import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' +import type { StorageEntry } from '@polkadot/types/primitive/types' import { hexToU8a, stringToHex } from '@polkadot/util' import type { HexString } from '@polkadot/util/types' -import { Blockchain } from './index.js' +import { compactHex } from '../utils/index.js' +import { getRuntimeVersion, runTask, taskHandler } from '../wasm-executor/index.js' +import type { RuntimeVersion, TaskCallResponse } from '../wasm-executor/index.js' +import type { Blockchain } from './index.js' import { RemoteStorageLayer, StorageLayer, - StorageLayerProvider, - StorageValue, + type StorageLayerProvider, + type StorageValue, StorageValueKind, } from './storage-layer.js' -import { compactHex } from '../utils/index.js' -import { getRuntimeVersion, runTask, taskHandler } from '../wasm-executor/index.js' -import type { RuntimeVersion, TaskCallResponse } from '../wasm-executor/index.js' /** * Block class. diff --git a/packages/core/src/blockchain/get-keys-paged.test.ts b/packages/core/src/blockchain/get-keys-paged.test.ts index 67f7578f..cf501381 100644 --- a/packages/core/src/blockchain/get-keys-paged.test.ts +++ b/packages/core/src/blockchain/get-keys-paged.test.ts @@ -1,7 +1,7 @@ -import { Api } from '../api.js' -import { RemoteStorageLayer, StorageLayer, StorageValue, StorageValueKind } from './storage-layer.js' -import { describe, expect, it, vi } from 'vitest' import _ from 'lodash' +import { describe, expect, it, vi } from 'vitest' +import { Api } from '../api.js' +import { RemoteStorageLayer, StorageLayer, type StorageValue, StorageValueKind } from './storage-layer.js' describe('getKeysPaged', () => { const hash = '0x1111111111111111111111111111111111111111111111111111111111111111' @@ -21,12 +21,12 @@ describe('getKeysPaged', () => { '0x94533e05c34400caee0d8976774f0dd064443ba500633e46053c7a0a68b8ef3392a72b59fc8b67b702000001a12dfa1fa4ab9a0000', ] - Api.prototype['getKeysPaged'] = vi.fn(async (prefix, pageSize, startKey) => { + Api.prototype.getKeysPaged = vi.fn(async (prefix, pageSize, startKey) => { const withPrefix = remoteKeys.filter((k) => k.startsWith(prefix) && k > startKey) const result = withPrefix.slice(0, pageSize) return result }) - Api.prototype['getStorage'] = vi.fn(async (_key, _at) => { + Api.prototype.getStorage = vi.fn(async (_key, _at) => { return '0x1' as any }) const mockApi = new Api(undefined!) @@ -364,7 +364,7 @@ describe('getKeysPaged', () => { ] const prefix = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' - const makeKey = (x: string) => prefix + '_' + Number(x).toString().padStart(2, '0') + const makeKey = (x: string) => `${prefix}_${Number(x).toString().padStart(2, '0')}` // build layers const layers: StorageLayer[] = [] @@ -437,7 +437,7 @@ describe('getKeysPaged', () => { it('fuzz', async () => { const oddPrefix = '0x1111111111111111111111111111111111111111111111111111111111111111' const evenPrefix = '0x2222222222222222222222222222222222222222222222222222222222222222' - const makeKey = (x: number) => (x % 2 === 0 ? evenPrefix : oddPrefix) + '_' + x.toString().padStart(2, '0') + const makeKey = (x: number) => `${x % 2 === 0 ? evenPrefix : oddPrefix}_${x.toString().padStart(2, '0')}` // create some random keys const pages: number[][] = [] @@ -457,12 +457,12 @@ describe('getKeysPaged', () => { const layers: StorageLayer[] = [] for (const page of pages) { const layer = new StorageLayer(layers[layers.length - 1]) - layer.setAll(page.map((x) => [makeKey(x), '0x' + Number(x).toString(16)] as [string, StorageValue])) + layer.setAll(page.map((x) => [makeKey(x), `0x${Number(x).toString(16)}`] as [string, StorageValue])) layers.push(layer) } const allKeys = pages - .flatMap((x) => x) + .flat() .reduce((acc, x) => { if (acc.includes(x)) { return acc diff --git a/packages/core/src/blockchain/head-state.ts b/packages/core/src/blockchain/head-state.ts index df8989e7..3bbcae2b 100644 --- a/packages/core/src/blockchain/head-state.ts +++ b/packages/core/src/blockchain/head-state.ts @@ -1,5 +1,5 @@ -import { Block } from './block.js' import { defaultLogger } from '../logger.js' +import type { Block } from './block.js' type Callback = (block: Block, pairs: [string, string | null][]) => void | Promise diff --git a/packages/core/src/blockchain/index.ts b/packages/core/src/blockchain/index.ts index 3cce078d..46a53cce 100644 --- a/packages/core/src/blockchain/index.ts +++ b/packages/core/src/blockchain/index.ts @@ -1,26 +1,32 @@ -import { ApplyExtrinsicResult, ChainProperties, Header } from '@polkadot/types/interfaces' -import { HexString } from '@polkadot/util/types' import { Metadata, TypeRegistry } from '@polkadot/types' -import { RegisteredTypes } from '@polkadot/types/types' -import { blake2AsHex, xxhashAsHex } from '@polkadot/util-crypto' import { getSpecExtensions, getSpecHasher, getSpecTypes } from '@polkadot/types-known/util' -import { objectSpread, u8aConcat, u8aToHex } from '@polkadot/util' -import _ from 'lodash' import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types' +import type { ApplyExtrinsicResult, ChainProperties, Header } from '@polkadot/types/interfaces' import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue' +import type { RegisteredTypes } from '@polkadot/types/types' +import { objectSpread, u8aConcat, u8aToHex } from '@polkadot/util' +import { blake2AsHex, xxhashAsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' +import _ from 'lodash' -import { Api } from '../api.js' -import { Block } from './block.js' -import { BuildBlockMode, BuildBlockParams, DownwardMessage, HorizontalMessage, TxPool } from './txpool.js' -import { Database } from '../database.js' -import { HeadState } from './head-state.js' -import { InherentProvider } from './inherent/index.js' +import type { Api } from '../api.js' +import type { Database } from '../database.js' +import { defaultLogger } from '../logger.js' import { OffchainWorker } from '../offchain.js' -import { RuntimeVersion } from '../wasm-executor/index.js' -import { StorageValue } from './storage-layer.js' import { compactHex } from '../utils/index.js' -import { defaultLogger } from '../logger.js' +import type { RuntimeVersion } from '../wasm-executor/index.js' import { dryRunExtrinsic, dryRunInherents } from './block-builder.js' +import { Block } from './block.js' +import { HeadState } from './head-state.js' +import type { InherentProvider } from './inherent/index.js' +import type { StorageValue } from './storage-layer.js' +import { + type BuildBlockMode, + type BuildBlockParams, + type DownwardMessage, + type HorizontalMessage, + TxPool, +} from './txpool.js' const logger = defaultLogger.child({ name: 'blockchain' }) diff --git a/packages/core/src/blockchain/inherent/index.ts b/packages/core/src/blockchain/inherent/index.ts index 69a82006..48d8a2e0 100644 --- a/packages/core/src/blockchain/inherent/index.ts +++ b/packages/core/src/blockchain/inherent/index.ts @@ -1,11 +1,11 @@ -import { Block } from '../block.js' -import { BuildBlockParams } from '../txpool.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' +import type { Block } from '../block.js' +import type { BuildBlockParams } from '../txpool.js' import { ParaInherentEnter } from './para-enter.js' import { SetBabeRandomness } from './parachain/babe-randomness.js' import { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js' -import { SetTimestamp } from './timestamp.js' import { SetValidationData } from './parachain/validation-data.js' +import { SetTimestamp } from './timestamp.js' export interface InherentProvider { createInherents(newBlock: Block, params: BuildBlockParams): Promise diff --git a/packages/core/src/blockchain/inherent/para-enter.ts b/packages/core/src/blockchain/inherent/para-enter.ts index 0b8cfda4..eb47746c 100644 --- a/packages/core/src/blockchain/inherent/para-enter.ts +++ b/packages/core/src/blockchain/inherent/para-enter.ts @@ -1,9 +1,9 @@ import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' -import { Block } from '../block.js' -import { BuildBlockParams } from '../txpool.js' -import { InherentProvider } from './index.js' +import type { Block } from '../block.js' +import type { BuildBlockParams } from '../txpool.js' +import type { InherentProvider } from './index.js' export class ParaInherentEnter implements InherentProvider { async createInherents(newBlock: Block, _params: BuildBlockParams): Promise { diff --git a/packages/core/src/blockchain/inherent/parachain/babe-randomness.ts b/packages/core/src/blockchain/inherent/parachain/babe-randomness.ts index e21c07b9..5af572cc 100644 --- a/packages/core/src/blockchain/inherent/parachain/babe-randomness.ts +++ b/packages/core/src/blockchain/inherent/parachain/babe-randomness.ts @@ -1,9 +1,9 @@ import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' -import { Block } from '../../block.js' -import { BuildBlockParams } from '../../txpool.js' -import { InherentProvider } from '../index.js' +import type { Block } from '../../block.js' +import type { BuildBlockParams } from '../../txpool.js' +import type { InherentProvider } from '../index.js' // Support for Moonbeam pallet-randomness mandatory inherent export class SetBabeRandomness implements InherentProvider { diff --git a/packages/core/src/blockchain/inherent/parachain/nimbus-author-inherent.ts b/packages/core/src/blockchain/inherent/parachain/nimbus-author-inherent.ts index 35042410..373c1632 100644 --- a/packages/core/src/blockchain/inherent/parachain/nimbus-author-inherent.ts +++ b/packages/core/src/blockchain/inherent/parachain/nimbus-author-inherent.ts @@ -1,9 +1,9 @@ -import { Block } from '../../block.js' -import { BuildBlockParams } from '../../txpool.js' import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' -import { InherentProvider } from '../index.js' +import type { HexString } from '@polkadot/util/types' import { compactHex } from '../../../utils/index.js' +import type { Block } from '../../block.js' +import type { BuildBlockParams } from '../../txpool.js' +import type { InherentProvider } from '../index.js' // Support for Nimbus Author Inherent export class SetNimbusAuthorInherent implements InherentProvider { async createInherents(newBlock: Block, _params: BuildBlockParams): Promise { diff --git a/packages/core/src/blockchain/inherent/parachain/validation-data.ts b/packages/core/src/blockchain/inherent/parachain/validation-data.ts index e81d5fc0..c74f1996 100644 --- a/packages/core/src/blockchain/inherent/parachain/validation-data.ts +++ b/packages/core/src/blockchain/inherent/parachain/validation-data.ts @@ -1,12 +1,11 @@ -import { AbridgedHrmpChannel, HrmpChannelId, Slot } from '@polkadot/types/interfaces' -import { BN, hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util' import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' +import type { AbridgedHrmpChannel, HrmpChannelId, Slot } from '@polkadot/types/interfaces' +import { type BN, hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' -import { Block } from '../../block.js' -import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js' -import { InherentProvider } from '../index.js' +import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto' +import { compactHex, getCurrentSlot, getParaId } from '../../../utils/index.js' import { WELL_KNOWN_KEYS, dmqMqcHead, @@ -16,9 +15,10 @@ import { paraHead, upgradeGoAheadSignal, } from '../../../utils/proof.js' -import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto' -import { compactHex, getCurrentSlot, getParaId } from '../../../utils/index.js' import { createProof, decodeProof } from '../../../wasm-executor/index.js' +import type { Block } from '../../block.js' +import type { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js' +import type { InherentProvider } from '../index.js' const MOCK_VALIDATION_DATA = { validationData: { @@ -272,7 +272,7 @@ export class SetValidationData implements InherentProvider { if (params.relayChainStateOverrides) { for (const [key, value] of params.relayChainStateOverrides) { // Remove any entry that matches the key being overridden - newEntries = newEntries.filter(([k, _]) => k != key) + newEntries = newEntries.filter(([k, _]) => k !== key) // Push override newEntries.push([key, value]) } diff --git a/packages/core/src/blockchain/inherent/timestamp.ts b/packages/core/src/blockchain/inherent/timestamp.ts index e7891f98..ea665c5b 100644 --- a/packages/core/src/blockchain/inherent/timestamp.ts +++ b/packages/core/src/blockchain/inherent/timestamp.ts @@ -1,8 +1,8 @@ -import { Block } from '../block.js' import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' -import { InherentProvider } from './index.js' +import type { HexString } from '@polkadot/util/types' import { getCurrentTimestamp, getSlotDuration } from '../../utils/index.js' +import type { Block } from '../block.js' +import type { InherentProvider } from './index.js' export class SetTimestamp implements InherentProvider { async createInherents(newBlock: Block): Promise { diff --git a/packages/core/src/blockchain/storage-layer.ts b/packages/core/src/blockchain/storage-layer.ts index b75141ee..e43dfbe6 100644 --- a/packages/core/src/blockchain/storage-layer.ts +++ b/packages/core/src/blockchain/storage-layer.ts @@ -1,17 +1,17 @@ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' -import { Api } from '../api.js' -import { CHILD_PREFIX_LENGTH, PREFIX_LENGTH, isPrefixedChildKey } from '../utils/index.js' -import { Database } from '../database.js' +import type { Api } from '../api.js' +import type { Database } from '../database.js' import { defaultLogger } from '../logger.js' +import { CHILD_PREFIX_LENGTH, PREFIX_LENGTH, isPrefixedChildKey } from '../utils/index.js' import KeyCache from '../utils/key-cache.js' const logger = defaultLogger.child({ name: 'layer' }) const BATCH_SIZE = 1000 -export const enum StorageValueKind { +export enum StorageValueKind { Deleted = 'Deleted', DeletedPrefix = 'DeletedPrefix', } @@ -114,7 +114,7 @@ export class RemoteStorageLayer implements StorageLayerProvider { // batch fetch storage values and save to db, they may be used later this.#api.getStorageBatch(prefix as HexString, batch as HexString[], this.#at as HexString).then((storage) => { for (const [key, value] of storage) { - this.#db!.saveStorage(this.#at as HexString, key as HexString, value) + this.#db?.saveStorage(this.#at as HexString, key as HexString, value) } }) } @@ -217,7 +217,8 @@ export class StorageLayer implements StorageLayerProvider { if (parentBest) { if (!maybeBest) { return parentBest - } else if (parentBest < maybeBest) { + } + if (parentBest < maybeBest) { return parentBest } } @@ -235,7 +236,7 @@ export class StorageLayer implements StorageLayerProvider { const next = await this.findNextKey(prefix, startKey, undefined) if (!next) break startKey = next - if ((await this.get(next, false)) == StorageValueKind.Deleted) continue + if ((await this.get(next, false)) === StorageValueKind.Deleted) continue keys.push(next) } return keys diff --git a/packages/core/src/blockchain/txpool.ts b/packages/core/src/blockchain/txpool.ts index a313f7e2..8f9f8835 100644 --- a/packages/core/src/blockchain/txpool.ts +++ b/packages/core/src/blockchain/txpool.ts @@ -1,14 +1,14 @@ -import { EventEmitter } from 'eventemitter3' -import { GenericExtrinsic } from '@polkadot/types' -import { HexString } from '@polkadot/util/types' +import type { GenericExtrinsic } from '@polkadot/types' import { hexToU8a } from '@polkadot/util/hex/toU8a' +import type { HexString } from '@polkadot/util/types' +import { EventEmitter } from 'eventemitter3' import _ from 'lodash' -import { Blockchain } from './index.js' -import { Deferred, defer } from '../utils/index.js' -import { InherentProvider } from './inherent/index.js' -import { buildBlock } from './block-builder.js' import { defaultLogger, truncate } from '../logger.js' +import { type Deferred, defer } from '../utils/index.js' +import { buildBlock } from './block-builder.js' +import type { Blockchain } from './index.js' +import type { InherentProvider } from './inherent/index.js' const logger = defaultLogger.child({ name: 'txpool' }) diff --git a/packages/core/src/chopsticks-provider.ts b/packages/core/src/chopsticks-provider.ts index d48ee79b..719bcb7f 100644 --- a/packages/core/src/chopsticks-provider.ts +++ b/packages/core/src/chopsticks-provider.ts @@ -1,15 +1,15 @@ -import { EventEmitter } from 'eventemitter3' -import { +import type { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, } from '@polkadot/rpc-provider/types' +import { EventEmitter } from 'eventemitter3' -import { Blockchain } from './blockchain/index.js' -import { Database } from './database.js' -import { Handlers, allHandlers } from './rpc/index.js' +import type { Blockchain } from './blockchain/index.js' +import type { Database } from './database.js' import { defaultLogger } from './logger.js' +import { type Handlers, allHandlers } from './rpc/index.js' import { setup } from './setup.js' const providerHandlers: Handlers = { @@ -155,10 +155,9 @@ export class ChopsticksProvider implements ProviderInterface { } return subid - } else { - logger.debug('call', { method, params }) - return rpcHandler({ chain: this.chain }, params, this.subscriptionManager) } + logger.debug('call', { method, params }) + return rpcHandler({ chain: this.chain }, params, this.subscriptionManager) } catch (e) { logger.error('send error.', e) throw e diff --git a/packages/core/src/database.ts b/packages/core/src/database.ts index 29a0338c..c6329316 100644 --- a/packages/core/src/database.ts +++ b/packages/core/src/database.ts @@ -1,4 +1,4 @@ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' export interface BlockEntry { hash: HexString diff --git a/packages/core/src/genesis-provider.ts b/packages/core/src/genesis-provider.ts index 1d092639..fbb7deba 100644 --- a/packages/core/src/genesis-provider.ts +++ b/packages/core/src/genesis-provider.ts @@ -1,15 +1,15 @@ -import { EventEmitter } from 'eventemitter3' -import { HexString } from '@polkadot/util/types' -import { +import type { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, } from '@polkadot/rpc-provider/types' +import type { HexString } from '@polkadot/util/types' +import { EventEmitter } from 'eventemitter3' -import { Genesis, genesisSchema } from './schema/index.js' -import { JsCallback, calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js' import { defaultLogger, isPrefixedChildKey } from './index.js' +import { type Genesis, genesisSchema } from './schema/index.js' +import { type JsCallback, calculateStateRoot, emptyTaskHandler } from './wasm-executor/index.js' /** * Provider to start a chain from genesis @@ -121,14 +121,14 @@ export class GenesisProvider implements ProviderInterface { const storage = this.#genesis.genesis.raw.top return { ...emptyTaskHandler, - getStorage: async function (key: HexString) { + getStorage: async (key: HexString) => { if (isPrefixedChildKey(key)) { defaultLogger.warn({ key }, 'genesis child storage not supported') return undefined } return storage[key] }, - getNextKey: async function (prefix: HexString, key: HexString) { + getNextKey: async (prefix: HexString, key: HexString) => { if (isPrefixedChildKey(key)) { defaultLogger.warn({ prefix, key }, 'genesis child storage not supported') return undefined diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c1e70f49..9c9519e3 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -8,7 +8,7 @@ * @packageDocumentation */ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' export type ChainProperties = { ss58Format?: number diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index 9ff55534..1062a7ed 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -29,10 +29,9 @@ const innerTruncate = switch (typeof val) { case 'string': if (val.length > 66 && !verboseLog) { - return val.slice(0, 34) + '…' + val.slice(-32) - } else { - return val + return `${val.slice(0, 34)}…${val.slice(-32)}` } + return val case 'object': if (Array.isArray(val)) { return val.map(innerTruncate(level + 1)) diff --git a/packages/core/src/offchain.ts b/packages/core/src/offchain.ts index 75a78f02..d9300d2e 100644 --- a/packages/core/src/offchain.ts +++ b/packages/core/src/offchain.ts @@ -1,8 +1,8 @@ -import { Block } from './blockchain/block.js' -import { HexString } from '@polkadot/util/types' import { blake2AsHex } from '@polkadot/util-crypto' -import { defaultLogger } from './logger.js' +import type { HexString } from '@polkadot/util/types' import { queueScheduler } from 'rxjs' +import type { Block } from './blockchain/block.js' +import { defaultLogger } from './logger.js' const logger = defaultLogger.child({ name: 'offchain' }) diff --git a/packages/core/src/rpc/dev/new-block.ts b/packages/core/src/rpc/dev/new-block.ts index ef7f06b8..1307fc7a 100644 --- a/packages/core/src/rpc/dev/new-block.ts +++ b/packages/core/src/rpc/dev/new-block.ts @@ -1,6 +1,6 @@ -import { Context, ResponseError, zHex } from '../shared.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' import { z } from 'zod' +import { type Context, ResponseError, zHex } from '../shared.js' import { defaultLogger } from '../../logger.js' diff --git a/packages/core/src/rpc/dev/set-block-build-mode.ts b/packages/core/src/rpc/dev/set-block-build-mode.ts index 71b523f8..8110d161 100644 --- a/packages/core/src/rpc/dev/set-block-build-mode.ts +++ b/packages/core/src/rpc/dev/set-block-build-mode.ts @@ -1,6 +1,6 @@ import { BuildBlockMode } from '../../blockchain/txpool.js' -import { Context, ResponseError } from '../shared.js' import { defaultLogger } from '../../logger.js' +import { type Context, ResponseError } from '../shared.js' /** * Set block build mode. diff --git a/packages/core/src/rpc/dev/set-head.ts b/packages/core/src/rpc/dev/set-head.ts index 25c64ab5..05a50834 100644 --- a/packages/core/src/rpc/dev/set-head.ts +++ b/packages/core/src/rpc/dev/set-head.ts @@ -1,6 +1,6 @@ -import { Block } from '../../blockchain/block.js' -import { Context, ResponseError, zHash } from '../shared.js' import { z } from 'zod' +import type { Block } from '../../blockchain/block.js' +import { type Context, ResponseError, zHash } from '../shared.js' const schema = zHash.or(z.number()) type Params = z.infer diff --git a/packages/core/src/rpc/dev/set-runtime-log-level.ts b/packages/core/src/rpc/dev/set-runtime-log-level.ts index 321244c1..c36b8af6 100644 --- a/packages/core/src/rpc/dev/set-runtime-log-level.ts +++ b/packages/core/src/rpc/dev/set-runtime-log-level.ts @@ -1,5 +1,5 @@ -import { Context, ResponseError } from '../shared.js' import { defaultLogger } from '../../logger.js' +import { type Context, ResponseError } from '../shared.js' /** * Set runtime log level. diff --git a/packages/core/src/rpc/dev/set-storage.ts b/packages/core/src/rpc/dev/set-storage.ts index a74c9889..01a38369 100644 --- a/packages/core/src/rpc/dev/set-storage.ts +++ b/packages/core/src/rpc/dev/set-storage.ts @@ -1,8 +1,8 @@ -import { Context, ResponseError } from '../shared.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' +import { type Context, ResponseError } from '../shared.js' -import { StorageValues, setStorage } from '../../utils/set-storage.js' import { defaultLogger } from '../../logger.js' +import { type StorageValues, setStorage } from '../../utils/set-storage.js' /** * Set storage values. diff --git a/packages/core/src/rpc/dev/time-travel.ts b/packages/core/src/rpc/dev/time-travel.ts index 8f0f2122..ad7cbc44 100644 --- a/packages/core/src/rpc/dev/time-travel.ts +++ b/packages/core/src/rpc/dev/time-travel.ts @@ -1,5 +1,5 @@ -import { Context, ResponseError } from '../shared.js' import { timeTravel } from '../../utils/time-travel.js' +import { type Context, ResponseError } from '../shared.js' /** * Travel to a specific time. diff --git a/packages/core/src/rpc/index.ts b/packages/core/src/rpc/index.ts index 254fbe97..512a9ec0 100644 --- a/packages/core/src/rpc/index.ts +++ b/packages/core/src/rpc/index.ts @@ -1,6 +1,6 @@ -import { Handlers } from './shared.js' import dev from './dev/index.js' import rpcSpec from './rpc-spec/index.js' +import type { Handlers } from './shared.js' import substrate from './substrate/index.js' export const allHandlers: Handlers = { diff --git a/packages/core/src/rpc/rpc-spec/chainHead_v1.ts b/packages/core/src/rpc/rpc-spec/chainHead_v1.ts index ffdf5559..0067656b 100644 --- a/packages/core/src/rpc/rpc-spec/chainHead_v1.ts +++ b/packages/core/src/rpc/rpc-spec/chainHead_v1.ts @@ -1,7 +1,7 @@ -import { Block } from '../../blockchain/block.js' -import { Handler, ResponseError, SubscriptionManager } from '../shared.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' +import type { Block } from '../../blockchain/block.js' import { defaultLogger } from '../../logger.js' +import { type Handler, ResponseError, type SubscriptionManager } from '../shared.js' const logger = defaultLogger.child({ name: 'rpc-chainHead_v1' }) diff --git a/packages/core/src/rpc/rpc-spec/chainSpec_v1.ts b/packages/core/src/rpc/rpc-spec/chainSpec_v1.ts index f3a64167..4b6cc965 100644 --- a/packages/core/src/rpc/rpc-spec/chainSpec_v1.ts +++ b/packages/core/src/rpc/rpc-spec/chainSpec_v1.ts @@ -1,6 +1,6 @@ -import { ChainProperties } from '../../index.js' -import { Handler, ResponseError } from '../shared.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' +import type { ChainProperties } from '../../index.js' +import { type Handler, ResponseError } from '../shared.js' export const chainSpec_v1_chainName: Handler<[], string> = async (context) => { return context.chain.api.getSystemChain() diff --git a/packages/core/src/rpc/rpc-spec/transaction_v1.ts b/packages/core/src/rpc/rpc-spec/transaction_v1.ts index 22b2549d..e5aa89ee 100644 --- a/packages/core/src/rpc/rpc-spec/transaction_v1.ts +++ b/packages/core/src/rpc/rpc-spec/transaction_v1.ts @@ -1,6 +1,6 @@ -import { Handler } from '../shared.js' -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' import { defaultLogger } from '../../logger.js' +import type { Handler } from '../shared.js' const logger = defaultLogger.child({ name: 'rpc-transaction_v1' }) const randomId = () => Math.random().toString(36).substring(2) diff --git a/packages/core/src/rpc/shared.ts b/packages/core/src/rpc/shared.ts index cd8bf8f9..32de0cb9 100644 --- a/packages/core/src/rpc/shared.ts +++ b/packages/core/src/rpc/shared.ts @@ -1,7 +1,7 @@ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' import { z } from 'zod' -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' import { defaultLogger } from '../logger.js' export const logger = defaultLogger.child({ name: 'rpc' }) diff --git a/packages/core/src/rpc/substrate/archive.ts b/packages/core/src/rpc/substrate/archive.ts index c9b4ffa2..f71749a4 100644 --- a/packages/core/src/rpc/substrate/archive.ts +++ b/packages/core/src/rpc/substrate/archive.ts @@ -1,6 +1,6 @@ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' -import { Handler, ResponseError } from '../shared.js' +import { type Handler, ResponseError } from '../shared.js' import { chain_getBlockHash } from './chain.js' import { state_call } from './state.js' diff --git a/packages/core/src/rpc/substrate/author.ts b/packages/core/src/rpc/substrate/author.ts index e00f68f0..8045d0cd 100644 --- a/packages/core/src/rpc/substrate/author.ts +++ b/packages/core/src/rpc/substrate/author.ts @@ -1,10 +1,10 @@ -import { HexString } from '@polkadot/util/types' -import { TransactionValidityError } from '@polkadot/types/interfaces' +import type { TransactionValidityError } from '@polkadot/types/interfaces' +import type { HexString } from '@polkadot/util/types' +import type { Block } from '../../blockchain/block.js' import { APPLY_EXTRINSIC_ERROR } from '../../blockchain/txpool.js' -import { Block } from '../../blockchain/block.js' -import { Handler, ResponseError, SubscriptionManager } from '../shared.js' import { defaultLogger } from '../../logger.js' +import { type Handler, ResponseError, type SubscriptionManager } from '../shared.js' const logger = defaultLogger.child({ name: 'rpc-author' }) diff --git a/packages/core/src/rpc/substrate/chain.ts b/packages/core/src/rpc/substrate/chain.ts index 7d00582e..925f1a0c 100644 --- a/packages/core/src/rpc/substrate/chain.ts +++ b/packages/core/src/rpc/substrate/chain.ts @@ -1,9 +1,9 @@ -import { Header as CodecHeader } from '@polkadot/types/interfaces' -import { HexString } from '@polkadot/util/types' +import type { Header as CodecHeader } from '@polkadot/types/interfaces' import { hexToNumber, isHex } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { Handler, ResponseError } from '../shared.js' import type { Header } from '../../index.js' +import { type Handler, ResponseError } from '../shared.js' const processHeader = ({ parentHash, number, stateRoot, extrinsicsRoot, digest }: CodecHeader) => { return { diff --git a/packages/core/src/rpc/substrate/payment.ts b/packages/core/src/rpc/substrate/payment.ts index 780f6930..8a4146a6 100644 --- a/packages/core/src/rpc/substrate/payment.ts +++ b/packages/core/src/rpc/substrate/payment.ts @@ -1,7 +1,7 @@ -import { HexString } from '@polkadot/util/types' import { hexToU8a } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { Handler, ResponseError } from '../shared.js' +import { type Handler, ResponseError } from '../shared.js' /** * @param context diff --git a/packages/core/src/rpc/substrate/state.ts b/packages/core/src/rpc/substrate/state.ts index b7a8ffcf..1d25c2ae 100644 --- a/packages/core/src/rpc/substrate/state.ts +++ b/packages/core/src/rpc/substrate/state.ts @@ -1,11 +1,11 @@ -import { HexString } from '@polkadot/util/types' import { stringToHex } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { Block } from '../../blockchain/block.js' -import { Handler, ResponseError } from '../shared.js' -import { RuntimeVersion } from '../../wasm-executor/index.js' +import type { Block } from '../../blockchain/block.js' import { defaultLogger } from '../../logger.js' import { isPrefixedChildKey, prefixedChildKey, stripChildPrefix } from '../../utils/index.js' +import type { RuntimeVersion } from '../../wasm-executor/index.js' +import { type Handler, ResponseError } from '../shared.js' const logger = defaultLogger.child({ name: 'rpc-state' }) diff --git a/packages/core/src/rpc/substrate/system.ts b/packages/core/src/rpc/substrate/system.ts index 1a4ff769..668cce44 100644 --- a/packages/core/src/rpc/substrate/system.ts +++ b/packages/core/src/rpc/substrate/system.ts @@ -1,9 +1,9 @@ -import { HexString } from '@polkadot/util/types' -import { Index } from '@polkadot/types/interfaces' +import type { Index } from '@polkadot/types/interfaces' import { hexToU8a } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { ChainProperties } from '../../index.js' -import { Handler } from '../shared.js' +import type { ChainProperties } from '../../index.js' +import type { Handler } from '../shared.js' export const system_localPeerId = async () => '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' export const system_nodeRoles = async () => ['Full'] diff --git a/packages/core/src/setup.ts b/packages/core/src/setup.ts index bf4cf088..ba81dc1c 100644 --- a/packages/core/src/setup.ts +++ b/packages/core/src/setup.ts @@ -1,16 +1,16 @@ import '@polkadot/types-codec' -import { HexString } from '@polkadot/util/types' import { HttpProvider, WsProvider } from '@polkadot/rpc-provider' -import { ProviderInterface } from '@polkadot/rpc-provider/types' -import { RegisteredTypes } from '@polkadot/types/types' +import type { ProviderInterface } from '@polkadot/rpc-provider/types' +import type { RegisteredTypes } from '@polkadot/types/types' +import type { HexString } from '@polkadot/util/types' import { Api } from './api.js' import { Blockchain } from './blockchain/index.js' -import { BuildBlockMode } from './blockchain/txpool.js' -import { Database } from './database.js' -import { GenesisProvider } from './genesis-provider.js' -import { defaultLogger } from './logger.js' import { inherentProviders } from './blockchain/inherent/index.js' +import type { BuildBlockMode } from './blockchain/txpool.js' +import type { Database } from './database.js' +import type { GenesisProvider } from './genesis-provider.js' +import { defaultLogger } from './logger.js' export type SetupOptions = { endpoint?: string | string[] diff --git a/packages/core/src/utils/decoder.ts b/packages/core/src/utils/decoder.ts index ab844337..984e62f7 100644 --- a/packages/core/src/utils/decoder.ts +++ b/packages/core/src/utils/decoder.ts @@ -1,16 +1,16 @@ import '@polkadot/types-codec' -import { Block } from '../blockchain/block.js' -import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' -import { HexString } from '@polkadot/util/types' -import { LRUCache } from 'lru-cache' -import { Registry } from '@polkadot/types-codec/types' -import { StorageEntry } from '@polkadot/types/primitive/types' -import { StorageKey } from '@polkadot/types' +import type { StorageKey } from '@polkadot/types' +import type { Registry } from '@polkadot/types-codec/types' +import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' +import type { StorageEntry } from '@polkadot/types/primitive/types' import { hexToU8a, u8aToHex } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' +import { LRUCache } from 'lru-cache' +import type { Block } from '../blockchain/block.js' -import { decodeWellKnownKey } from './well-known-keys.js' import { defaultLogger } from '../logger.js' +import { decodeWellKnownKey } from './well-known-keys.js' const logger = defaultLogger.child({ name: 'decoder' }) diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 764018c2..6644abb0 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,11 +1,11 @@ -import { BN, compactStripLength, u8aToHex } from '@polkadot/util' -import { HexString } from '@polkadot/util/types' -import { StorageKey } from '@polkadot/types' -import { getAuraSlotDuration } from '../wasm-executor/index.js' +import type { StorageKey } from '@polkadot/types' +import { type BN, compactStripLength, u8aToHex } from '@polkadot/util' import { hexAddPrefix, hexStripPrefix } from '@polkadot/util/hex' +import type { HexString } from '@polkadot/util/types' +import { getAuraSlotDuration } from '../wasm-executor/index.js' -import { Block } from '../blockchain/block.js' -import { Blockchain } from '../blockchain/index.js' +import type { Block } from '../blockchain/block.js' +import type { Blockchain } from '../blockchain/index.js' export * from './set-storage.js' export * from './time-travel.js' diff --git a/packages/core/src/utils/key-cache.ts b/packages/core/src/utils/key-cache.ts index c22e0d91..15d4a557 100644 --- a/packages/core/src/utils/key-cache.ts +++ b/packages/core/src/utils/key-cache.ts @@ -1,4 +1,4 @@ -import { HexString } from '@polkadot/util/types' +import type { HexString } from '@polkadot/util/types' import _ from 'lodash' export default class KeyCache { diff --git a/packages/core/src/utils/proof.ts b/packages/core/src/utils/proof.ts index b7da288b..ea14739d 100644 --- a/packages/core/src/utils/proof.ts +++ b/packages/core/src/utils/proof.ts @@ -1,8 +1,8 @@ -import { HexString } from '@polkadot/util/types' -import { HrmpChannelId } from '@polkadot/types/interfaces' +import type { u32 } from '@polkadot/types' +import type { HrmpChannelId } from '@polkadot/types/interfaces' import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util' -import { u32 } from '@polkadot/types' import { xxhashAsU8a } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' export const WELL_KNOWN_KEYS = { EPOCH_INDEX: '0x1cb6f36e027abb2091cfb5110ab5087f38316cbf8fa0da822a20ac1c55bf1be3' as HexString, diff --git a/packages/core/src/utils/set-storage.ts b/packages/core/src/utils/set-storage.ts index 474fd47a..bca614bf 100644 --- a/packages/core/src/utils/set-storage.ts +++ b/packages/core/src/utils/set-storage.ts @@ -1,10 +1,10 @@ -import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' -import { HexString } from '@polkadot/util/types' import { StorageKey } from '@polkadot/types' -import { stringCamelCase } from '@polkadot/util/string' +import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types' import { u8aToHex } from '@polkadot/util' +import { stringCamelCase } from '@polkadot/util/string' +import type { HexString } from '@polkadot/util/types' -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' import { StorageValueKind } from '../blockchain/storage-layer.js' type RawStorageValues = [string, string | null][] diff --git a/packages/core/src/utils/time-travel.ts b/packages/core/src/utils/time-travel.ts index 2b066fd4..5e12bf83 100644 --- a/packages/core/src/utils/time-travel.ts +++ b/packages/core/src/utils/time-travel.ts @@ -1,7 +1,7 @@ -import { BN, u8aToHex } from '@polkadot/util' -import { HexString } from '@polkadot/util/types' +import { type BN, u8aToHex } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' import { compactHex, getSlotDuration } from './index.js' import { setStorage } from './set-storage.js' diff --git a/packages/core/src/utils/well-known-keys.ts b/packages/core/src/utils/well-known-keys.ts index 762e4c4e..5af6bbcb 100644 --- a/packages/core/src/utils/well-known-keys.ts +++ b/packages/core/src/utils/well-known-keys.ts @@ -1,7 +1,7 @@ -import { HexString } from '@polkadot/util/types' -import { Registry } from '@polkadot/types-codec/types' -import { blake2AsHex } from '@polkadot/util-crypto' +import type { Registry } from '@polkadot/types-codec/types' import { hexToU8a, stringToHex } from '@polkadot/util' +import { blake2AsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' const decodeValue = (type: string) => (registry: Registry, value: HexString) => { return registry.createType(type, hexToU8a(value)).toJSON() @@ -54,7 +54,7 @@ const wellKnownKeys = [ prefixHex: '0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e', decodeKey: (registry: Registry, key: HexString) => { // get last 4 bytes - const last4Bytes = '0x' + key.slice(-8) + const last4Bytes = `0x${key.slice(-8)}` return [registry.createType('u32', hexToU8a(last4Bytes)).toJSON()] }, type: '(u32, u32)', diff --git a/packages/core/src/wasm-executor/browser-wasm-executor.js b/packages/core/src/wasm-executor/browser-wasm-executor.js index 8d974e99..6fbbaedf 100644 --- a/packages/core/src/wasm-executor/browser-wasm-executor.js +++ b/packages/core/src/wasm-executor/browser-wasm-executor.js @@ -1,5 +1,5 @@ -import * as Comlink from 'comlink' import * as pkg from '@acala-network/chopsticks-executor' +import * as Comlink from 'comlink' const getRuntimeVersion = async (code) => { return pkg.get_runtime_version(code) diff --git a/packages/core/src/wasm-executor/executor.test.ts b/packages/core/src/wasm-executor/executor.test.ts index 7385d79d..c3409140 100644 --- a/packages/core/src/wasm-executor/executor.test.ts +++ b/packages/core/src/wasm-executor/executor.test.ts @@ -1,10 +1,10 @@ -import * as Comlink from 'comlink' -import { HexString } from '@polkadot/util/types' -import { TypeRegistry } from '@polkadot/types' -import { describe, expect, it } from 'vitest' import { readFileSync } from 'node:fs' -import _ from 'lodash' import path from 'node:path' +import { TypeRegistry } from '@polkadot/types' +import type { HexString } from '@polkadot/util/types' +import * as Comlink from 'comlink' +import _ from 'lodash' +import { describe, expect, it } from 'vitest' import { WELL_KNOWN_KEYS, upgradeGoAheadSignal } from '../utils/proof.js' import { diff --git a/packages/core/src/wasm-executor/index.ts b/packages/core/src/wasm-executor/index.ts index e46034a1..895fed4d 100644 --- a/packages/core/src/wasm-executor/index.ts +++ b/packages/core/src/wasm-executor/index.ts @@ -1,15 +1,15 @@ -import * as Comlink from 'comlink' -import { HexString } from '@polkadot/util/types' import { hexToString, hexToU8a, u8aToBn } from '@polkadot/util' import { randomAsHex } from '@polkadot/util-crypto' +import type { HexString } from '@polkadot/util/types' +import * as Comlink from 'comlink' import _ from 'lodash' -import { Block } from '../blockchain/block.js' -import { PREFIX_LENGTH, stripChildPrefix } from '../utils/index.js' +import type { Block } from '../blockchain/block.js' import { defaultLogger, truncate } from '../logger.js' +import { PREFIX_LENGTH, stripChildPrefix } from '../utils/index.js' import type { JsCallback } from '@acala-network/chopsticks-executor' -export { JsCallback } +export type { JsCallback } export type RuntimeVersion = { specName: string @@ -141,10 +141,8 @@ export const runTask = async (task: TaskCall, callback: JsCallback = emptyTaskHa export const taskHandler = (block: Block): JsCallback => { return { - getStorage: async function (key: HexString) { - return block.get(key) - }, - getNextKey: async function (prefix: HexString, key: HexString) { + getStorage: async (key: HexString) => block.get(key), + getNextKey: async (prefix: HexString, key: HexString) => { const [nextKey] = await block.getKeysPaged({ prefix: prefix.length === 2 /** 0x */ ? key.slice(0, PREFIX_LENGTH) : prefix, pageSize: 1, @@ -152,17 +150,13 @@ export const taskHandler = (block: Block): JsCallback => { }) return nextKey && stripChildPrefix(nextKey as HexString) }, - offchainGetStorage: async function (key: HexString) { + offchainGetStorage: async (key: HexString) => { if (!block.chain.offchainWorker) throw new Error('offchain worker not found') return block.chain.offchainWorker.get(key) as string }, - offchainTimestamp: async function () { - return Date.now() - }, - offchainRandomSeed: async function () { - return randomAsHex(32) - }, - offchainSubmitTransaction: async function (tx: HexString) { + offchainTimestamp: async () => Date.now(), + offchainRandomSeed: async () => randomAsHex(32), + offchainSubmitTransaction: async (tx: HexString) => { if (!block.chain.offchainWorker) throw new Error('offchain worker not found') try { const hash = await block.chain.offchainWorker.pushExtrinsic(block, tx) @@ -177,22 +171,22 @@ export const taskHandler = (block: Block): JsCallback => { } export const emptyTaskHandler = { - getStorage: async function (_key: HexString) { + getStorage: async (_key: HexString) => { throw new Error('Method not implemented') }, - getNextKey: async function (_prefix: HexString, _key: HexString) { + getNextKey: async (_prefix: HexString, _key: HexString) => { throw new Error('Method not implemented') }, - offchainGetStorage: async function (_key: HexString) { + offchainGetStorage: async (_key: HexString) => { throw new Error('Method not implemented') }, - offchainTimestamp: async function () { + offchainTimestamp: async () => { throw new Error('Method not implemented') }, - offchainRandomSeed: async function () { + offchainRandomSeed: async () => { throw new Error('Method not implemented') }, - offchainSubmitTransaction: async function (_tx: HexString) { + offchainSubmitTransaction: async (_tx: HexString) => { throw new Error('Method not implemented') }, } diff --git a/packages/core/src/wasm-executor/node-wasm-executor.js b/packages/core/src/wasm-executor/node-wasm-executor.js index 354b6495..47e1b52f 100644 --- a/packages/core/src/wasm-executor/node-wasm-executor.js +++ b/packages/core/src/wasm-executor/node-wasm-executor.js @@ -1,5 +1,5 @@ -import * as Comlink from 'comlink' import * as pkg from '@acala-network/chopsticks-executor' +import * as Comlink from 'comlink' import { parentPort } from 'node:worker_threads' import nodeEndpoint from 'comlink/dist/umd/node-adapter.js' diff --git a/packages/core/src/wasm-executor/node-worker.ts b/packages/core/src/wasm-executor/node-worker.ts index 89dabc59..b425a1d0 100644 --- a/packages/core/src/wasm-executor/node-worker.ts +++ b/packages/core/src/wasm-executor/node-worker.ts @@ -1,6 +1,6 @@ +import threads from 'node:worker_threads' import { wrap } from 'comlink' import nodeEndpoint from 'comlink/dist/umd/node-adapter.js' -import threads from 'node:worker_threads' export const startWorker = async () => { const worker = new threads.Worker(new URL('node-wasm-executor.js', import.meta.url), { diff --git a/packages/core/src/xcm/downward.ts b/packages/core/src/xcm/downward.ts index 7191a726..8bcb8c6c 100644 --- a/packages/core/src/xcm/downward.ts +++ b/packages/core/src/xcm/downward.ts @@ -1,7 +1,7 @@ import { hexToU8a } from '@polkadot/util' -import { Blockchain } from '../blockchain/index.js' -import { DownwardMessage } from '../blockchain/txpool.js' +import type { Blockchain } from '../blockchain/index.js' +import type { DownwardMessage } from '../blockchain/txpool.js' import { compactHex, getParaId } from '../utils/index.js' import { setStorage } from '../utils/set-storage.js' import { xcmLogger } from './index.js' diff --git a/packages/core/src/xcm/horizontal.ts b/packages/core/src/xcm/horizontal.ts index 4fbcdf48..1fe1ea10 100644 --- a/packages/core/src/xcm/horizontal.ts +++ b/packages/core/src/xcm/horizontal.ts @@ -1,7 +1,7 @@ -import { HexString } from '@polkadot/util/types' import { hexToU8a } from '@polkadot/util' +import type { HexString } from '@polkadot/util/types' -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' import { compactHex } from '../utils/index.js' import { xcmLogger } from './index.js' diff --git a/packages/core/src/xcm/index.ts b/packages/core/src/xcm/index.ts index c57feec4..7cff2790 100644 --- a/packages/core/src/xcm/index.ts +++ b/packages/core/src/xcm/index.ts @@ -1,9 +1,9 @@ -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' +import { defaultLogger } from '../logger.js' +import { getParaId } from '../utils/index.js' import { connectDownward } from './downward.js' import { connectHorizontal } from './horizontal.js' import { connectUpward } from './upward.js' -import { defaultLogger } from '../logger.js' -import { getParaId } from '../utils/index.js' export const xcmLogger = defaultLogger.child({ name: 'xcm' }) diff --git a/packages/core/src/xcm/upward.ts b/packages/core/src/xcm/upward.ts index 668496ac..98adb84c 100644 --- a/packages/core/src/xcm/upward.ts +++ b/packages/core/src/xcm/upward.ts @@ -1,6 +1,6 @@ import { hexToU8a } from '@polkadot/util' -import { Blockchain } from '../blockchain/index.js' +import type { Blockchain } from '../blockchain/index.js' import { compactHex, getParaId } from '../utils/index.js' export const connectUpward = async (parachain: Blockchain, relaychain: Blockchain) => { diff --git a/packages/db/package.json b/packages/db/package.json index cd89ec08..8eaa9da8 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -24,7 +24,10 @@ "@swc/core": "^1.10.1", "typescript": "^5.7.2" }, - "files": ["dist/esm/**", "dist/cjs/**"], + "files": [ + "dist/esm/**", + "dist/cjs/**" + ], "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "exports": { diff --git a/packages/db/src/base-sql.ts b/packages/db/src/base-sql.ts index 16d97408..2b5266db 100644 --- a/packages/db/src/base-sql.ts +++ b/packages/db/src/base-sql.ts @@ -1,6 +1,6 @@ -import { BlockEntry, Database, KeyValueEntry } from '@acala-network/chopsticks-core' -import { DataSource } from 'typeorm' -import { HexString } from '@polkadot/util/types' +import type { BlockEntry, Database, KeyValueEntry } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' +import type { DataSource } from 'typeorm' import { BlockEntity, KeyValuePair } from './db/entities.js' diff --git a/packages/db/src/browser.ts b/packages/db/src/browser.ts index 9bfdc3de..ec9f9550 100644 --- a/packages/db/src/browser.ts +++ b/packages/db/src/browser.ts @@ -1,5 +1,5 @@ -import { BlockEntry, Database, KeyValueEntry } from '@acala-network/chopsticks-core' -import { DBSchema, IDBPDatabase, openDB } from 'idb' +import type { BlockEntry, Database, KeyValueEntry } from '@acala-network/chopsticks-core' +import { type DBSchema, type IDBPDatabase, openDB } from 'idb' interface Schema extends DBSchema { keyValue: { diff --git a/packages/db/src/db/entities.ts b/packages/db/src/db/entities.ts index dec79762..d9245554 100644 --- a/packages/db/src/db/entities.ts +++ b/packages/db/src/db/entities.ts @@ -1,4 +1,4 @@ -import { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core' +import type { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core' import { EntitySchema } from 'typeorm' export const KeyValuePair = new EntitySchema({ diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 6714c622..14cb008d 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -1,4 +1,4 @@ -import { DataSource } from 'typeorm' +import type { DataSource } from 'typeorm' import { BaseSqlDatabase } from './base-sql.js' import { openDb } from './db/index.js' diff --git a/packages/e2e/src/author-inherent-mock.test.ts b/packages/e2e/src/author-inherent-mock.test.ts index 9a03901f..4fe15a1b 100644 --- a/packages/e2e/src/author-inherent-mock.test.ts +++ b/packages/e2e/src/author-inherent-mock.test.ts @@ -1,5 +1,5 @@ -import { describe, it } from 'vitest' import { setupContext } from '@acala-network/chopsticks-testing' +import { describe, it } from 'vitest' describe.runIf(process.env.CI || process.env.RUN_ALL)('Nimbus author inherent mock', async () => { it('Manta build blocks', async () => { diff --git a/packages/e2e/src/author.test.ts b/packages/e2e/src/author.test.ts index 9d6f9d92..c4242fb4 100644 --- a/packages/e2e/src/author.test.ts +++ b/packages/e2e/src/author.test.ts @@ -1,4 +1,4 @@ -import { SubmittableResult } from '@polkadot/api' +import type { SubmittableResult } from '@polkadot/api' import { afterAll, describe, expect, it } from 'vitest' import { check, defer, mockCallback, testingPairs } from './helper.js' diff --git a/packages/e2e/src/batch-request.test.ts b/packages/e2e/src/batch-request.test.ts index bd0d8d96..48c05ec7 100644 --- a/packages/e2e/src/batch-request.test.ts +++ b/packages/e2e/src/batch-request.test.ts @@ -1,5 +1,5 @@ -import { WebSocket } from 'ws' import { afterAll, describe, expect, it } from 'vitest' +import { WebSocket } from 'ws' import networks from './networks.js' diff --git a/packages/e2e/src/build-parachain-block.test.ts b/packages/e2e/src/build-parachain-block.test.ts index 7fa13681..9609c028 100644 --- a/packages/e2e/src/build-parachain-block.test.ts +++ b/packages/e2e/src/build-parachain-block.test.ts @@ -1,8 +1,8 @@ import { describe, expect, it } from 'vitest' -import { TypeRegistry } from '@polkadot/types' import { decodeProof } from '@acala-network/chopsticks-core' import { upgradeRestrictionSignal } from '@acala-network/chopsticks-core/utils/proof.js' +import { TypeRegistry } from '@polkadot/types' import networks from './networks.js' describe('override-relay-state-proof', async () => { @@ -18,7 +18,7 @@ describe('override-relay-state-proof', async () => { await ws.send('dev_newBlock', [{ relayChainStateOverrides }]) const block = await api.rpc.chain.getBlock() const setValidationData = block.block.extrinsics - .find(({ method }) => method.method == 'setValidationData') + .find(({ method }) => method.method === 'setValidationData') ?.method.toJSON().args.data const relayParentStorageRoot = setValidationData.validationData.relayParentStorageRoot @@ -37,7 +37,7 @@ describe('override-relay-state-proof', async () => { await dev.newBlock({ relayParentNumber: 14355209 }) const block = await api.rpc.chain.getBlock() const setValidationData = block.block.extrinsics - .find(({ method }) => method.method == 'setValidationData') + .find(({ method }) => method.method === 'setValidationData') ?.method.toJSON().args.data expect(setValidationData.validationData.relayParentNumber).to.be.eq(14355209) diff --git a/packages/e2e/src/chainHead_v1.test.ts b/packages/e2e/src/chainHead_v1.test.ts index 2be4c895..22fc8015 100644 --- a/packages/e2e/src/chainHead_v1.test.ts +++ b/packages/e2e/src/chainHead_v1.test.ts @@ -1,9 +1,9 @@ -import { RuntimeContext } from '@polkadot-api/observable-client' +import type { RuntimeContext } from '@polkadot-api/observable-client' import { describe, expect, it } from 'vitest' -import { dev, env, observe, setupPolkadotApi, testingPairs } from './helper.js' -import { firstValueFrom } from 'rxjs' import { getPolkadotSigner } from 'polkadot-api/signer' +import { firstValueFrom } from 'rxjs' +import { dev, env, observe, setupPolkadotApi, testingPairs } from './helper.js' import { Binary } from 'polkadot-api' diff --git a/packages/e2e/src/chopsticks-provider.test.ts b/packages/e2e/src/chopsticks-provider.test.ts index a29447d4..67760194 100644 --- a/packages/e2e/src/chopsticks-provider.test.ts +++ b/packages/e2e/src/chopsticks-provider.test.ts @@ -1,5 +1,5 @@ -import { ApiPromise } from '@polkadot/api' import { BuildBlockMode, ChopsticksProvider, setStorage } from '@acala-network/chopsticks-core' +import { ApiPromise } from '@polkadot/api' import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { check, checkHex, env, testingPairs } from './helper.js' diff --git a/packages/e2e/src/crowdloan.redeem.test.ts b/packages/e2e/src/crowdloan.redeem.test.ts index 8771e83e..8b478e32 100644 --- a/packages/e2e/src/crowdloan.redeem.test.ts +++ b/packages/e2e/src/crowdloan.redeem.test.ts @@ -1,5 +1,5 @@ -import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { testingPairs } from '@acala-network/chopsticks-testing' +import { afterAll, beforeAll, describe, expect, it } from 'vitest' import networks from './networks.js' diff --git a/packages/e2e/src/decoder.test.ts b/packages/e2e/src/decoder.test.ts index 1bd7fa0a..38bd99c6 100644 --- a/packages/e2e/src/decoder.test.ts +++ b/packages/e2e/src/decoder.test.ts @@ -1,5 +1,5 @@ -import { afterAll, describe, expect, it } from 'vitest' import { decodeKey, decodeKeyValue, toStorageObject } from '@acala-network/chopsticks-core/utils/decoder.js' +import { afterAll, describe, expect, it } from 'vitest' import networks from './networks.js' diff --git a/packages/e2e/src/dev.test.ts b/packages/e2e/src/dev.test.ts index c6c17daa..32363654 100644 --- a/packages/e2e/src/dev.test.ts +++ b/packages/e2e/src/dev.test.ts @@ -1,5 +1,5 @@ -import { afterAll, describe, expect, it } from 'vitest' import { u8aToHex } from '@polkadot/util' +import { afterAll, describe, expect, it } from 'vitest' import { check, testingPairs } from './helper.js' import networks from './networks.js' diff --git a/packages/e2e/src/environment.test.ts b/packages/e2e/src/environment.test.ts index 8bfb0010..4ced6e0a 100644 --- a/packages/e2e/src/environment.test.ts +++ b/packages/e2e/src/environment.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest' import { environment, environmentSchema } from '@acala-network/chopsticks-core' +import { describe, expect, it } from 'vitest' describe('environment', () => { it('defaults are correct', async () => { diff --git a/packages/e2e/src/genesis-provider.test.ts b/packages/e2e/src/genesis-provider.test.ts index 6e3648e9..deb58f59 100644 --- a/packages/e2e/src/genesis-provider.test.ts +++ b/packages/e2e/src/genesis-provider.test.ts @@ -1,8 +1,8 @@ import { afterAll, describe, expect, it } from 'vitest' import { BuildBlockMode } from '@acala-network/chopsticks' -import { check, testingPairs } from './helper.js' import { setupContextWithConfig } from '@acala-network/chopsticks-testing' +import { check, testingPairs } from './helper.js' describe.each([ [ diff --git a/packages/e2e/src/helper.ts b/packages/e2e/src/helper.ts index 5436886b..7692a216 100644 --- a/packages/e2e/src/helper.ts +++ b/packages/e2e/src/helper.ts @@ -1,23 +1,23 @@ -import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api' -import { HexString } from '@polkadot/util/types' -import { Mock, beforeAll, beforeEach, expect, vi } from 'vitest' -import { Observable } from 'rxjs' -import { PolkadotClient, createClient } from 'polkadot-api' -import { ProviderInterface } from '@polkadot/rpc-provider/types' -import { RegisteredTypes } from '@polkadot/types/types' -import { SubstrateClient, createClient as createSubstrateClient } from '@polkadot-api/substrate-client' import { getObservableClient } from '@polkadot-api/observable-client' +import { type SubstrateClient, createClient as createSubstrateClient } from '@polkadot-api/substrate-client' import { getWsProvider } from '@polkadot-api/ws-provider/node' +import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api' +import type { ProviderInterface } from '@polkadot/rpc-provider/types' +import type { RegisteredTypes } from '@polkadot/types/types' +import type { HexString } from '@polkadot/util/types' +import { type PolkadotClient, createClient } from 'polkadot-api' +import type { Observable } from 'rxjs' +import { type Mock, beforeAll, beforeEach, expect, vi } from 'vitest' import { Api } from '@acala-network/chopsticks' -import { Blockchain, BuildBlockMode, StorageValues } from '@acala-network/chopsticks-core' -import { SqliteDatabase } from '@acala-network/chopsticks-db' -import { createServer } from '@acala-network/chopsticks/server.js' +import { Blockchain, BuildBlockMode, type StorageValues } from '@acala-network/chopsticks-core' +import { inherentProviders } from '@acala-network/chopsticks-core/blockchain/inherent/index.js' import { defer } from '@acala-network/chopsticks-core/utils/index.js' +import { SqliteDatabase } from '@acala-network/chopsticks-db' +import { withExpect } from '@acala-network/chopsticks-testing' import { genesisFromUrl } from '@acala-network/chopsticks/context.js' import { handler } from '@acala-network/chopsticks/rpc/index.js' -import { inherentProviders } from '@acala-network/chopsticks-core/blockchain/inherent/index.js' -import { withExpect } from '@acala-network/chopsticks-testing' +import { createServer } from '@acala-network/chopsticks/server.js' export { testingPairs, setupContext } from '@acala-network/chopsticks-testing' diff --git a/packages/e2e/src/hrmp.test.ts b/packages/e2e/src/hrmp.test.ts index ce6d7755..41e119bb 100644 --- a/packages/e2e/src/hrmp.test.ts +++ b/packages/e2e/src/hrmp.test.ts @@ -1,6 +1,6 @@ import { describe, it } from 'vitest' -import { HorizontalMessage } from '@acala-network/chopsticks-core/blockchain/txpool.js' +import type { HorizontalMessage } from '@acala-network/chopsticks-core/blockchain/txpool.js' import { checkSystemEvents, setupContext } from './helper.js' diff --git a/packages/e2e/src/http.test.ts b/packages/e2e/src/http.test.ts index 263d108e..0cf23946 100644 --- a/packages/e2e/src/http.test.ts +++ b/packages/e2e/src/http.test.ts @@ -1,5 +1,5 @@ +import { request } from 'node:http' import { describe, expect, it } from 'vitest' -import { request } from 'http' import { env, setupApi, ws } from './helper.js' diff --git a/packages/e2e/src/import-storage/index.test.ts b/packages/e2e/src/import-storage/index.test.ts index d5fe44d1..74efce47 100644 --- a/packages/e2e/src/import-storage/index.test.ts +++ b/packages/e2e/src/import-storage/index.test.ts @@ -1,9 +1,9 @@ -import { describe, expect, it } from 'vitest' import path from 'node:path' +import { describe, expect, it } from 'vitest' -import { api, chain, setupApi } from '../helper.js' import { compactHex } from '@acala-network/chopsticks' import { overrideStorage, overrideWasm } from '@acala-network/chopsticks/utils/override.js' +import { api, chain, setupApi } from '../helper.js' setupApi({ endpoint: 'wss://acala-rpc.aca-api.network', diff --git a/packages/e2e/src/metadata.test.ts b/packages/e2e/src/metadata.test.ts index db576b49..5a0affd6 100644 --- a/packages/e2e/src/metadata.test.ts +++ b/packages/e2e/src/metadata.test.ts @@ -1,5 +1,5 @@ -import { chain, setupApi } from './helper.js' import { describe, expect, it } from 'vitest' +import { chain, setupApi } from './helper.js' setupApi({ endpoint: 'wss://acala-rpc-1.aca-api.network', diff --git a/packages/e2e/src/migration.test.ts b/packages/e2e/src/migration.test.ts index 7cef979c..d9075377 100644 --- a/packages/e2e/src/migration.test.ts +++ b/packages/e2e/src/migration.test.ts @@ -1,5 +1,5 @@ -import { afterAll, describe, expect, it } from 'vitest' import { setupContext, testingPairs } from '@acala-network/chopsticks-testing' +import { afterAll, describe, expect, it } from 'vitest' describe('Migration', async () => { const { alice } = testingPairs() diff --git a/packages/e2e/src/mock-signature.test.ts b/packages/e2e/src/mock-signature.test.ts index 23a5f29a..802e9c32 100644 --- a/packages/e2e/src/mock-signature.test.ts +++ b/packages/e2e/src/mock-signature.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest' import { signFake, signFakeWithApi } from '@acala-network/chopsticks-testing' +import { describe, expect, it } from 'vitest' import { api, dev, env, setupApi, testingPairs } from './helper.js' diff --git a/packages/e2e/src/networks.ts b/packages/e2e/src/networks.ts index ad5ed005..ce9d63a6 100644 --- a/packages/e2e/src/networks.ts +++ b/packages/e2e/src/networks.ts @@ -1,6 +1,6 @@ import { config as dotenvConfig } from 'dotenv' -import { SetupOption, setupContext } from '@acala-network/chopsticks-testing' +import { type SetupOption, setupContext } from '@acala-network/chopsticks-testing' dotenvConfig() diff --git a/packages/e2e/src/resume.test.ts b/packages/e2e/src/resume.test.ts index 07bb49e5..069c8e6f 100644 --- a/packages/e2e/src/resume.test.ts +++ b/packages/e2e/src/resume.test.ts @@ -1,9 +1,9 @@ -import { resolve } from 'node:path' import { tmpdir } from 'node:os' +import { resolve } from 'node:path' -import { assert, describe, expect, it } from 'vitest' -import { connectUpward } from '@acala-network/chopsticks-core/xcm/upward.js' import { setStorage } from '@acala-network/chopsticks' +import { connectUpward } from '@acala-network/chopsticks-core/xcm/upward.js' +import { assert, describe, expect, it } from 'vitest' import { check, checkSystemEvents, testingPairs } from './helper.js' import networks from './networks.js' diff --git a/packages/e2e/src/rpc-extention-methods.test.ts b/packages/e2e/src/rpc-extention-methods.test.ts index a7888135..a6039cb0 100644 --- a/packages/e2e/src/rpc-extention-methods.test.ts +++ b/packages/e2e/src/rpc-extention-methods.test.ts @@ -1,7 +1,7 @@ +import { join, resolve } from 'node:path' +import { getRpcExtensionMethods, loadRpcMethodsByScripts } from '@acala-network/chopsticks/plugins/index.js' import { describe, expect, it } from 'vitest' import { env, setupApi, ws } from './helper.js' -import { getRpcExtensionMethods, loadRpcMethodsByScripts } from '@acala-network/chopsticks/plugins/index.js' -import { join, resolve } from 'path' setupApi(env.acala) diff --git a/packages/e2e/src/rpc-methods-test-scripts.js b/packages/e2e/src/rpc-methods-test-scripts.js index 0c15d4a1..cad8a68c 100644 --- a/packages/e2e/src/rpc-methods-test-scripts.js +++ b/packages/e2e/src/rpc-methods-test-scripts.js @@ -1,5 +1,3 @@ -/* eslint-disable */ -// used to test rpc methods, no need to lint return { async testdev_testRpcMethod1(context, params) { console.log('testdev_testRpcMethod 1', params) diff --git a/packages/e2e/src/rpc-spec.test.ts b/packages/e2e/src/rpc-spec.test.ts index bbef78bb..c8af9cd4 100644 --- a/packages/e2e/src/rpc-spec.test.ts +++ b/packages/e2e/src/rpc-spec.test.ts @@ -1,8 +1,8 @@ +import type { RuntimeContext } from '@polkadot-api/observable-client' import { ApiPromise } from '@polkadot/api' -import { RuntimeContext } from '@polkadot-api/observable-client' +import { firstValueFrom } from 'rxjs' import { describe, expect, it } from 'vitest' import { dev, env, observe, setupPolkadotApi, testingPairs } from './helper.js' -import { firstValueFrom } from 'rxjs' const testApi = await setupPolkadotApi(env.acalaV15) diff --git a/packages/e2e/src/state.test.ts b/packages/e2e/src/state.test.ts index 2b9e315b..831350c1 100644 --- a/packages/e2e/src/state.test.ts +++ b/packages/e2e/src/state.test.ts @@ -1,8 +1,8 @@ -import { HexString } from '@polkadot/util/types' -import { describe, expect, it } from 'vitest' import { readFileSync } from 'node:fs' -import { runTask, taskHandler } from '@acala-network/chopsticks-core' import path from 'node:path' +import { runTask, taskHandler } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' +import { describe, expect, it } from 'vitest' import { api, chain, check, checkHex, env, mockCallback, setupApi, testingPairs } from './helper.js' import networks from './networks.js' diff --git a/packages/e2e/src/time-travel.test.ts b/packages/e2e/src/time-travel.test.ts index 7bd0d2e9..2f2352ce 100644 --- a/packages/e2e/src/time-travel.test.ts +++ b/packages/e2e/src/time-travel.test.ts @@ -1,6 +1,6 @@ -import { describe, expect, it } from 'vitest' import { getCurrentTimestamp, getSlotDuration } from '@acala-network/chopsticks-core/utils/index.js' import { timeTravel } from '@acala-network/chopsticks-core/utils/time-travel.js' +import { describe, expect, it } from 'vitest' import networks from './networks.js' diff --git a/packages/e2e/src/upgrade.test.ts b/packages/e2e/src/upgrade.test.ts index 6b8ce646..55801cad 100644 --- a/packages/e2e/src/upgrade.test.ts +++ b/packages/e2e/src/upgrade.test.ts @@ -1,6 +1,6 @@ -import { afterAll, describe, expect, it } from 'vitest' import { readFileSync } from 'node:fs' import path from 'node:path' +import { afterAll, describe, expect, it } from 'vitest' import { check, testingPairs } from './helper.js' diff --git a/packages/e2e/src/xcm.test.ts b/packages/e2e/src/xcm.test.ts index 79b523fd..62ed9474 100644 --- a/packages/e2e/src/xcm.test.ts +++ b/packages/e2e/src/xcm.test.ts @@ -1,12 +1,12 @@ import { beforeEach, describe, it } from 'vitest' -import { DownwardMessage } from '@acala-network/chopsticks-core/blockchain/txpool.js' +import { setStorage } from '@acala-network/chopsticks-core' +import type { DownwardMessage } from '@acala-network/chopsticks-core/blockchain/txpool.js' import { connectDownward } from '@acala-network/chopsticks-core/xcm/downward.js' import { connectUpward } from '@acala-network/chopsticks-core/xcm/upward.js' -import { setStorage } from '@acala-network/chopsticks-core' import { check, checkSystemEvents, testingPairs } from './helper.js' -import networks, { Network } from './networks.js' +import networks, { type Network } from './networks.js' const downwardMessages: DownwardMessage[] = [ { diff --git a/packages/node-test/index.mjs b/packages/node-test/index.mjs index 8a9eb3ed..25463973 100644 --- a/packages/node-test/index.mjs +++ b/packages/node-test/index.mjs @@ -1,4 +1,4 @@ -import { setupWithServer, destroyWorker } from '@acala-network/chopsticks' +import { destroyWorker, setupWithServer } from '@acala-network/chopsticks' const server = await setupWithServer({ endpoint: ['wss://polkadot-rpc.dwellir.com', 'wss://rpc.ibp.network/polkadot', 'wss://rpc.polkadot.io'], diff --git a/packages/testing/package.json b/packages/testing/package.json index e853e499..dc5b1687 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -22,7 +22,10 @@ "@swc/core": "^1.10.1", "typescript": "^5.7.2" }, - "files": ["dist/esm/**", "dist/cjs/**"], + "files": [ + "dist/esm/**", + "dist/cjs/**" + ], "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "exports": { diff --git a/packages/testing/src/check.ts b/packages/testing/src/check.ts index 577f5406..e216823e 100644 --- a/packages/testing/src/check.ts +++ b/packages/testing/src/check.ts @@ -1,5 +1,5 @@ -import { ApiPromise } from '@polkadot/api' -import { Codec } from '@polkadot/types/types' +import type { ApiPromise } from '@polkadot/api' +import type { Codec } from '@polkadot/types/types' type CodecOrArray = Codec | Codec[] @@ -128,7 +128,8 @@ export class Checker { return filters.some((filter) => { if (typeof filter === 'string') { return evt.section === filter - } else if ('method' in filter) { + } + if ('method' in filter) { const { section, method } = filter return evt.section === section && evt.method === method } @@ -169,7 +170,7 @@ export class Checker { const processNumber = (value: number) => { if (precision > 0) { - const rounded = parseFloat(value.toPrecision(precision)) + const rounded = Number.parseFloat(value.toPrecision(precision)) if (rounded === value) { return rounded } @@ -191,7 +192,7 @@ export class Checker { if (typeof obj === 'string') { if (redactNumber && obj.match(/0x000000[0-9a-f]{26}/)) { // this is very likely u128 encoded in hex - const num = parseInt(obj) + const num = Number.parseInt(obj) return processNumber(num) } if (redactHash && obj.match(/0x[0-9a-f]{64}/)) { @@ -204,7 +205,7 @@ export class Checker { return '(address)' } if (redactNumber && obj.match(/^-?[\d,]+$/)) { - const num = parseInt(obj.replace(/,/g, '')) + const num = Number.parseInt(obj.replace(/,/g, '')) return processNumber(num) } return obj diff --git a/packages/utils/package.json b/packages/utils/package.json index 6416b955..8343ebb5 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -26,7 +26,10 @@ "@swc/core": "^1.10.1", "typescript": "^5.7.2" }, - "files": ["dist/esm/**", "dist/cjs/**"], + "files": [ + "dist/esm/**", + "dist/cjs/**" + ], "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "exports": { diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index e74356db..67414104 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,7 +1,6 @@ -import { ApiPromise, WsProvider } from '@polkadot/api' import { BuildBlockMode, - StorageValues, + type StorageValues, connectParachains, connectVertical, defaultLogger, @@ -9,12 +8,13 @@ import { fetchConfig, setupWithServer, } from '@acala-network/chopsticks' -import { Codec } from '@polkadot/types/types' -import { Config } from '@acala-network/chopsticks/schema/index.js' -import { HexString } from '@polkadot/util/types' +import type { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js' +import type { Config } from '@acala-network/chopsticks/schema/index.js' +import { ApiPromise, WsProvider } from '@polkadot/api' +import type { SubmittableExtrinsic } from '@polkadot/api-base/types' import { Keyring, createTestKeyring } from '@polkadot/keyring' -import { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js' -import { SubmittableExtrinsic } from '@polkadot/api-base/types' +import type { Codec } from '@polkadot/types/types' +import type { HexString } from '@polkadot/util/types' const logger = defaultLogger.child({ name: 'utils' }) diff --git a/packages/utils/src/signFake.ts b/packages/utils/src/signFake.ts index 3c6b5f61..de799998 100644 --- a/packages/utils/src/signFake.ts +++ b/packages/utils/src/signFake.ts @@ -1,6 +1,6 @@ -import { ApiPromise } from '@polkadot/api' -import { GenericExtrinsic } from '@polkadot/types' -import { SignatureOptions } from '@polkadot/types/types' +import type { ApiPromise } from '@polkadot/api' +import type { GenericExtrinsic } from '@polkadot/types' +import type { SignatureOptions } from '@polkadot/types/types' export type SignFakeOptions = Partial diff --git a/packages/web-test/src/App.tsx b/packages/web-test/src/App.tsx index 8a7dbf5d..f10d47bd 100644 --- a/packages/web-test/src/App.tsx +++ b/packages/web-test/src/App.tsx @@ -1,4 +1,7 @@ import '@polkadot/api-augment' +import { ChopsticksProvider, setStorage, setup } from '@acala-network/chopsticks-core' +import type { SetupOptions } from '@acala-network/chopsticks-core' +import { IdbDatabase } from '@acala-network/chopsticks-db/browser.js' import { Alert, Box, @@ -11,14 +14,11 @@ import { TextField, Typography, } from '@mui/material' +import { styled } from '@mui/system' import { ApiPromise } from '@polkadot/api' -import { ChopsticksProvider, setStorage, setup } from '@acala-network/chopsticks-core' -import { HexString } from '@polkadot/util/types' -import { IdbDatabase } from '@acala-network/chopsticks-db/browser.js' import { createTestPairs } from '@polkadot/keyring' -import { styled } from '@mui/system' -import { useEffect, useState } from 'react' -import type { SetupOptions } from '@acala-network/chopsticks-core' +import type { HexString } from '@polkadot/util/types' +import { useCallback, useEffect, useState } from 'react' const { alice, bob } = createTestPairs() @@ -93,14 +93,14 @@ function App() { const [bobBalance, setBobBalance] = useState('') const [transferDisabled, setTransferDisabled] = useState(false) - const resetState = () => { + const resetState = useCallback(() => { setBlocks([]) setDryRunLoading(false) setExtrinsic('0x0a000088dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee0f0090c04bb6db2b') setDryRunResult('') - } + }, []) - const setupChain = async () => { + const setupChain = useCallback(async () => { setChainLoading(true) const chain = await setup({ endpoint: config.endpoint, @@ -135,7 +135,7 @@ function App() { setChainLoading(false) setBlocks([{ number: chain.head.number, hash: chain.head.hash }]) - } + }, [config]) useEffect(() => { resetState() @@ -144,7 +144,7 @@ function App() { return () => { globalThis.chain?.close() } - }, []) + }, [resetState, setupChain]) const handleBuildBlock = async () => { // build a block diff --git a/packages/web-test/src/index.tsx b/packages/web-test/src/index.tsx index b1d8078c..49fecf6d 100644 --- a/packages/web-test/src/index.tsx +++ b/packages/web-test/src/index.tsx @@ -1,5 +1,5 @@ -import { createRoot } from 'react-dom/client' import React from 'react' +import { createRoot } from 'react-dom/client' import './index.css' import App from './App.js' diff --git a/packages/web-test/src/vite-env.d.ts b/packages/web-test/src/vite-env.d.ts index 51ef182b..60a8fae0 100644 --- a/packages/web-test/src/vite-env.d.ts +++ b/packages/web-test/src/vite-env.d.ts @@ -1,7 +1,7 @@ /// -import { ApiPromise } from '@polkadot/api' -import { Blockchain } from '@acala-network/chopsticks-core' +import type { Blockchain } from '@acala-network/chopsticks-core' +import type { ApiPromise } from '@polkadot/api' declare global { // eslint-disable-next-line no-var diff --git a/packages/web-test/tests/index.spec.ts b/packages/web-test/tests/index.spec.ts index 7bf671e9..a5a0fde4 100644 --- a/packages/web-test/tests/index.spec.ts +++ b/packages/web-test/tests/index.spec.ts @@ -1,5 +1,5 @@ -import { HexString } from '@polkadot/util/types' import { expect, test } from '@playwright/test' +import type { HexString } from '@polkadot/util/types' test.describe('index', () => { test.beforeEach(async ({ page }) => { diff --git a/packages/web-test/vite.config.mjs b/packages/web-test/vite.config.mjs index f8a090a8..c3fcdd0f 100644 --- a/packages/web-test/vite.config.mjs +++ b/packages/web-test/vite.config.mjs @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' import tsconfigPaths from 'vite-tsconfig-paths' export default defineConfig({ diff --git a/vitest.config.mts b/vitest.config.mts index c2b11608..76e29abf 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -1,6 +1,6 @@ -import { defineConfig } from 'vitest/config' import swc from 'unplugin-swc' import tsconfigPaths from 'vite-tsconfig-paths' +import { defineConfig } from 'vitest/config' export default defineConfig({ test: {