Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = true
[*]
indent_style=tab
indent_size=tab
indent_size=2
tab_width=4
end_of_line=lf
charset=utf-8
Expand Down
84 changes: 84 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": {
"ignoreUnknown": false,
"ignore": [
"*.txt",
"*.snap",
"*.wasm",
"*.html",
"*.md",
"*.gitignore",
"*.yml",
"*.tsbuildinfo",
"**/executor/**",
"**/vendor/**",
"**/dist/**",
"**/node_modules/**"
]
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [
"**/tsconfig.tsbuildinfo",
"**/.gitignore",
"**/.yarn",
"**/*.yml",
"**/*.md",
"**/executor/**",
"**/vendor/**",
"**/.pnp.cjs",
"**/.pnp.loader.mjs",
"**/lib/**",
"**/dist/**",
"**/node_modules/**",
"**/preview/",
"**/packages/core/scripts/",
"packages/core/src/wasm-executor/browser-wasm-executor.js",
"packages/core/src/wasm-executor/node-wasm-executor.js",
"packages/e2e/src/rpc-methods-test-scripts.js",
"packages/e2e/blobs/**",
"packages/web-test/playwright-report/**"
]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": { "recommended": true },
"ignore": [
"**/.eslintrc.js",
"**/node_modules/",
"**/executor/",
"**/vendor/",
"**/lib/",
"**/dist/",
"packages/core/scripts/",
"**/chopsticks.js",
"packages/core/src/wasm-executor/browser-wasm-executor.js",
"packages/core/src/wasm-executor/node-wasm-executor.js",
"packages/web-test/playwright-report"
]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
}
}
}
4 changes: 2 additions & 2 deletions loader.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +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 && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"lint": "tsc --noEmit --project tsconfig.lint.json && biome check .",
"fix": "biome check --write .",
"prepare": "husky install",
"clean": "yarn workspaces foreach --all -pvit run clean",
"build": "yarn workspaces foreach --all -pvit --include '@acala-network/*' run build",
Expand All @@ -34,30 +31,20 @@
"engines": {
"node": ">=v20"
},
"prettier": {
"tabWidth": 2,
"semi": false,
"singleQuote": true
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
"*.{js,ts,css,md}": "prettier --write"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@swc/core": "^1.10.1",
"@types/node": "^22.10.2",
"@types/prettier": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"husky": "^9.1.7",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typedoc": "^0.27.5",
"typedoc-plugin-markdown": "^4.3.3",
Expand Down
6 changes: 1 addition & 5 deletions packages/chopsticks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@
"@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": {
Expand Down
13 changes: 6 additions & 7 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
}
}

Expand Down
20 changes: 14 additions & 6 deletions packages/chopsticks/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
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' })

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)))
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ? ['-', '\\', '|', '/'] : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
Expand Down
6 changes: 3 additions & 3 deletions packages/chopsticks/src/plugins/decode-key/cli.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/chopsticks/src/plugins/dry-run/cli.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
})
Expand Down
22 changes: 11 additions & 11 deletions packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -15,25 +15,25 @@ 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())
}

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']) {
Expand Down
24 changes: 12 additions & 12 deletions packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/chopsticks/src/plugins/dry-run/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
})
Expand Down
Loading